want to develop a page which has multiple views and the ability to
switch between the views. To test out this idea I cam up with the
following code (see below) using RootPanel.clear() method. This does
work but it starts to slow down after a few switches, it seems that
the clear method creates its own overhead which grows as it is used.
Any thoughts on how to overcome this would be appreciated. (I would
like to stay with Java for the fix and not have to move to xml or HTML
complex solutions if possible).
The code is below, entry point is to another class which I am using
just a simple entry point to the application much like public static
void main (String [] args) is used in Java. The entry point calls
this GUI class.
public class GUI {
RootPanel rootPanel;
private Label viewOneLabel = new Label("This is view one");
private Label viewTwoLabel = new Label("This is view two");
private Button viewOneButton = new Button("Switch to view two");
private Button viewTwoButton = new Button("Switch to view one");
private boolean viewOne = true;
FlowPanel verticalPanelOne = new FlowPanel();
FlowPanel verticalPanelTwo = new FlowPanel();
public GUI(){
rootPanel = RootPanel.get("content");
rootPanel.getElement().getStyle().setPosition(Position.RELATIVE);
buildViewOne();
}
private void buildViewOne(){
verticalPanelOne.setSize("900px", "1200px");
verticalPanelOne.add(viewOneLabel);
viewOneButton.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
viewOne=false;
switchView();
}});
verticalPanelOne.add(viewOneButton);
viewOne=true;
rootPanel.clear();
rootPanel.add(verticalPanelOne);
}
private void buildViewTwo(){
verticalPanelTwo.setSize("900px", "1200px");
verticalPanelTwo.add(viewTwoLabel);
viewTwoButton.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
viewOne=true;
switchView();
}});
verticalPanelTwo.add(viewTwoButton);
viewOne=false;
rootPanel.clear();
rootPanel.add(verticalPanelTwo);
}
public void switchView(){
if(viewOne){
buildViewOne();
}else{
buildViewTwo();
}
}
}
--
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 google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment