blob: 2e16e0f3bfd8c0104f118c4bddff9cd6e7a6c94e (
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
|
/*****************************************************************************
* Copyright (c) 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:
*
* CEA LIST - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultSemanticEditPolicy;
import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.CustomGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.ElementTypes;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.GraphicalTypeRegistry;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementReorientCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementReorientCommand;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants;
/**
* <pre>
* Custom semantic edit policy that replace DefaultSemanticEditPolicy
* in order to manage Class Diagram specific elements (reference
* relationships COMMENT_ANNOTATED_ELEMENT and CONSTRAINT_CONSTRAINED_ELEMENT).
* </pre>
*/
public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy {
/** Local graphical type registry for graphical elements */
private IGraphicalTypeRegistry registry = new CustomGraphicalTypeRegistry();
/** Local graphical type registry for inherited graphical elements */
private IGraphicalTypeRegistry inheritedRegistry = new GraphicalTypeRegistry();
/**
* {@inheritDoc}
*/
@Override
protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
if(ElementTypes.COMMENT_ANNOTATED_ELEMENT == req.getElementType()) {
return getGEFWrapper(new CommentAnnotatedElementCreateCommand(req, req.getSource(), req.getTarget()));
}
if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT == req.getElementType()) {
return getGEFWrapper(new ConstraintConstrainedElementCreateCommand(req, req.getSource(), req.getTarget()));
}
String newEdgeGraphicalType = registry.getEdgeGraphicalType(req.getElementType());
if(inheritedRegistry.isKnownEdgeType(newEdgeGraphicalType)) {
return UnexecutableCommand.INSTANCE;
}
if(!registry.isKnownEdgeType(newEdgeGraphicalType)) {
return UnexecutableCommand.INSTANCE;
}
return super.getCreateRelationshipCommand(req);
}
/**
* {@inheritDoc}
*/
@Override
protected Command getReorientReferenceRelationshipCommand(ReorientReferenceRelationshipRequest req) {
View reconnectedView = (View)req.getParameter(RequestParameterConstants.GRAPHICAL_RECONNECTED_EDGE);
String reconnectedViewType = (reconnectedView != null) ? reconnectedView.getType() : IGraphicalTypeRegistry.UNDEFINED_TYPE;
if(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint().equals(reconnectedViewType)) {
return getGEFWrapper(new CommentAnnotatedElementReorientCommand(req));
}
if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint().equals(reconnectedViewType)) {
return getGEFWrapper(new ConstraintConstrainedElementReorientCommand(req));
}
return super.getReorientReferenceRelationshipCommand(req);
}
}
|