Search in sources :

Example 11 with AbstractContainerModel

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

the class PasteWidgetsAction method createPasteCommand.

/**
 * Creates the paste command.
 *
 * @return Command The paste command
 */
public Command createPasteCommand() {
    AbstractContainerModel targetModel = getTargetContainerModel();
    List<AbstractWidgetModel> widgets = getWidgetsFromClipboard();
    if (widgets != null) {
        if (_cursorLocation == null) {
            this.fetchCurrentCursorLocation();
        }
        Control cursorControl = Display.getCurrent().getCursorControl();
        Point pastePoint;
        if (isCursorAboveTargetContainer(cursorControl, targetModel)) {
            pastePoint = getCursorRelativePositionToTargetContainer(getCursorLocationOnDisplay(cursorControl), targetModel);
            // move the cursor location so that the user could know he has pasted how many widgets.
            Display.getCurrent().setCursorLocation(_cursorLocation.x + 10, _cursorLocation.y + 10);
        } else {
            Random rand = new Random();
            pastePoint = new Point(rand.nextInt(20), rand.nextInt(20));
        }
        List<Point> intrinsicLocations = getWidgetsIntrinsicRelativePositions(widgets);
        CompoundCommand cmd = new CompoundCommand("Paste " + widgets.size() + " Widget" + (widgets.size() > 0 ? "s" : ""));
        int i = 0;
        for (AbstractWidgetModel widgetModel : widgets) {
            // create command
            cmd.add(new WidgetCreateCommand(widgetModel, targetModel, new Rectangle(intrinsicLocations.get(i).translate(pastePoint), widgetModel.getSize()), (i == 0 ? false : true)));
            i++;
        }
        _cursorLocation = null;
        return cmd;
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) Random(java.util.Random) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand)

Example 12 with AbstractContainerModel

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

the class PasteWidgetsAction method getAbsolutePosition.

/**
 * @param widgetModel
 * @return the absolute position of a widget relative to display.
 */
private Point getAbsolutePosition(AbstractWidgetModel widgetModel) {
    if (widgetModel instanceof DisplayModel)
        return new Point(0, 0);
    Point result = widgetModel.getLocation();
    AbstractContainerModel parent = widgetModel.getParent();
    while (!(parent instanceof DisplayModel)) {
        result.translate(parent.getLocation());
        parent = parent.getParent();
    }
    return result;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) DisplayModel(org.csstudio.opibuilder.model.DisplayModel) Point(org.eclipse.draw2d.geometry.Point)

Example 13 with AbstractContainerModel

use of org.csstudio.opibuilder.model.AbstractContainerModel 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 (Object 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<AbstractWidgetModel>();
    List<AbstractWidgetModel> differentParentModels = new ArrayList<AbstractWidgetModel>();
    List<AbstractWidgetModel> result = new ArrayList<AbstractWidgetModel>();
    AbstractContainerModel parent = null;
    for (Object o : selection.toList()) {
        if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
            AbstractWidgetModel 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) {
        AbstractWidgetModel[] modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
        Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {

            @Override
            public int compare(AbstractWidgetModel o1, AbstractWidgetModel 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 14 with AbstractContainerModel

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

the class CreateGroupAction method run.

@Override
public void run(IAction action) {
    List<AbstractWidgetModel> originalSelectedWidgets = getSelectedWidgetModels();
    CompoundCommand compoundCommand = new CompoundCommand("Create Group");
    List<AbstractWidgetModel> selectedWidgets = new ArrayList<AbstractWidgetModel>();
    selectedWidgets.addAll(originalSelectedWidgets);
    // remove the selected widgets which are children of another selected widget.
    for (AbstractWidgetModel widget : originalSelectedWidgets) {
        if (widget instanceof DisplayModel) {
            selectedWidgets.remove(widget);
            continue;
        }
        if (widget instanceof AbstractContainerModel) {
            for (AbstractWidgetModel child : originalSelectedWidgets) {
                if (((AbstractContainerModel) widget).getChildren().contains(child))
                    selectedWidgets.remove(child);
            }
        }
    }
    int minDepth = Integer.MAX_VALUE;
    int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
    AbstractWidgetModel minDepthWidget = selectedWidgets.get(0);
    for (AbstractWidgetModel widget : selectedWidgets) {
        int leftX = widget.getLocation().x;
        int upY = widget.getLocation().y;
        int rightX = widget.getLocation().x + widget.getSize().width;
        int bottomY = widget.getLocation().y + widget.getSize().height;
        int 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.
    AbstractWidgetModel[] widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
    for (int i = widgetsArray.length - 1; i >= 0; i--) {
        compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
    }
    GroupingContainerModel groupingContainerModel = new GroupingContainerModel();
    SchemaService.getInstance().applySchema(groupingContainerModel);
    // the parent should be the widget with minimum nested depth
    AbstractContainerModel parent = minDepthWidget.getParent();
    int 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 (AbstractWidgetModel 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 15 with AbstractContainerModel

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

the class ChangeOrderAction method fillWidgetMap.

/**
 * @param widgetMap
 */
private void fillWidgetMap(Map<AbstractContainerModel, List<IndexedWidget>> widgetMap) {
    for (Object selection : getSelectedObjects()) {
        if (selection instanceof AbstractBaseEditPart) {
            AbstractBaseEditPart widgetEditpart = (AbstractBaseEditPart) selection;
            AbstractWidgetModel widgetModel = (AbstractWidgetModel) widgetEditpart.getModel();
            if (widgetEditpart.getParent() != null && widgetModel.getParent() != null) {
                AbstractContainerModel containerModel = (AbstractContainerModel) widgetEditpart.getParent().getModel();
                if (!widgetMap.containsKey(containerModel)) {
                    widgetMap.put(containerModel, new LinkedList<IndexedWidget>());
                }
                widgetMap.get(containerModel).add(new IndexedWidget(containerModel.getIndexOf(widgetModel), widgetModel));
            }
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart)

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