1 11 package org.eclipse.ui.internal.views; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.core.runtime.PlatformObject; 17 import org.eclipse.jface.resource.ImageDescriptor; 18 import org.eclipse.ui.plugin.AbstractUIPlugin; 19 20 29 public final class ViewsPlugin extends AbstractUIPlugin { 30 33 public static final String PLUGIN_ID = "org.eclipse.ui.views"; 35 private final static String ICONS_PATH = "$nl$/icons/full/"; 37 private static ViewsPlugin instance; 38 39 44 public static ViewsPlugin getDefault() { 45 return instance; 46 } 47 48 53 public ViewsPlugin() { 54 super(); 55 instance = this; 56 } 57 58 64 public static ImageDescriptor getViewImageDescriptor(String relativePath){ 65 return imageDescriptorFromPlugin(PLUGIN_ID, ICONS_PATH + relativePath); 66 } 67 68 91 public static Object getAdapter(Object sourceObject, Class adapter, boolean activatePlugins) { 92 Assert.isNotNull(adapter); 93 if (sourceObject == null) { 94 return null; 95 } 96 if (adapter.isInstance(sourceObject)) { 97 return sourceObject; 98 } 99 100 if (sourceObject instanceof IAdaptable) { 101 IAdaptable adaptable = (IAdaptable) sourceObject; 102 103 Object result = adaptable.getAdapter(adapter); 104 if (result != null) { 105 Assert.isTrue(adapter.isInstance(result)); 107 return result; 108 } 109 } 110 111 if (!(sourceObject instanceof PlatformObject)) { 112 Object result; 113 if (activatePlugins) { 114 result = Platform.getAdapterManager().loadAdapter(sourceObject, adapter.getName()); 115 } else { 116 result = Platform.getAdapterManager().getAdapter(sourceObject, adapter); 117 } 118 if (result != null) { 119 return result; 120 } 121 } 122 123 return null; 124 } 125 } 126 | Popular Tags |