org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy Java Examples

The following examples show how to use org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompartmentEditPolicy.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected Command createChangeConstraintCommand(
		EditPart child,
		Object constraint) {
	org.eclipse.draw2d.geometry.Rectangle newBounds = (org.eclipse.draw2d.geometry.Rectangle) constraint;
	View shapeView = (View) child.getModel();

	TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
	.getEditingDomain();

	ICommand boundsCommand = 
		new SetBoundsCommand(editingDomain,
				DiagramUIMessages.SetLocationCommand_Label_Resize,
				new EObjectAdapter(shapeView),
				newBounds); 
	return new ICommandProxy(boundsCommand);
}
 
Example #2
Source File: MultipleShapesVerticalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void executeCurrentCommand() {
	FiguresHelper.AVOID_OVERLAP_ENABLE = false ;
	super.executeCurrentCommand();
	FiguresHelper.AVOID_OVERLAP_ENABLE = true ;
	CompoundCommand cc = new CompoundCommand("Check Overlap") ;
	for(IGraphicalEditPart ep : _movingShapes){
		 Location loc = (Location) ((Node) ep.getNotationView()).getLayoutConstraint() ;
Point oldLoc = new Point(loc.getX(), loc.getY()) ;
Point newLoc = FiguresHelper.handleCompartmentMargin(ep, loc.getX(), loc.getY(),(ep.resolveSemanticElement() instanceof SubProcessEvent)) ;
if((newLoc.x != 0 && newLoc.y != 0) && !newLoc.equals(oldLoc)){
 cc.add(new ICommandProxy(new SetBoundsCommand(_container.getEditingDomain(), "Check Overlap", new EObjectAdapter(ep.getNotationView()),newLoc))) ;
}
	}
	executeCommand(cc) ;
}
 
Example #3
Source File: MultipleShapesVerticalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * creates the command to move the shapes left or right.
 */
protected Command getCommand() {
	if (_container == null) {
		return null;
	}
	CompoundCommand command = new CompoundCommand("Multiple Shape Move");
	TransactionalEditingDomain editingDomain = _container.getEditingDomain();

	Point moveDelta  = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
	Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
	ZoomManager zoomManager = ((DiagramRootEditPart) 
			getCurrentViewer().getRootEditPart()).getZoomManager();
	spSizeDelta.scale(1/zoomManager.getZoom());
	command.add(_container.getCommand(getSourceRequest()));


	for (IGraphicalEditPart sp : _subProcesses) {
		Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
		spDim.expand(spSizeDelta);
		SetBoundsCommand setBounds = 
			new SetBoundsCommand(editingDomain,"MultipleShape Move", sp, spDim);
		command.add(new ICommandProxy(setBounds));
	}
	return command;
}
 
Example #4
Source File: DragEditPartsTrackerExWithoutCopyWithModKeyPressed.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void executeCurrentCommand() {
	if(getOperationSet().size() > 1){
		FiguresHelper.AVOID_OVERLAP_ENABLE = false ;
		super.executeCurrentCommand();
		FiguresHelper.AVOID_OVERLAP_ENABLE = true ;
		CompoundCommand cc = new CompoundCommand("Check Overlap") ;
		for(Object ep : getOperationSet()){
			if(ep instanceof IGraphicalEditPart){
				IGraphicalEditPart gep = (IGraphicalEditPart) ep ;
				Location loc = (Location) ((Node) ((IGraphicalEditPart) ep).getNotationView()).getLayoutConstraint() ;
				Point oldLoc = new Point(loc.getX(), loc.getY()) ;
				Point newLoc = FiguresHelper.handleCompartmentMargin(gep, loc.getX(), loc.getY(),(gep.resolveSemanticElement() instanceof SubProcessEvent)) ;
				if((newLoc.x != 0 && newLoc.y != 0) && !newLoc.equals(oldLoc)){
					cc.add(new ICommandProxy(new SetBoundsCommand(gep.getEditingDomain(), "Check Overlap", new EObjectAdapter(gep.getNotationView()),newLoc))) ;
				}
			}
		}
		executeCommand(cc) ;
	}else{
		super.executeCurrentCommand() ;
	}
}
 
Example #5
Source File: MultipleShapesHorizontalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void executeCurrentCommand() {
 FiguresHelper.AVOID_OVERLAP_ENABLE = false ;
 super.executeCurrentCommand();
 FiguresHelper.AVOID_OVERLAP_ENABLE = true ;
 CompoundCommand cc = new CompoundCommand("Check Overlap") ;
 for(IGraphicalEditPart ep : _movingShapes){
	 Location loc = (Location) ((Node) ep.getNotationView()).getLayoutConstraint() ;
	 Point oldLoc = new Point(loc.getX(), loc.getY()) ;
	 Point newLoc = FiguresHelper.handleCompartmentMargin(ep, loc.getX(), loc.getY(),(ep.resolveSemanticElement() instanceof SubProcessEvent)) ;
	 if((newLoc.x != 0 && newLoc.y != 0) && !newLoc.equals(oldLoc)){
		 cc.add(new ICommandProxy(new SetBoundsCommand(_container.getEditingDomain(), "Check Overlap", new EObjectAdapter(ep.getNotationView()),newLoc))) ;
	 }
 }
 executeCommand(cc) ;
}
 
Example #6
Source File: MultipleShapesHorizontalMoveTool.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * creates the command to move the shapes left or right.
 */
protected Command getCommand() {
	if (_container == null) {
		return null;
	}
	CompoundCommand command = new CompoundCommand("Multiple Shape Move");
	TransactionalEditingDomain editingDomain = _container.getEditingDomain();

	Point moveDelta  = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
	Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
	ZoomManager zoomManager = ((DiagramRootEditPart) 
			getCurrentViewer().getRootEditPart()).getZoomManager();
	spSizeDelta.scale(1/zoomManager.getZoom());

	command.add(_container.getCommand(getSourceRequest()));


	for (IGraphicalEditPart sp : _subProcesses) {
		Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
		spDim.expand(spSizeDelta);
		SetBoundsCommand setBounds = 
			new SetBoundsCommand(editingDomain,"MultipleShape Move", sp, spDim);
		command.add(new ICommandProxy(setBounds));
	}
	return command;
}
 
Example #7
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the points of a connection.
 * 
 * @param connection
 *            - The connection
 * @param bendpoints
 *            - Start, end and bending points
 */
public static void setConnectionPoints(ConnectionNodeEditPart connection, List<Point> bendpoints) {
	TransactionalEditingDomain editingDomain = connection.getEditingDomain();
	SetConnectionBendpointsCommand cmd = new SetConnectionBendpointsCommand(editingDomain);
	cmd.setEdgeAdapter(new EObjectAdapter(connection.getNotationView()));

	Point first = bendpoints.get(0);
	Point last = bendpoints.get(bendpoints.size() - 1);
	Point sourceRef = new Point(first.x(), first.y());
	Point targetRef = new Point(last.x(), last.y());
	PointList pointList = new PointList();

	for (Point bendpoint : bendpoints) {
		pointList.addPoint(new Point(bendpoint.x(), bendpoint.y()));
	}

	cmd.setNewPointList(pointList, sourceRef, targetRef);
	Command proxy = new ICommandProxy(cmd);
	proxy.execute();
}
 
Example #8
Source File: TreeLayoutEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Command createChangeConstraintCommand(EditPart child,
		Object constraint) {
	if (constraint instanceof TreeLayoutConstraint) {
		if (((TreeLayoutConstraint) constraint).isRoot()) {
			return UnexecutableCommand.INSTANCE;
		} else {
			return new ICommandProxy(new UpdateAnnotationsOnMoveCommand(
					getHost().getEditingDomain(),
					(IGraphicalEditPart) child,
					(TreeLayoutConstraint) constraint));
		}

	}
	return super.createChangeConstraintCommand(child, constraint);
}
 
Example #9
Source File: CompartmentChildCreationEditPolicy.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Command getCreateCommand(CreateViewRequest request) {
	TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
	.getEditingDomain();
	CompositeTransactionalCommand cc = new CompositeTransactionalCommand(
			editingDomain, DiagramUIMessages.AddCommand_Label);

	Iterator<?> descriptors = request.getViewDescriptors().iterator();

	while (descriptors.hasNext()) {
		CreateViewRequest.ViewDescriptor descriptor =
			(CreateViewRequest.ViewDescriptor)descriptors.next();

		CreateCommand createCommand =
			new CompartmentChildCreateCommand(editingDomain,
					descriptor, 
					(View)(getHost().getModel()), getFeedbackIndexFor(request));

		cc.compose(createCommand);
	}
	return new ICommandProxy(cc.reduce());
}
 
Example #10
Source File: InitialPointsConnectionBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Command getBendpointsChangedCommand(Connection connection, Edge edge) {
	Point ptRef1 = connection.getSourceAnchor().getReferencePoint();
	getConnection().translateToRelative(ptRef1);

	Point ptRef2 = connection.getTargetAnchor().getReferencePoint();
	getConnection().translateToRelative(ptRef2);

	TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();

	SetConnectionBendpointsAndLabelCommmand sbbCommand = new SetConnectionBendpointsAndLabelCommmand(editingDomain);
	sbbCommand.setEdgeAdapter(new EObjectAdapter(edge));
	sbbCommand.setNewPointList(connection.getPoints(), ptRef1, ptRef2);

	return new ICommandProxy(sbbCommand);
}
 
Example #11
Source File: MessageFlowFactory.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void removeMessageFlow(TransactionalEditingDomain editingDomain, AbstractCatchMessageEvent target,
        DiagramEditPart dep) {

    EditPart ep = findEditPart(dep, target);
    CompositeCommand command = new CompositeCommand("Remove MessageFlows");

    for (Object connection : ((AbstractGraphicalEditPart) ep).getTargetConnections()) {
        if (connection instanceof MessageFlowEditPart) {
            MessageFlowEditPart connectionPart = (MessageFlowEditPart) connection;
            MessageFlow flow = (MessageFlow) connectionPart.resolveSemanticElement();
            SetCommand c = new SetCommand(editingDomain, flow.getTarget(),
                    ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT, null);
            editingDomain.getCommandStack().execute(c);
            command.add(new DeleteCommand(editingDomain, connectionPart.getPrimaryView()));
            DestroyElementRequest req = new DestroyElementRequest(editingDomain, flow, false);
            DestroyElementCommand rmComd = new DestroyElementCommand(req);
            command.add(rmComd);
        }
    }

    dep.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(command.reduce()));
    dep.getDiagramEditDomain().getDiagramCommandStack().flush();
    dep.refresh();
}
 
Example #12
Source File: FixedBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("restriction")
protected Command getBendpointsChangedCommand(ConnectionEditPart part) {
	Connection connection = part.getConnectionFigure();
	Point ptRef1 = connection.getSourceAnchor().getReferencePoint();
	connection.translateToRelative(ptRef1);

	Point ptRef2 = connection.getTargetAnchor().getReferencePoint();
	connection.translateToRelative(ptRef2);

	TransactionalEditingDomain editingDomain = getHost().getEditingDomain();

	SetConnectionBendpointsAndLabelCommmand sbbCommand = new SetConnectionBendpointsAndLabelCommmand(editingDomain);
	sbbCommand.setEdgeAdapter(new EObjectAdapter((EObject) part.getModel()));
	sbbCommand.setNewPointList(connection.getPoints(), ptRef1, ptRef2);
	sbbCommand.setLabelsToUpdate(part, getInitialPoints(connection));

	return new ICommandProxy(sbbCommand);
}
 
Example #13
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public void addTargetAnchor(final Point targetAnchor) throws ProcBuilderException {
    if (!(currentElement instanceof Connection)) {
        throw new ProcBuilderException("Impossible to add a source anchor on " + currentElement != null ? ((Element) currentElement).getName() : "null");
    }

    final IGraphicalEditPart edge = GMFTools.findEditPart(diagramPart, currentElement);

    if (edge != null) {
        /* Add source anchors */
        final SetConnectionAnchorsCommand setConnectionAnchorsCommand = new SetConnectionAnchorsCommand(editingDomain, "Add source anchor");
        setConnectionAnchorsCommand.setEdgeAdaptor(new EObjectAdapter(edge.getNotationView()));
        setConnectionAnchorsCommand.setNewTargetTerminal("(" + targetAnchor.preciseX() + "," + targetAnchor.preciseY() + ")");
        diagramPart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setConnectionAnchorsCommand));
    }

}
 
Example #14
Source File: CompartmentEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Command createAddCommand(EditPart child, EditPart after) {
	int index = getHost().getChildren().indexOf(after);
	TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
	AddCommand command = new AddCommand(editingDomain, new EObjectAdapter((View)getHost().getModel()),
			new EObjectAdapter((View)child.getModel()), index);
	return new ICommandProxy(command);
}
 
Example #15
Source File: PaletteToolTransferDropTargetListenerWithSelection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static void insertOnSequenceFlow(final Command command, final EditPart targetEditPart, final EditPartViewer viewer, final boolean correctOffset) {
    final InsertElementOnSequenceFlowCommand cmd = new InsertElementOnSequenceFlowCommand(command, (IGraphicalEditPart) targetEditPart, viewer,
            correctOffset);
    final ICommandProxy iCommandProxy = new ICommandProxy(cmd);
    if (iCommandProxy.canExecute()) {
        viewer.getEditDomain().getCommandStack().execute(iCommandProxy);
    }
}
 
Example #16
Source File: CompartmentEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Command createMoveChildCommand(EditPart child, EditPart after) {	

		int newIndex;
		int displacement;

		int childIndex = getHost().getChildren().indexOf(child);
		int afterIndex = getHost().getChildren().indexOf(after);	

		if(afterIndex == -1) {
			newIndex = getHost().getChildren().size()-1;			
			displacement = newIndex - childIndex;
		} else {		
			newIndex = afterIndex;
			displacement = afterIndex - childIndex;
			if (childIndex <= afterIndex) {
				newIndex--;
				displacement--;			
			}
		}

		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();

		RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand(child, editingDomain, "", 
				(EList<?>)((View)child.getParent().getModel()).getElement().eGet(feature), 
				((View)child.getModel()).getElement(), 
				displacement, newIndex);	

		return new ICommandProxy(command);
	}
 
Example #17
Source File: CustomFeedbackXYLayoutPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Override in order to change the location if a figure overrides another
 */
@Override
protected Command createChangeConstraintCommand(final EditPart child,
        final Object constraint) {
    final Rectangle newBounds = (Rectangle) constraint;
    final View shapeView = (View) child.getModel();
    final TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
    return new ICommandProxy(new OverlapSetBoundsCommand(editingDomain,
            (GraphicalEditPart) child,
            getHost(),
            new EObjectAdapter(shapeView),
            newBounds));
}
 
Example #18
Source File: SwitchPoolOrderCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected Command createMoveChildCommand(EditPart child, EditPart after) {	

		int newIndex;
		int displacement;

		List children = getHost().getChildren();
		int childIndex = children.indexOf(child);
		int afterIndex = children.indexOf(after);	

		if(afterIndex == -1) {
			newIndex = children.size()-1;			
			displacement = newIndex - childIndex;
		} else {		
			newIndex = afterIndex;
			displacement = afterIndex - childIndex;
//			if (childIndex <= afterIndex) {
//				newIndex--;
//				displacement--;			
//			}
		}

		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();

		RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand(child, editingDomain, "", 
				(EList<?>)((View)child.getParent().getModel()).getElement().eGet(ProcessPackage.Literals.CONTAINER__ELEMENTS), 
				((View)child.getModel()).getElement(), 
				displacement, newIndex);	

		return new ICommandProxy(command);
	}
 
Example #19
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void handleSequenceFlowAnchors(final Point sourceAnchor,
        final Point targetAnchor,
        final ConnectionViewAndElementDescriptor newObject) {
    final SetConnectionAnchorsCommand setConnectionAnchorsCommand = new SetConnectionAnchorsCommand(editingDomain, "Add anchors");
    setConnectionAnchorsCommand.setEdgeAdaptor(newObject);
    if (sourceAnchor != null) {
        setConnectionAnchorsCommand.setNewSourceTerminal("(" + sourceAnchor.preciseX() + "," + sourceAnchor.preciseY() + ")");
    }
    if (targetAnchor != null) {
        setConnectionAnchorsCommand.setNewTargetTerminal("(" + targetAnchor.preciseX() + "," + targetAnchor.preciseY() + ")");
    }
    diagramPart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setConnectionAnchorsCommand));
}
 
Example #20
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void setBendPoints(final PointList bendpoints,
        final ConnectionViewAndElementDescriptor newObject) {
    final SetConnectionBendpointsCommand setConnectionBendPointsCommand = new SetConnectionBendpointsCommand(editingDomain);
    setConnectionBendPointsCommand.setEdgeAdapter(newObject);
    setConnectionBendPointsCommand.setNewPointList(bendpoints, bendpoints.getFirstPoint(), bendpoints.getLastPoint());
    diagramPart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(setConnectionBendPointsCommand));
}
 
Example #21
Source File: InsertElementOnSequenceFlowCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected CommandResult doUndoWithResult(final IProgressMonitor monitor,
        final IAdaptable info) throws ExecutionException {
    if (setBendpointsCmdForOriginalEdge != null) {
        setBendpointsCmdForOriginalEdge.undo(monitor, info);
    }
    if (createConnectionCommand != null) {
        createConnectionCommand.undo(monitor, info);
    }
    if (targetEditPart instanceof ConnectionEditPart && originalTargetEditPart != null) {
        final ReconnectRequest reconnect = new ReconnectRequest(RequestConstants.REQ_RECONNECT_TARGET);
        reconnect.setConnectionEditPart((ConnectionEditPart) targetEditPart);
        reconnect.setTargetEditPart(originalTargetEditPart);
        final CompoundCommand reconnectCommand = (CompoundCommand) originalTargetEditPart.getCommand(reconnect);
        final CompoundCommand ccc = (CompoundCommand) reconnectCommand.getChildren()[1];
        for (final Object proxy : ccc.getChildren()) {
            if (proxy instanceof ICommandProxy) {
                ((ICommandProxy) proxy).getICommand().execute(monitor, info);
            }
        }
    }
    if (correctOffset && correctOffsetCmd != null && correctOffsetCmd.canUndo()) {
        correctOffsetCmd.undo(monitor, info);
    }
    if (creationCommand != null && creationCommand.canUndo()) {
        creationCommand.undo();
        creationCommand.dispose();
    }
    return CommandResult.newOKCommandResult();
}
 
Example #22
Source File: ConvertBPMNTypeCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected static void refreshBoundaryElements(final TransactionalEditingDomain editingDomain, final EObject targetElement,
        final GraphicalEditPart targetEditPart, final List<Pair<EObject, Point>> childPositions) {
    for (final Pair<EObject, Point> pair : childPositions) {
        final EObject childToResetPosition = pair.getFirst();
        if (targetElement.eContents().contains(childToResetPosition)) {
            final GraphicalEditPart editPart = (GraphicalEditPart) targetEditPart.findEditPart(targetEditPart, childToResetPosition);
            if (editPart != null) {
                final Point childPosition = pair.getSecond();
                childPosition.x = childPosition.x - targetEditPart.getFigure().getBounds().x;
                childPosition.y = childPosition.y - targetEditPart.getFigure().getBounds().y;
                final ICommand moveCommand = new SetBoundsCommand(editPart.getEditingDomain(),
                        DiagramUIMessages.Commands_MoveElement, new EObjectAdapter(
                                (View) editPart.getModel()), childPosition);
                editPart.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(moveCommand)) ;
            } else {
                /*
                 * If there is no editpart, it must be that a the boundary
                 * can't be set on this kind of Element
                 */
                if (targetElement instanceof Activity) {
                    /*
                     * Remove the BoundaryEvent from the list and
                     * its outgoing transition
                     */
                    final AbstractEMFOperation operation = new RemoveBoundaryWithItsFlows(editingDomain, (BoundaryEvent) childToResetPosition,
                            (Activity) targetElement);
                    try {
                        operation.execute(new NullProgressMonitor(), null);
                    } catch (final ExecutionException e) {
                        BonitaStudioLog.error(e);
                    }

                }
            }
        }
        targetEditPart.getRoot().refresh();
    }
}
 
Example #23
Source File: TreeLayoutEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Command getCreateCommand(CreateRequest request) {
	final CompoundCommand cmd = new CompoundCommand();
	cmd.add(super.getCreateCommand(request));
	if (request instanceof CreateViewAndElementRequest) {
		final CreateViewAndElementRequest req = (CreateViewAndElementRequest) request;
		if (shouldUpdateAnnotationsOnCreation(req)) {
			cmd.add(new ICommandProxy(
					new UpdateAnnotationsOnCreationCommand(getHost()
							.getEditingDomain(), req)));
		}
	}
	return cmd;
}
 
Example #24
Source File: CompartmentLayoutEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
protected Command createMoveChildCommand(EditPart child, EditPart after) {

	int newIndex;
	int displacement;

	int childIndex = getHost().getChildren().indexOf(child);
	int afterIndex = getHost().getChildren().indexOf(after);

	if (afterIndex == -1) {
		newIndex = getHost().getChildren().size() - 1;
		displacement = newIndex - childIndex;
	} else {
		newIndex = afterIndex;
		displacement = afterIndex - childIndex;
		if (childIndex <= afterIndex) {
			newIndex--;
			displacement--;
		}
	}

	TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
			.getEditingDomain();

	RepositionEObjectCommand command = new CompartmentRepositionEObjectCommand(
			child, editingDomain, "", (EList) ((View) child.getParent()
					.getModel()).getElement().eGet(feature),
			((View) child.getModel()).getElement(), displacement, newIndex);

	eraseLayoutTargetFeedback(null);

	return new ICommandProxy(command);
}
 
Example #25
Source File: CompartmentLayoutEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Command createAddCommand(EditPart child, EditPart after) {
	int index = getHost().getChildren().indexOf(after);
	TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost())
			.getEditingDomain();
	AddCommand command = new CompartmentAddCommand(editingDomain,
			new EObjectAdapter((View) getHost().getModel()),
			new EObjectAdapter((View) child.getModel()), index);
	return new ICommandProxy(command);
}
 
Example #26
Source File: TransitionExpressionComponentEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Command createDeleteSemanticCommand(GroupRequest deleteRequest) {
	SetRequest request = new SetRequest(getHost().resolveSemanticElement(),
			SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION,
			null);
	SetValueCommand result = new SetValueCommand(request);
	return new ICommandProxy(result);
}
 
Example #27
Source File: InitialPointsConnectionBendpointEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Command getBendpointsChangedCommand(BendpointRequest request) {
	PointList originalPoints = InitialPointsOfRequestDataManager.getOriginalPoints(request);
	Command result = super.getBendpointsChangedCommand(request);
	if (result instanceof ICommandProxy) {
		ICommand iCommand = ((ICommandProxy) result).getICommand();
		if (iCommand instanceof SetConnectionBendpointsAndLabelCommmand) {
			((SetConnectionBendpointsAndLabelCommmand) iCommand).setLabelsToUpdate(
					(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) getHost(), originalPoints);
		}
	}
	return result;
}
 
Example #28
Source File: EAttributeDirectEditPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
	Object value = request.getCellEditor().getValue();
	if (value == null)
		return null;
	SetRequest setRequest = new SetRequest(getHost().resolveSemanticElement(), provider.getAttribute(), value);
	SetValueCommand setCommand = new SetValueCommand(setRequest);
	return new ICommandProxy(setCommand);
}
 
Example #29
Source File: OpenDiagramEditPolicy.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
protected Command getOpenCommand(Request request) {
	EditPart targetEditPart = getTargetEditPart(request);
	if (false == targetEditPart.getModel() instanceof View) {
		return null;
	}
	View view = (View) targetEditPart.getModel();
	Style link = view.getStyle(NotationPackage.eINSTANCE.getHintedDiagramLinkStyle());
	if (false == link instanceof HintedDiagramLinkStyle) {
		return null;
	}
	return new ICommandProxy(new OpenDiagramCommand((HintedDiagramLinkStyle) link));
}
 
Example #30
Source File: InsertElementOnSequenceFlowCommand.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected CommandResult doExecuteWithResult(
        final IProgressMonitor monitor, final IAdaptable info)
        throws ExecutionException {
    if (targetEditPart instanceof ConnectionEditPart) {
        final ConnectionEditPart targetConnectionEditPart = (ConnectionEditPart) targetEditPart;
        for (final Iterator i = objects.iterator(); i.hasNext();) {
            final Object object = i.next();
            if (object instanceof ViewAndElementDescriptor) {
                final ViewAndElementDescriptor descriptor = (ViewAndElementDescriptor) object;
                final ShapeEditPart editPart = (ShapeEditPart) epRegistry.get(descriptor.getAdapter(View.class));
                final Bounds b = (Bounds) ((Node) editPart.getNotationView()).getLayoutConstraint();
                correctOffsetCmd = new SetBoundsCommand(editPart.getEditingDomain(), "", descriptor, new Point(b.getX() - 25, b.getY() - 25));

                final ReconnectRequest reconnect = new ReconnectRequest(RequestConstants.REQ_RECONNECT_TARGET);
                reconnect.setConnectionEditPart(targetConnectionEditPart);
                reconnect.setTargetEditPart(editPart);
                final CompoundCommand reconnectCommand = (CompoundCommand) editPart.getCommand(reconnect);

                final CreateConnectionViewAndElementRequest connectionRequest = new CreateConnectionViewAndElementRequest(
                        BonitaConnectionTypes.getElementType("org.bonitasoft.studio.diagram.SequenceFlow_4001"),
                        ((IHintedType) BonitaConnectionTypes.getElementType("org.bonitasoft.studio.diagram.SequenceFlow_4001")).getSemanticHint(),
                        new PreferencesHint("org.bonitasoft.studio.diagram"));
                originalTargetEditPart = targetConnectionEditPart.getTarget();
                createConnectionCommand = new DeferredCreateConnectionViewAndElementCommand(connectionRequest, descriptor, originalTargetEditPart,
                        editPart.getViewer());
                if (correctOffset) {
                    correctOffsetCmd.execute(monitor, info);
                }
                final CompoundCommand ccc = (CompoundCommand) reconnectCommand.getChildren()[1];
                for (final Object proxy : ccc.getChildren()) {
                    if (proxy instanceof ICommandProxy) {
                        final ICommand iCommand = ((ICommandProxy) proxy).getICommand();
                        if (iCommand.canExecute()) {
                            iCommand.execute(monitor, info);
                        }
                    }
                }
                createConnectionCommand.execute(monitor, info);

                if (connectionRequest != null) {
                    final ConnectionViewAndElementDescriptor connectionDescriptor = (ConnectionViewAndElementDescriptor) connectionRequest.getNewObject();
                    final Connector edge = (Connector) connectionDescriptor.getAdapter(Edge.class);
                    final org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connectionEP = (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) editPart
                            .getViewer().getEditPartRegistry().get(edge);
                    if (connectionEP != null) {
                        final TransactionalEditingDomain editingDomain = connectionEP.getEditingDomain();
                        setBendpointsCmdForNewEdge = createSetBendpointsCommand(monitor, info, edge, editingDomain);
                        setBendpointsCmdForNewEdge.execute(monitor, info);
                        setBendpointsCmdForOriginalEdge = createSetBendpointsCommand(monitor, info, (Connector) targetEditPart.getNotationView(),
                                editingDomain);
                        setBendpointsCmdForOriginalEdge.execute(monitor, info);
                    }
                }
            }
        }
    }
    correctBoundsToAvoidCollisions(monitor, info);
    return CommandResult.newOKCommandResult();
}