1
package net.launchpad.vide.flowchart.diagram.navigator;
3
import net.launchpad.vide.flowchart.Program;
4
import net.launchpad.vide.flowchart.diagram.edit.parts.FunctionalCommandCodeEditPart;
5
import net.launchpad.vide.flowchart.diagram.edit.parts.FunctionalCommandEditPart;
6
import net.launchpad.vide.flowchart.diagram.edit.parts.FunctionalCommandOutputEditPart;
7
import net.launchpad.vide.flowchart.diagram.edit.parts.ProgramEditPart;
8
import net.launchpad.vide.flowchart.diagram.part.FlowchartDiagramEditorPlugin;
9
import net.launchpad.vide.flowchart.diagram.part.FlowchartVisualIDRegistry;
10
import net.launchpad.vide.flowchart.diagram.providers.FlowchartElementTypes;
11
import net.launchpad.vide.flowchart.diagram.providers.FlowchartParserProvider;
13
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
14
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
15
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
16
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
17
import org.eclipse.gmf.runtime.notation.View;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.ImageRegistry;
20
import org.eclipse.jface.viewers.ITreePathLabelProvider;
21
import org.eclipse.jface.viewers.LabelProvider;
22
import org.eclipse.jface.viewers.TreePath;
23
import org.eclipse.jface.viewers.ViewerLabel;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.ui.IMemento;
26
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
27
import org.eclipse.ui.navigator.ICommonLabelProvider;
32
public class FlowchartNavigatorLabelProvider extends LabelProvider implements
33
ICommonLabelProvider, ITreePathLabelProvider {
39
FlowchartDiagramEditorPlugin
42
.put("Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
43
FlowchartDiagramEditorPlugin
46
.put("Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
52
public void updateLabel(ViewerLabel label, TreePath elementPath) {
53
Object element = elementPath.getLastSegment();
54
if (element instanceof FlowchartNavigatorItem
55
&& !isOwnView(((FlowchartNavigatorItem) element).getView())) {
58
label.setText(getText(element));
59
label.setImage(getImage(element));
65
public Image getImage(Object element) {
66
if (element instanceof FlowchartNavigatorGroup) {
67
FlowchartNavigatorGroup group = (FlowchartNavigatorGroup) element;
68
return FlowchartDiagramEditorPlugin.getInstance().getBundledImage(
72
if (element instanceof FlowchartNavigatorItem) {
73
FlowchartNavigatorItem navigatorItem = (FlowchartNavigatorItem) element;
74
if (!isOwnView(navigatorItem.getView())) {
75
return super.getImage(element);
77
return getImage(navigatorItem.getView());
80
return super.getImage(element);
86
public Image getImage(View view) {
87
switch (FlowchartVisualIDRegistry.getVisualID(view)) {
88
case FunctionalCommandOutputEditPart.VISUAL_ID:
90
"Navigator?Link?http://flowchart/1.0?FunctionalCommand?output", FlowchartElementTypes.FunctionalCommandOutput_4001); //$NON-NLS-1$
91
case ProgramEditPart.VISUAL_ID:
93
"Navigator?Diagram?http://flowchart/1.0?Program", FlowchartElementTypes.Program_1000); //$NON-NLS-1$
94
case FunctionalCommandEditPart.VISUAL_ID:
96
"Navigator?TopLevelNode?http://flowchart/1.0?FunctionalCommand", FlowchartElementTypes.FunctionalCommand_2001); //$NON-NLS-1$
98
return getImage("Navigator?UnknownElement", null); //$NON-NLS-1$
104
private Image getImage(String key, IElementType elementType) {
105
ImageRegistry imageRegistry = FlowchartDiagramEditorPlugin
106
.getInstance().getImageRegistry();
107
Image image = imageRegistry.get(key);
108
if (image == null && elementType != null
109
&& FlowchartElementTypes.isKnownElementType(elementType)) {
110
image = FlowchartElementTypes.getImage(elementType);
111
imageRegistry.put(key, image);
115
image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$
116
imageRegistry.put(key, image);
124
public String getText(Object element) {
125
if (element instanceof FlowchartNavigatorGroup) {
126
FlowchartNavigatorGroup group = (FlowchartNavigatorGroup) element;
127
return group.getGroupName();
130
if (element instanceof FlowchartNavigatorItem) {
131
FlowchartNavigatorItem navigatorItem = (FlowchartNavigatorItem) element;
132
if (!isOwnView(navigatorItem.getView())) {
135
return getText(navigatorItem.getView());
138
return super.getText(element);
144
public String getText(View view) {
145
if (view.getElement() != null && view.getElement().eIsProxy()) {
146
return getUnresolvedDomainElementProxyText(view);
148
switch (FlowchartVisualIDRegistry.getVisualID(view)) {
149
case FunctionalCommandOutputEditPart.VISUAL_ID:
150
return getFunctionalCommandOutput_4001Text(view);
151
case ProgramEditPart.VISUAL_ID:
152
return getProgram_1000Text(view);
153
case FunctionalCommandEditPart.VISUAL_ID:
154
return getFunctionalCommand_2001Text(view);
156
return getUnknownElementText(view);
162
private String getFunctionalCommand_2001Text(View view) {
163
IParser parser = FlowchartParserProvider.getParser(
164
FlowchartElementTypes.FunctionalCommand_2001,
165
view.getElement() != null ? view.getElement() : view,
166
FlowchartVisualIDRegistry
167
.getType(FunctionalCommandCodeEditPart.VISUAL_ID));
168
if (parser != null) {
169
return parser.getPrintString(new EObjectAdapter(
170
view.getElement() != null ? view.getElement() : view),
171
ParserOptions.NONE.intValue());
173
FlowchartDiagramEditorPlugin.getInstance().logError(
174
"Parser was not found for label " + 5001); //$NON-NLS-1$
175
return ""; //$NON-NLS-1$
182
private String getFunctionalCommandOutput_4001Text(View view) {
183
return ""; //$NON-NLS-1$
189
private String getProgram_1000Text(View view) {
190
Program domainModelElement = (Program) view.getElement();
191
if (domainModelElement != null) {
192
return domainModelElement.getName();
194
FlowchartDiagramEditorPlugin.getInstance().logError(
195
"No domain element for view with visualID = " + 1000); //$NON-NLS-1$
196
return ""; //$NON-NLS-1$
203
private String getUnknownElementText(View view) {
204
return "<UnknownElement Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$ //$NON-NLS-2$
210
private String getUnresolvedDomainElementProxyText(View view) {
211
return "<Unresolved domain element Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$ //$NON-NLS-2$
217
public void init(ICommonContentExtensionSite aConfig) {
223
public void restoreState(IMemento aMemento) {
229
public void saveState(IMemento aMemento) {
235
public String getDescription(Object anElement) {
242
private boolean isOwnView(View view) {
243
return ProgramEditPart.MODEL_ID.equals(FlowchartVisualIDRegistry