0

简介:
我编写了一个 Eclipse 插件,其中包含一个我用GEF实现的编辑器。我的编辑器中有节点和边。节点有名称,我想通过直接编辑来编辑节点的名称。

我将直接编辑策略安装到节点编辑部分:

installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new NodeNameDirectEditPolicy());

直接编辑策略执行直接编辑命令。

问题是: 要确认直接编辑,我必须按 STRG + ENTER。如果我只按 ENTER,则直接编辑将扩展为新行。有什么方法可以使直接编辑可以简单地用 ENTER 确认?不需要多行节点名称。

4

1 回答 1

1

您应该能够通过TextCellEditor(Composite parent, int style)在自己的扩展中扩展构造函数来实现它TextCellEditor

createCellEditorOn(Composite composite)然后,在你的扩展类中调用时DirectEditManager,让它返回new YOURTextCellEditor(composite, SWT.SINGLE)

详细地说:

你自己TextCellEditor的构造函数实现

public YOURTextCellEditor(Composite parent, int style) {
  super(parent, style);
}

createCellEditorOn(Composite composite)在 DirectEditManager 的实现中

@Override
protected CellEditor createCellEditorOn(Composite composite) {
    return new YOURTextCellEditor(composite, SWT.SINGLE);
}

YOURTextCellEditor也许检查您是否返回withSWT.MULTI或类似的新实例SWT.MULTI|SWT.WRAP,这使您的文本单元格编辑器的 SWT 控件成为多行文本小部件(参见SWT 小部件概述)。

于 2013-09-10T12:57:29.970 回答