0

我有一个 GXT 2.x 应用程序,它带有一个呈现单独 LayoutContainer 的菜单栏项。

这是层次结构 MainUI.java -> MenuBar.java -> ReservationPopUp.java

我已经用 LayoutContainer 实现的已知工作示例替换了我的 ReservationPopUp.java 内容,它们响应 ESC 键和“X”按钮。

这是 MenuItem 如何呈现 ReservationPopUp.java

MenuItem mntmReserve = new MenuItem("Reserve"); 
mntmReserve.addSelectionListener(new SelectionListener<MenuEvent>() {
    public void componentSelected(MenuEvent ce) {
        RootPanel.get().add(new ReservationPopUp());

}

这是我的 ReservationPopUp.java 的精简版

public class ReservationPopUp extends LayoutContainer  {
public ReservationPopUp() {
}

@Override  
  protected void onRender(Element parent, int pos) {  

    super.onRender(parent, pos);
    setSize("1024", "809");
    final Window window = new Window();
    window.setDraggable(false);
    window.setSize(537, 399);  
    window.setPlain(true);  
    window.setModal(true);  
    window.setBlinkModal(true);  
    window.setHeading("Reserve A Server");
    window.setClosable(true);
    window.setOnEsc(true);
    window.setSize("465", "345");
    window.setLayout(new AbsoluteLayout());

    LabelField lblfldUsers = new LabelField("Users");
    window.add(lblfldUsers, new AbsoluteData(43, 218));
    final ComboBox<AsyncUser> userList = new ComboBox<AsyncUser>();

    window.add(userList, new AbsoluteData(81, 218));
    userList.setEmptyText("Select a User...");
    userList.setSize("347px", "24px");

    LabelField labelServers = new LabelField("Servers");
    window.add(labelServers, new AbsoluteData(32, 6));

    final DualListField<AsyncServer> serverList = new DualListField<AsyncServer>();  
        ....
    window.add(serverList, new AbsoluteData(81, 6));
    serverList.setSize("347px", "206px");

    window.addButton(new Button("Cancel", new SelectionListener<ButtonEvent>() {  
          @Override  
          public void componentSelected(ButtonEvent ce) {  
            ReservationPopUp.this.hide();  
          }  
    }));

    window.addButton(new Button("Reserve", new SelectionListener<ButtonEvent>() {  
          @Override  
          public void componentSelected(ButtonEvent ce) {
            if (serverList.getToList().getListView().getItemCount() == 0 ) {
                MessageBox.alert("Invalid Selection","No Server(s) Selected", null);
            } else if ( userList.getValue() == null) {

            } else {
                // DO some stuff
                ReservationPopUp.this.hide();  
            }
          }  
        }));

    window.addWindowListener(new WindowListener() {  
        @Override  
        public void windowHide(WindowEvent we) {
            ReservationPopUp.this.hide();
        }  
      }); 
    window.setFocusWidget(window.getButtonBar().getItem(0));
    add(window);

}

}

4

1 回答 1

2

Window是一个弹出窗口,它不需要(也不应该)添加到任何东西。扩展Window类而不是LayoutContainer,而不是添加ReservationPopup到页面,只需调用Window.show().

于 2012-04-19T03:05:47.813 回答