use of org.eclipse.jface.viewers.TextCellEditor in project yamcs-studio by yamcs.
the class SpinnerTextEditManager method createCellEditorOn.
@Override
protected CellEditor createCellEditorOn(Composite composite) {
CellEditor editor = new TextCellEditor(composite, (multiLine ? SWT.MULTI : SWT.SINGLE) | SWT.WRAP) {
@Override
protected void focusLost() {
// lose focus should cancel the editing.
if (editPart.getExecutionMode() == ExecutionMode.RUN_MODE && editPart instanceof IPVWidgetEditpart && ((IPVWidgetEditpart) editPart).getPV() != null) {
if (isActivated()) {
fireCancelEditor();
deactivate();
}
editPart.getFigure().requestFocus();
} else
super.focusLost();
}
@Override
protected void handleDefaultSelection(SelectionEvent event) {
// In run mode, hit ENTER should force to write the new value even it doesn't change.
if (editPart.getExecutionMode() == ExecutionMode.RUN_MODE) {
setDirty(true);
}
super.handleDefaultSelection(event);
}
@Override
protected void keyReleaseOccured(KeyEvent keyEvent) {
// In run mode, CTRL+ENTER will always perform a write if it is multiline text input
if (keyEvent.character == '\r' && editPart.getExecutionMode() == ExecutionMode.RUN_MODE) {
// Return key
if (text != null && !text.isDisposed() && (text.getStyle() & SWT.MULTI) != 0) {
if ((keyEvent.stateMask & SWT.CTRL) != 0) {
setDirty(true);
}
}
}
if (keyEvent.keyCode == SWT.ARROW_UP) {
doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) + step_increment));
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
stack.execute(getEditPart().getCommand(getDirectEditRequest()));
}
if (keyEvent.keyCode == SWT.ARROW_DOWN) {
doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) - step_increment));
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
stack.execute(getEditPart().getCommand(getDirectEditRequest()));
}
if (keyEvent.keyCode == SWT.PAGE_UP) {
doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) + page_increment));
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
stack.execute(getEditPart().getCommand(getDirectEditRequest()));
}
if (keyEvent.keyCode == SWT.PAGE_DOWN) {
doSetValue(String.valueOf(Double.valueOf(doGetValue().toString()) - page_increment));
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
stack.execute(getEditPart().getCommand(getDirectEditRequest()));
}
super.keyReleaseOccured(keyEvent);
}
};
editor.getControl().moveAbove(null);
return editor;
}
Aggregations