Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse插件-是否有任何可编辑的TreeSelection类_Eclipse_Eclipse Plugin - Fatal编程技术网

Eclipse插件-是否有任何可编辑的TreeSelection类

Eclipse插件-是否有任何可编辑的TreeSelection类,eclipse,eclipse-plugin,Eclipse,Eclipse Plugin,我正在寻找一种解决方案,使此树选择在PackageExplorer视图本身中可编辑 想法 例如,如果我们在PackageExplorer中的任何类上单击rename,它将提示一个新窗口进行重命名。此功能对于实现TreeSelection类的任何类都是相同的 但是我正在寻找的解决方案是——当调用rename时,rename选项显示在树本身(就像我们在Windows资源管理器视图中看到的那样) 关于如何在eclipse上实现此行为的任何建议 您不需要特殊的可编辑选择,只需要使树可编辑即可。为此,您可

我正在寻找一种解决方案,使此树选择在PackageExplorer视图本身中可编辑

想法

例如,如果我们在PackageExplorer中的任何类上单击rename,它将提示一个新窗口进行重命名。此功能对于实现TreeSelection类的任何类都是相同的

但是我正在寻找的解决方案是——当调用rename时,rename选项显示在树本身(就像我们在Windows资源管理器视图中看到的那样)

关于如何在eclipse上实现此行为的任何建议


您不需要特殊的可编辑选择,只需要使树可编辑即可。为此,您可以使用
编辑支持
,如下所示(改编自):

public class NameEditingSupport extends EditingSupport {
  private final TreeViewer viewer;

  public FirstNameEditingSupport(TreeViewer viewer) {
    super(viewer);
    this.viewer = viewer;
  }

  @Override
  protected CellEditor getCellEditor(Object element) {
    return new TextCellEditor(viewer.getTree());
  }

  @Override
  protected boolean canEdit(Object element) {
    return true;
  }

  @Override
  protected Object getValue(Object element) {
    // return the name
  }

  @Override
  protected void setValue(Object element, Object value) {
    // update the name of your object
    viewer.update(element, null);
  }
} 

// in the code creating the tree
treeViewer.setEditingSupport(new NameEditingSupport(treeViewer));