GWT 2.6:从匿名内部类设置接口类型实例变量

时间:2014-11-12 02:25:39

标签: class gwt event-handling outer-join

我正在使用一个带有PresenterClass的GWT 2.6应用程序来驱动包含FlexTable的视图。我已将演示者中的拖放事件处理程序连接到FlexTable。细胞可以是空的或含有条目。当拖动操作开始时,我确定正在拖动哪种类型的单元格,并且从DragStartHandler中我将外部类中的可拖动变量设置为正在拖动的类型。但是当调用DragOverHandler时,外部类中的可拖动实例字段为空。

我没有看到或理解什么?我认为匿名内部类可以访问外部类字段。

public class PresenterClass {
  private class CellId {
    int row;
    int column;
  }
  private interface Draggable {
    void beginDrag(CellId cellId);
    void canDrop(CellId cellId);
    void drop(CellId cellId);
  }
  private class VacantSelectedCells implements Draggable {
    .
    .
    .
  }
  private final VacantSelectedCells selectedCells = new SelectedCells();
  private class DraggableEntry implements Draggable {
    .
    . 
    .
  }
  private Draggable draggable;
  private final DragStartHandler dragStartHandler = new DragStartHandler() {
    @override
    public void onDragStart(DragStartEvent event) {
      // Determine what is being dragged
      if (selected cells)
        draggable = selectedCells;
      else
        draggable = new DraggableEntry();
  }
  private final DragOverHandler dragOverHandler = new DragOverHandler() {
    @override
    public void onDragOver(DragOverEvent event) {
      // find cellId for event
      if (draggable.canDrop(cellId))
        doSomething();
    }
  }

0 个答案:

没有答案