Java Code Examples for org.eclipse.gef.commands.Command#execute()

The following examples show how to use org.eclipse.gef.commands.Command#execute() . 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: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Hides the labels on the connections of the given elements
 * 
 * @param elements
 *            - The EditParts which's connection labels is to be hidden
 * @param excluding
 *            - The types of connection labels which are not wanted to be
 *            hidden
 */
public static void hideConnectionLabelsForEditParts(List<GraphicalEditPart> elements,
		List<java.lang.Class<?>> excluding) {
	for (EditPart editpart : elements) {
		GraphicalEditPart ep = ((GraphicalEditPart) editpart);
		@SuppressWarnings("unchecked")
		List<ConnectionNodeEditPart> connections = ep.getSourceConnections();
		for (ConnectionNodeEditPart connection : connections) {
			@SuppressWarnings("unchecked")
			List<ConnectionNodeEditPart> labels = connection.getChildren();
			for (EditPart label : labels) {
				if (!isInstanceOfAny(label, excluding)) {
					ShowHideLabelsRequest request = new ShowHideLabelsRequest(false, ((View) label.getModel()));
					Command com = connection.getCommand(request);
					if (com != null && com.canExecute())
						com.execute();
				}
			}

		}
	}
}
 
Example 2
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 3
Source File: ElementsManagerUtils.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Calls the {@link DropObjectsRequest} on an EditPart. 
 * @param EP - The EditPart that is to be added to
 * @param diagramElements - The Elements that are to be added
 */
@SuppressWarnings("unchecked")
public static void addElementsToEditPart(EditPart EP, Collection<? extends Element> diagramElements) {
	List<Element> diagramElementsList;
	
	if(!(diagramElements instanceof List<?>)){
		diagramElementsList = (List<Element>) createList(diagramElements);
	}else{
		diagramElementsList = (List<Element>) diagramElements;
	}
	
	if(!diagramElementsList.isEmpty()){
		DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
		dropObjectsRequest.setObjects(diagramElementsList);
		dropObjectsRequest.setLocation(new Point(0,0));
		Command commandDrop = EP.getCommand(dropObjectsRequest);
		if (commandDrop != null){
			commandDrop.execute();
		}
	}
}
 
Example 4
Source File: WrapperCommandStack.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void execute( Command command )
{
	if ( command == null )
	{
		return;
	}

	if ( command.getLabel( ) == null )
	{
		command.setLabel( "" ); //$NON-NLS-1$
	}
	ar.startTrans( command.getLabel( ) );
	command.execute( );
	ar.commit( );

}
 
Example 5
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Resizes a GraphicalEditPart
 * 
 * @param graphEP
 *            - The GraphicalEditPart that is to be resized
 * @param new_width
 *            - The new width of the EditPart
 * @param new_height
 *            - The new height of the EditPart
 */
public static void resizeGraphicalEditPart(GraphicalEditPart graphEP, int new_width, int new_height) {
	Dimension figuredim = graphEP.getFigure().getSize();
	ChangeBoundsRequest resize_req = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
	resize_req.setSizeDelta(new Dimension(new_width - figuredim.width(), new_height - figuredim.height()));
	resize_req.setEditParts(graphEP);

	Command cmd = graphEP.getCommand(resize_req);
	if (cmd != null)
		cmd.execute();
}
 
Example 6
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Moves a GraphicalEditPart to the given location
 * 
 * @param graphEP
 *            - The GraphicalEditPart
 * @param new_X
 *            - The new x coordinate
 * @param new_Y
 *            - The new y coordinate
 */
public static void moveGraphicalEditPart(GraphicalEditPart graphEP, int new_X, int new_Y) {
	Rectangle figurebounds = graphEP.getFigure().getBounds();
	ChangeBoundsRequest move_req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
	move_req.setMoveDelta(new Point(new_X - figurebounds.x(), new_Y - figurebounds.y()));
	move_req.setEditParts(graphEP);

	Command cmd = graphEP.getCommand(move_req);
	if (cmd != null && cmd.canExecute())
		cmd.execute();
}
 
Example 7
Source File: AbstractDiagramElementsGmfArranger.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Arranges the children of an EditPart with the GMF arranging algorithm 
 * @param parent - The children of this EditPart will be arranged
 */
protected void arrangeChildren(EditPart parent) {
	@SuppressWarnings("unchecked")
	List<EditPart> elements = parent.getChildren();

	if(!elements.isEmpty()){
		ArrangeRequest arrangeRequest = new ArrangeRequest(ActionIds.ACTION_ARRANGE_ALL);
		List<EditPart> l = new ArrayList<EditPart>();
		l.addAll(elements);
		arrangeRequest.setPartsToArrange(l);
		Command cmd = parent.getCommand(arrangeRequest);
		cmd.execute();
	}
}
 
Example 8
Source File: AbstractDiagramElementsGmfArranger.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Calls an autosize on the given GraphicalEditPart
 * @param graphicalEditPart - The GraphicalEditPart that is to be resized
 */
public void autoresizeGraphicalEditPart(GraphicalEditPart graphicalEditPart) {
	List<IGraphicalEditPart> l = new ArrayList<IGraphicalEditPart>();
	l.add(graphicalEditPart);
	SizeAction action = new SizeAction(SizeAction.PARAMETER_AUTOSIZE, l);
	Command cmd = action.getCommand();
	
	if (cmd != null && cmd.canExecute()){
		cmd.execute();
	}
}
 
Example 9
Source File: CamelEditorDropTargetListener.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
private void execCommandStack(Command command) {
    CommandStack cs = editor.getCommandStack();
    if (cs != null) {
        cs.execute(command);
    } else {
        command.execute();
    }
}
 
Example 10
Source File: ProcBuilder.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addSequenceFlow(final String name, final String sourceId, final String targetId, final boolean isDefault, final Point sourceAnchor,
        final Point targetAnchor, final PointList bendpoints) throws ProcBuilderException {
    final String srcId = NamingUtils.convertToId(sourceId);
    final String trgtId = NamingUtils.convertToId(targetId);
    final ShapeNodeEditPart sourceNode = editParts.get(srcId);
    final ShapeNodeEditPart targetNode = editParts.get(trgtId);

    if (!canSequenceFlowBeCreated(srcId, trgtId, sourceNode, targetNode)) {
        return;
    }

    final CreateConnectionViewAndElementRequest request = new CreateConnectionViewAndElementRequest(ProcessElementTypes.SequenceFlow_4001,
            ((IHintedType) ProcessElementTypes.SequenceFlow_4001).getSemanticHint(), diagramPart
                    .getDiagramPreferencesHint());
    final Command createSequenceFlowCommand = CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceNode, targetNode);
    if(!createSequenceFlowCommand.canExecute()) {
       return;
    }
    createSequenceFlowCommand.execute();
    
    final ConnectionViewAndElementDescriptor newObject = (ConnectionViewAndElementDescriptor) request.getNewObject();
    final Edge edge = (Edge) newObject.getAdapter(Edge.class);
    final SequenceFlow createdElement = (SequenceFlow) newObject.getElementAdapter().getAdapter(EObject.class);
    if (createdElement == null) {
        throw new ProcBuilderException("Impossible to create SequenceFlow " + name);
    }

    if (bendpoints != null && bendpoints.size() > 1) {
        setBendPoints(bendpoints, newObject);
    }

    handleSequenceFlowAnchors(sourceAnchor, targetAnchor, newObject);
    if (name != null) {
        commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.Literals.ELEMENT__NAME, name));
    }
    commandStack.append(SetCommand.create(editingDomain, createdElement, ProcessPackage.eINSTANCE.getSequenceFlow_IsDefault(), isDefault));
    if (edge != null) {
        commandStack.append(SetCommand.create(editingDomain, edge.getStyle(NotationPackage.eINSTANCE.getLineStyle()),
                NotationPackage.eINSTANCE.getLineStyle_LineColor(), FigureUtilities.colorToInteger(ColorConstants.lightGray)));
    }

    createdSequenceFlows.add(new Pair<String, String>(srcId, trgtId));
    currentElement = createdElement;
    currentView = edge;
    execute();
}
 
Example 11
Source File: DiagramElementsModifier.java    From txtUML with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Sets the anchors of a connection according to the given terminals in
 * format: (float, float) .
 * 
 * @param connection
 *            - The connection
 * @param src
 *            - Source Terminal
 * @param trg
 *            - Target Terminal
 */
public static void setConnectionAnchors(ConnectionNodeEditPart connection, String src, String trg) {
	TransactionalEditingDomain editingDomain = connection.getEditingDomain();
	SetConnectionAnchorsCommand cmd = new SetConnectionAnchorsCommand(editingDomain, "Rearrange Anchor");
	cmd.setEdgeAdaptor(new EObjectAdapter(connection.getNotationView()));
	cmd.setNewSourceTerminal(src);
	cmd.setNewTargetTerminal(trg);
	Command proxy = new ICommandProxy(cmd);
	proxy.execute();
}