Search in sources :

Example 16 with AbstractContainerModel

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

the class LayoutWidgetsImp method run.

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

Example 17 with AbstractContainerModel

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

the class ReplaceWidgetCommand method getAllConnections.

private List<ConnectionModel> getAllConnections(AbstractWidgetModel widget, boolean source) {
    List<ConnectionModel> result = new ArrayList<ConnectionModel>();
    result.addAll(source ? widget.getSourceConnections() : widget.getTargetConnections());
    if (widget instanceof AbstractContainerModel) {
        for (AbstractWidgetModel child : ((AbstractContainerModel) widget).getAllDescendants()) {
            result.addAll(source ? child.getSourceConnections() : child.getTargetConnections());
        }
    }
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ArrayList(java.util.ArrayList) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel)

Example 18 with AbstractContainerModel

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

the class WidgetCreateCommand method redo.

@Override
public void redo() {
    if (newWidget instanceof AbstractLayoutModel && container.getLayoutWidget() != null) {
        MessageDialog.openError(null, "Creating widget failed", "There is already a layout widget in the container. " + "Please delete it before you can add a new layout widget.");
        return;
    }
    if (bounds != null) {
        newWidget.setLocation(bounds.x, bounds.y);
        if (bounds.width > 0 && bounds.height > 0)
            newWidget.setSize(bounds.width, bounds.height);
    }
    boolean autoName = false;
    for (AbstractWidgetModel child : container.getChildren()) {
        if (child.getName().equals(newWidget.getName()))
            autoName = true;
    }
    if (autoName) {
        Map<String, Integer> nameMap = new HashMap<String, Integer>();
        for (AbstractWidgetModel child : container.getChildren()) {
            String key = child.getName();
            int tailNo = 0;
            if (key.matches(".*_\\d+")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                int i = key.lastIndexOf('_');
                tailNo = Integer.parseInt(key.substring(i + 1));
                key = key.substring(0, i);
            }
            if (nameMap.containsKey(key))
                nameMap.put(key, Math.max(nameMap.get(key) + 1, tailNo));
            else
                nameMap.put(key, 0);
        }
        String nameHead = newWidget.getName();
        if (nameHead.matches(".*_\\d+")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            nameHead = nameHead.substring(0, nameHead.lastIndexOf('_'));
        }
        newWidget.setName(nameHead + // $NON-NLS-1$
        "_" + (nameMap.get(nameHead) == null ? 0 : nameMap.get(nameHead) + 1));
    }
    container.addChild(index, newWidget);
    container.selectWidget(newWidget, append);
    if (newWidget instanceof AbstractContainerModel) {
        try {
            XMLUtil.fillLinkingContainers((AbstractContainerModel) newWidget);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) HashMap(java.util.HashMap) AbstractLayoutModel(org.csstudio.opibuilder.model.AbstractLayoutModel)

Example 19 with AbstractContainerModel

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

the class PerformAutoSizeAction method run.

@Override
public void run(IAction action) {
    if (getContainerEditpart().getChildren().size() <= 0) {
        return;
    }
    CompoundCommand compoundCommand = new CompoundCommand("Perform AutoSize");
    AbstractContainerEditpart containerEditpart = getContainerEditpart();
    AbstractContainerModel containerModel = containerEditpart.getWidgetModel();
    // temporary unlock children so children will not be resized.
    if (containerEditpart instanceof GroupingContainerEditPart) {
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, false));
    }
    IFigure figure = getContainerFigure();
    Rectangle childrenRange = GeometryUtil.getChildrenRange(containerEditpart);
    Point tranlateSize = new Point(childrenRange.x, childrenRange.y);
    compoundCommand.add(new SetBoundsCommand(containerModel, new Rectangle(containerModel.getLocation().translate(tranlateSize), new Dimension(childrenRange.width + figure.getInsets().left + figure.getInsets().right, childrenRange.height + figure.getInsets().top + figure.getInsets().bottom))));
    for (Object editpart : containerEditpart.getChildren()) {
        AbstractWidgetModel widget = ((AbstractBaseEditPart) editpart).getWidgetModel();
        compoundCommand.add(new SetBoundsCommand(widget, new Rectangle(widget.getLocation().translate(tranlateSize.getNegated()), widget.getSize())));
    }
    // recover lock
    if (containerEditpart instanceof GroupingContainerEditPart) {
        Object oldvalue = containerEditpart.getWidgetModel().getPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN);
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, oldvalue));
    }
    execute(compoundCommand);
}
Also used : AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GroupingContainerEditPart(org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) IFigure(org.eclipse.draw2d.IFigure)

Example 20 with AbstractContainerModel

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

the class ActionButtonEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    PropertyChangeListener styleListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            AbstractWidgetModel model = getWidgetModel();
            WidgetDescriptor descriptor = WidgetsService.getInstance().getWidgetDescriptor(model.getTypeID());
            String type = descriptor == null ? model.getTypeID().substring(model.getTypeID().lastIndexOf(".") + 1) : descriptor.getName();
            model.setPropertyValue(AbstractWidgetModel.PROP_WIDGET_TYPE, type);
            AbstractContainerModel parent = model.getParent();
            parent.removeChild(model);
            parent.addChild(model);
            parent.selectWidget(model, true);
        }
    };
    getWidgetModel().getProperty(ActionButtonModel.PROP_STYLE).addPropertyChangeListener(styleListener);
    updatePropSheet();
    delegate.registerPropertyChangeHandlers();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) PropertyChangeListener(java.beans.PropertyChangeListener) WidgetDescriptor(org.csstudio.opibuilder.util.WidgetDescriptor)

Aggregations

AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)34 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)27 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)11 ArrayList (java.util.ArrayList)10 Rectangle (org.eclipse.draw2d.geometry.Rectangle)10 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)9 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)7 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)6 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)5 IFigure (org.eclipse.draw2d.IFigure)5 Point (org.eclipse.draw2d.geometry.Point)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)4 PropertyChangeListener (java.beans.PropertyChangeListener)4 List (java.util.List)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)4 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)4 Dimension (org.eclipse.draw2d.geometry.Dimension)4 HashMap (java.util.HashMap)3 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)3