Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2fe630f70dd07d98d3d447c82416c8b56683c86a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*****************************************************************************
 * Copyright (c) 2010 CEA
 *
 *    
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Atos Origin - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.command;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest.ConnectionViewDescriptor;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.IdentityAnchor;
import org.eclipse.gmf.runtime.notation.NotationFactory;


/**
 * Command used to change the target of an edge.
 * It create an IdentityAnchor to attach the edge.
 * 
 * @author Mathieu Velten
 * 
 */
public class ChangeEdgeTargetCommand extends AbstractTransactionalCommand {

	protected CreateElementAndNodeCommand createElementAndNodeCommand;

	protected ConnectionViewDescriptor descriptor;

	protected String anchorId;

	/**
	 * 
	 * @param editingDomain
	 *        the editing domain.
	 * @param createElementAndNodeCommand
	 *        used to retrieve the target new node of the edge.
	 * @param descriptor
	 *        used to retrieve the edge.
	 * @param anchorId
	 *        the identity of the anchor which will be created to attach the edge.
	 */
	public ChangeEdgeTargetCommand(TransactionalEditingDomain editingDomain, CreateElementAndNodeCommand createElementAndNodeCommand, ConnectionViewDescriptor descriptor, String anchorId) {
		super(editingDomain, "Change message graphical target", null);
		this.createElementAndNodeCommand = createElementAndNodeCommand;
		this.descriptor = descriptor;
		this.anchorId = anchorId;
	}

	@Override
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {

		// retrieve the edge from the descriptor
		Object obj = descriptor.getAdapter(Edge.class);

		if(obj instanceof Edge) {
			Edge edge = (Edge)obj;
			edge.setTarget(createElementAndNodeCommand.getCreatedView());

			IdentityAnchor anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
			anchor.setId(anchorId);

			edge.setTargetAnchor(anchor);
		}
		return null;
	}

}

Back to the top