blob: 93c2000d5cacf5ab68a1efc8afd84623226ad1e8 (
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
127
128
129
130
131
132
133
134
135
136
137
138
|
/*****************************************************************************
* Copyright (c) 2008-2009 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.diagram.common.editparts;
import org.eclipse.draw2d.Label;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.appearance.helper.NameLabelIconHelper;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeNamedElementFigure;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.uml2.uml.NamedElement;
/**
* <pre>
* Abstract EditPart supporting font and icon management of name and qualified name labels.
* Similar implementation to {@link NamedElementEditPart} but indirectly inheriting from
* {@link BorderedBorderItemEditPart} in order to provide support for Affixed Child nodes.
* </pre>
*/
public abstract class BorderNamedElementEditPart extends BorderUMLNodeEditPart implements IUMLNamedElementEditPart {
/**
*
* Constructor.
*
* @param view
*/
public BorderNamedElementEditPart(View view) {
super(view);
}
/**
* {@inheritDoc}
*/
public NamedElement getNamedElement() {
return (NamedElement)getUMLElement();
}
/**
* {@inheritDoc}
*/
@Override
protected void handleNotificationEvent(Notification event) {
super.handleNotificationEvent(event);
if(resolveSemanticElement() != null) {
refreshIconNamedLabel();
refreshFontColor();
}
}
/**
* Refresh the icon in name label
*/
private void refreshIconNamedLabel() {
getNodeNamedElementFigure().setNameLabelIcon(NameLabelIconHelper.showLabelIcon((View)getModel()));
}
/**
* {@inheritDoc}
*/
@Override
protected void refreshVisuals() {
super.refreshVisuals();
if((getNodeNamedElementFigure() != null) && (resolveSemanticElement() != null)) {
refreshIconNamedLabel();
refreshFontColor();
}
}
/**
* A method to specify the labels to be update when the font is refreshed.
* Subclasses should call super.refreshLabelsFont(font)
*
* @param font
* the font to use
*/
protected void refreshLabelsFont(Font font) {
super.refreshLabelsFont(font);
// Apply the font to the Name Label
getNodeNamedElementFigure().getNameLabel().setFont(font);
// Apply the font to the Qualified Name
Label qualifiedNameLabel = getNodeNamedElementFigure().getQualifiedNameLabel();
if(qualifiedNameLabel != null) {
qualifiedNameLabel.setFont(font);
}
// Apply the font to the tagged Label
Label tagLabel = getNodeNamedElementFigure().getTaggedLabel();
if(tagLabel != null) {
tagLabel.setFont(font);
}
}
/**
* Get EditPart figure.
*
* @return the EditPart figure
*/
private IPapyrusNodeNamedElementFigure getNodeNamedElementFigure() {
return (IPapyrusNodeNamedElementFigure)getPrimaryShape();
}
/**
* {@inheritDoc}
*/
@Override
protected void setFontColor(Color color) {
super.setFontColor(color);
// Qualified Name
Label qualifiedNameLabel = getNodeNamedElementFigure().getQualifiedNameLabel();
if(qualifiedNameLabel != null) {
qualifiedNameLabel.setForegroundColor(color);
}
// Tagged Label
Label tagLabel = getNodeNamedElementFigure().getTaggedLabel();
if(tagLabel != null) {
tagLabel.setForegroundColor(color);
}
}
}
|