Search in sources :

Example 1 with AbstractBaseEditPart

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

the class OPIRunnerContextMenuProvider method addWidgetActionToMenu.

/**
 * Adds the defined {@link AbstractWidgetAction}s to the given {@link IMenuManager}.
 *
 * @param menu
 *            The {@link IMenuManager}
 */
private void addWidgetActionToMenu(final IMenuManager menu) {
    List<?> selectedEditParts = ((IStructuredSelection) getViewer().getSelection()).toList();
    if (selectedEditParts.size() == 1) {
        if (selectedEditParts.get(0) instanceof AbstractBaseEditPart) {
            AbstractBaseEditPart editPart = (AbstractBaseEditPart) selectedEditParts.get(0);
            AbstractWidgetModel widget = editPart.getWidgetModel();
            // add menu Open, Open in New Tab and Open in New Window
            List<AbstractWidgetAction> hookedActions = editPart.getHookedActions();
            if (hookedActions != null && hookedActions.size() == 1) {
                AbstractWidgetAction hookedAction = hookedActions.get(0);
                if (hookedAction instanceof OpenDisplayAction) {
                    final OpenDisplayAction original_action = (OpenDisplayAction) hookedAction;
                    menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.DEFAULT));
                    menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_TAB));
                    menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_WINDOW));
                    menu.add(new OpenRelatedDisplayAction(original_action, OpenDisplayTarget.NEW_SHELL));
                }
            }
            ActionsInput ai = widget.getActionsInput();
            if (ai != null) {
                List<AbstractWidgetAction> widgetActions = ai.getActionsList();
                if (!widgetActions.isEmpty()) {
                    MenuManager actionMenu = new MenuManager("Actions", "actions");
                    for (AbstractWidgetAction action : widgetActions) {
                        actionMenu.add(new WidgetActionMenuAction(action));
                    }
                    menu.add(actionMenu);
                }
            }
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) WidgetActionMenuAction(org.csstudio.opibuilder.actions.WidgetActionMenuAction) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) OpenDisplayAction(org.csstudio.opibuilder.widgetActions.OpenDisplayAction) ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) OpenRelatedDisplayAction(org.csstudio.opibuilder.actions.OpenRelatedDisplayAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Example 2 with AbstractBaseEditPart

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

the class OPIRunnerContextMenuProvider method addSettingPropertiesAction.

private void addSettingPropertiesAction(final IMenuManager menu) {
    List<?> selectedEditParts = ((IStructuredSelection) getViewer().getSelection()).toList();
    if (selectedEditParts.size() == 1) {
        if (selectedEditParts.get(0) instanceof AbstractBaseEditPart) {
            AbstractBaseEditPart editPart = (AbstractBaseEditPart) selectedEditParts.get(0);
            AbstractWidgetModel widget = editPart.getWidgetModel();
            if (widget.getRuntimePropertyList() != null) {
                menu.add(new ConfigureRuntimePropertiesAction(getViewer().getControl().getShell(), widget));
            }
        }
    }
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ConfigureRuntimePropertiesAction(org.csstudio.opibuilder.actions.ConfigureRuntimePropertiesAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with AbstractBaseEditPart

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

the class WidgetXYLayoutEditPolicy method createChangeConstraintCommand.

@Override
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
    if (!(child instanceof AbstractBaseEditPart) || !(constraint instanceof Rectangle))
        return super.createChangeConstraintCommand(request, child, constraint);
    AbstractBaseEditPart part = (AbstractBaseEditPart) child;
    AbstractWidgetModel widgetModel = part.getWidgetModel();
    IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(widgetModel.getTypeID());
    Command cmd = null;
    if (feedbackFactory != null)
        cmd = feedbackFactory.createChangeBoundsCommand(widgetModel, request, (Rectangle) constraint);
    if (cmd == null)
        cmd = new WidgetSetConstraintCommand(widgetModel, request, (Rectangle) constraint);
    List<ConnectionModel> allConnections = new ArrayList<ConnectionModel>(part.getWidgetModel().getSourceConnections());
    allConnections.addAll(part.getWidgetModel().getTargetConnections());
    if (part.getWidgetModel() instanceof AbstractContainerModel) {
        for (AbstractWidgetModel d : ((AbstractContainerModel) part.getWidgetModel()).getAllDescendants()) {
            allConnections.addAll(d.getSourceConnections());
            allConnections.addAll(d.getTargetConnections());
        }
    }
    if (allConnections.size() > 0) {
        CompoundCommand reRouteCmd = new CompoundCommand();
        for (ConnectionModel srcConn : allConnections) {
            reRouteCmd.add(new SetWidgetPropertyCommand(srcConn, ConnectionModel.PROP_POINTS, new PointList()));
        }
        cmd = cmd.chain(reRouteCmd);
    }
    if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
        Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
        if (guidePos != null) {
            cmd = chainGuideAttachmentCommand(request, part, cmd, true);
        } else if (GuideUtil.getInstance().getGuide(widgetModel, true) != null) {
            // SnapToGuides didn't provide a horizontal guide, but
            // this part is attached
            // to a horizontal guide. Now we check to see if the
            // part is attached to
            // the guide along the edge being resized. If that is
            // the case, we need to
            // detach the part from the guide; otherwise, we leave
            // it alone.
            int alignment = GuideUtil.getInstance().getGuide(widgetModel, true).getAlignment(widgetModel);
            int edgeBeingResized = 0;
            if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
                edgeBeingResized = -1;
            } else {
                edgeBeingResized = 1;
            }
            if (alignment == edgeBeingResized) {
                cmd = cmd.chain(new ChangeGuideCommand(widgetModel, true));
            }
        }
    }
    if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
        Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
        if (guidePos != null) {
            cmd = chainGuideAttachmentCommand(request, part, cmd, false);
        } else if (GuideUtil.getInstance().getGuide(widgetModel, false) != null) {
            int alignment = GuideUtil.getInstance().getGuide(widgetModel, false).getAlignment(widgetModel);
            int edgeBeingResized = 0;
            if ((request.getResizeDirection() & PositionConstants.WEST) != 0) {
                edgeBeingResized = -1;
            } else {
                edgeBeingResized = 1;
            }
            if (alignment == edgeBeingResized) {
                cmd = cmd.chain(new ChangeGuideCommand(widgetModel, false));
            }
        }
    }
    if (request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_ALIGN_CHILDREN)) {
        cmd = chainGuideAttachmentCommand(request, part, cmd, true);
        cmd = chainGuideAttachmentCommand(request, part, cmd, false);
        cmd = chainGuideDetachmentCommand(request, part, cmd, true);
        cmd = chainGuideDetachmentCommand(request, part, cmd, false);
    }
    return cmd;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PrecisionRectangle(org.eclipse.draw2d.geometry.PrecisionRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ArrayList(java.util.ArrayList) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AddWidgetCommand(org.csstudio.opibuilder.commands.AddWidgetCommand) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) WidgetCreateCommand(org.csstudio.opibuilder.commands.WidgetCreateCommand) CloneCommand(org.csstudio.opibuilder.commands.CloneCommand) WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand)

Example 4 with AbstractBaseEditPart

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

the class WidgetXYLayoutEditPolicy method getCloneCommand.

@SuppressWarnings("deprecation")
@Override
protected Command getCloneCommand(ChangeBoundsRequest request) {
    CloneCommand clone = new CloneCommand((AbstractContainerModel) getHost().getModel());
    for (AbstractBaseEditPart part : sortSelectedWidgets(request.getEditParts())) {
        clone.addPart((AbstractWidgetModel) part.getModel(), (Rectangle) getConstraintForClone(part, request));
    }
    // Attach to horizontal guide, if one is given
    Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
    if (guidePos != null) {
        int hAlignment = ((Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_ANCHOR)).intValue();
        clone.setGuide(findGuideAt(guidePos.intValue(), true), hAlignment, true);
    }
    // Attach to vertical guide, if one is given
    guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
    if (guidePos != null) {
        int vAlignment = ((Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_ANCHOR)).intValue();
        clone.setGuide(findGuideAt(guidePos.intValue(), false), vAlignment, false);
    }
    return clone;
}
Also used : CloneCommand(org.csstudio.opibuilder.commands.CloneCommand) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart)

Example 5 with AbstractBaseEditPart

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

the class WidgetXYLayoutEditPolicy method sortSelectedWidgets.

/**
 * Sort the selected widget as they were in their parents
 *
 * @return a list with all widget editpart that are currently selected
 */
private final List<AbstractBaseEditPart> sortSelectedWidgets(List<?> selection) {
    List<AbstractBaseEditPart> sameParentWidgets = new ArrayList<AbstractBaseEditPart>();
    List<AbstractBaseEditPart> differentParentWidgets = new ArrayList<AbstractBaseEditPart>();
    List<AbstractBaseEditPart> result = new ArrayList<AbstractBaseEditPart>();
    AbstractContainerModel parent = null;
    for (Object o : selection) {
        if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
            AbstractWidgetModel widgetModel = ((AbstractBaseEditPart) o).getWidgetModel();
            if (parent == null)
                parent = widgetModel.getParent();
            if (widgetModel.getParent() == parent)
                sameParentWidgets.add((AbstractBaseEditPart) o);
            else
                differentParentWidgets.add((AbstractBaseEditPart) o);
        }
    }
    // sort widgets to its original order
    if (sameParentWidgets.size() > 1) {
        AbstractBaseEditPart[] modelArray = sameParentWidgets.toArray(new AbstractBaseEditPart[0]);
        Arrays.sort(modelArray, new Comparator<AbstractBaseEditPart>() {

            @Override
            public int compare(AbstractBaseEditPart o1, AbstractBaseEditPart o2) {
                if (o1.getWidgetModel().getParent().getChildren().indexOf(o1.getWidgetModel()) > o2.getWidgetModel().getParent().getChildren().indexOf(o2.getWidgetModel()))
                    return 1;
                else
                    return -1;
            }
        });
        result.addAll(Arrays.asList(modelArray));
        if (differentParentWidgets.size() > 0)
            result.addAll(differentParentWidgets);
        return result;
    }
    if (differentParentWidgets.size() > 0)
        sameParentWidgets.addAll(differentParentWidgets);
    return sameParentWidgets;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) ArrayList(java.util.ArrayList) DisplayEditpart(org.csstudio.opibuilder.editparts.DisplayEditpart)

Aggregations

AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)24 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)16 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)8 ArrayList (java.util.ArrayList)6 DisplayEditpart (org.csstudio.opibuilder.editparts.DisplayEditpart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)6 GraphicalViewer (org.eclipse.gef.GraphicalViewer)4 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)4 AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Job (org.eclipse.core.runtime.jobs.Job)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 PointList (org.eclipse.draw2d.geometry.PointList)3 EditPart (org.eclipse.gef.EditPart)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 EventObject (java.util.EventObject)2 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)2 SetBoundsCommand (org.csstudio.opibuilder.commands.SetBoundsCommand)2 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)2