开发者

How to replace the center panel of a DockLayoutPanel in GWT?

开发者 https://www.devze.com 2023-04-11 07:49 出处:网络
From an EntryPoint class I load a custom build westPanel. From this WestPanel I would like to replace the center of the DockLayoutPanel present on my EntryPoint class.

From an EntryPoint class I load a custom build westPanel. From this WestPanel I would like to replace the center of the DockLayoutPanel present on my EntryPoint class.

Here is my EntryPoint class:

public class MainEntryPoint implements EntryPoint {
    private VerticalPanel mainPanel = new VerticalPanel();
    private DockLayoutPanel dockLayoutPanel = new DockLayoutPanel(Unit.EM);
    private NorthMenu northMenu = new NorthMenu();
    private VerticalPanel mainPanel = new VerticalPanel();
    //other panels

    @Override
    public void onModuleLoad() {
        dockLayoutPanel.addNorth(northMenu, 40);
        dockLayoutPanel.add(mainPanel);
        //add other panels
        RootLayoutPanel panel = RootLayoutPanel.get();
        panel.add(dockLayoutPanel);     
    }
}

WestPanel should replace DockLayout's mainPanel with a MyOtherPanel:

public class WestMenu extends Composite {
    private StackLayoutPanel stack开发者_StackOverflow中文版LayoutPanel = new StackLayoutPanel(Unit.EM);  
    public WestMenu(){  
        Tree configuration = new Tree();
        configuration.addSelectionHandler( new SelectionHandler(){
            @Override
            public void onSelection(SelectionEvent event) {
                MyOtherPanel builderPanel = new MyOtherPanel();
                RootLayoutPanel panel = RootLayoutPanel.get();
                DockLayoutPanel dlp = (DockLayoutPanel)panel.getWidget(0);
                dlp.add(builderPanel);
            }           
        });
        //other init configurations
        initWidget(stackLayoutPanel);
    }   
} 

I keep on getting an Exception saying that I can not replace it. What is the best way to replace/change the center panel of a DockLayoutPanel?

thanks.


You need to explicitly remove the center (see javadoc of the protected insert method in DockLayoutPanel):

dlp.remove(currentCenterPanel);

But that's not very developer friendly, as you need to keep track of the center widget and always make sure you call remove before adding. I don't know why they did it like this.

Another solution could be to simple put a SimpleLayoutPanel as center widget and set your own center widget on this panel, via setWidget. That way you don't have to do the remove.

The latter technique also makes it possible to combine the implementation with the ActivityManager by setting the SimpleLayoutPanel as the display in ActivityManager.setDiplay(...). As your implementation looks like the main content of your application, the ActiviyManager might be useful here.

0

精彩评论

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

关注公众号