Direct Edit Confirmation in GEF EditParts

184 views Asked by At

Introduction:
I write an Eclipse plugin containing an editor which I implement with GEF. I have nodes and edges in my editor. The nodes have names and I want to edit the name of the nodes via direct edit.

I install the direct edit policy to the node edit parts:

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

and the direct edit policy implements the direct edit command.

The problem is: To confirm the direct edit I have to press STRG + ENTER. If I only press ENTER the direct edit is expanded to a new line. Is there any way to make it possible that the direct edit can be confirmed simply with ENTER? multiline node names are not needed.

1

There are 1 answers

1
s.d On BEST ANSWER

You should be able to achieve it by extending the TextCellEditor(Composite parent, int style) constructor in your own extension of TextCellEditor.

Then, when calling createCellEditorOn(Composite composite) in your DirectEditManager extension class, let it return new YOURTextCellEditor(composite, SWT.SINGLE).

Verbosely:

Your own implementation of TextCellEditor's constructor

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

createCellEditorOn(Composite composite) in your implementation of DirectEditManager`

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

Perhaps check if you return a new instance of YOURTextCellEditor with SWT.MULTI or SWT.MULTI|SWT.WRAP or similar, this makes your text cell editor's SWT control a multi-line text widget (cf. SWT Widgets overview).