blob: 04625899f3d86f955424826ab5d8c7c3f96293aa (
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
|
/*****************************************************************************
* Copyright (c) 2016 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
* Nicolas FAUVERGUE (ALL4TEC) nicolas.fauvergue@all4tec.net - Bug 496905
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.activity.helper;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IndirectMaskLabelEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.Messages;
import org.eclipse.papyrus.uml.diagram.common.helper.StereotypedElementLabelHelper;
import org.eclipse.papyrus.uml.internationalization.utils.utils.UMLLabelInternationalization;
import org.eclipse.papyrus.uml.tools.utils.ICustomAppearance;
import org.eclipse.papyrus.uml.tools.utils.TypeUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Pin;
import org.eclipse.uml2.uml.TypedElement;
/**
* Helper for labels displaying {@link Pin}
*/
public class PinLabelHelper extends StereotypedElementLabelHelper {
private static PinLabelHelper labelHelper;
private final Map<String, String> masks = new HashMap<String, String>();
/**
* {@inheritDoc}
*/
public static PinLabelHelper getInstance() {
if (labelHelper == null) {
labelHelper = new PinLabelHelper();
}
return labelHelper;
}
private PinLabelHelper() {
masks.put(ICustomAppearance.DISP_TYPE, Messages.ICustomAppearance_PIN_DISP_TYPE);
}
/**
* {@inheritDoc}
*/
@Override
protected String elementLabel(GraphicalEditPart editPart) {
IMaskManagedLabelEditPolicy policy = (IMaskManagedLabelEditPolicy) editPart.getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
if (policy == null) {
policy = (IMaskManagedLabelEditPolicy) editPart.getEditPolicy(IndirectMaskLabelEditPolicy.INDRIRECT_MASK_MANAGED_LABEL);
}
Collection<String> displayValue = Collections.emptySet();
if (policy != null) {
displayValue = policy.getCurrentDisplayValue();
}
NamedElement namedElement = getUMLElement(editPart);
return namedElement != null ? getCustomLabel(namedElement, displayValue) : "";
}
/**
* {@inheritDoc}
*/
private String getCustomLabel(NamedElement namedElement, Collection<String> maskValues) {
StringBuffer buffer = new StringBuffer();
if (maskValues.contains(ICustomAppearance.DISP_NAME)) {
buffer.append(" ");
String name = UMLLabelInternationalization.getInstance().getLabel(namedElement);
buffer.append(null == name ? "" : name);
}
if (namedElement instanceof TypedElement) {
if (maskValues.contains(ICustomAppearance.DISP_TYPE)) {
if (((TypedElement) namedElement).getType() != null) {
buffer.append(": " + UMLLabelInternationalization.getInstance().getLabel(((TypedElement) namedElement).getType()));
} else {
buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
}
}
}
return buffer.toString().trim();
}
/**
* {@inheritDoc}
*/
public Map<String, String> getMasks() {
return masks;
}
/**
* {@inheritDoc}
*/
@Override
public Pin getUMLElement(GraphicalEditPart editPart) {
Element element = super.getUMLElement(editPart);
return element instanceof Pin ? (Pin) element : null;
}
}
|