简体   繁体   English

GWT使用小部件和事件

[英]GWT work with widgets and events

I m working with GWT 2.4 on an new application. 我米,GWT 2.4的新应用程序的工作。 I made a docklayoutpanel and I inserted a celllist on the west section of it. 我做了一个docklayoutpanel,并在它的西段插入了一个单元格列表。 I need to create an event, every time a user clicks on an element of celllist on the west side of page a specific widget will load at the content of the docklayoutpanel. 我需要创建一个事件,每次用户单击页面西侧的单元格列表元素时,都会在docklayoutpanel的内容中加载特定的小部件。

Any suggestions? 有什么建议么?

Thank you 谢谢

The following example should be self explanatory 以下示例应为自我解释

// Create a cell to render each value.
TextCell textCell = new TextCell();

// Create a CellList that uses the cell.
CellList<String> cellList = new CellList<String>(textCell);
cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

// Add a selection model to handle user selection.
final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();
cellList.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
  public void onSelectionChange(SelectionChangeEvent event) {
    String selected = selectionModel.getSelectedObject();
    if (selected != null) {
      Window.alert("You selected: " + selected);
    }
  }
});

Instead of Window.alert("You selected: " + selected); 代替Window.alert("You selected: " + selected); you will need to change the widget shown on the eastern side of your panel. 您将需要更改面板东部显示的小部件。

This can be done in several ways, one of which is to expose the Dockpanel to the Selection Change Event either by declaring the Panel as a field to the class (not a local Variable in the constructor of the class) or as a final local variable in the constructor. 这可以通过多种方式完成,其中一种方式是通过将Panel声明为类的字段(而不是类的构造函数中的局部变量)或作为最终的局部变量,使Dockpanel暴露于Selection Change事件。在构造函数中。

Another way is to do this by event handling. 另一种方法是通过事件处理来实现。 The eventBus methodology on the MVP design pattern is the proper way to do all thesee here for more information. 在MVP的设计模式的eventBus方法是做所有thesee有道这里了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM