use of org.eclipse.jface.viewers.CellEditor 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;
}
use of org.eclipse.jface.viewers.CellEditor in project yamcs-studio by yamcs.
the class PVWidgetSelectionHandle method createDragTracker.
@Override
protected DragTracker createDragTracker() {
DragEditPartsTracker tracker = new DragEditPartsTracker(getOwner()) {
@Override
protected boolean handleButtonDown(int button) {
if ((button == 1 || button == 3) && widgetModel instanceof IPVWidgetModel) {
DirectEditManager directEditManager = new PVNameDirectEditManager(getOwner(), new CellEditorLocator() {
@Override
public void relocate(CellEditor celleditor) {
Rectangle rect;
int width = 120;
if (!pvName.isEmpty() && getTextExtent().width > 120)
width = getTextExtent().width + 4;
rect = new Rectangle(PVWidgetSelectionHandle.this.getLocation(), new Dimension(width, getTextExtent().height));
translateToAbsolute(rect);
Text control = (Text) celleditor.getControl();
org.eclipse.swt.graphics.Rectangle trim = control.computeTrim(0, 0, 0, 0);
rect.translate(trim.x, trim.y);
rect.width += trim.width;
rect.height += trim.height;
control.setBounds(rect.x, rect.y, rect.width, rect.height);
}
});
directEditManager.show();
}
return true;
}
};
tracker.setDefaultCursor(getCursor());
return tracker;
}
Aggregations