Search in sources :

Example 26 with AbstractWidgetModel

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

the class NativeTextEditpart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    super.registerPropertyChangeHandlers();
    removeAllPropertyChangeHandlers(NativeTextModel.PROP_ALIGN_H);
    PropertyChangeListener updatePropSheetListener = evt -> updatePropSheet();
    getWidgetModel().getProperty(NativeTextModel.PROP_MULTILINE_INPUT).addPropertyChangeListener(updatePropSheetListener);
    IWidgetPropertyChangeHandler handler = (oldValue, newValue, figure) -> {
        AbstractWidgetModel model = getWidgetModel();
        var parent = model.getParent();
        parent.removeChild(model);
        parent.addChild(model);
        parent.selectWidget(model, true);
        return false;
    };
    setPropertyChangeHandler(NativeTextModel.PROP_SHOW_NATIVE_BORDER, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_MULTILINE_INPUT, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_WRAP_WORDS, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_SHOW_H_SCROLL, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_SHOW_V_SCROLL, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_PASSWORD_INPUT, handler);
    setPropertyChangeHandler(NativeTextModel.PROP_ALIGN_H, handler);
}
Also used : Text(org.eclipse.swt.widgets.Text) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) NativeTextModel(org.csstudio.opibuilder.widgets.model.NativeTextModel) FocusEvent(org.eclipse.swt.events.FocusEvent) IFigure(org.eclipse.draw2d.IFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) PropertyChangeListener(java.beans.PropertyChangeListener) SWT(org.eclipse.swt.SWT) KeyEvent(org.eclipse.swt.events.KeyEvent) NativeTextFigure(org.csstudio.opibuilder.widgets.figures.NativeTextFigure) EditPolicy(org.eclipse.gef.EditPolicy) FocusAdapter(org.eclipse.swt.events.FocusAdapter) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) TextInputModel(org.csstudio.opibuilder.widgets.model.TextInputModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)

Example 27 with AbstractWidgetModel

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

the class AbstractContainerEditpart method registerBasePropertyChangeHandlers.

@Override
protected void registerBasePropertyChangeHandlers() {
    super.registerBasePropertyChangeHandlers();
    setPropertyChangeHandler(PROP_MACROS, (oldValue, newValue, figure) -> {
        var macrosInput = (MacrosInput) newValue;
        var macrosMap = new LinkedHashMap<String, String>();
        if (macrosInput.isInclude_parent_macros()) {
            macrosMap.putAll(getWidgetModel().getParentMacroMap());
        }
        macrosMap.putAll(macrosInput.getMacrosMap());
        getWidgetModel().setMacroMap(macrosMap);
        return false;
    });
    layout();
    childrenPropertyChangeListener = evt -> {
        if (evt.getOldValue() instanceof Integer) {
            addChild(createChild(evt.getNewValue()), ((Integer) evt.getOldValue()).intValue());
            layout();
        } else if (evt.getOldValue() instanceof AbstractWidgetModel) {
            var child = (EditPart) getViewer().getEditPartRegistry().get(evt.getOldValue());
            if (child != null) {
                removeChild(child);
                layout();
            }
        } else {
            refreshChildren();
        }
    };
    getWidgetModel().getChildrenProperty().addPropertyChangeListener(childrenPropertyChangeListener);
    if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
        selectionPropertyChangeListener = new PropertyChangeListener() {

            @SuppressWarnings("unchecked")
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                var widgets = (List<AbstractWidgetModel>) evt.getNewValue();
                var widgetEditparts = new ArrayList<EditPart>();
                for (var w : widgets) {
                    var e = (EditPart) getViewer().getEditPartRegistry().get(w);
                    if (e != null) {
                        widgetEditparts.add(e);
                    }
                }
                if (!(Boolean) evt.getOldValue()) {
                    // append
                    getViewer().deselectAll();
                }
                for (var editpart : widgetEditparts) {
                    if (editpart.isSelectable()) {
                        getViewer().appendSelection(editpart);
                    }
                }
            }
        };
        getWidgetModel().getSelectionProperty().addPropertyChangeListener(selectionPropertyChangeListener);
    }
}
Also used : MacrosInput(org.csstudio.opibuilder.util.MacrosInput) PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PropertyChangeListener(java.beans.PropertyChangeListener) EditPart(org.eclipse.gef.EditPart) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with AbstractWidgetModel

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

the class LayoutWidgetsImp method run.

public static void run(AbstractLayoutEditpart layoutWidget, CommandStack commandStack) {
    var container = layoutWidget.getWidgetModel().getParent();
    List<AbstractWidgetModel> modelChildren = new ArrayList<>();
    modelChildren.addAll(container.getChildren());
    modelChildren.remove(layoutWidget.getWidgetModel());
    if (modelChildren.size() == 0) {
        return;
    }
    var newBounds = layoutWidget.getNewBounds(modelChildren, container.getBounds());
    var compoundCommand = new CompoundCommand("Layout Widgets");
    var i = 0;
    for (var model : modelChildren) {
        compoundCommand.add(new SetBoundsCommand(model, newBounds.get(i)));
        i++;
    }
    commandStack.execute(compoundCommand);
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ArrayList(java.util.ArrayList) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 29 with AbstractWidgetModel

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

the class CreateGroupAction method run.

@Override
public void run(IAction action) {
    var originalSelectedWidgets = getSelectedWidgetModels();
    var compoundCommand = new CompoundCommand("Create Group");
    List<AbstractWidgetModel> selectedWidgets = new ArrayList<>();
    selectedWidgets.addAll(originalSelectedWidgets);
    // remove the selected widgets which are children of another selected widget.
    for (var widget : originalSelectedWidgets) {
        if (widget instanceof DisplayModel) {
            selectedWidgets.remove(widget);
            continue;
        }
        if (widget instanceof AbstractContainerModel) {
            for (var child : originalSelectedWidgets) {
                if (((AbstractContainerModel) widget).getChildren().contains(child)) {
                    selectedWidgets.remove(child);
                }
            }
        }
    }
    var minDepth = Integer.MAX_VALUE;
    int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
    var minDepthWidget = selectedWidgets.get(0);
    for (var widget : selectedWidgets) {
        var leftX = widget.getLocation().x;
        var upY = widget.getLocation().y;
        var rightX = widget.getLocation().x + widget.getSize().width;
        var bottomY = widget.getLocation().y + widget.getSize().height;
        var depth = widget.getNestedDepth();
        if (leftX < minX) {
            minX = leftX;
        }
        if (upY < minY) {
            minY = upY;
        }
        if (rightX > maxX) {
            maxX = rightX;
        }
        if (bottomY > maxY) {
            maxY = bottomY;
        }
        if (minDepth > depth) {
            minDepth = depth;
            minDepthWidget = widget;
        }
    }
    // Orphan order should be reversed so that undo operation has the correct order.
    var widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
    for (var i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
    }
    var groupingContainerModel = new GroupingContainerModel();
    SchemaService.getInstance().applySchema(groupingContainerModel);
    // the parent should be the widget with minimum nested depth
    var parent = minDepthWidget.getParent();
    var borderWidth = 0;
    if (groupingContainerModel.getBorderStyle() == BorderStyle.GROUP_BOX) {
        borderWidth = 30;
    }
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN, true);
    groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_SHOW_SCROLLBAR, false);
    compoundCommand.add(new WidgetCreateCommand(groupingContainerModel, parent, new Rectangle(minX, minY, maxX - minX + borderWidth, maxY - minY + borderWidth), false));
    for (var widget : selectedWidgets) {
        compoundCommand.add(new AddWidgetCommand(groupingContainerModel, widget, new Rectangle(widget.getLocation().translate(-minX, -minY), widget.getSize())));
    }
    execute(compoundCommand);
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) GroupingContainerModel(org.csstudio.opibuilder.widgets.model.GroupingContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) OrphanChildCommand(org.csstudio.opibuilder.commands.OrphanChildCommand)

Example 30 with AbstractWidgetModel

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

the class CreateGroupAction method getSelectedWidgetModels.

// /**
// * Gets the widget models of all currently selected EditParts.
// *
// * @return a list with all widget models that are currently selected
// */
// protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
// 
// List<AbstractWidgetModel> selectedWidgetModels = new ArrayList<AbstractWidgetModel>();
// 
// for (var o : selection.toList()) {
// if (o instanceof AbstractBaseEditPart) {
// selectedWidgetModels.add(((AbstractBaseEditPart) o)
// .getWidgetModel());
// }
// }
// return selectedWidgetModels;
// }
// 
/**
 * 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.toList()) {
        if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
            var widgetModel = ((AbstractBaseEditPart) o).getWidgetModel();
            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)

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