开发者

GWT: Loading contents of a panel from another class

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 d开发者_如何学运维one without creating a bespoke widget for each Option?

If so how? please help!

Your help is appreciated!

Harperonline


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜