tags:

views:

289

answers:

2

Hi,

I am a GWT newbie so please bear with me.

I am trying to implement a HorizontalPanel from within a onModuleLoad() where the left side is a simple navigation menu.

However, I wish to load the right-hand side of the panel depeneding on what the user selects in the navigation menu. This is simple enough in one HUGE class, but I wish to write a class for each navigation option.

For example:

  1. User clicks option1 in left menu, instantiate Option1 object from Option1 class and add it to the right hand pane.
  2. User clicks option2 in left menu, instantiate Option2 object from Option2 class and overide whatever was in the right hand pane previously.

Can this be done without creating a bespoke widget for each Option?

If so how? please help!

Your help is appreciated!

Harperonline

A: 

Assuming you're using a HorizontalSplitPane, you can do the following:

Option2:

HorizPanel.getRightWidget().removeFromParent(); 
HorizPanel.setRightWidget( new Option2() );

Option1:

 Widget W = HorizPanel.getRightWidget(); 
 w.add( new Option1() );

Other than that, I'm not sure exactly what you're asking. You have to keep track of the element you want to update in some fashion. But GWT gives you the ability to override already created widgets, so what you're doing shouldn't be impossible.

Chris Kaminski
Thanks. I like the idea of:HorizPanel.getRightWidget().removeFromParent(); HorizPanel.setRightWidget( new Option2() );As the HorizontalPanel will only be 2 cells accross so I can just stomp over what is in the right panel when the user selects a new option in the left nav menu.Cheers!
Happy to help! I'm just getting started with GWT as well, so this was actually quite useful to me. Regards.
Chris Kaminski
A: 

Simply create a public static class Widget variable (public static Widget contentPanel = new VerticalPanel()) on your GWT start class. Add this widget to the right of the horizontal panel. Then when you click the left navigation you just create the each of their class as you need to and make the class constructor to call contentPanel.clear() and finally contentPanel.add().

If you want to simplify the process. You can have your individual content classes implement a common abstract class to handle all the common works.

Ning120