use of org.csstudio.opibuilder.editparts.IPVWidgetEditpart in project yamcs-studio by yamcs.
the class TextEditManager 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);
}
}
}
super.keyReleaseOccured(keyEvent);
}
};
editor.getControl().moveAbove(null);
return editor;
}
use of org.csstudio.opibuilder.editparts.IPVWidgetEditpart in project yamcs-studio by yamcs.
the class ArrayEditPart method hookChild.
/**
*Hook child with array index
* @param editPart
*/
protected void hookChild(final EditPart editPart, final int indexOfArrayChild, boolean directChild) {
if (editPart instanceof AbstractContainerEditpart) {
for (Object grandChild : ((AbstractContainerEditpart) editPart).getChildren()) hookChild((EditPart) grandChild, indexOfArrayChild, false);
}
AbstractWidgetModel childModel = ((AbstractBaseEditPart) editPart).getWidgetModel();
if (directChild) {
if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
for (String propId : INVISIBLE_CHILD_PROPIDS) try {
childModel.setPropertyVisibleAndSavable(propId, false, true);
} catch (NonExistPropertyException e) {
}
}
try {
childModel.setScaleOptions(false, false, false);
// $NON-NLS-1$
childModel.setPropertyValue(IPVWidgetModel.PROP_PVNAME, "");
childModel.setPropertyValue(IPVWidgetModel.PROP_BORDER_ALARMSENSITIVE, false);
} catch (NonExistPropertyException e) {
}
}
if (getExecutionMode() == ExecutionMode.RUN_MODE && editPart instanceof IPVWidgetEditpart) {
((IPVWidgetEditpart) editPart).addSetPVValueListener(new ISetPVValueListener() {
// Capture set PV value event on children and write to the PV on
// the array widget
@Override
public void beforeSetPVValue(String pvPropId, Object value) {
int index = getArrayFigure().getIndex() + indexOfArrayChild;
try {
ArrayDataType dataType = getWidgetModel().getDataType();
switch(dataType) {
case OBJECT_ARRAY:
((Object[]) valueArray)[index] = value;
break;
case DOUBLE_ARRAY:
double doubleValue;
if (value instanceof Number)
doubleValue = ((Number) value).doubleValue();
else {
doubleValue = Double.valueOf(value.toString());
}
((double[]) valueArray)[index] = doubleValue;
break;
case BYTE_ARRAY:
byte byteValue;
if (value instanceof Number)
byteValue = ((Number) value).byteValue();
else {
byteValue = Byte.valueOf(value.toString());
}
((byte[]) valueArray)[index] = byteValue;
break;
case INT_ARRAY:
int intValue;
if (value instanceof Number)
intValue = ((Number) value).intValue();
else {
intValue = Byte.valueOf(value.toString());
}
((int[]) valueArray)[index] = intValue;
break;
case SHORT_ARRAY:
short shortValue;
if (value instanceof Number)
shortValue = ((Number) value).shortValue();
else {
shortValue = Short.valueOf(value.toString());
}
((short[]) valueArray)[index] = shortValue;
break;
case FLOAT_ARRAY:
float floatValue;
if (value instanceof Number)
floatValue = ((Number) value).floatValue();
else {
floatValue = Float.valueOf(value.toString());
}
((float[]) valueArray)[index] = floatValue;
break;
case LONG_ARRAY:
long longValue;
if (value instanceof Number)
longValue = ((Number) value).longValue();
else {
longValue = Long.valueOf(value.toString());
}
((long[]) valueArray)[index] = longValue;
break;
case STRING_ARRAY:
((String[]) valueArray)[index] = value.toString();
break;
default:
break;
}
if (getPV() != null)
// but EPICS PV doesn't support write long[]. should be removed after switched to pv manager
if (valueArray instanceof long[]) {
int[] temp = new int[((long[]) valueArray).length];
for (int i = 0; i < ((long[]) valueArray).length; i++) temp[i] = (int) ((long[]) valueArray)[i];
setPVValue(ArrayModel.PROP_PVNAME, temp);
} else
setPVValue(ArrayModel.PROP_PVNAME, valueArray);
} catch (NumberFormatException e) {
String msg = NLS.bind("Writing failed: The input data {0} is not compatible with array data type.", value.toString());
// recover the original data in children widgets.
setValue(getValue());
ErrorHandlerUtil.handleError(msg, e);
}
}
});
}
}
use of org.csstudio.opibuilder.editparts.IPVWidgetEditpart 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.csstudio.opibuilder.editparts.IPVWidgetEditpart in project yamcs-studio by yamcs.
the class WritePVAction method run.
@Override
public void run() {
display = null;
if (getWidgetModel() != null) {
display = getWidgetModel().getRootDisplayModel().getViewer().getControl().getDisplay();
} else {
display = DisplayUtils.getDisplay();
}
if (!getConfirmMessage().isEmpty())
if (!GUIUtil.openConfirmDialog("PV Name: " + getPVName() + "\nNew Value: " + getValue() + "\n\n" + getConfirmMessage()))
return;
// If it has the same nave as widget PV name, use it.
if (getWidgetModel() instanceof IPVWidgetModel) {
String mainPVName = ((IPVWidgetModel) getWidgetModel()).getPVName();
if (getPVName().equals(mainPVName)) {
Object o = getWidgetModel().getRootDisplayModel().getViewer().getEditPartRegistry().get(getWidgetModel());
if (o instanceof IPVWidgetEditpart) {
((IPVWidgetEditpart) o).setPVValue(IPVWidgetModel.PROP_PVNAME, getValue().trim());
return;
}
}
}
Job job = new Job(getDescription()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
return writePVInSync();
}
};
job.schedule();
}
Aggregations