blob: 7a7c2daef8295a128218ec121ca89092154cd002 (
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
|
/*****************************************************************************
* Copyright (c) 2012 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:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.providers;
import javax.swing.text.Element;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPartService;
import org.eclipse.gmf.runtime.notation.BasicCompartment;
import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
import org.eclipse.papyrus.infra.gmfdiag.common.types.NotationTypesMap;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
import org.eclipse.swt.graphics.Image;
import org.eclipse.uml2.uml.NamedElement;
/**
* A Label Provider for GMF Notation model
*/
public class NotationLabelProvider extends EMFLabelProvider {
/** icon for a compartment */
public static final String ICON_COMPARTMENT = "/icons/none_comp_vis.gif"; //$NON-NLS-1$
@Override
public void dispose() {
super.dispose();
}
@Override
public Image getImage(Object element) {
EObject eObject = EMFHelper.getEObject(element);
if (eObject != null) {
return getImage(eObject);
}
return super.getImage(element);
}
@Override
protected Image getImage(EObject element) {
if(element instanceof Diagram) {
ViewPrototype proto = DiagramUtils.getPrototype((Diagram)element);
if (proto == null)
return null;
return proto.getIcon();
}
// if the element is a compartment
if(element instanceof BasicCompartment || element instanceof DecorationNode) {
return org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage(Activator.ID, ICON_COMPARTMENT);
}
return super.getImage(element);
}
/**
*
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*
* @param element
* @return <ul>
* <li>if element is a {@link NamedElement}, we return its name</li>
* <li>else if element is a {@link Element}, we return its type + a index</li>
* <li>else return Messages#EditorLabelProvider_No_name</li>
* </ul>
*/
@Override
protected String getText(EObject element) {
if(element instanceof Diagram) {
return ((Diagram)element).getName();
}
if(element instanceof View) { // maybe it is a view of a compartment
String humanType = NotationTypesMap.instance.getHumanReadableType((View)element);
if(humanType != null) {
return humanType;
}
EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View)element);
if(dummyEP instanceof ResizableCompartmentEditPart) {
return ((ResizableCompartmentEditPart)dummyEP).getCompartmentName();
}
}
return super.getText(element);
}
}
|