1 11 package org.eclipse.pde.internal.ui; 12 13 import java.util.Locale ; 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 getText(Object 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 getObjectText(ExecutionEnvironment environment) { 176 return preventNull(environment.getName()); 177 } 178 179 public String getObjectText(IPluginBase pluginBase) { 180 String name = 181 isFullNameModeEnabled() 182 ? pluginBase.getTranslatedName() 183 : pluginBase.getId(); 184 name = preventNull(name); 185 String version = pluginBase.getVersion(); 186 187 String 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; return text; 196 } 197 198 private String preventNull(String text) { 199 return text!=null?text:""; } 201 202 public String getObjectText(IPluginExtension extension) { 203 return preventNull(isFullNameModeEnabled() 204 ? extension.getTranslatedName() 205 : extension.getPoint()); 206 } 207 208 public String getObjectText(IPluginExtensionPoint point) { 209 return preventNull(isFullNameModeEnabled() 210 ? point.getTranslatedName() 211 : point.getId()); 212 } 213 214 public String getObjectText(ImportObject obj) { 215 String version = obj.getImport().getVersion(); 216 if (version != null && version.length() > 0) 217 version = formatVersion(version); 218 219 String text = isFullNameModeEnabled() ? obj.toString() : preventNull(obj.getId()); 220 return version == null || version.length() == 0 ? text : text + " " + version; } 222 223 public String getObjectText(IProductPlugin obj) { 224 if (isFullNameModeEnabled()) { 225 String 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 : "?"; } 232 return preventNull(obj.getId()); 233 } 234 235 public String getObjectText(BundleDescription bundle) { 236 String 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 : "?"; } 244 return preventNull(id); 245 } 246 247 public String getObjectText(IPluginImport obj) { 248 if (isFullNameModeEnabled()) { 249 String 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 : "?"; } 256 return preventNull(obj.getId()); 257 } 258 public String getObjectText(IBuildEntry obj) { 259 return obj.getName(); 260 } 261 262 public String getObjectText(IPluginLibrary obj) { 263 return preventNull(obj.getName()); 264 } 265 266 public String getObjectText(ISchemaObject obj) { 267 StringBuffer text = new StringBuffer (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(" ("); text.append(minOccurs); 278 text.append(" - "); if (unbounded) 280 text.append('*'); 281 else 282 text.append(maxOccurs); 283 text.append(')'); 284 } 285 } 286 287 return text.toString(); 288 } 289 290 294 public String 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 314 public String 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 getObjectText(FeaturePlugin obj) { 326 String name = 327 isFullNameModeEnabled() ? obj.getLabel() : obj.getId(); 328 String version = obj.getVersion(); 329 330 String 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 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 getObjectText(IFeatureModel obj, boolean showVersion) { 356 IFeature feature = obj.getFeature(); 357 String 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 getObjectText(IFeatureModel obj) { 368 return getObjectText(obj, true); 369 } 370 371 public String getObjectText(FeatureChild obj) { 372 return preventNull(obj.getId()) + ' ' + formatVersion(obj.getVersion()); 373 } 374 375 public String 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 getObjectText(ISiteFeature obj) { 381 IFeatureModel model = PDECore.getDefault().getFeatureModelManager().findFeatureModel( 382 obj.getId(), 383 obj.getVersion() != null ? obj.getVersion() : "0.0.0"); if (model != null) 385 return getObjectText(model); 386 return preventNull(obj.getURL()); 387 } 388 389 public String getObjectText(ISiteArchive obj) { 390 return preventNull(obj.getPath()); 391 } 392 public String getObjectText(ISiteCategoryDefinition obj) { 393 return preventNull(obj.getLabel()); 394 } 395 public String getObjectText(PackageObject obj) { 396 StringBuffer buffer = new StringBuffer (obj.getName()); 397 String version = obj.getVersion(); 398 if (version != null && !version.equals(Version.emptyVersion.toString())) { 399 version = formatVersion(version); 401 buffer.append(' ').append(version); 402 } 403 return buffer.toString(); 404 } 405 public String 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 getObjectText(ITargetPlugin obj) { 413 if (isFullNameModeEnabled()) { 414 String 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 : "?"; } 421 return preventNull(obj.getId()); 422 } 423 424 public String 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 getObjectText(IAdditionalLocation obj) { 430 return preventNull(obj.getPath()); 431 } 432 433 public Image getImage(Object 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 property = 617 project.getPersistentProperty( 618 PDECore.EXTERNAL_PROJECT_PROPERTY); 619 if (property != null) { 620 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 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 text = info.getDescription(); 837 if (text != null) 838 text = text.trim(); 839 if (text != null && text.length() > 0) { 840 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 899 900 903 private static boolean isRTL() { 904 Locale locale = Locale.getDefault(); 905 String localeString = locale.toString(); 906 return (localeString.startsWith("ar") || localeString.startsWith("he")); } 909 910 913 public static String formatVersion(String versionRange) { 914 boolean isBasicVersion = versionRange == null || versionRange.length() == 0 || Character.isDigit(versionRange.charAt(0)); 915 if (isBasicVersion) { 916 if (BidiUtil.isBidiPlatform()) 917 return "\u200f(\u200e" + versionRange + ")"; return ("(" + versionRange + ')'); } else if (isRTL() && BidiUtil.isBidiPlatform()) { 923 int index = versionRange.indexOf(','); 927 if (index > 0) { 928 StringBuffer buffer = new StringBuffer ("\u200f\u202e"); buffer.append(versionRange.charAt(0)); 933 buffer.append('\u202d'); 935 buffer.append(versionRange.substring(1, index)); 937 buffer.append("\u202c, \u202d"); buffer.append(versionRange.substring(index + 1, versionRange.length() - 1)); 942 buffer.append('\u202c'); 944 buffer.append(versionRange.charAt(versionRange.length() - 1)); 946 return buffer.toString(); 947 } 948 } 951 return versionRange; 952 } 953 } 954 | Popular Tags |