Re: Observer pattern on this design, yes or no/how and why?

2008-11-19 Thread mives29

3.B of my previous post takes tabpanel out as an option.

On Nov 20, 5:05 am, sre [EMAIL PROTECTED] wrote:
 Not sure if this will help. Another approach you may what to consider
 raising is using tabs, TabPanel and TabBar from 
 here:http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/g...

 You would get your single entry point and the designer would get their
 window.

 -sre

 On Nov 19, 11:38 am, mives29 [EMAIL PROTECTED] wrote:

  To gregor,

  1)We dont want to use dialogbox because it overlays the display.
  2)Actually I've thought about using hidden panels, but our team's
  designer seems fixated with using a separate window. If I could only
  convince him..
  3)We dont want to use the back/forward way because a)its not
  comfortable for the user b)we want both of the windows visible at the
  same time when the user clicks on the 2nd page's(entrypoint) link.

  Hopefully in our next meeting I could address theses issues to him(our
  designer), and convince him to use alternatives (like a hidden panel)

  On Nov 18, 8:06 pm, gregor [EMAIL PROTECTED] wrote:

   The issue is not having a separate page or a pop up dialog box - it's
   having an actual separate browser window or browser tab within the
   same application that causes the trouble. There are a number of ways
   to achieve the same objective that are more web style, e.g.

   1) Use a DialogBox. There are a number of implementations of this
   around that look like windows (but they are popups basically).
   2) Use a hidden panel that becomes visible when some button/hyperlink
   is clicked. For example seehttp://www.bbc.co.uk/customizeyour
   homepage button.
   3) Use GWT history support, i.e. throw a new page, add a back link
   from it back to the main application page, but also enable the user
   to use the browser back/forward buttons to switch between the two. I
   think most people expect web applications to behave like that.

   regards
   gregor

   On Nov 18, 10:28 am, francescoNemesi [EMAIL PROTECTED] wrote:

You use GWTxhttp://code.google.com/p/gwtxtouse
PropertyChangeSupport events. If used cleverly this allows event
handling among various modules, i.e. a module could send a
PropertyChangeEvent of a given named property and another module could
listen for it and execute accordingly. Just an idea...

On Nov 18, 3:24 am, gregor [EMAIL PROTECTED] wrote:

 That's a Windows way of looking at things. Check the link I gave,
 and there are others both on this group and around the net, that
 explain better than I can why you should maybe reconsider that idea.

 On Nov 18, 1:51 am, mives29 [EMAIL PROTECTED] wrote:

  Well, the reason for the two entrypoints is that me and my 
  colleagues
  are looking for a way to implement a sort of pop-up dialog box, 
  but,
  something that resides on a separate window, so it wouldn't overlay
  with the main page.  (so the user can alt+tab between the two
  windows).

  If there's another way to do this other than creating another
  entrypoint, please let me know. Thanks.

  On Nov 17, 7:54 pm, gregor [EMAIL PROTECTED] wrote:

   Clearly if a module is using a class declared in another module it
   must explicitly inherit the other module in it's module.get.xml 
   file
   otherwise the GWT compiler  won't have access to the class's 
   source
   which it needs. Frankly I'm not sure how this would work in the
   situation as you describe since I have always followed the 
   canonical
   GWT approach which is using a single HTML page and EntryPoint for 
   each
   separate application. I'm not sure what your motivation is in 
   having
   two EntryPoints. I think this results in two separate javascript 
   .js
   files loaded into your HTML page, therefore there will be a wall
   between them that accounts for your difficulties. I think it is
   possible to communicate between separate javascript files using 
   JSNI
   but that would make your life much more difficult.

   On the other hand there is no reason not to have your
   com.try.popup.client.PopUp.java in a separate module (i.e. having 
   it's
   own module.gwt.xml file) and have this inherited by the
   com.try.client.Page1.java module. That way it would be compiled as
   part of your main application (making your problem go away) but 
   still
   be usable in other applications as well. As I say, what is your
   motivation for having two EnrtyPoints?

   regards
   gregor

   On Nov 17, 9:42 am, mives29 [EMAIL PROTECTED] wrote:

The problem is im using two entrypoints, running on two 
windows, where
the 2nd composite is shown thru Window.open(). I need the first
entrypoint's composite to listen to the second entrypoint's 
composite,
but I cant do that since the second

Re: Observer pattern on this design, yes or no/how and why?

2008-11-18 Thread mives29

To gregor,

1)We dont want to use dialogbox because it overlays the display.
2)Actually I've thought about using hidden panels, but our team's
designer seems fixated with using a separate window. If I could only
convince him..
3)We dont want to use the back/forward way because a)its not
comfortable for the user b)we want both of the windows visible at the
same time when the user clicks on the 2nd page's(entrypoint) link.

Hopefully in our next meeting I could address theses issues to him(our
designer), and convince him to use alternatives (like a hidden panel)

On Nov 18, 8:06 pm, gregor [EMAIL PROTECTED] wrote:
 The issue is not having a separate page or a pop up dialog box - it's
 having an actual separate browser window or browser tab within the
 same application that causes the trouble. There are a number of ways
 to achieve the same objective that are more web style, e.g.

 1) Use a DialogBox. There are a number of implementations of this
 around that look like windows (but they are popups basically).
 2) Use a hidden panel that becomes visible when some button/hyperlink
 is clicked. For example seehttp://www.bbc.co.uk/customize your
 homepage button.
 3) Use GWT history support, i.e. throw a new page, add a back link
 from it back to the main application page, but also enable the user
 to use the browser back/forward buttons to switch between the two. I
 think most people expect web applications to behave like that.

 regards
 gregor

 On Nov 18, 10:28 am, francescoNemesi [EMAIL PROTECTED] wrote:

  You use GWTxhttp://code.google.com/p/gwtxtouse
  PropertyChangeSupport events. If used cleverly this allows event
  handling among various modules, i.e. a module could send a
  PropertyChangeEvent of a given named property and another module could
  listen for it and execute accordingly. Just an idea...

  On Nov 18, 3:24 am, gregor [EMAIL PROTECTED] wrote:

   That's a Windows way of looking at things. Check the link I gave,
   and there are others both on this group and around the net, that
   explain better than I can why you should maybe reconsider that idea.

   On Nov 18, 1:51 am, mives29 [EMAIL PROTECTED] wrote:

Well, the reason for the two entrypoints is that me and my colleagues
are looking for a way to implement a sort of pop-up dialog box, but,
something that resides on a separate window, so it wouldn't overlay
with the main page.  (so the user can alt+tab between the two
windows).

If there's another way to do this other than creating another
entrypoint, please let me know. Thanks.

On Nov 17, 7:54 pm, gregor [EMAIL PROTECTED] wrote:

 Clearly if a module is using a class declared in another module it
 must explicitly inherit the other module in it's module.get.xml file
 otherwise the GWT compiler  won't have access to the class's source
 which it needs. Frankly I'm not sure how this would work in the
 situation as you describe since I have always followed the canonical
 GWT approach which is using a single HTML page and EntryPoint for each
 separate application. I'm not sure what your motivation is in having
 two EntryPoints. I think this results in two separate javascript .js
 files loaded into your HTML page, therefore there will be a wall
 between them that accounts for your difficulties. I think it is
 possible to communicate between separate javascript files using JSNI
 but that would make your life much more difficult.

 On the other hand there is no reason not to have your
 com.try.popup.client.PopUp.java in a separate module (i.e. having it's
 own module.gwt.xml file) and have this inherited by the
 com.try.client.Page1.java module. That way it would be compiled as
 part of your main application (making your problem go away) but still
 be usable in other applications as well. As I say, what is your
 motivation for having two EnrtyPoints?

 regards
 gregor

 On Nov 17, 9:42 am, mives29 [EMAIL PROTECTED] wrote:

  The problem is im using two entrypoints, running on two windows, 
  where
  the 2nd composite is shown thru Window.open(). I need the first
  entrypoint's composite to listen to the second entrypoint's 
  composite,
  but I cant do that since the second entrypoint's composite is
  instantiated on the second composite, not the first one, so I cant 
  add
  the first entrypoint's composite as a listener of the second
  entrypoint's composite.

  Anyone knows a work around/alternative method of implementing 
  observer
  pattern on my problem?

  On Nov 17, 4:00 pm, mives29 [EMAIL PROTECTED] wrote:

   I tested it on same module, this implementation of the observer
   pattern works. however, when using this on two modules it 
   doesn't. Do
   I need to do deferred binding here? I hope not coz I dont know 
   how to.
   =)

   On Nov 17, 1:29 pm, mives29 [EMAIL PROTECTED

Re: Observer pattern on this design, yes or no/how and why?

2008-11-17 Thread mives29

I tested it on same module, this implementation of the observer
pattern works. however, when using this on two modules it doesn't. Do
I need to do deferred binding here? I hope not coz I dont know how to.
=)

On Nov 17, 1:29 pm, mives29 [EMAIL PROTECTED] wrote:
 oops CnP mistake. on this line:
 buttons.addChangeListener(this);  //where this pertains to
 Page1Compo1

 i meant
 xx.addChangeListener(this);    //where this pertains to Page1Compo1

 On Nov 17, 1:22 pm, mives29 [EMAIL PROTECTED] wrote:

  Hi. I tried your recommendations but there are some errors that I
  encounter that I think is related to my project's structure
  compatibility with your code. As I said above, my project has two
  entrypoints. First entrypoint(com.try.client.Page1.java) contains a
  vertical panel that contains three composites. Second entrypoint
  (com.try.popup.client.PopUp.java) contains a vertical panel than
  contains two composites. (Note: they(entrypoints) are from different
  modules, same app.)

  Now I need Page1.java's panel's contained composites to become
  listeners of PopUp.java's horizontal panel's contained composites. For
  example, I click something on PopUp.java, Page1.java would show a
  reaction thru its composites that are listeners of PopUp.java's
  composite # 2. However, as I followed your instruction, I got this
  errror:

  First, my CODE:
  //On Page1.java's first composite: Page1Compo1.java, I included the
  following
  //declaration of composite # 2
   xx;

  //somewhere on the code
  buttons.addChangeListener(this);    //where this pertains to
  Page1Compo1

  THE ERROR:
  No source code is available for type com.xxxzzz.client..java; did
  you forget to inherit a required module?

  note: .java above is composite # 2 of PopUp.java vertical panel.

  It seems I cannot use .java on Page1Compo1.java.. What am I
  missing?

  On Nov 14, 8:50 pm, gregor [EMAIL PROTECTED] wrote:

   Oh, as to why, well as you see ConfigPanel has no real knowledge of
   the other panels that are listening to it and does need to call any
   methods on them. As a result any number of panels can be registered as
   a listener with it, and subsequently swapped out for new ones if
   required, without affecting ConfigPanel's code at all. It is up to the
   listeners to decide for themselves, individually, what they need to do
   when they receive a change event. So there is a very weak association
   between ConfigPanel and it's listeners and none at all between the
   listeners == low coupling == application components easy to change and
   maintain.

   On Nov 14, 12:40 pm, gregor [EMAIL PROTECTED] wrote:

GWT has a range of Observer/Observable gadgets off the shelf:
SourcesEvents   Listener and xxxListenerCollection utility
classes. If they don't work quite right for you, it's easy to copy the
principle and design your own event handling interfaces.

You could have your config Composite implement SourcesChangeEvents,
for example. Then Comps 1  2 can implement ChangeListener and are
registered with the config Comp. It might work like so:

public class ConfigPanel extends Composite implements
SourcesChangeEvents {

  private ChangeListenerCollection listeners = new
ChangeListenerCollection();
  private Button saveBtn = new Button(Save,new ClickListener() {
            public void onClick(Widget widget) {
                  // you want to send the ConfigPanel itself, not the
Button!
                  // if you just used this it would send the button
                  listeners.fireChange(ConfigPanel.this).;
                }
            });

}

public class Comp1 extends Composite implements changeListener {

     public void onChange(Widget sender) {
         is (sender instanceof ConfigPanel) {
             ConfigPanel configPanel = (ConfigPanel) sender;
             // call whatever methods you need
         }

}

Don't forget you have to register Comp1 as a lister with ConfigPanel
somewhere or it won't work, e.g.:

    confPanel.addChangeListener(comp1);

And that's about it - goodbye to your static method calls.

regards
gregor

On Nov 14, 8:45 am, mives29 [EMAIL PROTECTED] wrote:

 i meant static methods, not static classes (2nd paragraph 2nd line)

 On Nov 14, 4:43 pm, mives29 [EMAIL PROTECTED] wrote:

  I'd go straight to what I want to do.

  I have 3 composites in 1 panel, in 1 entrypoint. I have another
  entrypoint that pops up when you click a link on the 2nd composite 
  on
  the 1st entrypoint. on that second entrypoint you can configure 
  stuff,
  that will affect the displayed data on the first entrypoint's
  composites. now, im thinking (actually, a friend thought of it, not
  me) that the observer pattern is great to use in here, as the 3
  composites of the 1st entrypoint will listen to whatever

Re: Observer pattern on this design, yes or no/how and why?

2008-11-17 Thread mives29

The problem is im using two entrypoints, running on two windows, where
the 2nd composite is shown thru Window.open(). I need the first
entrypoint's composite to listen to the second entrypoint's composite,
but I cant do that since the second entrypoint's composite is
instantiated on the second composite, not the first one, so I cant add
the first entrypoint's composite as a listener of the second
entrypoint's composite.

Anyone knows a work around/alternative method of implementing observer
pattern on my problem?

On Nov 17, 4:00 pm, mives29 [EMAIL PROTECTED] wrote:
 I tested it on same module, this implementation of the observer
 pattern works. however, when using this on two modules it doesn't. Do
 I need to do deferred binding here? I hope not coz I dont know how to.
 =)

 On Nov 17, 1:29 pm, mives29 [EMAIL PROTECTED] wrote:

  oops CnP mistake. on this line:
  buttons.addChangeListener(this);  //where this pertains to
  Page1Compo1

  i meant
  xx.addChangeListener(this);    //where this pertains to Page1Compo1

  On Nov 17, 1:22 pm, mives29 [EMAIL PROTECTED] wrote:

   Hi. I tried your recommendations but there are some errors that I
   encounter that I think is related to my project's structure
   compatibility with your code. As I said above, my project has two
   entrypoints. First entrypoint(com.try.client.Page1.java) contains a
   vertical panel that contains three composites. Second entrypoint
   (com.try.popup.client.PopUp.java) contains a vertical panel than
   contains two composites. (Note: they(entrypoints) are from different
   modules, same app.)

   Now I need Page1.java's panel's contained composites to become
   listeners of PopUp.java's horizontal panel's contained composites. For
   example, I click something on PopUp.java, Page1.java would show a
   reaction thru its composites that are listeners of PopUp.java's
   composite # 2. However, as I followed your instruction, I got this
   errror:

   First, my CODE:
   //On Page1.java's first composite: Page1Compo1.java, I included the
   following
   //declaration of composite # 2
    xx;

   //somewhere on the code
   buttons.addChangeListener(this);    //where this pertains to
   Page1Compo1

   THE ERROR:
   No source code is available for type com.xxxzzz.client..java; did
   you forget to inherit a required module?

   note: .java above is composite # 2 of PopUp.java vertical panel.

   It seems I cannot use .java on Page1Compo1.java.. What am I
   missing?

   On Nov 14, 8:50 pm, gregor [EMAIL PROTECTED] wrote:

Oh, as to why, well as you see ConfigPanel has no real knowledge of
the other panels that are listening to it and does need to call any
methods on them. As a result any number of panels can be registered as
a listener with it, and subsequently swapped out for new ones if
required, without affecting ConfigPanel's code at all. It is up to the
listeners to decide for themselves, individually, what they need to do
when they receive a change event. So there is a very weak association
between ConfigPanel and it's listeners and none at all between the
listeners == low coupling == application components easy to change and
maintain.

On Nov 14, 12:40 pm, gregor [EMAIL PROTECTED] wrote:

 GWT has a range of Observer/Observable gadgets off the shelf:
 SourcesEvents   Listener and xxxListenerCollection utility
 classes. If they don't work quite right for you, it's easy to copy the
 principle and design your own event handling interfaces.

 You could have your config Composite implement SourcesChangeEvents,
 for example. Then Comps 1  2 can implement ChangeListener and are
 registered with the config Comp. It might work like so:

 public class ConfigPanel extends Composite implements
 SourcesChangeEvents {

   private ChangeListenerCollection listeners = new
 ChangeListenerCollection();
   private Button saveBtn = new Button(Save,new ClickListener() {
             public void onClick(Widget widget) {
                   // you want to send the ConfigPanel itself, not the
 Button!
                   // if you just used this it would send the button
                   listeners.fireChange(ConfigPanel.this).;
                 }
             });

 }

 public class Comp1 extends Composite implements changeListener {

      public void onChange(Widget sender) {
          is (sender instanceof ConfigPanel) {
              ConfigPanel configPanel = (ConfigPanel) sender;
              // call whatever methods you need
          }

 }

 Don't forget you have to register Comp1 as a lister with ConfigPanel
 somewhere or it won't work, e.g.:

     confPanel.addChangeListener(comp1);

 And that's about it - goodbye to your static method calls.

 regards
 gregor

 On Nov 14, 8:45 am, mives29 [EMAIL PROTECTED] wrote:

  i meant static methods

Re: Observer pattern on this design, yes or no/how and why?

2008-11-17 Thread mives29

Well, the reason for the two entrypoints is that me and my colleagues
are looking for a way to implement a sort of pop-up dialog box, but,
something that resides on a separate window, so it wouldn't overlay
with the main page.  (so the user can alt+tab between the two
windows).

If there's another way to do this other than creating another
entrypoint, please let me know. Thanks.

On Nov 17, 7:54 pm, gregor [EMAIL PROTECTED] wrote:
 Clearly if a module is using a class declared in another module it
 must explicitly inherit the other module in it's module.get.xml file
 otherwise the GWT compiler  won't have access to the class's source
 which it needs. Frankly I'm not sure how this would work in the
 situation as you describe since I have always followed the canonical
 GWT approach which is using a single HTML page and EntryPoint for each
 separate application. I'm not sure what your motivation is in having
 two EntryPoints. I think this results in two separate javascript .js
 files loaded into your HTML page, therefore there will be a wall
 between them that accounts for your difficulties. I think it is
 possible to communicate between separate javascript files using JSNI
 but that would make your life much more difficult.

 On the other hand there is no reason not to have your
 com.try.popup.client.PopUp.java in a separate module (i.e. having it's
 own module.gwt.xml file) and have this inherited by the
 com.try.client.Page1.java module. That way it would be compiled as
 part of your main application (making your problem go away) but still
 be usable in other applications as well. As I say, what is your
 motivation for having two EnrtyPoints?

 regards
 gregor

 On Nov 17, 9:42 am, mives29 [EMAIL PROTECTED] wrote:

  The problem is im using two entrypoints, running on two windows, where
  the 2nd composite is shown thru Window.open(). I need the first
  entrypoint's composite to listen to the second entrypoint's composite,
  but I cant do that since the second entrypoint's composite is
  instantiated on the second composite, not the first one, so I cant add
  the first entrypoint's composite as a listener of the second
  entrypoint's composite.

  Anyone knows a work around/alternative method of implementing observer
  pattern on my problem?

  On Nov 17, 4:00 pm, mives29 [EMAIL PROTECTED] wrote:

   I tested it on same module, this implementation of the observer
   pattern works. however, when using this on two modules it doesn't. Do
   I need to do deferred binding here? I hope not coz I dont know how to.
   =)

   On Nov 17, 1:29 pm, mives29 [EMAIL PROTECTED] wrote:

oops CnP mistake. on this line:
buttons.addChangeListener(this);  //where this pertains to
Page1Compo1

i meant
xx.addChangeListener(this);    //where this pertains to Page1Compo1

On Nov 17, 1:22 pm, mives29 [EMAIL PROTECTED] wrote:

 Hi. I tried your recommendations but there are some errors that I
 encounter that I think is related to my project's structure
 compatibility with your code. As I said above, my project has two
 entrypoints. First entrypoint(com.try.client.Page1.java) contains a
 vertical panel that contains three composites. Second entrypoint
 (com.try.popup.client.PopUp.java) contains a vertical panel than
 contains two composites. (Note: they(entrypoints) are from different
 modules, same app.)

 Now I need Page1.java's panel's contained composites to become
 listeners of PopUp.java's horizontal panel's contained composites. For
 example, I click something on PopUp.java, Page1.java would show a
 reaction thru its composites that are listeners of PopUp.java's
 composite # 2. However, as I followed your instruction, I got this
 errror:

 First, my CODE:
 //On Page1.java's first composite: Page1Compo1.java, I included the
 following
 //declaration of composite # 2
  xx;

 //somewhere on the code
 buttons.addChangeListener(this);    //where this pertains to
 Page1Compo1

 THE ERROR:
 No source code is available for type com.xxxzzz.client..java; did
 you forget to inherit a required module?

 note: .java above is composite # 2 of PopUp.java vertical panel.

 It seems I cannot use .java on Page1Compo1.java.. What am I
 missing?

 On Nov 14, 8:50 pm, gregor [EMAIL PROTECTED] wrote:

  Oh, as to why, well as you see ConfigPanel has no real knowledge of
  the other panels that are listening to it and does need to call any
  methods on them. As a result any number of panels can be registered 
  as
  a listener with it, and subsequently swapped out for new ones if
  required, without affecting ConfigPanel's code at all. It is up to 
  the
  listeners to decide for themselves, individually, what they need to 
  do
  when they receive a change event. So there is a very weak 
  association
  between ConfigPanel and it's listeners

Re: Observer pattern on this design, yes or no/how and why?

2008-11-16 Thread mives29

Hi. I tried your recommendations but there are some errors that I
encounter that I think is related to my project's structure
compatibility with your code. As I said above, my project has two
entrypoints. First entrypoint(com.try.client.Page1.java) contains a
vertical panel that contains three composites. Second entrypoint
(com.try.popup.client.PopUp.java) contains a vertical panel than
contains two composites. (Note: they(entrypoints) are from different
modules, same app.)

Now I need Page1.java's panel's contained composites to become
listeners of PopUp.java's horizontal panel's contained composites. For
example, I click something on PopUp.java, Page1.java would show a
reaction thru its composites that are listeners of PopUp.java's
composite # 2. However, as I followed your instruction, I got this
errror:

First, my CODE:
//On Page1.java's first composite: Page1Compo1.java, I included the
following
//declaration of composite # 2
 xx;

//somewhere on the code
buttons.addChangeListener(this);//where this pertains to
Page1Compo1

THE ERROR:
No source code is available for type com.xxxzzz.client..java; did
you forget to inherit a required module?

note: .java above is composite # 2 of PopUp.java vertical panel.

It seems I cannot use .java on Page1Compo1.java.. What am I
missing?



On Nov 14, 8:50 pm, gregor [EMAIL PROTECTED] wrote:
 Oh, as to why, well as you see ConfigPanel has no real knowledge of
 the other panels that are listening to it and does need to call any
 methods on them. As a result any number of panels can be registered as
 a listener with it, and subsequently swapped out for new ones if
 required, without affecting ConfigPanel's code at all. It is up to the
 listeners to decide for themselves, individually, what they need to do
 when they receive a change event. So there is a very weak association
 between ConfigPanel and it's listeners and none at all between the
 listeners == low coupling == application components easy to change and
 maintain.

 On Nov 14, 12:40 pm, gregor [EMAIL PROTECTED] wrote:

  GWT has a range of Observer/Observable gadgets off the shelf:
  SourcesEvents   Listener and xxxListenerCollection utility
  classes. If they don't work quite right for you, it's easy to copy the
  principle and design your own event handling interfaces.

  You could have your config Composite implement SourcesChangeEvents,
  for example. Then Comps 1  2 can implement ChangeListener and are
  registered with the config Comp. It might work like so:

  public class ConfigPanel extends Composite implements
  SourcesChangeEvents {

    private ChangeListenerCollection listeners = new
  ChangeListenerCollection();
    private Button saveBtn = new Button(Save,new ClickListener() {
              public void onClick(Widget widget) {
                    // you want to send the ConfigPanel itself, not the
  Button!
                    // if you just used this it would send the button
                    listeners.fireChange(ConfigPanel.this).;
                  }
              });

  }

  public class Comp1 extends Composite implements changeListener {

       public void onChange(Widget sender) {
           is (sender instanceof ConfigPanel) {
               ConfigPanel configPanel = (ConfigPanel) sender;
               // call whatever methods you need
           }

  }

  Don't forget you have to register Comp1 as a lister with ConfigPanel
  somewhere or it won't work, e.g.:

      confPanel.addChangeListener(comp1);

  And that's about it - goodbye to your static method calls.

  regards
  gregor

  On Nov 14, 8:45 am, mives29 [EMAIL PROTECTED] wrote:

   i meant static methods, not static classes (2nd paragraph 2nd line)

   On Nov 14, 4:43 pm, mives29 [EMAIL PROTECTED] wrote:

I'd go straight to what I want to do.

I have 3 composites in 1 panel, in 1 entrypoint. I have another
entrypoint that pops up when you click a link on the 2nd composite on
the 1st entrypoint. on that second entrypoint you can configure stuff,
that will affect the displayed data on the first entrypoint's
composites. now, im thinking (actually, a friend thought of it, not
me) that the observer pattern is great to use in here, as the 3
composites of the 1st entrypoint will listen to whatever the second
entrypoint configures, then change themselves according to the
specified configurations on the second entrypoint.

Currently, I do the changes on the first entrypoint's composites by
calling their static classes (from the second entrypoint's
clicklisteners and stuff) that configures them, which I think is not a
very good practice to implement because it's not easily extensible and
not that good of a design.

Now, is it wise to use the observer pattern(personally, I think it
is)? If yes, how do you implement that on GWT 1.5? (we use GWT 1.5.2)

thanks in advance
mives29

Re: Observer pattern on this design, yes or no/how and why?

2008-11-16 Thread mives29

oops CnP mistake. on this line:
buttons.addChangeListener(this);  //where this pertains to
Page1Compo1

i meant
xx.addChangeListener(this);//where this pertains to Page1Compo1

On Nov 17, 1:22 pm, mives29 [EMAIL PROTECTED] wrote:
 Hi. I tried your recommendations but there are some errors that I
 encounter that I think is related to my project's structure
 compatibility with your code. As I said above, my project has two
 entrypoints. First entrypoint(com.try.client.Page1.java) contains a
 vertical panel that contains three composites. Second entrypoint
 (com.try.popup.client.PopUp.java) contains a vertical panel than
 contains two composites. (Note: they(entrypoints) are from different
 modules, same app.)

 Now I need Page1.java's panel's contained composites to become
 listeners of PopUp.java's horizontal panel's contained composites. For
 example, I click something on PopUp.java, Page1.java would show a
 reaction thru its composites that are listeners of PopUp.java's
 composite # 2. However, as I followed your instruction, I got this
 errror:

 First, my CODE:
 //On Page1.java's first composite: Page1Compo1.java, I included the
 following
 //declaration of composite # 2
  xx;

 //somewhere on the code
 buttons.addChangeListener(this);    //where this pertains to
 Page1Compo1

 THE ERROR:
 No source code is available for type com.xxxzzz.client..java; did
 you forget to inherit a required module?

 note: .java above is composite # 2 of PopUp.java vertical panel.

 It seems I cannot use .java on Page1Compo1.java.. What am I
 missing?

 On Nov 14, 8:50 pm, gregor [EMAIL PROTECTED] wrote:

  Oh, as to why, well as you see ConfigPanel has no real knowledge of
  the other panels that are listening to it and does need to call any
  methods on them. As a result any number of panels can be registered as
  a listener with it, and subsequently swapped out for new ones if
  required, without affecting ConfigPanel's code at all. It is up to the
  listeners to decide for themselves, individually, what they need to do
  when they receive a change event. So there is a very weak association
  between ConfigPanel and it's listeners and none at all between the
  listeners == low coupling == application components easy to change and
  maintain.

  On Nov 14, 12:40 pm, gregor [EMAIL PROTECTED] wrote:

   GWT has a range of Observer/Observable gadgets off the shelf:
   SourcesEvents   Listener and xxxListenerCollection utility
   classes. If they don't work quite right for you, it's easy to copy the
   principle and design your own event handling interfaces.

   You could have your config Composite implement SourcesChangeEvents,
   for example. Then Comps 1  2 can implement ChangeListener and are
   registered with the config Comp. It might work like so:

   public class ConfigPanel extends Composite implements
   SourcesChangeEvents {

     private ChangeListenerCollection listeners = new
   ChangeListenerCollection();
     private Button saveBtn = new Button(Save,new ClickListener() {
               public void onClick(Widget widget) {
                     // you want to send the ConfigPanel itself, not the
   Button!
                     // if you just used this it would send the button
                     listeners.fireChange(ConfigPanel.this).;
                   }
               });

   }

   public class Comp1 extends Composite implements changeListener {

        public void onChange(Widget sender) {
            is (sender instanceof ConfigPanel) {
                ConfigPanel configPanel = (ConfigPanel) sender;
                // call whatever methods you need
            }

   }

   Don't forget you have to register Comp1 as a lister with ConfigPanel
   somewhere or it won't work, e.g.:

       confPanel.addChangeListener(comp1);

   And that's about it - goodbye to your static method calls.

   regards
   gregor

   On Nov 14, 8:45 am, mives29 [EMAIL PROTECTED] wrote:

i meant static methods, not static classes (2nd paragraph 2nd line)

On Nov 14, 4:43 pm, mives29 [EMAIL PROTECTED] wrote:

 I'd go straight to what I want to do.

 I have 3 composites in 1 panel, in 1 entrypoint. I have another
 entrypoint that pops up when you click a link on the 2nd composite on
 the 1st entrypoint. on that second entrypoint you can configure stuff,
 that will affect the displayed data on the first entrypoint's
 composites. now, im thinking (actually, a friend thought of it, not
 me) that the observer pattern is great to use in here, as the 3
 composites of the 1st entrypoint will listen to whatever the second
 entrypoint configures, then change themselves according to the
 specified configurations on the second entrypoint.

 Currently, I do the changes on the first entrypoint's composites by
 calling their static classes (from the second entrypoint's
 clicklisteners and stuff) that configures them, which I think is not a
 very good

Re: Observer pattern on this design, yes or no/how and why?

2008-11-15 Thread mives29

Wow. That seems too easy. =D

Seems GWT really simplified observer pattern there, was thinking of
doing some extending of the observable class in Java, good thing GWT
1.5 has it already, and its much simpler. thanks a lot.

On 14 Nob, 20:50, gregor [EMAIL PROTECTED] wrote:
 Oh, as to why, well as you see ConfigPanel has no real knowledge of
 the other panels that are listening to it and does need to call any
 methods on them. As a result any number of panels can be registered as
 a listener with it, and subsequently swapped out for new ones if
 required, without affecting ConfigPanel's code at all. It is up to the
 listeners to decide for themselves, individually, what they need to do
 when they receive a change event. So there is a very weak association
 between ConfigPanel and it's listeners and none at all between the
 listeners == low coupling == application components easy to change and
 maintain.

 On Nov 14, 12:40 pm, gregor [EMAIL PROTECTED] wrote:

  GWT has a range of Observer/Observable gadgets off the shelf:
  SourcesEvents   Listener and xxxListenerCollection utility
  classes. If they don't work quite right for you, it's easy to copy the
  principle and design your own event handling interfaces.

  You could have your config Composite implement SourcesChangeEvents,
  for example. Then Comps 1  2 can implement ChangeListener and are
  registered with the config Comp. It might work like so:

  public class ConfigPanel extends Composite implements
  SourcesChangeEvents {

    private ChangeListenerCollection listeners = new
  ChangeListenerCollection();
    private Button saveBtn = new Button(Save,new ClickListener() {
              public void onClick(Widget widget) {
                    // you want to send the ConfigPanel itself, not the
  Button!
                    // if you just used this it would send the button
                    listeners.fireChange(ConfigPanel.this).;
                  }
              });

  }

  public class Comp1 extends Composite implements changeListener {

       public void onChange(Widget sender) {
           is (sender instanceof ConfigPanel) {
               ConfigPanel configPanel = (ConfigPanel) sender;
               // call whatever methods you need
           }

  }

  Don't forget you have to register Comp1 as a lister with ConfigPanel
  somewhere or it won't work, e.g.:

      confPanel.addChangeListener(comp1);

  And that's about it - goodbye to your static method calls.

  regards
  gregor

  On Nov 14, 8:45 am, mives29 [EMAIL PROTECTED] wrote:

   i meant static methods, not static classes (2nd paragraph 2nd line)

   On Nov 14, 4:43 pm, mives29 [EMAIL PROTECTED] wrote:

I'd go straight to what I want to do.

I have 3 composites in 1 panel, in 1 entrypoint. I have another
entrypoint that pops up when you click a link on the 2nd composite on
the 1st entrypoint. on that second entrypoint you can configure stuff,
that will affect the displayed data on the first entrypoint's
composites. now, im thinking (actually, a friend thought of it, not
me) that the observer pattern is great to use in here, as the 3
composites of the 1st entrypoint will listen to whatever the second
entrypoint configures, then change themselves according to the
specified configurations on the second entrypoint.

Currently, I do the changes on the first entrypoint's composites by
calling their static classes (from the second entrypoint's
clicklisteners and stuff) that configures them, which I think is not a
very good practice to implement because it's not easily extensible and
not that good of a design.

Now, is it wise to use the observer pattern(personally, I think it
is)? If yes, how do you implement that on GWT 1.5? (we use GWT 1.5.2)

thanks in advance
mives29
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Observer pattern on this design, yes or no/how and why?

2008-11-14 Thread mives29

I'd go straight to what I want to do.

I have 3 composites in 1 panel, in 1 entrypoint. I have another
entrypoint that pops up when you click a link on the 2nd composite on
the 1st entrypoint. on that second entrypoint you can configure stuff,
that will affect the displayed data on the first entrypoint's
composites. now, im thinking (actually, a friend thought of it, not
me) that the observer pattern is great to use in here, as the 3
composites of the 1st entrypoint will listen to whatever the second
entrypoint configures, then change themselves according to the
specified configurations on the second entrypoint.

Currently, I do the changes on the first entrypoint's composites by
calling their static classes (from the second entrypoint's
clicklisteners and stuff) that configures them, which I think is not a
very good practice to implement because it's not easily extensible and
not that good of a design.

Now, is it wise to use the observer pattern(personally, I think it
is)? If yes, how do you implement that on GWT 1.5? (we use GWT 1.5.2)

thanks in advance
mives29

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Observer pattern on this design, yes or no/how and why?

2008-11-14 Thread mives29

i meant static methods, not static classes (2nd paragraph 2nd line)

On Nov 14, 4:43 pm, mives29 [EMAIL PROTECTED] wrote:
 I'd go straight to what I want to do.

 I have 3 composites in 1 panel, in 1 entrypoint. I have another
 entrypoint that pops up when you click a link on the 2nd composite on
 the 1st entrypoint. on that second entrypoint you can configure stuff,
 that will affect the displayed data on the first entrypoint's
 composites. now, im thinking (actually, a friend thought of it, not
 me) that the observer pattern is great to use in here, as the 3
 composites of the 1st entrypoint will listen to whatever the second
 entrypoint configures, then change themselves according to the
 specified configurations on the second entrypoint.

 Currently, I do the changes on the first entrypoint's composites by
 calling their static classes (from the second entrypoint's
 clicklisteners and stuff) that configures them, which I think is not a
 very good practice to implement because it's not easily extensible and
 not that good of a design.

 Now, is it wise to use the observer pattern(personally, I think it
 is)? If yes, how do you implement that on GWT 1.5? (we use GWT 1.5.2)

 thanks in advance
 mives29
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Reading XML file from localhost

2008-11-13 Thread mives29

to greg, thank you for your insight on the matter. it's not that i
want to force using a utility class, its just that, well, its a
requirement for me (to use a utility class, since other fellow devs
here in my team will use it) and i thought its more convenient. and on
the matter of where to place the fetch calls, i made it that way with
create things only on the time that you would need them. but i guess
that the lesson learned here (for me) is flexibility.

to jason, thank you for your technical explanation of these callback
objects. ill experiment with them a bit more when i have time.

unfortunately, my team decided to implement a singleton on the server-
side to parse, then transfer the data onto beans, which will then be
accessed by services. but this has been a great learning experience
for me, thanks to all those that replied.

mives29
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Reading XML file from localhost

2008-11-10 Thread mives29

yes. you got my problem right. now probably tommorow or the day after
that, I'll have the chance to re-do my code. For now, back to reading
some company documents. Will get back here as soon as I've redone the
code.

Thanks Jason,
mives29

On Nov 10, 5:58 pm, Jason Morris [EMAIL PROTECTED] wrote:
 Heya,

 Your basic problem here is that you can't have your XmlParserUtil return a
 Document object. The doc field will only be filled in when the async
 RequestBuilder request returns and the parser is finished with the XML string.
 By that time, your method has already returned.

 The only way to solve this is to create something like a:

 public interface CallbackV {
         void callback(V value);

 }

 and have the XmlParserUtil look something more like this:

 public class XmlParserUtil {
         String url;
         Document doc;
         public RequestBuilder requestBuilder;
         String xmlStr;

         public XmlParserUtil(String xmlFileName) {
                 this.url = xmlFileName;
         }

         public void getDocument(CallbackDocument callback) {
                 if(doc != null) {
                         callback.callback(doc);
                         return;
                 }

                 try {
                         requestBuilder = new 
 RequestBuilder(RequestBuilder.GET,url);
                         requestBuilder.sendRequest(null,new RequestCallback()
                         {public void onResponseReceived(Request arg0, 
 Response arg1) {
                                 xmlStr = arg1.getText();
                                 callback.callback(doc = 
 XMLParser.parse(xmlStr));
                         }
                         public void onError(Request request, Throwable 
 exception) {

                         }});
                 }
                 catch (RequestException ex) {
                         GWT.log(ex.getMessage(), ex);
             }
         }

 }

 For more information about async problems, it's related to RPC, but applicable
 to the RequestBuilder as well:

 http://lemnik.wordpress.com/2008/07/04/gwt-rpc-is-called-aynchronous-...

 mives29 wrote:
  okay, let me be clear on this, again, my code. (now posting full
  reworked source code)

  // A composite w/c contains a tree.
  public class TreeX extends Composite {
     Document doc;
     Tree t = new Tree();
     int imgUris;
     XmlParserUtil xmlParser;
     public TreePol() {
             TreeItem tItem = getTreeItem();
             t.addItem(tItem);
             initWidget(t);
     }
     private TreeItem getTreeItem() {
             doc = getDoc();
             imgUris = doc.getElementsByTagName(Image).getLength();
             TreeItem root = null;
             root = new TreeItem(Image Names);
             for (int i=0;iimgUris;i++) {
                     String tmpImgUri =
  doc.getElementsByTagName(Image).item(i).getChildNodes().item(1).toString();
                     root.addItem(tmpImgUri);
             }
             return root;
     }
     public Document getDoc() {
             xmlParser = new XmlParserUtil(image_uris.xml);
               while (doc==null) {
                       doc = xmlParser.getDocument();
               }
             return doc;
     }
  }

  //A class that i want to use as a utility class for parsing xml
  documents. intended to be reusable
  public class XmlParserUtil {
     String url;
     Document doc;
     public RequestBuilder requestBuilder;
     String xmlStr;

     public XmlParserUtil(String xmlFileName) {
             this.url = xmlFileName;
     }

     public Document getDocument() {
             try {
                     requestBuilder = new 
  RequestBuilder(RequestBuilder.GET,url);
                     requestBuilder.sendRequest(null,new RequestCallback()
                     {public void onResponseReceived(Request arg0, Response 
  arg1) {
                             xmlStr = arg1.getText();
                             doc = XMLParser.parse(xmlStr);
                     }
                     public void onError(Request request, Throwable 
  exception) {

                     }});
             }
             catch (RequestException ex) {
                     GWT.log(ex.getMessage(), ex);
         }
             return doc;
     }
  }

  //my entrypoint's onModuleLoad(), which adds the various custom
  widgets i made to a tab panel

  public void onModuleLoad() {
       RichTextAreaX1 rtaPol = new RichTextAreaX1();
       PictureViewer imgBrowser = new PictureViewer();
       TreeX tree = new TreeX();

       TabPanel tp = new TabPanel();
       tp.add(tree, 1);
       tp.add(rtaPol, 2);
       tp.add(imgBrowser, 3);

       tp.selectTab(0);
       tp.setWidth(100%);

       RootPanel.get(leftpanel).add(tp);
    }

  as you can see, I intend the XmlParserUtil class to be reusable. If I
  place there various logic, then it would be out of scope for that
  classs, because I intend to use XmlParserUtil just to parse an XML
  file

Re: Reading XML file from localhost

2008-11-10 Thread mives29

okay, let me be clear on this, again, my code. (now posting full
reworked source code)

// A composite w/c contains a tree.
public class TreeX extends Composite {
Document doc;
Tree t = new Tree();
int imgUris;
XmlParserUtil xmlParser;
public TreePol() {
TreeItem tItem = getTreeItem();
t.addItem(tItem);
initWidget(t);
}
private TreeItem getTreeItem() {
doc = getDoc();
imgUris = doc.getElementsByTagName(Image).getLength();
TreeItem root = null;
root = new TreeItem(Image Names);
for (int i=0;iimgUris;i++) {
String tmpImgUri =
doc.getElementsByTagName(Image).item(i).getChildNodes().item(1).toString();
root.addItem(tmpImgUri);
}
return root;
}
public Document getDoc() {
xmlParser = new XmlParserUtil(image_uris.xml);
  while (doc==null) {
  doc = xmlParser.getDocument();
  }
return doc;
}
}

//A class that i want to use as a utility class for parsing xml
documents. intended to be reusable
public class XmlParserUtil {
String url;
Document doc;
public RequestBuilder requestBuilder;
String xmlStr;

public XmlParserUtil(String xmlFileName) {
this.url = xmlFileName;
}

public Document getDocument() {
try {
requestBuilder = new 
RequestBuilder(RequestBuilder.GET,url);
requestBuilder.sendRequest(null,new RequestCallback()
{public void onResponseReceived(Request arg0, Response 
arg1) {
xmlStr = arg1.getText();
doc = XMLParser.parse(xmlStr);
}
public void onError(Request request, Throwable 
exception) {

}});
}
catch (RequestException ex) {
GWT.log(ex.getMessage(), ex);
}
return doc;
}
}

//my entrypoint's onModuleLoad(), which adds the various custom
widgets i made to a tab panel

public void onModuleLoad() {
  RichTextAreaX1 rtaPol = new RichTextAreaX1();
  PictureViewer imgBrowser = new PictureViewer();
  TreeX tree = new TreeX();

  TabPanel tp = new TabPanel();
  tp.add(tree, 1);
  tp.add(rtaPol, 2);
  tp.add(imgBrowser, 3);

  tp.selectTab(0);
  tp.setWidth(100%);

  RootPanel.get(leftpanel).add(tp);
  }

as you can see, I intend the XmlParserUtil class to be reusable. If I
place there various logic, then it would be out of scope for that
classs, because I intend to use XmlParserUtil just to parse an XML
file, and bring me back a parsed Document object. now how would I do
that if XmlParserUtil, which contains the requestbuilder and callback,
would be used by another class (which is a composite).

im new to this async thing, more so the  requestbuilder stuff. thank
you for replying, i hope you could answer my question.

On Nov 10, 3:44 pm, alex.d [EMAIL PROTECTED] wrote:
 You have to accept the asynchronous nature of RPC-Requests in GWT and
 stop trying to build smth. synchronous around them. This code:
 ---
 doc = getDoc(); //(where doc is a Document object)
 String subject =
 doc.getElementsByTagName(Image).item(0).getChildNodes().item(1).toString();
 String subject2 =
 doc.getElementsByTagName(Image).item(1).getFirstChild().getNodeValue();
 ---
 should not be executed in the onload-routine but in the
 onResponseReceived()-method (or in any other procedure that you call
 out of it).

 On 10 Nov., 07:12, mives29 [EMAIL PROTECTED] wrote:

  hi all. ive re-done my code just a while ago(been a busy week) and my
  code kinda bothers me.  here's the code re-done:

  Entrypoint onModuleLoad() method:

  doc = getDoc(); //(where doc is a Document object)
  String subject =
  doc.getElementsByTagName(Image).item(0).getChildNodes().item(1).toString();
  String subject2 =
  doc.getElementsByTagName(Image).item(1).getFirstChild().getNodeValue();

  Entrypoiny getDoc() method:
  public Document getDoc() {
            XmlParserUtil xmlParser = new XmlParserUtil(image_uris.xml);
            int i = 0;
            while (doc==null) {
                    doc = xmlParser.getDocument();
            }
          return doc;
    }

  here's the service implementation:
  public class XmlParserUtil {
          String url;
          Document doc;
          RequestBuilder requestBuilder;
          public String xmlStr;

          public XmlParserUtil(String xmlFileName) {
                  this.url = xmlFileName;
          }

          public

Re: Reading XML file from localhost

2008-11-10 Thread mives29

Hi! I've just re-read your reply, but I cant understand how the
interface would affect the program, and how would I use that new
getDocument() method of the XmlUtilParser class. Could you provide
another example (a working one, if possible)?

This whole AsyncCallback/asynchronous stuff of GWT is driving me nuts.
I've created the same parser using a service, and Java's own DOM
parser, and it works already, however I really want to develop this
app of mine full GWT-style. Hope you could help me again, thanks.

On Nov 10, 5:58 pm, Jason Morris [EMAIL PROTECTED] wrote:
 Heya,

 Your basic problem here is that you can't have your XmlParserUtil return a
 Document object. The doc field will only be filled in when the async
 RequestBuilder request returns and the parser is finished with the XML string.
 By that time, your method has already returned.

 The only way to solve this is to create something like a:

 public interface CallbackV {
         void callback(V value);

 }

 and have the XmlParserUtil look something more like this:

 public class XmlParserUtil {
         String url;
         Document doc;
         public RequestBuilder requestBuilder;
         String xmlStr;

         public XmlParserUtil(String xmlFileName) {
                 this.url = xmlFileName;
         }

         public void getDocument(CallbackDocument callback) {
                 if(doc != null) {
                         callback.callback(doc);
                         return;
                 }

                 try {
                         requestBuilder = new 
 RequestBuilder(RequestBuilder.GET,url);
                         requestBuilder.sendRequest(null,new RequestCallback()
                         {public void onResponseReceived(Request arg0, 
 Response arg1) {
                                 xmlStr = arg1.getText();
                                 callback.callback(doc = 
 XMLParser.parse(xmlStr));
                         }
                         public void onError(Request request, Throwable 
 exception) {

                         }});
                 }
                 catch (RequestException ex) {
                         GWT.log(ex.getMessage(), ex);
             }
         }

 }

 For more information about async problems, it's related to RPC, but applicable
 to the RequestBuilder as well:

 http://lemnik.wordpress.com/2008/07/04/gwt-rpc-is-called-aynchronous-...

 mives29 wrote:
  okay, let me be clear on this, again, my code. (now posting full
  reworked source code)

  // A composite w/c contains a tree.
  public class TreeX extends Composite {
     Document doc;
     Tree t = new Tree();
     int imgUris;
     XmlParserUtil xmlParser;
     public TreePol() {
             TreeItem tItem = getTreeItem();
             t.addItem(tItem);
             initWidget(t);
     }
     private TreeItem getTreeItem() {
             doc = getDoc();
             imgUris = doc.getElementsByTagName(Image).getLength();
             TreeItem root = null;
             root = new TreeItem(Image Names);
             for (int i=0;iimgUris;i++) {
                     String tmpImgUri =
  doc.getElementsByTagName(Image).item(i).getChildNodes().item(1).toString();
                     root.addItem(tmpImgUri);
             }
             return root;
     }
     public Document getDoc() {
             xmlParser = new XmlParserUtil(image_uris.xml);
               while (doc==null) {
                       doc = xmlParser.getDocument();
               }
             return doc;
     }
  }

  //A class that i want to use as a utility class for parsing xml
  documents. intended to be reusable
  public class XmlParserUtil {
     String url;
     Document doc;
     public RequestBuilder requestBuilder;
     String xmlStr;

     public XmlParserUtil(String xmlFileName) {
             this.url = xmlFileName;
     }

     public Document getDocument() {
             try {
                     requestBuilder = new 
  RequestBuilder(RequestBuilder.GET,url);
                     requestBuilder.sendRequest(null,new RequestCallback()
                     {public void onResponseReceived(Request arg0, Response 
  arg1) {
                             xmlStr = arg1.getText();
                             doc = XMLParser.parse(xmlStr);
                     }
                     public void onError(Request request, Throwable 
  exception) {

                     }});
             }
             catch (RequestException ex) {
                     GWT.log(ex.getMessage(), ex);
         }
             return doc;
     }
  }

  //my entrypoint's onModuleLoad(), which adds the various custom
  widgets i made to a tab panel

  public void onModuleLoad() {
       RichTextAreaX1 rtaPol = new RichTextAreaX1();
       PictureViewer imgBrowser = new PictureViewer();
       TreeX tree = new TreeX();

       TabPanel tp = new TabPanel();
       tp.add(tree, 1);
       tp.add(rtaPol, 2);
       tp.add(imgBrowser, 3);

       tp.selectTab(0);
       tp.setWidth(100

Re: Reading XML file from localhost

2008-11-05 Thread mives29

Oh. I didnt know that! Thanks a lot! Will try to modify it. Thanks
again.

mives29

On Nov 5, 3:31 pm, Lothar Kimmeringer [EMAIL PROTECTED] wrote:
 mives29 schrieb:

  requestBuilder = new RequestBuilder(RequestBuilder.GET,url);
  requestBuilder.sendRequest(null,xmlRcb);
  doc = xmlRcb.getDoc();             //calls xmlRcb's getDoc method, w/c 
  returns

 sendRequest happens asynchronously, so the callback-
 method is not called at this time you try to get
 the document.

 You have to place the logic that happens when the XML-
 file has been received inside the onResponseReceived-
 method of the callback-class.

 Regards, Lothar
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Reading XML file from localhost

2008-11-04 Thread mives29

Hi. I'm a newbie in GWT, and I've been tasked to create a utility
class to parse xml files that the contents would be used in layouting
the widgets in its container panel (along with other UI
configurations).

I've accomplished this by using a service, which uses Java's DOM style
of parsing. This service returns an array list of serializable objects
that I created (a POJO that stores the configurations). Then I use the
POJOs inside that array list to set various stuff in the UI (xpos,
ypos, etc) for different widgets.


Then I've found out that GWT has the xml api, that I can use to parse
my XML. However, XMLParser .parse() only accepts the string
representation of the actual XML file. I thought that I could do the
same thing I did with my service implementation (using
documentbuilder.parse(path-to-xmlfile).

Now I'm thinking of creating a service that would return a string
representation of the XML file, then send it to my GWT class and let
that class handle the parsing. Is this possible? or is this even
acceptable?

Ive been seeing stuff on the net using HttpRequest(or RequestBuilder?)
to get XML from a script, but I dont know how to do that(the example
was on php.)

Any idea how can I implement this properly? Thanks

mives29

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Reading XML file from localhost

2008-11-04 Thread mives29

sammi,

thanks for the reply. will try that asap.

On Nov 5, 12:34 pm, Sammi [EMAIL PROTECTED] wrote:
 Hi mives29,
    I just solve the problem. It's quite direct and easy.

 1. upload your xml file to any webserver, e.g.http://a.b.c/test.xml

 2. use RequestBuilder to get it. your url.

 3. String xmlStr = response.getText();

 4. use XMlParser to parse the xmlStr. that's it. Sample snippet code
 here:

     String url = test.xml;
     RequestBuilder requestBuilder = new
 RequestBuilder(RequestBuilder.GET,url);
     try {
            requestBuilder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
            }
            public void onResponseReceived(Request request, Response
 response){
                 String xmlStr=response.getText();
                 //Parse it then.
            }
           }
           );
         } catch (RequestException ex) {
             GWT.log(ex.getMessage(), ex);
         }

 Hope that helps
 Sammi

 On Nov 4, 7:24 pm, mives29 [EMAIL PROTECTED] wrote:

  Hi. I'm a newbie in GWT, and I've been tasked to create a utility
  class to parse xml files that the contents would be used in layouting
  the widgets in its container panel (along with other UI
  configurations).

  I've accomplished this by using a service, which uses Java's DOM style
  of parsing. This service returns an array list of serializable objects
  that I created (a POJO that stores the configurations). Then I use the
  POJOs inside that array list to set various stuff in the UI (xpos,
  ypos, etc) for different widgets.

  Then I've found out that GWT has the xml api, that I can use to parse
  my XML. However, XMLParser .parse() only accepts the string
  representation of the actual XML file. I thought that I could do the
  same thing I did with my service implementation (using
  documentbuilder.parse(path-to-xmlfile).

  Now I'm thinking of creating a service that would return a string
  representation of the XML file, then send it to my GWT class and let
  that class handle the parsing. Is this possible? or is this even
  acceptable?

  Ive been seeing stuff on the net using HttpRequest(or RequestBuilder?)
  to get XML from a script, but I dont know how to do that(the example
  was on php.)

  Any idea how can I implement this properly? Thanks

  mives29
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~--~~~~--~~--~--~---



Re: Reading XML file from localhost

2008-11-04 Thread mives29

Hi. Im having a problem using RequestBuilder. Instead of using an
inner class of type RequestCallBack, I created a class that implements
it. Here's what I've done,

1)Created a utility class named XmlParserUtil. This will return a
parsed XML document. (Document object)
2)Inside, there's 1 method,getDocument and 1 inner class,
XmlRequestCallback. The former returns the parsed XML document object,
the latter implements RequestCallback interface and has 3 methods, the
2 implemented methods and 1 method I created, getDocument() which is
called by XmlParserUtil.getDocument and returns the parsed document.
3)I instantiate XmlParserUtil and a Document object on my entrypoint
on the onModuleLoad method, so that the document object takes in the
value on XmlParserUtil's getDocument method.

Now, I get NullPointerException. I checked it and it seems that my
XmlParserutil.getDocument returns a null document object.

I placed a print statement on the onResponseReceived() method. I also
placed a print statment on the getDoc() class of the inner class so it
prints everytime it is called. But when i run the program, the
getDoc()'s print get exceuted before the onResponseReceived()'s print,
so naturally the returned string of getDoc() is null. they both print
xmlStrReq, the string form of the xml file.

Could you help me? Here's my code:

XmlParserUtil.java :

package com.trylang.pol.client.util;

import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.XMLParser;

public class XmlParserUtil {
String url;
Document doc;
RequestBuilder requestBuilder;
private String xmlStr;

//on instantiation, you must provide the xml file name to be
parsed
public XmlParserUtil(String xmlFileName) {
this.url = xmlFileName;
}

public Document getDocument() {
//created an instance of the inner class located after
this method
XmlRequestCallBack xmlRcb = new XmlRequestCallBack();
try {
requestBuilder = new 
RequestBuilder(RequestBuilder.GET,url);
requestBuilder.sendRequest(null,xmlRcb);
doc = xmlRcb.getDoc();  //calls xmlRcb's getDoc 
method, w/c returns
a parsed xml
//
doc.
}
catch (RequestException ex) {
GWT.log(ex.getMessage(), ex);
}
return doc;
}

//a class that implements the requestcallback interface
class XmlRequestCallBack implements RequestCallback {
private String xmlStrReq;
private Document docReq;
public void onError(Request request, Throwable exception) {

}
public void onResponseReceived(Request request, Response 
response) {
//gets the text form of the xml file, then parses it.
xmlStrReq=response.getText();
docReq = XMLParser.parse(xmlStrReq);
System.out.println(xmlStrReq);
}
public Document getDoc() {
System.out.println(xmlStrReq);
return docReq;
}
}
}

The entrypoint's onModuleLoad() method:
public void onModuleLoad() {
  

  XmlParserUtil xmlParser = new XmlParserUtil(image_uris.xml);
  Document doc = xmlParser.getDocument();

  String subject =
doc.getElementsByTagName(Image).item(0).getFirstChild().getNodeValue();
  String subject2 =
doc.getElementsByTagName(Image).item(1).getFirstChild().getNodeValue();

   ...


im very sorry for the long post. ive been tinkering with my codes for
almost an hour and I cant fix it. thanks!

On Nov 5, 12:34 pm, Sammi [EMAIL PROTECTED] wrote:
 Hi mives29,
    I just solve the problem. It's quite direct and easy.

 1. upload your xml file to any webserver, e.g.http://a.b.c/test.xml

 2. use RequestBuilder to get it. your url.

 3. String xmlStr = response.getText();

 4. use XMlParser to parse the xmlStr. that's it. Sample snippet code
 here:

     String url = test.xml;
     RequestBuilder requestBuilder = new
 RequestBuilder(RequestBuilder.GET,url);
     try {
            requestBuilder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
            }
            public void onResponseReceived(Request request, Response
 response){
                 String xmlStr=response.getText();
                 //Parse