Gridview Vaadin网格进入/离开编辑模式的侦听器?

Gridview Vaadin网格进入/离开编辑模式的侦听器?,gridview,vaadin,Gridview,Vaadin,我想在vaadin网格进入编辑模式时启用/禁用一些复选框 不幸的是,我找不到正确的钩子。我得到的最接近的是SelectionListener,但它与编辑模式不匹配 grid.addSelectionListener(new SelectionListener() { ... } ); 当网格进入编辑模式时,有没有办法获取事件?对于Vaadin 8 对于vaadin8您可以扩展网格,并返回一个自定义的编辑器(据我所知,目前还没有实现用于捕获启动事件的侦听器) 此外,您还可以添加cancel&sa

我想在vaadin网格进入编辑模式时启用/禁用一些复选框

不幸的是,我找不到正确的钩子。我得到的最接近的是SelectionListener,但它与编辑模式不匹配

grid.addSelectionListener(new SelectionListener() { ... } );
当网格进入编辑模式时,有没有办法获取事件?

对于Vaadin 8 对于vaadin8您可以扩展
网格
,并返回一个自定义的
编辑器
(据我所知,目前还没有实现用于捕获启动事件的侦听器)

此外,您还可以添加cancel&save侦听器(已由框架实现)以查看编辑器是否已关闭


CustomEditor.java

public class CustomEditor<T> extends EditorImpl<T> {

  private EventRouter eventRouter = new EventRouter();

  public CustomEditor(PropertySet<T> propertySet) {
    super(propertySet);
  }

  public Registration addStartListener(EditorStartListener<T> listener) {
    return eventRouter.addListener(EditorStartEvent.class, listener,
                                   EditorStartListener.class.getDeclaredMethods()[0]);
  }

  @Override
  protected void doEdit(T bean) {
    super.doEdit(bean);
    fireToggleEvent(bean);
  }

  private void fireToggleEvent(T bean) {
    eventRouter.fireEvent(new EditorStartEvent<>(this, bean));
  }
}
@FunctionalInterface
public interface EditorStartListener<T> extends Serializable {

  void onEditorStart(EditorStartEvent<T> event);
}
public class EditorStartEvent<T> extends EventObject {

  private T bean;

  public EditorStartEvent(Editor<T> editor, T bean) {
    super(editor);
    this.bean = bean;
  }

  @SuppressWarnings("unchecked")
  @Override
  public Editor<T> getSource() {
    return (Editor<T>) super.getSource();
  }

  public Grid<T> getGrid() {
    return getSource().getGrid();
  }

  public T getBean() {
    return bean;
  }
}
public class CustomGrid<T> extends Grid<T> {

  private PropertySet<T> propertySet;

  public CustomGrid() {
    super();
  }

  // Other constructors omitted for clarity

  @Override
  protected void setPropertySet(PropertySet<T> propertySet) {
    this.propertySet = propertySet;
    super.setPropertySet(propertySet);
  }

  @Override
  protected Editor<T> createEditor() {
    return new CustomEditor<T>(propertySet);
  }
}
public interface EditStartListener extends Serializable {

    public static final Method EDIT_START_METHOD = ReflectTools.findMethod(EditStartListener.class, "editStart", EditStartEvent.class);

    public void editStart(EditStartEvent event);

}
public class CustomGrid extends Grid {

    public void addEditStartListener(EditStartListener listener) {
      addListener(EditStartEvent.class, listener, EditStartListener.EDIT_START_METHOD);
    }

    @Override
    protected void doEditItem() {
      super.doEditItem();
      fireEvent(new EditStartEvent(this));
    }
}

EditStartEvent.java

public class EditStartEvent extends Component.Event {

    public EditStartEvent(Component source) {
      super(source);
    }

    public Grid getGrid() {
      return (Grid) getSource();
    }
}

CustomGrid.java

public class CustomEditor<T> extends EditorImpl<T> {

  private EventRouter eventRouter = new EventRouter();

  public CustomEditor(PropertySet<T> propertySet) {
    super(propertySet);
  }

  public Registration addStartListener(EditorStartListener<T> listener) {
    return eventRouter.addListener(EditorStartEvent.class, listener,
                                   EditorStartListener.class.getDeclaredMethods()[0]);
  }

  @Override
  protected void doEdit(T bean) {
    super.doEdit(bean);
    fireToggleEvent(bean);
  }

  private void fireToggleEvent(T bean) {
    eventRouter.fireEvent(new EditorStartEvent<>(this, bean));
  }
}
@FunctionalInterface
public interface EditorStartListener<T> extends Serializable {

  void onEditorStart(EditorStartEvent<T> event);
}
public class EditorStartEvent<T> extends EventObject {

  private T bean;

  public EditorStartEvent(Editor<T> editor, T bean) {
    super(editor);
    this.bean = bean;
  }

  @SuppressWarnings("unchecked")
  @Override
  public Editor<T> getSource() {
    return (Editor<T>) super.getSource();
  }

  public Grid<T> getGrid() {
    return getSource().getGrid();
  }

  public T getBean() {
    return bean;
  }
}
public class CustomGrid<T> extends Grid<T> {

  private PropertySet<T> propertySet;

  public CustomGrid() {
    super();
  }

  // Other constructors omitted for clarity

  @Override
  protected void setPropertySet(PropertySet<T> propertySet) {
    this.propertySet = propertySet;
    super.setPropertySet(propertySet);
  }

  @Override
  protected Editor<T> createEditor() {
    return new CustomEditor<T>(propertySet);
  }
}
public interface EditStartListener extends Serializable {

    public static final Method EDIT_START_METHOD = ReflectTools.findMethod(EditStartListener.class, "editStart", EditStartEvent.class);

    public void editStart(EditStartEvent event);

}
public class CustomGrid extends Grid {

    public void addEditStartListener(EditStartListener listener) {
      addListener(EditStartEvent.class, listener, EditStartListener.EDIT_START_METHOD);
    }

    @Override
    protected void doEditItem() {
      super.doEditItem();
      fireEvent(new EditStartEvent(this));
    }
}