替换GWT DockLayoutPanel内容 [英] Replace GWT DockLayoutPanel Contents

查看:93
本文介绍了替换GWT DockLayoutPanel内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从MenuBar中替换DockLayoutPanel的CENTER部分的内容。 MenuBar将坐在北部,但内容(表单,报告等)将驻留在中心。



我想我可以通过从RootPanel抓取整个DockLayoutPanel(索引0,因为这是唯一直接附加到它的小部件),然后以某种方式删除当前内容中心并插入新的。不幸的是,getWidget(int index)是非静态的,所以它不起作用。

任何人都可以用正确的方式来做到这一点吗?非工作代码如下:

  //剪切包和导入详细信息

公共类menubar扩展复合{

私人静态menubarUiBinder uiBinder = GWT.create(menubarUiBinder.class);

接口menubarUiBinder扩展了UiBinder< Widget,menubar> {
}

@UiField MenuBar applicationMenuBar;
@UiField MenuBar processMenuBar;
@UiField MenuBar reportsMenuBar;
@UiField MenuItem addPowerRequirementCmd;
@UiField MenuItem powerUsageReportCmd;

public menubar(){
initWidget(uiBinder.createAndBindUi(this));

//用于替换DockLayoutPanel.CENTER中的任何内容w AddPowerRequirement
FormPanel $ b $ addPowerRequirementCmd.setCommand(new Command(){

@Override
public void execute(){

//从RootPanel获取DockLayoutPanel(它是唯一的部件,应该是
//索引0
DockLayoutPanel dlp = (DockLayoutPanel)RootPanel.getWidget(0);

//清除DockLayoutPanel.CENTER

//将FormLayoutPanel插入DockLayoutPanel.CENTER
dlp.add(新的PowerRequirementForm());
}
});

//用于替换DockLayoutPanel.CENTER带电量报告的命令
powerUsageReportCmd.setCommand( new Command(){

@Override
public void execute(){
$ b}
});
}

}



谢谢!

解决方案使用 ui:field 属性,就像您对MenuBar所做的那样通过UiBinder获得对DockLayoutPanel的引用:

 < g:DockLayoutPanel ui:field =dockPanel/> 

以及在课程中:

  @UiField DockLayoutPanel dockPanel; 

然而,这听起来像你想要一组小部件显示在面板取决于应用程序状态。 DeckPanel 是更好的解决方案:

 < g:DockLayoutPanel> 
< g:FlowPanel> Panel#0< / g:FlowPanel>
< g:FlowPanel>面板#1< / g:FlowPanel>
< / g:DeckPanel>
< / g:center>
< / g:DockLayoutPanel>

然后切换显示的DeckPanel的子元素:

  deck.showWidget(1); //显示面板#1 
deck.showWidget(0); // Show panel#0


I'm trying to replace the contents of the CENTER portion of a DockLayoutPanel from a MenuBar. The MenuBar will sit at the North, but "content" (forms, reports, etc) will reside in Center.

I thought I could do it by grabbing the entire DockLayoutPanel from the RootPanel (index 0, since that's the only widget directly attached to it), then somehow remove the current contents of center and insert the new. Unfortunately, getWidget(int index) is non-static, so it's not working.

Can anyone how me with the right way to do this? Non-working code is below:

// snipped package and import details

public class menubar extends Composite {

private static menubarUiBinder uiBinder = GWT.create(menubarUiBinder.class);

interface menubarUiBinder extends UiBinder<Widget, menubar> {
}

@UiField MenuBar applicationMenuBar;
@UiField MenuBar processMenuBar;
@UiField MenuBar reportsMenuBar;
@UiField MenuItem addPowerRequirementCmd;
@UiField MenuItem powerUsageReportCmd;

public menubar() {
    initWidget(uiBinder.createAndBindUi(this));

    // command to replace whatever is in DockLayoutPanel.CENTER w/ AddPowerRequirement
    // FormPanel
    addPowerRequirementCmd.setCommand(new Command() {

        @Override
        public void execute() {

            // get DockLayoutPanel from the RootPanel (it's the only widget, should be
            // index 0
            DockLayoutPanel dlp = (DockLayoutPanel) RootPanel.getWidget(0);

            // clear out DockLayoutPanel.CENTER

            // insert the FormLayoutPanel into DockLayoutPanel.CENTER
            dlp.add(new PowerRequirementForm());
        }
    });

    // command to replace whatever is in DockLayoutPanel.CENTER w/ power usage report
    powerUsageReportCmd.setCommand(new Command() {

        @Override
        public void execute() {

        }
    });
}

}

Thanks!

解决方案

Use a ui:field attribute, like you do for the MenuBar, to get a reference to the DockLayoutPanel from UiBinder:

<g:DockLayoutPanel ui:field="dockPanel"/>

and in the class:

@UiField DockLayoutPanel dockPanel;

However, it sounds like you want to have a set of widgets that are shown in the center of the panel depending on application state. A DeckPanel is a better solution for this:

<g:DockLayoutPanel>
  <g:center>
    <g:DeckPanel ui:field="deck">
      <g:FlowPanel>Panel #0</g:FlowPanel>
      <g:FlowPanel>Panel #1</g:FlowPanel>
    </g:DeckPanel>
  </g:center>
</g:DockLayoutPanel>

And then to switch the displayed child of the DeckPanel:

 deck.showWidget(1); // Show Panel #1
 deck.showWidget(0); // Show panel #0

这篇关于替换GWT DockLayoutPanel内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆