GXT:LayoutContainer不响应ESC键或“X”按钮关闭

时间:2012-04-19 01:56:46

标签: gwt gxt

我有一个带有菜单栏项目的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);

}

}

1 个答案:

答案 0 :(得分:2)

Window是一个弹出窗口,不需要(也不应该)添加到任何内容中。扩展Window类而不是LayoutContainer,而不是将ReservationPopup添加到页面,只需致电Window.show()