~peta-power-group/+junk/vIDE-trunk

« back to all changes in this revision

Viewing changes to net.launchpad.vide.diagram/src/net/launchpad/vide/flowchart/diagram/navigator/FlowchartNavigatorLabelProvider.java

  • Committer: Dražen Lučanin
  • Date: 2010-12-16 01:15:35 UTC
  • Revision ID: kermit666@gmail.com-20101216011535-5uk4xtiwbu9ia3hl
Added the algorithm domain model & deleted the old generated projects

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package net.launchpad.vide.flowchart.diagram.navigator;
2
 
 
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;
12
 
 
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;
28
 
 
29
 
/**
30
 
 * @generated
31
 
 */
32
 
public class FlowchartNavigatorLabelProvider extends LabelProvider implements
33
 
                ICommonLabelProvider, ITreePathLabelProvider {
34
 
 
35
 
        /**
36
 
         * @generated
37
 
         */
38
 
        static {
39
 
                FlowchartDiagramEditorPlugin
40
 
                                .getInstance()
41
 
                                .getImageRegistry()
42
 
                                .put("Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
43
 
                FlowchartDiagramEditorPlugin
44
 
                                .getInstance()
45
 
                                .getImageRegistry()
46
 
                                .put("Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
47
 
        }
48
 
 
49
 
        /**
50
 
         * @generated
51
 
         */
52
 
        public void updateLabel(ViewerLabel label, TreePath elementPath) {
53
 
                Object element = elementPath.getLastSegment();
54
 
                if (element instanceof FlowchartNavigatorItem
55
 
                                && !isOwnView(((FlowchartNavigatorItem) element).getView())) {
56
 
                        return;
57
 
                }
58
 
                label.setText(getText(element));
59
 
                label.setImage(getImage(element));
60
 
        }
61
 
 
62
 
        /**
63
 
         * @generated
64
 
         */
65
 
        public Image getImage(Object element) {
66
 
                if (element instanceof FlowchartNavigatorGroup) {
67
 
                        FlowchartNavigatorGroup group = (FlowchartNavigatorGroup) element;
68
 
                        return FlowchartDiagramEditorPlugin.getInstance().getBundledImage(
69
 
                                        group.getIcon());
70
 
                }
71
 
 
72
 
                if (element instanceof FlowchartNavigatorItem) {
73
 
                        FlowchartNavigatorItem navigatorItem = (FlowchartNavigatorItem) element;
74
 
                        if (!isOwnView(navigatorItem.getView())) {
75
 
                                return super.getImage(element);
76
 
                        }
77
 
                        return getImage(navigatorItem.getView());
78
 
                }
79
 
 
80
 
                return super.getImage(element);
81
 
        }
82
 
 
83
 
        /**
84
 
         * @generated
85
 
         */
86
 
        public Image getImage(View view) {
87
 
                switch (FlowchartVisualIDRegistry.getVisualID(view)) {
88
 
                case FunctionalCommandOutputEditPart.VISUAL_ID:
89
 
                        return getImage(
90
 
                                        "Navigator?Link?http://flowchart/1.0?FunctionalCommand?output", FlowchartElementTypes.FunctionalCommandOutput_4001); //$NON-NLS-1$
91
 
                case ProgramEditPart.VISUAL_ID:
92
 
                        return getImage(
93
 
                                        "Navigator?Diagram?http://flowchart/1.0?Program", FlowchartElementTypes.Program_1000); //$NON-NLS-1$
94
 
                case FunctionalCommandEditPart.VISUAL_ID:
95
 
                        return getImage(
96
 
                                        "Navigator?TopLevelNode?http://flowchart/1.0?FunctionalCommand", FlowchartElementTypes.FunctionalCommand_2001); //$NON-NLS-1$
97
 
                }
98
 
                return getImage("Navigator?UnknownElement", null); //$NON-NLS-1$
99
 
        }
100
 
 
101
 
        /**
102
 
         * @generated
103
 
         */
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);
112
 
                }
113
 
 
114
 
                if (image == null) {
115
 
                        image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$
116
 
                        imageRegistry.put(key, image);
117
 
                }
118
 
                return image;
119
 
        }
120
 
 
121
 
        /**
122
 
         * @generated
123
 
         */
124
 
        public String getText(Object element) {
125
 
                if (element instanceof FlowchartNavigatorGroup) {
126
 
                        FlowchartNavigatorGroup group = (FlowchartNavigatorGroup) element;
127
 
                        return group.getGroupName();
128
 
                }
129
 
 
130
 
                if (element instanceof FlowchartNavigatorItem) {
131
 
                        FlowchartNavigatorItem navigatorItem = (FlowchartNavigatorItem) element;
132
 
                        if (!isOwnView(navigatorItem.getView())) {
133
 
                                return null;
134
 
                        }
135
 
                        return getText(navigatorItem.getView());
136
 
                }
137
 
 
138
 
                return super.getText(element);
139
 
        }
140
 
 
141
 
        /**
142
 
         * @generated
143
 
         */
144
 
        public String getText(View view) {
145
 
                if (view.getElement() != null && view.getElement().eIsProxy()) {
146
 
                        return getUnresolvedDomainElementProxyText(view);
147
 
                }
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);
155
 
                }
156
 
                return getUnknownElementText(view);
157
 
        }
158
 
 
159
 
        /**
160
 
         * @generated
161
 
         */
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());
172
 
                } else {
173
 
                        FlowchartDiagramEditorPlugin.getInstance().logError(
174
 
                                        "Parser was not found for label " + 5001); //$NON-NLS-1$
175
 
                        return ""; //$NON-NLS-1$
176
 
                }
177
 
        }
178
 
 
179
 
        /**
180
 
         * @generated
181
 
         */
182
 
        private String getFunctionalCommandOutput_4001Text(View view) {
183
 
                return ""; //$NON-NLS-1$
184
 
        }
185
 
 
186
 
        /**
187
 
         * @generated
188
 
         */
189
 
        private String getProgram_1000Text(View view) {
190
 
                Program domainModelElement = (Program) view.getElement();
191
 
                if (domainModelElement != null) {
192
 
                        return domainModelElement.getName();
193
 
                } else {
194
 
                        FlowchartDiagramEditorPlugin.getInstance().logError(
195
 
                                        "No domain element for view with visualID = " + 1000); //$NON-NLS-1$
196
 
                        return ""; //$NON-NLS-1$
197
 
                }
198
 
        }
199
 
 
200
 
        /**
201
 
         * @generated
202
 
         */
203
 
        private String getUnknownElementText(View view) {
204
 
                return "<UnknownElement Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
205
 
        }
206
 
 
207
 
        /**
208
 
         * @generated
209
 
         */
210
 
        private String getUnresolvedDomainElementProxyText(View view) {
211
 
                return "<Unresolved domain element Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
212
 
        }
213
 
 
214
 
        /**
215
 
         * @generated
216
 
         */
217
 
        public void init(ICommonContentExtensionSite aConfig) {
218
 
        }
219
 
 
220
 
        /**
221
 
         * @generated
222
 
         */
223
 
        public void restoreState(IMemento aMemento) {
224
 
        }
225
 
 
226
 
        /**
227
 
         * @generated
228
 
         */
229
 
        public void saveState(IMemento aMemento) {
230
 
        }
231
 
 
232
 
        /**
233
 
         * @generated
234
 
         */
235
 
        public String getDescription(Object anElement) {
236
 
                return null;
237
 
        }
238
 
 
239
 
        /**
240
 
         * @generated
241
 
         */
242
 
        private boolean isOwnView(View view) {
243
 
                return ProgramEditPart.MODEL_ID.equals(FlowchartVisualIDRegistry
244
 
                                .getModelID(view));
245
 
        }
246
 
 
247
 
}