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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*****************************************************************************
* Copyright (c) 2008 CEA LIST.
*
*
* 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:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.clazz.custom.command;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.notation.Location;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLViewProvider;
import org.eclipse.papyrus.infra.gmfdiag.common.adapter.SemanticAdapter;
/**
* Custom class to create the associationClass node
*
* @author Patrick Tessier
*/
public class AssociationDiamonViewCreateCommand extends AbstractCustomCommand {
private View containerView;
private Point location;
private PreferencesHint preferenceHint;
public EObjectAdapter result;
private SemanticAdapter semanticApdater;
/**
* constructor
*
* @param createConnectionViewAndElementRequest
* the request that is used to obtained the associationclass
* @param domain
* the current edit domain
* @param container
* the container view
* @param viewer
* the viewer
* @param preferencesHint
* the preference hint of the diagram
* @param point
* the location of the future association node
*/
public AssociationDiamonViewCreateCommand(TransactionalEditingDomain domain, View container, EditPartViewer viewer, PreferencesHint preferencesHint, Point point, SemanticAdapter semanticAdapter) {
super(domain, "AssociationDiamonViewCreateCommand", null); //$NON-NLS-1$
this.containerView = container;
this.viewer = viewer;
this.preferenceHint = preferencesHint;
this.location = point;
this.semanticApdater = semanticAdapter;
setResult(CommandResult.newOKCommandResult(semanticAdapter));
}
/**
*
* {@inheritDoc}
*/
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
// / get the factory of the viewer
// Dependency2ViewFactory factory = new Dependency2ViewFactory();
// creation of the element
// this.node = factory.createView(semanticApdater, this.containerView,
// ((IHintedType) UMLElementTypes.Dependency_2014)
// .getSemanticHint(), -1, true, preferenceHint);
UMLViewProvider viewProvider = new UMLViewProvider();
setNode(viewProvider.createAssociation_Shape(((EObject) semanticApdater.getAdapter(EObject.class)), this.containerView, -1, true, preferenceHint));
// put to the good position
Location notationLocation = NotationFactory.eINSTANCE.createLocation();
notationLocation.setX(location.x);
notationLocation.setY(location.y);
if (getNode() instanceof Node)
{
((Node) getNode()).setLayoutConstraint(notationLocation);
}
semanticApdater.setView(getNode());
return CommandResult.newOKCommandResult(semanticApdater);
}
}
|