KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > PDELabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui;
12
13 import java.util.Locale JavaDoc;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.jdt.ui.ISharedImages;
19 import org.eclipse.jdt.ui.JavaUI;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.osgi.service.resolver.BundleDescription;
22 import org.eclipse.osgi.service.resolver.ResolverError;
23 import org.eclipse.pde.core.build.IBuildEntry;
24 import org.eclipse.pde.core.plugin.IFragment;
25 import org.eclipse.pde.core.plugin.IFragmentModel;
26 import org.eclipse.pde.core.plugin.IPlugin;
27 import org.eclipse.pde.core.plugin.IPluginBase;
28 import org.eclipse.pde.core.plugin.IPluginExtension;
29 import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
30 import org.eclipse.pde.core.plugin.IPluginImport;
31 import org.eclipse.pde.core.plugin.IPluginLibrary;
32 import org.eclipse.pde.core.plugin.IPluginModel;
33 import org.eclipse.pde.core.plugin.IPluginModelBase;
34 import org.eclipse.pde.core.plugin.PluginRegistry;
35 import org.eclipse.pde.internal.core.PDECore;
36 import org.eclipse.pde.internal.core.TargetPlatformHelper;
37 import org.eclipse.pde.internal.core.WorkspaceModelManager;
38 import org.eclipse.pde.internal.core.builders.CompilerFlags;
39 import org.eclipse.pde.internal.core.feature.FeatureChild;
40 import org.eclipse.pde.internal.core.feature.FeatureImport;
41 import org.eclipse.pde.internal.core.feature.FeaturePlugin;
42 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
43 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
44 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSConstants;
45 import org.eclipse.pde.internal.core.icheatsheet.simple.ISimpleCSObject;
46 import org.eclipse.pde.internal.core.ifeature.IFeature;
47 import org.eclipse.pde.internal.core.ifeature.IFeatureChild;
48 import org.eclipse.pde.internal.core.ifeature.IFeatureData;
49 import org.eclipse.pde.internal.core.ifeature.IFeatureImport;
50 import org.eclipse.pde.internal.core.ifeature.IFeatureInfo;
51 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
52 import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin;
53 import org.eclipse.pde.internal.core.ifeature.IFeatureURLElement;
54 import org.eclipse.pde.internal.core.iproduct.IProductFeature;
55 import org.eclipse.pde.internal.core.iproduct.IProductPlugin;
56 import org.eclipse.pde.internal.core.ischema.IDocumentSection;
57 import org.eclipse.pde.internal.core.ischema.IMetaAttribute;
58 import org.eclipse.pde.internal.core.ischema.ISchema;
59 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
60 import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
61 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
62 import org.eclipse.pde.internal.core.ischema.ISchemaInclude;
63 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
64 import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference;
65 import org.eclipse.pde.internal.core.ischema.ISchemaRepeatable;
66 import org.eclipse.pde.internal.core.isite.ISiteArchive;
67 import org.eclipse.pde.internal.core.isite.ISiteCategory;
68 import org.eclipse.pde.internal.core.isite.ISiteCategoryDefinition;
69 import org.eclipse.pde.internal.core.isite.ISiteFeature;
70 import org.eclipse.pde.internal.core.itarget.IAdditionalLocation;
71 import org.eclipse.pde.internal.core.itarget.ITargetFeature;
72 import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
73 import org.eclipse.pde.internal.core.plugin.ImportObject;
74 import org.eclipse.pde.internal.core.text.bundle.ExecutionEnvironment;
75 import org.eclipse.pde.internal.core.text.bundle.PackageObject;
76 import org.eclipse.pde.internal.core.util.PDETextHelper;
77 import org.eclipse.pde.internal.ui.elements.NamedElement;
78 import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
79 import org.eclipse.swt.graphics.Image;
80 import org.eclipse.swt.internal.BidiUtil;
81 import org.eclipse.ui.PlatformUI;
82 import org.osgi.framework.Version;
83
84 public class PDELabelProvider extends SharedLabelProvider {
85     public PDELabelProvider() {
86     }
87     public String JavaDoc getText(Object JavaDoc obj) {
88         if (obj instanceof IPluginModelBase) {
89             return getObjectText(((IPluginModelBase) obj).getPluginBase());
90         }
91         if (obj instanceof IPluginBase) {
92             return getObjectText((IPluginBase) obj);
93         }
94         if (obj instanceof ImportObject) {
95             return getObjectText((ImportObject) obj);
96         }
97         if (obj instanceof IProductPlugin) {
98             return getObjectText((IProductPlugin)obj);
99         }
100         if (obj instanceof BundleDescription) {
101             return getObjectText((BundleDescription)obj);
102         }
103         if (obj instanceof IPluginImport) {
104             return getObjectText((IPluginImport)obj);
105         }
106         if (obj instanceof IPluginLibrary) {
107             return getObjectText((IPluginLibrary) obj);
108         }
109         if (obj instanceof IPluginExtension) {
110             return getObjectText((IPluginExtension)obj);
111         }
112         if (obj instanceof IPluginExtensionPoint) {
113             return getObjectText((IPluginExtensionPoint) obj);
114         }
115         if (obj instanceof NamedElement) {
116             return ((NamedElement) obj).getLabel();
117         }
118         if (obj instanceof ISchemaObject) {
119             return getObjectText((ISchemaObject) obj);
120         }
121         if (obj instanceof ISimpleCSObject) {
122             return getObjectText((ISimpleCSObject) obj);
123         }
124         if (obj instanceof ICompCSObject) {
125             return getObjectText((ICompCSObject) obj);
126         }
127         if (obj instanceof FeaturePlugin) {
128             return getObjectText((FeaturePlugin) obj);
129         }
130         if (obj instanceof FeatureImport) {
131             return getObjectText((FeatureImport) obj);
132         }
133         if (obj instanceof IFeatureModel) {
134             return getObjectText((IFeatureModel) obj);
135         }
136         if (obj instanceof FeatureChild) {
137             return getObjectText((FeatureChild) obj);
138         }
139         if (obj instanceof IProductFeature) {
140             return getObjectText((IProductFeature)obj);
141         }
142         if (obj instanceof ISiteFeature) {
143             return getObjectText((ISiteFeature) obj);
144         }
145         if (obj instanceof ISiteArchive) {
146             return getObjectText((ISiteArchive) obj);
147         }
148         if (obj instanceof ISiteCategoryDefinition) {
149             return getObjectText((ISiteCategoryDefinition) obj);
150         }
151         if (obj instanceof ISiteCategory) {
152             return getObjectText((ISiteCategory) obj);
153         }
154         if (obj instanceof IBuildEntry) {
155             return getObjectText((IBuildEntry)obj);
156         }
157         if (obj instanceof PackageObject) {
158             return getObjectText((PackageObject)obj);
159         }
160         if (obj instanceof ITargetPlugin) {
161             return getObjectText((ITargetPlugin)obj);
162         }
163         if (obj instanceof ITargetFeature) {
164             return getObjectText((ITargetFeature)obj);
165         }
166         if (obj instanceof IAdditionalLocation) {
167             return getObjectText((IAdditionalLocation)obj);
168         }
169         if (obj instanceof ExecutionEnvironment) {
170             return getObjectText((ExecutionEnvironment)obj);
171         }
172         return super.getText(obj);
173     }
174
175     private String JavaDoc getObjectText(ExecutionEnvironment environment) {
176         return preventNull(environment.getName());
177     }
178     
179     public String JavaDoc getObjectText(IPluginBase pluginBase) {
180         String JavaDoc name =
181             isFullNameModeEnabled()
182                 ? pluginBase.getTranslatedName()
183                 : pluginBase.getId();
184         name = preventNull(name);
185         String JavaDoc version = pluginBase.getVersion();
186
187         String JavaDoc text;
188
189         if (version != null && version.length() > 0)
190             text = name + ' ' + formatVersion(pluginBase.getVersion());
191         else
192             text = name;
193         if (pluginBase.getModel() != null && !pluginBase.getModel().isInSync())
194             text += " " + PDEUIMessages.PluginModelManager_outOfSync; //$NON-NLS-1$
195
return text;
196     }
197     
198     private String JavaDoc preventNull(String JavaDoc text) {
199         return text!=null?text:""; //$NON-NLS-1$
200
}
201
202     public String JavaDoc getObjectText(IPluginExtension extension) {
203         return preventNull(isFullNameModeEnabled()
204             ? extension.getTranslatedName()
205             : extension.getPoint());
206     }
207
208     public String JavaDoc getObjectText(IPluginExtensionPoint point) {
209         return preventNull(isFullNameModeEnabled()
210             ? point.getTranslatedName()
211             : point.getId());
212     }
213
214     public String JavaDoc getObjectText(ImportObject obj) {
215         String JavaDoc version = obj.getImport().getVersion();
216         if (version != null && version.length() > 0)
217             version = formatVersion(version);
218
219         String JavaDoc text = isFullNameModeEnabled() ? obj.toString() : preventNull(obj.getId());
220         return version == null || version.length() == 0 ? text : text + " " + version; //$NON-NLS-1$
221
}
222     
223     public String JavaDoc getObjectText(IProductPlugin obj) {
224         if (isFullNameModeEnabled()) {
225             String JavaDoc id = obj.getId();
226             IPluginModelBase model = PluginRegistry.findModel(obj.getId());
227             if (model != null) {
228                 return model.getPluginBase().getTranslatedName();
229             }
230             return id != null ? id : "?"; //$NON-NLS-1$
231
}
232         return preventNull(obj.getId());
233     }
234     
235     public String JavaDoc getObjectText(BundleDescription bundle) {
236         String JavaDoc id = bundle.getSymbolicName();
237         if (isFullNameModeEnabled()) {
238             IPluginModelBase model = PluginRegistry.findModel(bundle);
239             if (model != null) {
240                 return model.getPluginBase().getTranslatedName();
241             }
242             return id != null ? id : "?"; //$NON-NLS-1$
243
}
244         return preventNull(id);
245     }
246     
247     public String JavaDoc getObjectText(IPluginImport obj) {
248         if (isFullNameModeEnabled()) {
249             String JavaDoc id = obj.getId();
250             IPluginModelBase model = PluginRegistry.findModel(obj.getId());
251             if (model != null) {
252                 return model.getPluginBase().getTranslatedName();
253             }
254             return id != null ? id : "?"; //$NON-NLS-1$
255
}
256         return preventNull(obj.getId());
257     }
258     public String JavaDoc getObjectText(IBuildEntry obj) {
259         return obj.getName();
260     }
261
262     public String JavaDoc getObjectText(IPluginLibrary obj) {
263         return preventNull(obj.getName());
264     }
265
266     public String JavaDoc getObjectText(ISchemaObject obj) {
267         StringBuffer JavaDoc text = new StringBuffer JavaDoc(obj.getName());
268         if (obj instanceof ISchemaRepeatable) {
269             ISchemaRepeatable rso = (ISchemaRepeatable) obj;
270             boolean unbounded = rso.getMaxOccurs() == Integer.MAX_VALUE;
271             int maxOccurs = rso.getMaxOccurs();
272             int minOccurs = rso.getMinOccurs();
273             if (maxOccurs != 1 || minOccurs != 1) {
274                 if (isRTL() && BidiUtil.isBidiPlatform())
275                     text.append('\u200f');
276                 text.append(" ("); //$NON-NLS-1$
277
text.append(minOccurs);
278                 text.append(" - "); //$NON-NLS-1$ //$NON-NLS-2$
279
if (unbounded)
280                     text.append('*');
281                 else
282                     text.append(maxOccurs);
283                 text.append(')');
284             }
285         }
286         
287         return text.toString();
288     }
289     
290     /**
291      * @param obj
292      * @return
293      */

294     public String JavaDoc getObjectText(ISimpleCSObject obj) {
295         int limit = 50;
296         
297         if (obj.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) {
298             limit = 40;
299         } else if (obj.getType() == ISimpleCSConstants.TYPE_ITEM) {
300             limit = 36;
301         } else if (obj.getType() == ISimpleCSConstants.TYPE_INTRO) {
302             limit = 36;
303         } else if (obj.getType() == ISimpleCSConstants.TYPE_SUBITEM) {
304             limit = 32;
305         }
306         return PDETextHelper.truncateAndTrailOffText(
307                 PDETextHelper.translateReadText(obj.getName()), limit);
308     }
309
310     /**
311      * @param obj
312      * @return
313      */

314     public String JavaDoc getObjectText(ICompCSObject obj) {
315         int limit = 40;
316         ICompCSObject parent = obj.getParent();
317         while(parent != null) {
318             limit = limit - 4;
319             parent = parent.getParent();
320         }
321         return PDETextHelper.truncateAndTrailOffText(
322                 PDETextHelper.translateReadText(obj.getName()), limit);
323     }
324     
325     public String JavaDoc getObjectText(FeaturePlugin obj) {
326         String JavaDoc name =
327             isFullNameModeEnabled() ? obj.getLabel() : obj.getId();
328         String JavaDoc version = obj.getVersion();
329
330         String JavaDoc text;
331
332         if (version != null && version.length() > 0)
333             text = name + ' ' + formatVersion(version);
334         else
335             text = name;
336         return preventNull(text);
337     }
338
339     public String JavaDoc getObjectText(FeatureImport obj) {
340         int type = obj.getType();
341         if (type == IFeatureImport.PLUGIN) {
342             IPlugin plugin = obj.getPlugin();
343             if (plugin != null && isFullNameModeEnabled()) {
344                 return preventNull(plugin.getTranslatedName());
345             }
346         } else if (type == IFeatureImport.FEATURE) {
347             IFeature feature = obj.getFeature();
348             if (feature != null && isFullNameModeEnabled()) {
349                 return preventNull(feature.getTranslatableLabel());
350             }
351         }
352         return preventNull(obj.getId());
353     }
354
355     public String JavaDoc getObjectText(IFeatureModel obj, boolean showVersion) {
356         IFeature feature = obj.getFeature();
357         String JavaDoc name =
358             (isFullNameModeEnabled())
359                 ? feature.getTranslatableLabel()
360                 : feature.getId();
361         if (!showVersion)
362             return preventNull(name);
363         return preventNull(name) + ' ' + formatVersion(feature.getVersion());
364
365     }
366
367     public String JavaDoc getObjectText(IFeatureModel obj) {
368         return getObjectText(obj, true);
369     }
370
371     public String JavaDoc getObjectText(FeatureChild obj) {
372         return preventNull(obj.getId()) + ' ' + formatVersion(obj.getVersion());
373     }
374     
375     public String JavaDoc getObjectText(IProductFeature obj) {
376         IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModel(obj.getId());
377         return (model != null) ? getObjectText(model, false) : preventNull(obj.getId());
378     }
379
380     public String JavaDoc getObjectText(ISiteFeature obj) {
381         IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModel(
382                 obj.getId(),
383                 obj.getVersion() != null ? obj.getVersion() : "0.0.0"); //$NON-NLS-1$
384
if (model != null)
385             return getObjectText(model);
386         return preventNull(obj.getURL());
387     }
388
389     public String JavaDoc getObjectText(ISiteArchive obj) {
390         return preventNull(obj.getPath());
391     }
392     public String JavaDoc getObjectText(ISiteCategoryDefinition obj) {
393         return preventNull(obj.getLabel());
394     }
395     public String JavaDoc getObjectText(PackageObject obj) {
396         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(obj.getName());
397         String JavaDoc version = obj.getVersion();
398         if (version != null && !version.equals(Version.emptyVersion.toString())) {
399             // Format version range for ImportPackageObject. ExportPackageObject is handled correctly in this function
400
version = formatVersion(version);
401             buffer.append(' ').append(version);
402         }
403         return buffer.toString();
404     }
405     public String JavaDoc getObjectText(ISiteCategory obj) {
406         ISiteCategoryDefinition def = obj.getDefinition();
407         if (def != null)
408             return preventNull(def.getLabel());
409         return preventNull(obj.getName());
410     }
411     
412     public String JavaDoc getObjectText(ITargetPlugin obj) {
413         if (isFullNameModeEnabled()) {
414             String JavaDoc id = obj.getId();
415             IPluginModelBase model = PluginRegistry.findModel(obj.getId());
416             if (model != null) {
417                 return model.getPluginBase().getTranslatedName();
418             }
419             return id != null ? id : "?"; //$NON-NLS-1$
420
}
421         return preventNull(obj.getId());
422     }
423     
424     public String JavaDoc getObjectText(ITargetFeature obj) {
425         IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModel(obj.getId());
426         return (model != null) ? getObjectText(model, false) : preventNull(obj.getId());
427     }
428     
429     public String JavaDoc getObjectText(IAdditionalLocation obj) {
430         return preventNull(obj.getPath());
431     }
432
433     public Image getImage(Object JavaDoc obj) {
434         if (obj instanceof IPlugin) {
435             return getObjectImage((IPlugin) obj);
436         }
437         if (obj instanceof IFragment) {
438             return getObjectImage((IFragment) obj);
439         }
440         if (obj instanceof IPluginModel) {
441             return getObjectImage(((IPluginModel) obj).getPlugin());
442         }
443         if (obj instanceof IFragmentModel) {
444             return getObjectImage(((IFragmentModel) obj).getFragment());
445         }
446         if (obj instanceof ImportObject) {
447             return getObjectImage((ImportObject) obj);
448         }
449         if (obj instanceof IPluginImport) {
450             return getObjectImage((IPluginImport) obj);
451         }
452         if (obj instanceof IProductPlugin) {
453             return getObjectImage((IProductPlugin)obj);
454         }
455         if (obj instanceof BundleDescription) {
456             return getObjectImage((BundleDescription)obj);
457         }
458         
459         if (obj instanceof IPluginLibrary) {
460             return getObjectImage((IPluginLibrary) obj);
461         }
462         if (obj instanceof IPluginExtension) {
463             return getObjectImage((IPluginExtension) obj);
464         }
465         if (obj instanceof IPluginExtensionPoint) {
466             return getObjectImage((IPluginExtensionPoint) obj);
467         }
468         if (obj instanceof NamedElement) {
469             return ((NamedElement) obj).getImage();
470         }
471         if (obj instanceof ISchemaElement) {
472             return getObjectImage((ISchemaElement) obj);
473         }
474         if (obj instanceof ISimpleCSObject) {
475             return getObjectImage((ISimpleCSObject)obj);
476         }
477         if (obj instanceof ICompCSObject) {
478             return getObjectImage((ICompCSObject)obj);
479         }
480         if (obj instanceof ISchemaAttribute) {
481             return getObjectImage((ISchemaAttribute) obj);
482         }
483         if (obj instanceof ISchemaInclude) {
484             ISchema schema = ((ISchemaInclude)obj).getIncludedSchema();
485             return get(PDEPluginImages.DESC_PAGE_OBJ, schema == null || !schema.isValid() ? F_ERROR : 0);
486         }
487         if (obj instanceof IDocumentSection || obj instanceof ISchema) {
488             return get(PDEPluginImages.DESC_DOC_SECTION_OBJ);
489         }
490         if (obj instanceof ISchemaCompositor) {
491             return getObjectImage((ISchemaCompositor) obj);
492         }
493         if (obj instanceof IFeatureURLElement) {
494             return getObjectImage((IFeatureURLElement) obj);
495         }
496         if (obj instanceof IFeatureModel) {
497             int flags = 0;
498             if (((IFeatureModel)obj).getUnderlyingResource() == null)
499                 flags |= F_EXTERNAL;
500             return get(PDEPluginImages.DESC_FEATURE_OBJ, flags);
501         }
502         if (obj instanceof IFeatureChild) {
503             return getObjectImage((IFeatureChild) obj);
504         }
505         if (obj instanceof IProductFeature) {
506             return getObjectImage((IProductFeature)obj);
507         }
508         if (obj instanceof IFeaturePlugin) {
509             return getObjectImage((IFeaturePlugin) obj);
510         }
511         if (obj instanceof IFeatureData) {
512             return getObjectImage((IFeatureData) obj);
513         }
514         if (obj instanceof IFeatureImport) {
515             return getObjectImage((IFeatureImport) obj);
516         }
517         if (obj instanceof IFeatureInfo) {
518             return getObjectImage((IFeatureInfo) obj);
519         }
520         if (obj instanceof IBuildEntry) {
521             return get(PDEPluginImages.DESC_BUILD_VAR_OBJ);
522         }
523         if (obj instanceof ISiteFeature) {
524             return getObjectImage((ISiteFeature) obj);
525         }
526         if (obj instanceof ISiteArchive) {
527             return getObjectImage((ISiteArchive) obj);
528         }
529         if (obj instanceof ISiteCategoryDefinition) {
530             return getObjectImage((ISiteCategoryDefinition) obj);
531         }
532         if (obj instanceof ISiteCategory) {
533             return getObjectImage((ISiteCategory) obj);
534         }
535         if (obj instanceof PackageObject) {
536             return getObjectImage((PackageObject) obj);
537         }
538         if (obj instanceof ITargetPlugin) {
539             return getObjectImage((ITargetPlugin) obj);
540         }
541         if (obj instanceof ITargetFeature) {
542             return getObjectImage((ITargetFeature) obj);
543         }
544         if (obj instanceof IAdditionalLocation) {
545             return getObjectImage((IAdditionalLocation)obj);
546         }
547         if (obj instanceof ExecutionEnvironment) {
548             return getObjectImage((ExecutionEnvironment)obj);
549         }
550         if (obj instanceof ResolverError) {
551             return getObjectImage((ResolverError)obj);
552         }
553         return super.getImage(obj);
554     }
555
556     private Image getObjectImage(ResolverError obj) {
557         int type = obj.getType();
558         switch (type) {
559         case ResolverError.MISSING_IMPORT_PACKAGE:
560         case ResolverError.EXPORT_PACKAGE_PERMISSION:
561         case ResolverError.IMPORT_PACKAGE_PERMISSION:
562         case ResolverError.IMPORT_PACKAGE_USES_CONFLICT:
563             return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PACKAGE);
564         case ResolverError.MISSING_EXECUTION_ENVIRONMENT:
565             return get(PDEPluginImages.DESC_JAVA_LIB_OBJ);
566         case ResolverError.MISSING_FRAGMENT_HOST:
567         case ResolverError.MISSING_REQUIRE_BUNDLE:
568         case ResolverError.PROVIDE_BUNDLE_PERMISSION:
569         case ResolverError.REQUIRE_BUNDLE_PERMISSION:
570         case ResolverError.REQUIRE_BUNDLE_USES_CONFLICT:
571         case ResolverError.HOST_BUNDLE_PERMISSION:
572             return get(PDEPluginImages.DESC_PLUGIN_OBJ);
573         }
574         return null;
575     }
576     private Image getObjectImage(ExecutionEnvironment environment) {
577         return get(PDEPluginImages.DESC_JAVA_LIB_OBJ);
578     }
579     
580     private Image getObjectImage(IPlugin plugin) {
581         return getObjectImage(plugin, false, false);
582     }
583     
584     private Image getObjectImage(BundleDescription bundle) {
585         return bundle.getHost() == null
586             ? get(PDEPluginImages.DESC_PLUGIN_OBJ)
587             : get(PDEPluginImages.DESC_FRAGMENT_OBJ);
588     }
589
590     public Image getObjectImage(
591         IPlugin plugin,
592         boolean checkEnabled,
593         boolean javaSearch) {
594         IPluginModelBase model = plugin.getPluginModel();
595         int flags = getModelFlags(model);
596
597         if (javaSearch)
598             flags |= F_JAVA;
599         ImageDescriptor desc = PDEPluginImages.DESC_PLUGIN_OBJ;
600         if (checkEnabled && model.isEnabled() == false)
601             desc = PDEPluginImages.DESC_EXT_PLUGIN_OBJ;
602         return get(desc, flags);
603     }
604
605     private int getModelFlags(IPluginModelBase model) {
606         int flags = 0;
607         if (!(model.isLoaded() && model.isInSync()))
608             flags = F_ERROR;
609         IResource resource = model.getUnderlyingResource();
610         if (resource == null) {
611             flags |= F_EXTERNAL;
612         } else {
613             IProject project = resource.getProject();
614             try {
615                 if (WorkspaceModelManager.isBinaryProject(project)) {
616                     String JavaDoc property =
617                         project.getPersistentProperty(
618                             PDECore.EXTERNAL_PROJECT_PROPERTY);
619                     if (property != null) {
620                         /*
621                         if (property.equals(PDECore.EXTERNAL_PROJECT_VALUE))
622                             flags |= F_EXTERNAL;
623                         else if (property.equals(PDECore.BINARY_PROJECT_VALUE))
624                         */

625                         flags |= F_BINARY;
626                     }
627                 }
628             } catch (CoreException e) {
629             }
630         }
631         return flags;
632     }
633
634     private Image getObjectImage(IFragment fragment) {
635         return getObjectImage(fragment, false, false);
636     }
637
638     public Image getObjectImage(
639         IFragment fragment,
640         boolean checkEnabled,
641         boolean javaSearch) {
642         IPluginModelBase model = fragment.getPluginModel();
643         int flags = getModelFlags(model);
644         if (javaSearch)
645             flags |= F_JAVA;
646         ImageDescriptor desc = PDEPluginImages.DESC_FRAGMENT_OBJ;
647         if (checkEnabled && !model.isEnabled())
648             desc = PDEPluginImages.DESC_EXT_FRAGMENT_OBJ;
649         return get(desc, flags);
650     }
651
652     private Image getObjectImage(ImportObject iobj) {
653         int flags = 0;
654         IPluginImport iimport = iobj.getImport();
655         if (!iobj.isResolved())
656             flags = iimport.isOptional() ? F_WARNING : F_ERROR;
657         else if (iimport.isReexported())
658             flags = F_EXPORT;
659         IPlugin plugin = iobj.getPlugin();
660         if (plugin != null) {
661             IPluginModelBase model = plugin.getPluginModel();
662             flags |= getModelFlags(model);
663         }
664         return get(getRequiredPluginImageDescriptor(iimport), flags);
665     }
666     
667     protected ImageDescriptor getRequiredPluginImageDescriptor(IPluginImport iobj) {
668         return PDEPluginImages.DESC_REQ_PLUGIN_OBJ;
669     }
670
671     private Image getObjectImage(IPluginImport obj) {
672         int flags = 0;
673         if (obj.isReexported())
674             flags = F_EXPORT;
675         return get(getRequiredPluginImageDescriptor(obj), flags);
676     }
677     
678     private Image getObjectImage(IProductPlugin obj) {
679         BundleDescription desc = TargetPlatformHelper.getState().getBundle(obj.getId(), null);
680         if (desc != null) {
681             return desc.getHost() == null
682                 ? get(PDEPluginImages.DESC_PLUGIN_OBJ)
683                 : get(PDEPluginImages.DESC_FRAGMENT_OBJ);
684         }
685         return get(PDEPluginImages.DESC_PLUGIN_OBJ, F_ERROR);
686     }
687
688     private Image getObjectImage(IPluginLibrary library) {
689         return get(PDEPluginImages.DESC_JAVA_LIB_OBJ);
690     }
691     private Image getObjectImage(IPluginExtension point) {
692         return get(PDEPluginImages.DESC_EXTENSION_OBJ);
693     }
694     private Image getObjectImage(IPluginExtensionPoint point) {
695         return get(PDEPluginImages.DESC_EXT_POINT_OBJ);
696     }
697
698     private Image getObjectImage(ISimpleCSObject object) {
699
700         if (object.getType() == ISimpleCSConstants.TYPE_ITEM) {
701             return get(PDEPluginImages.DESC_CSITEM_OBJ);
702         } else if (object.getType() == ISimpleCSConstants.TYPE_SUBITEM) {
703             return get(PDEPluginImages.DESC_CSSUBITEM_OBJ);
704         } else if (object.getType() == ISimpleCSConstants.TYPE_REPEATED_SUBITEM) {
705             return get(PDEPluginImages.DESC_CSUNSUPPORTED_OBJ);
706         } else if (object.getType() == ISimpleCSConstants.TYPE_CONDITIONAL_SUBITEM) {
707             return get(PDEPluginImages.DESC_CSUNSUPPORTED_OBJ);
708         } else if (object.getType() == ISimpleCSConstants.TYPE_CHEAT_SHEET) {
709             return get(PDEPluginImages.DESC_SIMPLECS_OBJ);
710         } else if (object.getType() == ISimpleCSConstants.TYPE_INTRO) {
711             return get(PDEPluginImages.DESC_CSINTRO_OBJ);
712         } else if (object.getType() == ISimpleCSConstants.TYPE_PERFORM_WHEN) {
713             return get(PDEPluginImages.DESC_CSUNSUPPORTED_OBJ);
714         }
715         return get(PDEPluginImages.DESC_SIMPLECS_OBJ, F_ERROR);
716     }
717
718     /**
719      * @param object
720      * @return
721      */

722     private Image getObjectImage(ICompCSObject object) {
723
724         if (object.getType() == ICompCSConstants.TYPE_TASK) {
725             return get(PDEPluginImages.DESC_SIMPLECS_OBJ);
726         } else if (object.getType() == ICompCSConstants.TYPE_TASKGROUP) {
727             return get(PDEPluginImages.DESC_CSTASKGROUP_OBJ);
728         } else if (object.getType() == ICompCSConstants.TYPE_COMPOSITE_CHEATSHEET) {
729             return get(PDEPluginImages.DESC_COMPCS_OBJ);
730         }
731         return get(PDEPluginImages.DESC_SIMPLECS_OBJ, F_ERROR);
732     }
733     
734     private Image getObjectImage(ISchemaElement element) {
735         int flags = 0;
736         if (element instanceof ISchemaObjectReference &&
737                 ((ISchemaObjectReference)element).getReferencedObject() == null)
738             flags |= F_ERROR;
739         ImageDescriptor desc = element instanceof ISchemaObjectReference
740                                 ? PDEPluginImages.DESC_XML_ELEMENT_REF_OBJ
741                                 : PDEPluginImages.DESC_GEL_SC_OBJ;
742         return get(desc, flags);
743     }
744     
745     private Image getObjectImage(ISchemaAttribute att) {
746         if (att.getKind() == IMetaAttribute.JAVA)
747             return get(PDEPluginImages.DESC_ATT_CLASS_OBJ);
748         if (att.getKind() == IMetaAttribute.RESOURCE)
749             return get(PDEPluginImages.DESC_ATT_FILE_OBJ);
750         if (att.getUse() == ISchemaAttribute.REQUIRED)
751             return get(PDEPluginImages.DESC_ATT_REQ_OBJ);
752         return get(PDEPluginImages.DESC_ATT_IMPL_OBJ);
753     }
754
755     private Image getObjectImage(ISchemaCompositor compositor) {
756         switch (compositor.getKind()) {
757             case ISchemaCompositor.ALL :
758                 return get(PDEPluginImages.DESC_ALL_SC_OBJ);
759             case ISchemaCompositor.CHOICE :
760                 return get(PDEPluginImages.DESC_CHOICE_SC_OBJ);
761             case ISchemaCompositor.SEQUENCE :
762                 return get(PDEPluginImages.DESC_SEQ_SC_OBJ);
763             case ISchemaCompositor.GROUP :
764                 return get(PDEPluginImages.DESC_GROUP_SC_OBJ);
765         }
766         return null;
767     }
768
769     private Image getObjectImage(IFeatureURLElement url) {
770         return get(PDEPluginImages.DESC_LINK_OBJ);
771     }
772
773     private Image getObjectImage(IFeaturePlugin plugin) {
774         int flags = 0;
775         if (((FeaturePlugin) plugin).getPluginBase() == null) {
776             int cflag = CompilerFlags.getFlag(null, CompilerFlags.F_UNRESOLVED_PLUGINS);
777             if (cflag==CompilerFlags.ERROR)
778                 flags = F_ERROR;
779             else if (cflag==CompilerFlags.WARNING)
780                 flags = F_WARNING;
781         }
782         if (plugin.isFragment())
783             return get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
784         return get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
785     }
786
787     private Image getObjectImage(IFeatureChild feature) {
788         int flags = 0;
789         if (((FeatureChild) feature).getReferencedFeature() == null) {
790             int cflag = CompilerFlags.getFlag(null, CompilerFlags.F_UNRESOLVED_FEATURES);
791             if (cflag==CompilerFlags.ERROR)
792                 flags = F_ERROR;
793             else if (cflag==CompilerFlags.WARNING)
794                 flags = F_WARNING;
795         }
796         return get(PDEPluginImages.DESC_FEATURE_OBJ, flags);
797     }
798     
799     private Image getObjectImage(IProductFeature feature) {
800         return get(PDEPluginImages.DESC_FEATURE_OBJ, 0);
801     }
802
803     private Image getObjectImage(IFeatureData data) {
804         int flags = 0;
805         if (!data.exists())
806             flags = F_ERROR;
807         ImageDescriptor desc =
808             PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(
809                 data.getId());
810         return get(desc, flags);
811     }
812
813     private Image getObjectImage(IFeatureImport obj) {
814         FeatureImport iimport = (FeatureImport) obj;
815         int type = iimport.getType();
816         ImageDescriptor base;
817         int flags = 0;
818         
819         if (type==IFeatureImport.FEATURE) {
820             base = PDEPluginImages.DESC_FEATURE_OBJ;
821             IFeature feature = iimport.getFeature();
822             if (feature == null)
823                 flags = F_ERROR;
824         }
825         else {
826             base = PDEPluginImages.DESC_REQ_PLUGIN_OBJ;
827             IPlugin plugin = iimport.getPlugin();
828             if (plugin == null)
829                 flags = F_ERROR;
830         }
831
832         return get(base, flags);
833     }
834     private Image getObjectImage(IFeatureInfo info) {
835         int flags = 0;
836         String JavaDoc text = info.getDescription();
837         if (text != null)
838             text = text.trim();
839         if (text != null && text.length() > 0) {
840             // complete
841
flags = F_EDIT;
842         }
843         return get(PDEPluginImages.DESC_DOC_SECTION_OBJ, flags);
844     }
845
846     public Image getObjectImage(ISiteFeature obj) {
847         int flags = 0;
848         if (obj.getArchiveFile() != null) {
849             flags = F_BINARY;
850         }
851         return get(PDEPluginImages.DESC_JAVA_LIB_OBJ, flags);
852     }
853
854     public Image getObjectImage(ISiteArchive obj) {
855         return get(PDEPluginImages.DESC_JAVA_LIB_OBJ, 0);
856     }
857     public Image getObjectImage(ISiteCategoryDefinition obj) {
858         return get(PDEPluginImages.DESC_CATEGORY_OBJ);
859     }
860
861     public Image getObjectImage(ISiteCategory obj) {
862         int flags = obj.getDefinition() == null ? F_ERROR : 0;
863         return get(PDEPluginImages.DESC_CATEGORY_OBJ, flags);
864     }
865     public Image getObjectImage(PackageObject obj) {
866         return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_PACKAGE);
867     }
868     
869     public Image getObjectImage(ITargetPlugin obj) {
870         BundleDescription desc = TargetPlatformHelper.getState().getBundle(obj.getId(), null);
871         if (desc != null) {
872             return desc.getHost() == null
873                 ? get(PDEPluginImages.DESC_PLUGIN_OBJ)
874                 : get(PDEPluginImages.DESC_FRAGMENT_OBJ);
875         }
876         return get(PDEPluginImages.DESC_PLUGIN_OBJ, 0);
877     }
878     
879     public Image getObjectImage(ITargetFeature obj) {
880         return get(PDEPluginImages.DESC_FEATURE_OBJ, 0);
881     }
882     
883     public Image getObjectImage(IAdditionalLocation obj) {
884         return get(PDEPluginImages.DESC_SITE_OBJ);
885     }
886     
887     public boolean isFullNameModeEnabled() {
888         return PDEPlugin.isFullNameModeEnabled();
889     }
890     
891     /*
892      * BIDI support (bug 183417)
893      * Any time we display a bracketed version, we should preface it with /u200f (zero width arabic character).
894      * Then inside the bracket, we should include /u200e (zero width latin character). Since the leading separator
895      * will be resolved based on its surrounding text, when it is surrounded by a arabic character and a latin character
896      * the bracket will take the proper shape based on the underlying embedded direction. The latin character must
897      * come after the bracket since versions are represented with latin numbers. This ensure proper number format.
898      */

899
900     /*
901      * returns true if instance has either arabic of hebrew locale (text displayed RTL)
902      */

903     private static boolean isRTL() {
904         Locale JavaDoc locale = Locale.getDefault();
905         String JavaDoc localeString = locale.toString();
906         return (localeString.startsWith("ar") || //$NON-NLS-1$
907
localeString.startsWith("he")); //$NON-NLS-1$
908
}
909     
910     /*
911      * Returns a String containing the unicode to properly display the version ranging when running bidi.
912      */

913     public static String JavaDoc formatVersion(String JavaDoc versionRange) {
914         boolean isBasicVersion = versionRange == null || versionRange.length() == 0 || Character.isDigit(versionRange.charAt(0));
915         if (isBasicVersion) {
916             if (BidiUtil.isBidiPlatform())
917                 // The versionRange is a single version. Since parenthesis is neutral, it direction is determined by leading and following character.
918
// Since leading character is arabic and following character is latin, the parenthesis will take default (proper) direction.
919
// Must have the following character be the latin character to ensure version is formatted as latin (LTR)
920
return "\u200f(\u200e" + versionRange + ")"; //$NON-NLS-1$ //$NON-NLS-2$
921
return ("(" + versionRange + ')'); //$NON-NLS-1$
922
} else if (isRTL() && BidiUtil.isBidiPlatform()) {
923             // when running RTL and formatting a versionRange, we need to break up the String to make sure it is properly formatted.
924
// A version should always be formatted LTR (start with \u202d, ends with \u202c) since it is composed of latin characaters.
925
// With specifying this format, if the qualifier has a latin character, it will not be formatted correctly.
926
int index = versionRange.indexOf(',');
927             if (index > 0) {
928                 // begin with zero length arabic character so version appears on left (correct) side of id.
929
// Then add RTL strong encoding so parentheses and comma have RTL formatting.
930
StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("\u200f\u202e"); //$NON-NLS-1$
931
// begin with leading separator (either parenthesis or bracket)
932
buffer.append(versionRange.charAt(0));
933                 // start LTR encoding for min version
934
buffer.append('\u202d');
935                 // min version
936
buffer.append(versionRange.substring(1, index));
937                 // end LTR encoding, add ',' (which will be RTL due to first RTL strong encoding), and start LTR encoding for max version
938
// We require a space between the two numbers otherwise it is considered 1 number in arabic (comma is digit grouping system).
939
buffer.append("\u202c, \u202d"); //$NON-NLS-1$
940
// max version
941
buffer.append(versionRange.substring(index + 1, versionRange.length() - 1));
942                 // end LTR encoding
943
buffer.append('\u202c');
944                 // add trailing separator
945
buffer.append(versionRange.charAt(versionRange.length() - 1));
946                 return buffer.toString();
947             }
948 // } else {
949
// since the version is LTR and we are running LTR, do nothing. This is the case for version ranges when run in LTR
950
}
951         return versionRange;
952     }
953 }
954
Popular Tags