Search in sources :

Example 1 with AbstractContainerEditpart

use of org.csstudio.opibuilder.editparts.AbstractContainerEditpart in project yamcs-studio by yamcs.

the class SelectParentAction method run.

@Override
public void run(IAction action) {
    AbstractContainerEditpart containerEditpart = getParentContainerEditpart();
    containerEditpart.getViewer().select(containerEditpart);
}
Also used : AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart)

Example 2 with AbstractContainerEditpart

use of org.csstudio.opibuilder.editparts.AbstractContainerEditpart 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);
                }
            }
        });
    }
}
Also used : NonExistPropertyException(org.csstudio.opibuilder.model.NonExistPropertyException) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) VString(org.diirt.vtype.VString) IPVWidgetEditpart(org.csstudio.opibuilder.editparts.IPVWidgetEditpart) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) ArrayDataType(org.csstudio.opibuilder.widgets.model.ArrayModel.ArrayDataType)

Example 3 with AbstractContainerEditpart

use of org.csstudio.opibuilder.editparts.AbstractContainerEditpart in project yamcs-studio by yamcs.

the class DropPVtoContainerEditPolicy method getCommand.

@Override
public Command getCommand(Request request) {
    if (request.getType() == DropPVRequest.REQ_DROP_PV && request instanceof DropPVRequest) {
        var dropPVRequest = (DropPVRequest) request;
        if (dropPVRequest.getTargetWidget() != null && dropPVRequest.getTargetWidget() instanceof AbstractContainerEditpart) {
            var dialog = new WidgetsSelectDialog(getHost().getViewer().getControl().getShell(), dropPVRequest.getPvNames().length, true);
            if (dialog.open() == Window.OK) {
                var typeID = dialog.getOutput();
                var command = new CompoundCommand("Create Widget");
                var pvNames = dropPVRequest.getPvNames();
                var location = dropPVRequest.getLocation().getCopy();
                var container = ((AbstractContainerEditpart) dropPVRequest.getTargetWidget()).getWidgetModel();
                var parent = container.getParent();
                var temp = container;
                while (parent != null) {
                    location.translate(temp.getLocation().getNegated());
                    temp = parent;
                    parent = parent.getParent();
                }
                var i = 1;
                int lastWidth = 0, lastHeight = 0;
                for (var pvName : pvNames) {
                    var widgetModel = WidgetsService.getInstance().getWidgetDescriptor(typeID).getWidgetModel();
                    command.add(new WidgetCreateCommand(widgetModel, container, new Rectangle(location.getCopy().translate(lastWidth, lastHeight), new Dimension(-1, -1)), i != 1, true));
                    command.add(new SetWidgetPropertyCommand(widgetModel, AbstractPVWidgetModel.PROP_PVNAME, pvName.trim()));
                    if (i % WIDGETS_ACCOUNT_ON_A_ROW == 0) {
                        lastWidth = 0;
                        lastHeight += widgetModel.getHeight();
                    } else {
                        lastWidth += widgetModel.getWidth();
                    }
                    i++;
                }
                return command;
            }
        }
    }
    return null;
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) WidgetsSelectDialog(org.csstudio.opibuilder.visualparts.WidgetsSelectDialog) Dimension(org.eclipse.draw2d.geometry.Dimension) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand)

Aggregations

AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)3 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)1 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 IPVWidgetEditpart (org.csstudio.opibuilder.editparts.IPVWidgetEditpart)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 NonExistPropertyException (org.csstudio.opibuilder.model.NonExistPropertyException)1 WidgetsSelectDialog (org.csstudio.opibuilder.visualparts.WidgetsSelectDialog)1 ArrayDataType (org.csstudio.opibuilder.widgets.model.ArrayModel.ArrayDataType)1 VString (org.diirt.vtype.VString)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 EditPart (org.eclipse.gef.EditPart)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1