blob: c2c8ec22991f01b493ade337c00eed2866fd3db2 (
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
|
/*****************************************************************************
* Copyright (c) 2013 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.textedit.port.xtext.ui.contribution;
import org.eclipse.papyrus.uml.alf.naming.ALFIDConverter;
import org.eclipse.papyrus.uml.tools.utils.MultiplicityElementUtil;
import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
import org.eclipse.papyrus.uml.tools.utils.PortUtil;
import org.eclipse.papyrus.uml.tools.utils.PropertyUtil;
import org.eclipse.papyrus.uml.tools.utils.TypeUtil;
import org.eclipse.papyrus.uml.xtext.integration.CompletionProposalUtils;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.util.UMLSwitch;
public class UMLPortEditorPropertyUtil extends PortUtil {
public static String getLabel(Port port) {
StringBuffer buffer = new StringBuffer();
// visibility
buffer.append(NamedElementUtil.getVisibilityAsSign(port));
buffer.append(" ");
// derived property
buffer.append(getDerived(port));
// name
buffer.append(ALFIDConverter.nameToID(getName(port)));
// is conjugated
if (port.isConjugated()) {
buffer.append(" : ~");
} else {
buffer.append(" : ");
}
// type
if (port.getType() != null) {
buffer.append(CompletionProposalUtils.getQualifiedNameLabelWithSufficientDepth(port.getType(),
port.getNamespace()));
} else {
buffer.append(TypeUtil.UNDEFINED_TYPE_NAME);
}
// multiplicity -> do not display [1]
String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(port);
if (!multiplicity.trim().equals("[1]")) {
buffer.append(multiplicity);
}
// property modifiers
buffer.append(" ");
buffer.append(PropertyUtil.getModifiersAsString(port, false));
// default value
if (port.getDefaultValue() != null) {
String defaultValue = new UMLSwitch<String>() {
@Override
public String caseLiteralBoolean(org.eclipse.uml2.uml.LiteralBoolean object) {
return Boolean.toString(object.booleanValue());
}
@Override
public String caseLiteralInteger(org.eclipse.uml2.uml.LiteralInteger object) {
return Integer.toString(object.integerValue());
}
@Override
public String caseLiteralNull(org.eclipse.uml2.uml.LiteralNull object) {
return "null"; //$NON-NLS-1$
}
@Override
public String caseLiteralString(org.eclipse.uml2.uml.LiteralString object) {
return "\"" + object.stringValue() + "\"";
}
@Override
public String caseLiteralReal(org.eclipse.uml2.uml.LiteralReal object) {
return Double.toString(object.getValue());
}
@Override
public String caseLiteralUnlimitedNatural(org.eclipse.uml2.uml.LiteralUnlimitedNatural object) {
return object.getValue() < 0 ? "*" : Integer.toString(object.getValue());
}
}.doSwitch(port.getDefaultValue());
if (defaultValue != null) {
buffer.append(" = ");
buffer.append(defaultValue);
}
}
return buffer.toString();
}
}
|