1 11 package org.eclipse.pde.internal.ui; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.net.URL ; 15 import java.util.Hashtable ; 16 17 import org.eclipse.core.resources.IWorkspace; 18 import org.eclipse.core.resources.ResourcesPlugin; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Status; 22 import org.eclipse.debug.core.DebugPlugin; 23 import org.eclipse.debug.core.ILaunchConfigurationListener; 24 import org.eclipse.jface.dialogs.ErrorDialog; 25 import org.eclipse.jface.preference.IPreferenceStore; 26 import org.eclipse.pde.internal.ui.launcher.LaunchConfigurationListener; 27 import org.eclipse.pde.internal.ui.launcher.LaunchListener; 28 import org.eclipse.pde.internal.ui.launcher.LauncherUtils; 29 import org.eclipse.pde.internal.ui.launcher.OSGiFrameworkManager; 30 import org.eclipse.pde.internal.ui.util.SWTUtil; 31 import org.eclipse.swt.widgets.Display; 32 import org.eclipse.swt.widgets.Shell; 33 import org.eclipse.ui.IWorkbenchPage; 34 import org.eclipse.ui.IWorkbenchWindow; 35 import org.eclipse.ui.editors.text.TextFileDocumentProvider; 36 import org.eclipse.ui.forms.FormColors; 37 import org.eclipse.ui.plugin.AbstractUIPlugin; 38 import org.eclipse.ui.texteditor.IDocumentProvider; 39 import org.osgi.framework.BundleContext; 40 41 public class PDEPlugin extends AbstractUIPlugin implements IPDEUIConstants { 42 43 private static PDEPlugin fInstance; 45 46 private LaunchListener fLaunchListener; 48 49 private BundleContext fBundleContext; 50 51 private java.util.Hashtable fCounters; 52 53 private FormColors fFormColors; 55 private PDELabelProvider fLabelProvider; 56 private ILaunchConfigurationListener fLaunchConfigurationListener; 57 58 62 private IDocumentProvider fTextFileDocumentProvider; 63 64 private OSGiFrameworkManager fOSGiFrameworkManager; 65 66 public PDEPlugin() { 67 fInstance = this; 68 } 69 70 public URL getInstallURL() { 71 return getDefault().getBundle().getEntry("/"); } 73 74 public static IWorkbenchPage getActivePage() { 75 return getDefault().internalGetActivePage(); 76 } 77 public static Shell getActiveWorkbenchShell() { 78 IWorkbenchWindow window = getActiveWorkbenchWindow(); 79 if (window != null) { 80 return window.getShell(); 81 } 82 return null; 83 } 84 public static IWorkbenchWindow getActiveWorkbenchWindow() { 85 return getDefault().getWorkbench().getActiveWorkbenchWindow(); 86 } 87 public static PDEPlugin getDefault() { 88 return fInstance; 89 } 90 public Hashtable getDefaultNameCounters() { 91 if (fCounters == null) 92 fCounters = new Hashtable (); 93 return fCounters; 94 } 95 public static String getPluginId() { 96 return getDefault().getBundle().getSymbolicName(); 97 } 98 99 public static IWorkspace getWorkspace() { 100 return ResourcesPlugin.getWorkspace(); 101 } 102 103 private IWorkbenchPage internalGetActivePage() { 104 return getWorkbench().getActiveWorkbenchWindow().getActivePage(); 105 } 106 107 public static void log(IStatus status) { 108 ResourcesPlugin.getPlugin().getLog().log(status); 109 } 110 111 public static void logErrorMessage(String message) { 112 log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, message, null)); 113 } 114 115 public static void logException( 116 Throwable e, 117 final String title, 118 String message) { 119 if (e instanceof InvocationTargetException ) { 120 e = ((InvocationTargetException ) e).getTargetException(); 121 } 122 IStatus status = null; 123 if (e instanceof CoreException) 124 status = ((CoreException) e).getStatus(); 125 else { 126 if (message == null) 127 message = e.getMessage(); 128 if (message == null) 129 message = e.toString(); 130 status = new Status(IStatus.ERROR, getPluginId(), IStatus.OK, message, e); 131 } 132 ResourcesPlugin.getPlugin().getLog().log(status); 133 Display display = SWTUtil.getStandardDisplay(); 134 final IStatus fstatus = status; 135 display.asyncExec(new Runnable () { 136 public void run() { 137 ErrorDialog.openError(null, title, null, fstatus); 138 } 139 }); 140 } 141 142 public static void logException(Throwable e) { 143 logException(e, null, null); 144 } 145 146 public static void log(Throwable e) { 147 if (e instanceof InvocationTargetException ) 148 e = ((InvocationTargetException ) e).getTargetException(); 149 IStatus status = null; 150 if (e instanceof CoreException) 151 status = ((CoreException) e).getStatus(); 152 else 153 status = 154 new Status(IStatus.ERROR, getPluginId(), IStatus.OK, e.getMessage(), e); 155 log(status); 156 } 157 158 public FormColors getFormColors(Display display) { 159 if (fFormColors == null) { 160 fFormColors = new FormColors(display); 161 fFormColors.markShared(); 162 } 163 return fFormColors; 164 } 165 166 169 public void start(BundleContext context) throws Exception { 170 super.start(context); 171 this.fBundleContext = context; 172 fLaunchConfigurationListener = new LaunchConfigurationListener(); 173 DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(fLaunchConfigurationListener); 174 } 175 176 public BundleContext getBundleContext() { 177 return fBundleContext; 178 } 179 180 183 public void stop(BundleContext context) throws Exception { 184 if (fLaunchListener != null) 185 fLaunchListener.shutdown(); 186 if (fFormColors != null) { 187 fFormColors.dispose(); 188 fFormColors = null; 189 } 190 if (fLabelProvider != null) { 191 fLabelProvider.dispose(); 192 fLabelProvider = null; 193 } 194 if (fLaunchConfigurationListener != null) { 195 DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(fLaunchConfigurationListener); 196 fLaunchConfigurationListener = null; 197 } 198 LauncherUtils.shutdown(); 199 super.stop(context); 200 } 201 202 public PDELabelProvider getLabelProvider() { 203 if (fLabelProvider == null) 204 fLabelProvider = new PDELabelProvider(); 205 return fLabelProvider; 206 } 207 208 public LaunchListener getLaunchListener() { 209 if (fLaunchListener == null) 210 fLaunchListener = new LaunchListener(); 211 return fLaunchListener; 212 } 213 214 public OSGiFrameworkManager getOSGiFrameworkManager() { 215 if (fOSGiFrameworkManager == null) 216 fOSGiFrameworkManager = new OSGiFrameworkManager(); 217 return fOSGiFrameworkManager; 218 } 219 220 public static boolean isFullNameModeEnabled() { 221 IPreferenceStore store = getDefault().getPreferenceStore(); 222 return store.getString(IPreferenceConstants.PROP_SHOW_OBJECTS).equals(IPreferenceConstants.VALUE_USE_NAMES); 223 } 224 225 231 public synchronized IDocumentProvider getTextFileDocumentProvider() { 232 if (fTextFileDocumentProvider == null) { 233 fTextFileDocumentProvider = new TextFileDocumentProvider() { 234 protected FileInfo createFileInfo(Object element) throws CoreException { 235 FileInfo info = super.createFileInfo(element); 236 if (info != null && info.fTextFileBuffer != null) 237 info.fModel = info.fTextFileBuffer.getAnnotationModel(); 238 setUpSynchronization(info); 239 return info; 240 } 241 }; 242 } 243 return fTextFileDocumentProvider; 244 } 245 } 246 | Popular Tags |