1 11 12 package org.eclipse.ui.internal.ide; 13 14 import com.ibm.icu.text.MessageFormat; 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import org.eclipse.core.resources.IWorkspace; 19 import org.eclipse.core.resources.ResourcesPlugin; 20 import org.eclipse.core.runtime.CoreException; 21 import org.eclipse.core.runtime.IBundleGroup; 22 import org.eclipse.core.runtime.IBundleGroupProvider; 23 import org.eclipse.core.runtime.IConfigurationElement; 24 import org.eclipse.core.runtime.IProduct; 25 import org.eclipse.core.runtime.IStatus; 26 import org.eclipse.core.runtime.Platform; 27 import org.eclipse.jface.resource.ImageDescriptor; 28 import org.eclipse.swt.custom.BusyIndicator; 29 import org.eclipse.ui.internal.ide.registry.MarkerImageProviderRegistry; 30 import org.eclipse.ui.internal.ide.registry.ProjectImageRegistry; 31 import org.eclipse.ui.plugin.AbstractUIPlugin; 32 import org.osgi.framework.Bundle; 33 34 45 public class IDEWorkbenchPlugin extends AbstractUIPlugin { 46 private static IDEWorkbenchPlugin inst; 48 49 public static boolean DEBUG = false; 52 53 56 public static final String IDE_WORKBENCH = "org.eclipse.ui.ide"; 58 62 public static final String DEFAULT_TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; 64 public static final String PL_MARKER_IMAGE_PROVIDER = "markerImageProviders"; 67 public static final String PL_MARKER_HELP = "markerHelp"; 69 public static final String PL_MARKER_RESOLUTION = "markerResolution"; 71 public static final String PL_CAPABILITIES = "capabilities"; 73 public static final String PL_PROJECT_NATURE_IMAGES = "projectNatureImages"; 75 private final static String ICONS_PATH = "$nl$/icons/full/"; 77 80 private ProjectImageRegistry projectImageRegistry = null; 81 82 85 private MarkerImageProviderRegistry markerImageProviderRegistry = null; 86 87 90 public IDEWorkbenchPlugin() { 91 super(); 92 inst = this; 93 } 94 104 public static Object createExtension(final IConfigurationElement element, 105 final String classAttribute) throws CoreException { 106 Bundle plugin = Platform.getBundle(element.getNamespace()); 109 if (plugin.getState() == Bundle.ACTIVE) { 110 return element.createExecutableExtension(classAttribute); 111 } else { 112 final Object [] ret = new Object [1]; 113 final CoreException[] exc = new CoreException[1]; 114 BusyIndicator.showWhile(null, new Runnable () { 115 public void run() { 116 try { 117 ret[0] = element 118 .createExecutableExtension(classAttribute); 119 } catch (CoreException e) { 120 exc[0] = e; 121 } 122 } 123 }); 124 if (exc[0] != null) { 125 throw exc[0]; 126 } else { 127 return ret[0]; 128 } 129 } 130 } 131 132 136 public static IDEWorkbenchPlugin getDefault() { 137 return inst; 138 } 139 140 146 public static IWorkspace getPluginWorkspace() { 147 return ResourcesPlugin.getWorkspace(); 148 } 149 150 163 public static void log(String message) { 164 getDefault().getLog().log( 165 StatusUtil.newStatus(IStatus.ERROR, message, null)); 166 } 167 168 181 public static void log(String message, Throwable t) { 182 IStatus status = StatusUtil.newStatus(IStatus.ERROR, message, t); 183 log(message, status); 184 } 185 186 201 public static void log(Class clazz, String methodName, Throwable t) { 202 String msg = MessageFormat.format("Exception in {0}.{1}: {2}", new Object [] { clazz.getName(), methodName, t }); 204 log(msg, t); 205 } 206 207 219 public static void log(String message, IStatus status) { 220 221 223 if (message != null) { 224 getDefault().getLog().log( 225 StatusUtil.newStatus(IStatus.ERROR, message, null)); 226 } 227 228 getDefault().getLog().log(status); 229 } 230 231 234 protected void refreshPluginActions() { 235 } 237 238 239 242 public ProjectImageRegistry getProjectImageRegistry() { 243 if (projectImageRegistry == null) { 244 projectImageRegistry = new ProjectImageRegistry(); 245 projectImageRegistry.load(); 246 } 247 return projectImageRegistry; 248 } 249 250 255 public MarkerImageProviderRegistry getMarkerImageProviderRegistry() { 256 if (markerImageProviderRegistry == null) { 257 markerImageProviderRegistry = new MarkerImageProviderRegistry(); 258 } 259 return markerImageProviderRegistry; 260 } 261 262 263 269 public AboutInfo[] getFeatureInfos() { 270 List infos = new ArrayList (); 272 273 IBundleGroupProvider[] providers = Platform.getBundleGroupProviders(); 275 if (providers != null) { 276 for (int i = 0; i < providers.length; ++i) { 277 IBundleGroup[] bundleGroups = providers[i].getBundleGroups(); 278 for (int j = 0; j < bundleGroups.length; ++j) { 279 infos.add(new AboutInfo(bundleGroups[j])); 280 } 281 } 282 } 283 284 return (AboutInfo[]) infos.toArray(new AboutInfo[infos.size()]); 285 } 286 287 293 public AboutInfo getPrimaryInfo() { 294 IProduct product = Platform.getProduct(); 295 return product == null ? null : new AboutInfo(product); 296 } 297 298 304 public static ImageDescriptor getIDEImageDescriptor(String relativePath){ 305 return imageDescriptorFromPlugin(IDE_WORKBENCH, ICONS_PATH + relativePath); 306 } 307 308 309 } 310 | Popular Tags |