How to Remove widgets/panel from DockPanel.CENTER

306 views
Skip to first unread message
Message has been deleted

mixtou

unread,
Jan 16, 2008, 2:25:08 AM1/16/08
to Google Web Toolkit
I am creating a portal application Using GWT and i have created a
MenuBar in order to update accordingly my DockPanel.CENTER when a
menuItem is clicked.
The first time i click on a menu item everything works fine. However
when i click a second menu item i get the message that in
DockPanel.CENTER only one panel/widget is allowed.
So i want to check if a widget/panel is available in my
DockPanel.CENTER in order to remove it before adding a new component.
I am trying to implement this by using a public variable of the class
implementing the EntryPoint of type int with initial default value
(-1) called widget_index which holds the index of the widget added to
the dock. Then by checking this value i am trying to remove the
corresponding widget. However this doesn't work. I get unhadled event.
The menuItems code is as follows:
menu.addItem("<hr>", true, (Command)null);
menu.addItem("News", new cmd("Νews"));
menu.addItem("<hr>", true, (Command)null);
menu.addItem("Forum", new cmd("Forum"));
menu.addItem("<hr>", true, (Command)null);
menu.addItem("Login", new cmd("Login"));
menu.addItem("<hr>", true, (Command)null);
menu.addItem("Sign In", new cmd("Sign In"));
menu.addItem("<hr>", true, (Command)null);
panel.add(menu);
My code sample in command executed when a menu item is clicked is
shown below

public class cmd implements Command{
private String name = null;


public cmd(String text){
this.name=text;
}

public void execute(){

if(this.name == "Login"){
if(widget_index != -1){
dock.remove(widget_index);
}


final LoginPanel panel = new LoginPanel();
dock.add( panel , DockPanel.CENTER);
widget_index = dock.getWidgetIndex(panel);
dock.setCellHorizontalAlignment(panel, DockPanel.ALIGN_CENTER);

}
else if (this.name == "News") {
if(widget_index != -1){
dock.remove(widget_index);
}

final Label label = new Label("Νέα");
widget_index = dock.getWidgetIndex(label);
dock.add(label, DockPanel.CENTER);

}
else if (this.name == "Forum") {
if(widget_index != -1){
dock.remove(widget_index);
}

final Label label = new Label("Forum");
widget_index = dock.getWidgetIndex(label);
dock.add(label, DockPanel.CENTER);
}
}
}

Thanks in advance.

walden

unread,
Jan 16, 2008, 9:16:03 AM1/16/08
to Google Web Toolkit
mixtou,

I'm not sure exactly what you are trying to do with an integer index,
but it can be simpler if you just keep a reference to the widget.

Widget centerWidget;
DockPanel dp;

...

public void execute() {
if (centerWidget != null) {
dp.remove(centerWidget);
dp.add(centerWidget = new MyOtherWidget(), DockPanel.CENTER)
}

Walden
Reply all
Reply to author
Forward
0 new messages