blob: ec7588971b0c94ffcf2b1b8477ba1836b485de3d (
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*****************************************************************************
* Copyright (c) 2009-2011 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:
* Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
import org.eclipse.papyrus.uml.diagram.composite.custom.edit.command.CustomConnectorCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.custom.edit.command.CustomRoleBindingCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConnectorEditPart;
import org.eclipse.papyrus.uml.diagram.composite.providers.UMLElementTypes;
/**
* <pre>
* This class provides a custom edit policy used to replace the SEMANTIC_ROLE
* generated for the Port element (when used in CompositeStructure Diagram)
* </pre>
*/
public class CustomPortItemSemanticEditPolicy extends org.eclipse.papyrus.uml.diagram.composite.edit.policies.PortItemSemanticEditPolicy {
@Override
protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
switch (getVisualID(req)) {
case ConnectorEditPart.VISUAL_ID:
IElementEditService provider = ElementEditServiceUtils.getCommandProvider(req.getRelationship());
if (provider == null) {
return UnexecutableCommand.INSTANCE;
}
// Add graphical new end View in request parameters
View targetView = (View) getHost().getModel();
req.setParameter(org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants.EDGE_REORIENT_REQUEST_END_VIEW, targetView);
// Retrieve re-orient command from the Element Edit service
ICommand reorientCommand = provider.getEditCommand(req);
if (reorientCommand == null) {
return UnexecutableCommand.INSTANCE;
}
return getGEFWrapper(reorientCommand.reduce());
}
return super.getReorientRelationshipCommand(req);
}
/**
* <pre>
* Forbid direct destruction of Port in case the graphical parent is not
* the semantic parent.
*
* {@inheritDoc}
* </pre>
*/
@Override
protected Command getDestroyElementCommand(DestroyElementRequest req) {
EObject graphicalParent = ((GraphicalEditPart) getHost().getParent()).resolveSemanticElement();
EObject semanticParent = req.getElementToDestroy().eContainer();
if (graphicalParent != semanticParent) {
return UnexecutableCommand.INSTANCE;
}
return super.getDestroyElementCommand(req);
}
/**
* <pre>
* Calls a custom creation command to allow the creation of a Connector connected to a Port
* on its source end.
*
* {@inheritDoc}
* </pre>
*/
@Override
protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) {
if (UMLElementTypes.Connector_4013 == req.getElementType()) {
return getGEFWrapper(new CustomConnectorCreateCommand(req, req.getSource(), null));
}
if (UMLElementTypes.Dependency_4017 == req.getElementType()) {
return getGEFWrapper(new CustomRoleBindingCreateCommand(req, req.getSource(), req.getTarget()));
}
return super.getStartCreateRelationshipCommand(req);
}
/**
* <pre>
* Calls a custom creation command to allow the creation of a Connector connected to a Port
* on its target end.
*
* {@inheritDoc}
* </pre>
*/
@Override
protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
if (UMLElementTypes.Connector_4013 == req.getElementType()) {
return getGEFWrapper(new CustomConnectorCreateCommand(req, req.getSource(), req.getTarget()));
}
if (UMLElementTypes.Dependency_4017 == req.getElementType()) {
return getGEFWrapper(new CustomRoleBindingCreateCommand(req, req.getSource(), req.getTarget()));
}
return super.getCompleteCreateRelationshipCommand(req);
}
}
|