1 11 package org.eclipse.ui.externaltools.internal.model; 12 13 14 import java.net.MalformedURLException ; 15 import java.net.URL ; 16 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Status; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.jface.resource.ImageRegistry; 22 import org.eclipse.swt.widgets.Display; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.ui.IWorkbenchPage; 25 import org.eclipse.ui.IWorkbenchWindow; 26 import org.eclipse.ui.plugin.AbstractUIPlugin; 27 import org.osgi.framework.Bundle; 28 import org.osgi.framework.BundleContext; 29 30 33 public final class ExternalToolsPlugin extends AbstractUIPlugin { 34 37 public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); 39 private static ExternalToolsPlugin plugin; 40 41 private static final String EMPTY_STRING= ""; 43 46 public ExternalToolsPlugin() { 47 super(); 48 plugin = this; 49 } 50 51 55 public static ExternalToolsPlugin getDefault() { 56 return plugin; 57 } 58 59 62 public static IStatus newErrorStatus(String message, Throwable exception) { 63 if (message == null) { 64 message= EMPTY_STRING; 65 } 66 return new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception); 67 } 68 69 72 public static CoreException newError(String message, Throwable exception) { 73 return new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception)); 74 } 75 76 81 public void log(String message, Throwable exception) { 82 IStatus status = newErrorStatus(message, exception); 83 getLog().log(status); 84 } 85 86 public void log(Throwable exception) { 87 getLog().log(newErrorStatus("Internal error logged from External Tools UI: ", exception)); } 91 92 97 public ImageDescriptor getImageDescriptor(String path) { 98 try { 99 Bundle bundle= getDefault().getBundle(); 100 URL installURL = bundle.getEntry("/"); URL url = new URL (installURL, path); 102 return ImageDescriptor.createFromURL(url); 103 } catch (MalformedURLException e) { 104 return null; 105 } 106 } 107 108 111 public static IWorkbenchWindow getActiveWorkbenchWindow() { 112 return getDefault().getWorkbench().getActiveWorkbenchWindow(); 113 } 114 115 118 public static IWorkbenchPage getActivePage() { 119 IWorkbenchWindow window= getActiveWorkbenchWindow(); 120 if (window != null) { 121 return window.getActivePage(); 122 } 123 return null; 124 } 125 126 129 public static Shell getActiveWorkbenchShell() { 130 IWorkbenchWindow window = getActiveWorkbenchWindow(); 131 if (window != null) { 132 return window.getShell(); 133 } 134 return null; 135 } 136 137 142 public static Display getStandardDisplay() { 143 Display display = Display.getCurrent(); 144 if (display == null) { 145 display = Display.getDefault(); 146 } 147 return display; 148 } 149 150 153 protected ImageRegistry createImageRegistry() { 154 return ExternalToolsImages.initializeImageRegistry(); 155 } 156 157 160 public void stop(BundleContext context) throws Exception { 161 try { 162 ExternalToolsImages.disposeImageDescriptorRegistry(); 163 } finally { 164 super.stop(context); 165 } 166 } 167 } 168 | Popular Tags |