Search in sources :

Example 31 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class WidgetTreeContainerEditPolicy method getAddCommand.

@Override
protected Command getAddCommand(ChangeBoundsRequest request) {
    var cmd = new CompoundCommand();
    var editparts = request.getEditParts();
    var index = findIndexOfTreeItemAt(request.getLocation());
    for (var i = 0; i < editparts.size(); i++) {
        var child = (EditPart) editparts.get(index >= 0 ? editparts.size() - 1 - i : i);
        if (isAncestor(child, getHost())) {
            cmd.add(UnexecutableCommand.INSTANCE);
        } else {
            var childModel = (AbstractWidgetModel) child.getModel();
            cmd.add(createCreateCommand(childModel, new Rectangle(new Point(), childModel.getSize()), index, "Reparent Widgets"));
        }
    }
    return cmd;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) EditPart(org.eclipse.gef.EditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 32 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class WidgetTreeContainerEditPolicy method getMoveChildrenCommand.

@Override
protected Command getMoveChildrenCommand(ChangeBoundsRequest request) {
    var command = new CompoundCommand();
    var editparts = request.getEditParts();
    var children = getHost().getChildren();
    var newIndex = findIndexOfTreeItemAt(request.getLocation());
    var tempIndex = newIndex;
    for (var i = 0; i < editparts.size(); i++) {
        var child = (EditPart) editparts.get(editparts.size() - 1 - i);
        var oldIndex = children.indexOf(child);
        if (oldIndex == tempIndex || oldIndex + 1 == tempIndex) {
            command.add(UnexecutableCommand.INSTANCE);
            return command;
        } else if (oldIndex <= tempIndex) {
            tempIndex--;
        }
        command.add(new ChangeOrderCommand(tempIndex, (AbstractContainerModel) getHost().getModel(), (AbstractWidgetModel) child.getModel()));
    }
    return command;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ChangeOrderCommand(org.csstudio.opibuilder.commands.ChangeOrderCommand) EditPart(org.eclipse.gef.EditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 33 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class CopyWidgetsAction method getSelectedWidgetModels.

/**
 * Gets the widget models of all currently selected EditParts.
 *
 * @return a list with all widget models that are currently selected. The order of the selected widgets was kept.
 */
protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
    List<?> selection = getSelectedObjects();
    List<AbstractWidgetModel> sameParentModels = new ArrayList<>();
    List<AbstractWidgetModel> differentParentModels = new ArrayList<>();
    List<AbstractWidgetModel> result = new ArrayList<>();
    AbstractContainerModel parent = null;
    for (var o : selection) {
        if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
            var widgetModel = (AbstractWidgetModel) ((EditPart) o).getModel();
            if (parent == null) {
                parent = widgetModel.getParent();
            }
            if (widgetModel.getParent() == parent) {
                sameParentModels.add(widgetModel);
            } else {
                differentParentModels.add(widgetModel);
            }
        }
    }
    // sort widgets to its original order
    if (sameParentModels.size() > 1) {
        var modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
        Arrays.sort(modelArray, (o1, o2) -> {
            if (o1.getParent().getChildren().indexOf(o1) > o2.getParent().getChildren().indexOf(o2)) {
                return 1;
            } else {
                return -1;
            }
        });
        result.addAll(Arrays.asList(modelArray));
        if (differentParentModels.size() > 0) {
            result.addAll(differentParentModels);
        }
        return result;
    }
    if (differentParentModels.size() > 0) {
        sameParentModels.addAll(differentParentModels);
    }
    return sameParentModels;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Example 34 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.

the class PasteWidgetsAction method getWidgetsIntrinsicRelativePositions.

private List<Point> getWidgetsIntrinsicRelativePositions(List<AbstractWidgetModel> widgets) {
    PointList pointList = new PointList(widgets.size());
    for (AbstractWidgetModel widgetModel : widgets) {
        pointList.addPoint(widgetModel.getLocation());
    }
    Point upperLeftCorner = pointList.getBounds().getLocation();
    List<Point> result = new ArrayList<Point>(widgets.size());
    for (int i = 0; i < widgets.size(); i++) {
        result.add(pointList.getPoint(i).translate(-upperLeftCorner.x, -upperLeftCorner.y));
    }
    return result;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 35 with AbstractWidgetModel

use of org.csstudio.opibuilder.model.AbstractWidgetModel 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)

Aggregations

AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)50 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)15 ArrayList (java.util.ArrayList)11 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)10 Point (org.eclipse.draw2d.geometry.Point)7 Rectangle (org.eclipse.draw2d.geometry.Rectangle)7 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)7 EditPart (org.eclipse.gef.EditPart)6 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)5 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)5 IFigure (org.eclipse.draw2d.IFigure)5 PropertyChangeListener (java.beans.PropertyChangeListener)4 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)3 ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)3 EditPolicy (org.eclipse.gef.EditPolicy)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 List (java.util.List)2 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)2