1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: Ontotext Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.grounding.sawsdl.ui.editor;
26
27 import org.eclipse.jface.resource.ImageDescriptor;
28 import org.eclipse.jface.viewers.*;
29 import org.eclipse.swt.graphics.Image;
30 import org.eclipse.ui.plugin.AbstractUIPlugin;
31 import org.w3c.dom.*;
32 import org.wsmostudio.grounding.sawsdl.ui.UiPlugin;
33
34 public class WSDLTreeLabelProvider implements ILabelProvider {
35
36 private Image inputIcon,
37 outputIcon,
38 serviceIcon,
39 operationIcon,
40 messageIcon,
41 partIcon,
42 portTypeIcon,
43 bindingIcon,
44 typesIcon,
45 elementIcon,
46 tagIcon,
47 schemaIcon,
48 schemaGrayIcon,
49 precondIcon,
50 effectIcon,
51 wsdlIcon,
52 complexTypeIcon,
53 simpleTypeIcon,
54 categoryIcon,
55 attrIcon,
56 txtIcon,
57 faultIcon,
58 liftingIcon,
59 loweringIcon,
60 extAttrIcon;
61
62 private boolean showExtInfo = true;
63 private WSDLAnnotationManager manager;
64
65 public WSDLTreeLabelProvider(WSDLAnnotationManager manager) {
66 initImages();
67 this.manager = manager;
68 }
69
70 public Image getImage(Object element) {
71 if (element instanceof Text) {
72 return txtIcon;
73 }
74 if (element instanceof String) {
75 String data = element.toString();
76 if (data.startsWith(WSDLTreeContentProvider.LIFTING_PREFIX)) {
77 return liftingIcon;
78 }
79 if (data.startsWith(WSDLTreeContentProvider.LOWERING_PREFIX)) {
80 return loweringIcon;
81 }
82 }
83 if (false == element instanceof Element) {
84 return null;
85 }
86 String lName = Utils.getLocalName((Node)element);
87 if (lName.equalsIgnoreCase(Utils.OPERATION_ELEMENT)) {
88 return operationIcon;
89 }
90 if (lName.equalsIgnoreCase(Utils.INTERFACE_ELEMENT)) {
91 return portTypeIcon;
92 }
93 if (lName.equalsIgnoreCase(Utils.PORT_TYPE_ELEMENT)) {
94 return portTypeIcon;
95 }
96 if (lName.equalsIgnoreCase("input")) {
97 return inputIcon;
98 }
99 if (lName.equalsIgnoreCase("output")) {
100 return outputIcon;
101 }
102 if (lName.equalsIgnoreCase("service")) {
103 return serviceIcon;
104 }
105 if (lName.equalsIgnoreCase("binding")) {
106 return bindingIcon;
107 }
108 if (lName.equalsIgnoreCase("types")) {
109 return typesIcon;
110 }
111 if (lName.equalsIgnoreCase(Utils.ATTR_EXTENSIONS)
112 && UiPlugin.hasWSDL11Support()) {
113 return extAttrIcon;
114 }
115 if (lName.equalsIgnoreCase("schema")) {
116 return schemaIcon;
117 }
118 if (lName.equalsIgnoreCase("import")) {
119 return schemaGrayIcon;
120 }
121 if (lName.equalsIgnoreCase(Utils.ELEMENT_ELEMENT)) {
122 return elementIcon;
123 }
124 if (lName.equalsIgnoreCase("precondition")) {
125 return precondIcon;
126 }
127 if (lName.equalsIgnoreCase("effect")) {
128 return effectIcon;
129 }
130 if (lName.equalsIgnoreCase("description")) {
131 return wsdlIcon;
132 }
133 if (lName.equalsIgnoreCase("definitions")) {
134 return wsdlIcon;
135 }
136 if (lName.equalsIgnoreCase("message")) {
137 return messageIcon;
138 }
139 if (lName.equalsIgnoreCase(Utils.PART_ELEMENT)) {
140 return partIcon;
141 }
142 if (lName.equalsIgnoreCase(Utils.COMPLEX_TYPE_ELEMENT)) {
143 return complexTypeIcon;
144 }
145 if (lName.equalsIgnoreCase(Utils.SIMPLE_TYPE_ELEMENT)) {
146 return simpleTypeIcon;
147 }
148 if (lName.equalsIgnoreCase("category")) {
149 return categoryIcon;
150 }
151 if (lName.equalsIgnoreCase(Utils.ATTRIBUTE_ELEMENT)) {
152 return attrIcon;
153 }
154 if (lName.equalsIgnoreCase(Utils.FAULT_ELEMENT)) {
155 return faultIcon;
156 }
157 return tagIcon;
158 }
159
160 public String getText(Object element) {
161
162 if (element instanceof Element) {
163 return labelForElement((Element)element);
164 }
165 if (element instanceof Text) {
166 return ((Text)element).getData().trim();
167 }
168 if (element instanceof Attr) {
169 return labelForAttribute((Attr)element);
170 }
171 if (element instanceof String) {
172 String data = element.toString();
173 if (data.startsWith(WSDLTreeContentProvider.LIFTING_PREFIX)) {
174 return data.substring(WSDLTreeContentProvider.LIFTING_PREFIX.length());
175 }
176 if (data.startsWith(WSDLTreeContentProvider.LOWERING_PREFIX)) {
177 return data.substring(WSDLTreeContentProvider.LOWERING_PREFIX.length());
178 }
179 }
180
181 return element.toString();
182 }
183
184 public void addListener(ILabelProviderListener listener) {
185 }
186 public void dispose() {
187 }
188 public boolean isLabelProperty(Object element, String property) {
189 return false;
190 }
191 public void removeListener(ILabelProviderListener listener) {
192 }
193
194 public void setShowExtensionInfo(boolean stat) {
195 this.showExtInfo = stat;
196 }
197
198 public String labelForAttribute(Attr attr) {
199 String localName = Utils.getLocalName(attr);
200 if (localName.equalsIgnoreCase(Utils.LIFTING_ATTRIBUTE)) {
201 return "LIFTING SCHEMA: " + attr.getValue();
202 }
203 if (localName.equalsIgnoreCase(Utils.LOWERING_ATTRIBUTE)) {
204 return "LOWERING SCHEMA: " + attr.getValue();
205 }
206 return attr.getName() + " = " + attr.getValue();
207 }
208 public String labelForElement(Element el) {
209 String localName = Utils.getLocalName(el);
210 String result = null;
211 if (localName.equalsIgnoreCase(Utils.INTERFACE_ELEMENT)) {
212 result = el.getAttribute("name");
213 }
214 if (localName.equalsIgnoreCase(Utils.PORT_TYPE_ELEMENT)) {
215 result = el.getAttribute("name");
216 }
217 else if (localName.equalsIgnoreCase(Utils.OPERATION_ELEMENT)
218 || localName.equalsIgnoreCase(Utils.FAULT_ELEMENT)) {
219 result = el.getAttribute("name");
220 }
221 else if (localName.equalsIgnoreCase("input")
222 || localName.equalsIgnoreCase("output")) {
223 String messageLab = el.getAttribute("messageLabel");
224 if (messageLab != null && messageLab.length() > 0) {
225 result = '[' + messageLab + "] " + el.getAttribute("element");
226 }
227 else {
228 result = el.getAttribute("element");
229 }
230 }
231 else if (localName.equalsIgnoreCase("precondition")) {
232 result = el.getAttribute("name");
233 }
234 else if (localName.equalsIgnoreCase("effect")) {
235 result = el.getAttribute("name");
236 }
237 else if (localName.equalsIgnoreCase("description")
238 || localName.equalsIgnoreCase("definitions")) {
239 result = el.getAttribute("name");
240 }
241 else if (localName.equalsIgnoreCase(Utils.ELEMENT_ELEMENT)) {
242 result = el.getAttribute("name");
243 String type = el.getAttribute("type");
244 if (type != null && type.trim().length() > 0) {
245 result += " (" + type + ")";
246 }
247 }
248 else if (localName.equalsIgnoreCase(Utils.ATTRIBUTE_ELEMENT)) {
249 result = el.getAttribute("name");
250 String type = el.getAttribute("type");
251 if (type != null && type.trim().length() > 0) {
252 result += " (" + type + ")";
253 }
254 }
255 else if (localName.equalsIgnoreCase("import")) {
256 result = "import: " + el.getAttribute("schemaLocation");
257 }
258 else if (localName.equalsIgnoreCase("message")) {
259 result = el.getAttribute("name");
260 }
261 else if (localName.equalsIgnoreCase(Utils.PART_ELEMENT)) {
262 result = el.getAttribute("name");
263 String type = el.getAttribute("element");
264 if (type == null
265 || type.trim().length() == 0) {
266 type = el.getAttribute("type");
267 }
268 if (type != null
269 && type.trim().length() > 0) {
270 result += " (" + type + ")";
271 }
272 }
273 else if (localName.equalsIgnoreCase("category")
274 || localName.equalsIgnoreCase("group")
275 || localName.equalsIgnoreCase("attributeGroup")) {
276 result = localName + " [" + el.getAttribute("name") + "]";
277 }
278 else if (localName.equalsIgnoreCase(Utils.COMPLEX_TYPE_ELEMENT)) {
279 result = "complexType";
280 String name = el.getAttribute("name");
281 if (name != null
282 && name.trim().length() > 0) {
283 result += " [" + name + "]";
284 }
285 }
286 else if (localName.equalsIgnoreCase(Utils.SIMPLE_TYPE_ELEMENT)) {
287 result = "simpleType [" + el.getAttribute("name") + "]";
288 }
289 else if (localName.equalsIgnoreCase("enumeration")) {
290 result = "enumeration [" + el.getAttribute("value") + "]";
291 }
292 else if (localName.equalsIgnoreCase("restriction")
293 || localName.equalsIgnoreCase("extension")) {
294 result = localName + " [" + el.getAttribute("base") + "]";
295 }
296 if (result != null
297 && result.trim().length() > 0) {
298 return (showExtInfo) ? Utils.addExtInfo(result, el, manager) : result;
299 }
300 return (showExtInfo) ? Utils.addExtInfo(el.getTagName(), el, manager) : el.getTagName();
301 }
302
303 private void initImages() {
304 inputIcon = loadImage("icons/input.gif");
305 outputIcon = loadImage("icons/output.gif");
306 serviceIcon = loadImage("icons/webservice.gif");
307 operationIcon = loadImage("icons/operation.gif");
308 messageIcon = loadImage("icons/message.gif");
309 partIcon = loadImage("icons/part.gif");
310 portTypeIcon = loadImage("icons/interface.gif");
311 bindingIcon = loadImage("icons/binding.gif");
312 typesIcon = loadImage("icons/types.gif");
313 elementIcon = loadImage("icons/type.gif");
314 tagIcon = loadImage("icons/tag.gif");
315 schemaIcon = loadImage("icons/schema.gif");
316 schemaGrayIcon = loadImage("icons/schemagray.gif");
317 precondIcon = loadImage("icons/axiompre.gif");
318 effectIcon = loadImage("icons/axiomeff.gif");
319 wsdlIcon = loadImage("icons/wsdl16.gif");
320 complexTypeIcon = loadImage("icons/ctype.gif");
321 simpleTypeIcon = loadImage("icons/stype.gif");
322 categoryIcon = loadImage("icons/category.gif");
323 attrIcon = loadImage("icons/attr.gif");
324 txtIcon = loadImage("icons/txticon.gif");
325 faultIcon = loadImage("icons/faulticon.gif");
326 liftingIcon = loadImage("icons/lift.gif");
327 loweringIcon = loadImage("icons/low.gif");
328 extAttrIcon = loadImage("icons/attrExts.gif");
329 }
330
331 private Image loadImage(String path) {
332
333 ImageDescriptor descr = AbstractUIPlugin.imageDescriptorFromPlugin(
334 "org.wsmostudio.grounding.sawsdl",
335 path);
336 return descr.createImage();
337 }
338
339
340 }
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382