blob: 0e239e232aad11dfbb908541686448c41740972d (
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
122
123
124
125
126
|
/*****************************************************************************
* Copyright (c) 2009 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.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.papyrus.uml.diagram.common.helper.ILinkMappingHelper;
import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper;
import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper.CommonSourceUMLSwitch;
import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper.CommonTargetUMLSwitch;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Gate;
import org.eclipse.uml2.uml.GeneralOrdering;
import org.eclipse.uml2.uml.MessageEnd;
import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
import org.eclipse.uml2.uml.OccurrenceSpecification;
/**
* A link mapping helper used for dNd.
*
* See {@link CustomDiagramDragDropEditPolicy}
*/
public class SequenceLinkMappingHelper implements ILinkMappingHelper {
/**
* SingletonHolder is loaded at the first execution of getInstance() method
*/
private static class SingletonHolder {
private final static SequenceLinkMappingHelper instance = new SequenceLinkMappingHelper();
}
/**
* Gets the single instance of ClassLinkMappingHelper.
*
* @return single instance of ClassLinkMappingHelper
*/
public static SequenceLinkMappingHelper getInstance() {
return SingletonHolder.instance;
}
/**
* private constructor
*/
private SequenceLinkMappingHelper() {
// do nothing
}
/**
* {@inheritDoc}
*/
public Collection<?> getSource(Element link) {
return LinkMappingHelper.getSource(link, new CommonSourceUMLSwitch() {
public java.util.Collection<?> caseMessage(org.eclipse.uml2.uml.Message object) {
if(object.getSendEvent() != null) {
MessageEnd messageEnd = object.getSendEvent();
if(messageEnd instanceof MessageOccurrenceSpecification) {
return ((MessageOccurrenceSpecification)messageEnd).getCovereds();
} else if(messageEnd instanceof Gate) {
ArrayList<Element> sources = new ArrayList<Element>();
sources.add(((Gate)messageEnd).getOwner());
return sources;
}
} else {
return Collections.singletonList(object.getInteraction());
}
return Collections.EMPTY_LIST;
};
public Collection<?> caseGeneralOrdering(GeneralOrdering object) {
if(object.getBefore() != null) {
OccurrenceSpecification before = object.getBefore();
return before.getCovereds();
}
return Collections.EMPTY_LIST;
}
});
}
/**
* {@inheritDoc}
*/
public Collection<?> getTarget(Element link) {
return LinkMappingHelper.getTarget(link, new CommonTargetUMLSwitch() {
public java.util.Collection<?> caseMessage(org.eclipse.uml2.uml.Message object) {
if(object.getReceiveEvent() != null) {
MessageEnd messageEnd = (MessageEnd)object.getReceiveEvent();
if(messageEnd instanceof MessageOccurrenceSpecification) {
return ((MessageOccurrenceSpecification)messageEnd).getCovereds();
} else if(messageEnd instanceof Gate) {
ArrayList<Element> sources = new ArrayList<Element>();
sources.add(((Gate)messageEnd).getOwner());
return sources;
}
} else {
return Collections.singletonList(object.getInteraction());
}
return Collections.EMPTY_LIST;
};
public Collection<?> caseGeneralOrdering(GeneralOrdering object) {
if(object.getAfter() != null) {
OccurrenceSpecification after = object.getAfter();
return after.getCovereds();
}
return Collections.EMPTY_LIST;
}
});
}
}
|