Search in sources :

Example 41 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class WidgetTreeContainerEditPolicy method getMoveChildrenCommand.

@Override
protected Command getMoveChildrenCommand(ChangeBoundsRequest request) {
    CompoundCommand command = new CompoundCommand();
    @SuppressWarnings("rawtypes") List editparts = request.getEditParts();
    @SuppressWarnings("rawtypes") List children = getHost().getChildren();
    int newIndex = findIndexOfTreeItemAt(request.getLocation());
    int tempIndex = newIndex;
    for (int i = 0; i < editparts.size(); i++) {
        EditPart child = (EditPart) editparts.get(editparts.size() - 1 - i);
        int oldIndex = children.indexOf(child);
        if (oldIndex == tempIndex || oldIndex + 1 == tempIndex) {
            command.add(UnexecutableCommand.INSTANCE);
            return command;
        } else if (oldIndex <= tempIndex) {
            tempIndex--;
        }
        command.add(new ChangeOrderCommand(tempIndex, (AbstractContainerModel) getHost().getModel(), (AbstractWidgetModel) child.getModel()));
    }
    return command;
}
Also used : AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) ChangeOrderCommand(org.csstudio.opibuilder.commands.ChangeOrderCommand) EditPart(org.eclipse.gef.EditPart) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 42 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class WidgetTreeContainerEditPolicy method getAddCommand.

@Override
protected Command getAddCommand(ChangeBoundsRequest request) {
    CompoundCommand cmd = new CompoundCommand();
    @SuppressWarnings("rawtypes") List editparts = request.getEditParts();
    int index = findIndexOfTreeItemAt(request.getLocation());
    for (int i = 0; i < editparts.size(); i++) {
        EditPart child = (EditPart) editparts.get(index >= 0 ? editparts.size() - 1 - i : i);
        if (isAncestor(child, getHost())) {
            cmd.add(UnexecutableCommand.INSTANCE);
        } else {
            AbstractWidgetModel childModel = (AbstractWidgetModel) child.getModel();
            cmd.add(createCreateCommand(childModel, new Rectangle(new Point(), childModel.getSize()), index, "Reparent Widgets"));
        }
    }
    return cmd;
}
Also used : AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) EditPart(org.eclipse.gef.EditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) List(java.util.List) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 43 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class WidgetXYLayoutEditPolicy method getResizeChildrenCommand.

// This has been overriden to fix a bug when handle bounds does not equal with bounds. For example, polyline figue.
/* (non-Javadoc)
     * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#getResizeChildrenCommand(org.eclipse.gef.requests.ChangeBoundsRequest)
     */
@Override
protected Command getResizeChildrenCommand(ChangeBoundsRequest request) {
    CompoundCommand resize = new CompoundCommand();
    Command c;
    GraphicalEditPart child;
    List<?> children = request.getEditParts();
    for (int i = 0; i < children.size(); i++) {
        child = (GraphicalEditPart) children.get(i);
        c = createChangeConstraintCommand(request, child, translateToModelConstraint(getConstraintForResize(request, child)));
        resize.add(c);
    }
    return resize.unwrap();
}
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) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 44 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand 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 45 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project yamcs-studio by yamcs.

the class WidgetXYLayoutEditPolicy method getCreateCommand.

@Override
protected Command getCreateCommand(CreateRequest request) {
    String typeId = determineTypeIdFromRequest(request);
    IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(typeId);
    Command widgetCreateCommand = createWidgetCreateCommand(request);
    if (widgetCreateCommand == null)
        return null;
    if (feedbackFactory != null) {
        CompoundCommand compoundCommand = new CompoundCommand();
        compoundCommand.add(widgetCreateCommand);
        Command initialBoundsCommand = feedbackFactory.createInitialBoundsCommand((AbstractWidgetModel) request.getNewObject(), request, (Rectangle) getConstraintFor(request));
        if (initialBoundsCommand != null)
            compoundCommand.add(initialBoundsCommand);
        return compoundCommand;
    } else
        return widgetCreateCommand;
}
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) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

CompoundCommand (org.eclipse.gef.commands.CompoundCommand)148 Command (org.eclipse.gef.commands.Command)63 EObject (org.eclipse.emf.ecore.EObject)28 ArrayList (java.util.ArrayList)23 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)22 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)17 List (java.util.List)16 EditPart (org.eclipse.gef.EditPart)16 IElementParameter (org.talend.core.model.process.IElementParameter)16 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)14 Point (org.eclipse.draw2d.geometry.Point)14 Rectangle (org.eclipse.draw2d.geometry.Rectangle)14 INode (org.talend.core.model.process.INode)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 RepositoryNode (org.talend.repository.model.RepositoryNode)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)11