Search in sources :

Example 1 with ChangeGuideCommand

use of org.csstudio.opibuilder.commands.ChangeGuideCommand 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 2 with ChangeGuideCommand

use of org.csstudio.opibuilder.commands.ChangeGuideCommand in project yamcs-studio by yamcs.

the class WidgetXYLayoutEditPolicy method chainGuideDetachmentCommand.

/**
 * Adds a ChangeGuideCommand to the given Command.
 *
 * @param request
 *            The request
 * @param part
 *            The AbstractWidgetEditPart, which model should be detached
 *            from a guide
 * @param cmd
 *            The Command
 * @param horizontal
 *            A boolean, true if the guide is horizontal, false otherwise
 * @return Command The given command
 */
private Command chainGuideDetachmentCommand(final Request request, final AbstractBaseEditPart part, final Command cmd, final boolean horizontal) {
    Command result = cmd;
    // Detach from guide, if none is given
    Integer guidePos = (Integer) request.getExtendedData().get(horizontal ? SnapToGuides.KEY_HORIZONTAL_GUIDE : SnapToGuides.KEY_VERTICAL_GUIDE);
    if (guidePos == null) {
        result = result.chain(new ChangeGuideCommand(part.getWidgetModel(), horizontal));
    }
    return result;
}
Also used : 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) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand)

Example 3 with ChangeGuideCommand

use of org.csstudio.opibuilder.commands.ChangeGuideCommand in project yamcs-studio by yamcs.

the class WidgetXYLayoutEditPolicy method chainGuideAttachmentCommand.

/**
 * Adds a ChangeGuideCommand to the given Command.
 *
 * @param request
 *            The Request
 * @param part
 *            The AbstractWidgetEditPart, which model should be detached
 *            from a guide
 * @param cmd
 *            The Command
 * @param horizontal
 *            A boolean, true if the guide is horizontal, false otherwise
 * @return Command The given command
 */
private Command chainGuideAttachmentCommand(final Request request, final AbstractBaseEditPart part, final Command cmd, final boolean horizontal) {
    Command result = cmd;
    // Attach to guide, if one is given
    Integer guidePos = (Integer) request.getExtendedData().get(horizontal ? SnapToGuides.KEY_HORIZONTAL_GUIDE : SnapToGuides.KEY_VERTICAL_GUIDE);
    if (guidePos != null) {
        int alignment = ((Integer) request.getExtendedData().get(horizontal ? SnapToGuides.KEY_HORIZONTAL_ANCHOR : SnapToGuides.KEY_VERTICAL_ANCHOR)).intValue();
        ChangeGuideCommand cgm = new ChangeGuideCommand(part.getWidgetModel(), horizontal);
        cgm.setNewGuide(findGuideAt(guidePos.intValue(), horizontal), alignment);
        result = result.chain(cgm);
    }
    return result;
}
Also used : 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) ChangeGuideCommand(org.csstudio.opibuilder.commands.ChangeGuideCommand)

Aggregations

AddWidgetCommand (org.csstudio.opibuilder.commands.AddWidgetCommand)3 ChangeGuideCommand (org.csstudio.opibuilder.commands.ChangeGuideCommand)3 CloneCommand (org.csstudio.opibuilder.commands.CloneCommand)3 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)3 WidgetCreateCommand (org.csstudio.opibuilder.commands.WidgetCreateCommand)3 WidgetSetConstraintCommand (org.csstudio.opibuilder.commands.WidgetSetConstraintCommand)3 Command (org.eclipse.gef.commands.Command)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 ArrayList (java.util.ArrayList)1 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 IGraphicalFeedbackFactory (org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory)1 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 ConnectionModel (org.csstudio.opibuilder.model.ConnectionModel)1 PointList (org.eclipse.draw2d.geometry.PointList)1 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1