blob: e42e292e62b905a9bce59a5f4dd17b7236a2e5d0 (
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
|
/*****************************************************************************
* Copyright (c) 2018 CEA LIST, EclipseSource and others.
*
* 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:
* EclipseSource - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.parts;
import java.util.List;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeConnectionRequest;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.sequence.anchors.CenterAnchor;
import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.DestructionOccurrenceGraphicalNodeEditPolicy;
import org.eclipse.papyrus.uml.diagram.sequence.figures.DestructionEventNodePlate;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
public class CDestructionOccurrenceSpecificationEditPart extends DestructionOccurrenceSpecificationEditPart {
public CDestructionOccurrenceSpecificationEditPart(View view) {
super(view);
}
@Override
protected void createDefaultEditPolicies() {
super.createDefaultEditPolicies();
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new DestructionOccurrenceGraphicalNodeEditPolicy());
}
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
if (request instanceof CreateUnspecifiedTypeConnectionRequest) {
CreateUnspecifiedTypeConnectionRequest createRequest = (CreateUnspecifiedTypeConnectionRequest) request;
List<?> relationshipTypes = createRequest.getElementTypes();
for (Object type : relationshipTypes) {
if (UMLElementTypes.DurationConstraint_Edge.equals(type) || UMLElementTypes.DurationObservation_Edge.equals(type)) {
return new CenterAnchor(getFigure());
}
}
} else if (request instanceof CreateConnectionViewRequest) {
CreateConnectionViewRequest createRequest = (CreateConnectionViewRequest) request;
if (isDurationLink(createRequest)) {
return new CenterAnchor(getFigure());
}
}
return super.getTargetConnectionAnchor(request);
}
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
if (request instanceof CreateUnspecifiedTypeConnectionRequest) {
CreateUnspecifiedTypeConnectionRequest createRequest = (CreateUnspecifiedTypeConnectionRequest) request;
List<?> relationshipTypes = createRequest.getElementTypes();
for (Object type : relationshipTypes) {
if (UMLElementTypes.DurationConstraint_Edge.equals(type) || UMLElementTypes.DurationObservation_Edge.equals(type)) {
return new CenterAnchor(getFigure());
}
}
} else if (request instanceof CreateConnectionViewRequest) {
CreateConnectionViewRequest createRequest = (CreateConnectionViewRequest) request;
if (isDurationLink(createRequest)) {
return new CenterAnchor(getFigure());
}
}
return super.getSourceConnectionAnchor(request);
}
@Override
protected NodeFigure createNodePlate() {
// Use a custom NodePlate to support the Destruction's CenterAnchor
DestructionEventNodePlate nodePlate = new DestructionEventNodePlate(40, 40);
return nodePlate;
}
private boolean isDurationLink(CreateConnectionViewRequest createRequest) {
String semanticHint = createRequest.getConnectionViewDescriptor().getSemanticHint();
switch (semanticHint) {
case DurationConstraintLinkEditPart.VISUAL_ID:
case DurationObservationLinkEditPart.VISUAL_ID:
return true;
}
return false;
}
}
|