1 package net.sourceforge.phpeclipse.xdebug.ui;
3 import java.util.MissingResourceException;
4 import java.util.ResourceBundle;
6 import org.eclipse.core.runtime.CoreException;
7 import org.eclipse.core.runtime.IStatus;
8 import org.eclipse.core.runtime.Status;
9 import org.eclipse.jface.dialogs.ErrorDialog;
10 import org.eclipse.jface.resource.ImageDescriptor;
11 import org.eclipse.swt.widgets.Display;
12 import org.eclipse.swt.widgets.Shell;
13 import org.eclipse.ui.plugin.AbstractUIPlugin;
14 import org.osgi.framework.BundleContext;
17 * The main plugin class to be used in the desktop.
19 public class XDebugUIPlugin extends AbstractUIPlugin {
21 private static final String BUNDLE_NAME = "net.sourceforge.phpeclipse.xdebug.ui.XDebugUIMessages"; //$NON-NLS-1$
23 private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
24 .getBundle(BUNDLE_NAME);
26 private static final String PLUGIN_ID = "net.sourceforge.phpeclipse.xdebug.ui";
28 // The shared instance.
29 private static XDebugUIPlugin plugin;
34 public XDebugUIPlugin() {
39 * This method is called upon plug-in activation
41 public void start(BundleContext context) throws Exception {
46 * This method is called when the plug-in is stopped
48 public void stop(BundleContext context) throws Exception {
54 * Returns the shared instance.
56 public static XDebugUIPlugin getDefault() {
61 * Returns an image descriptor for the image file at the given plug-in
66 * @return the image descriptor
68 public static ImageDescriptor getImageDescriptor(String path) {
69 return AbstractUIPlugin.imageDescriptorFromPlugin(
70 "net.sourceforge.phpeclipse.xdebug.ui", path);
74 * Convenience method which returns the unique identifier of this plugin.
76 public static String getUniqueIdentifier() {
81 * Utility method with conventions
83 public static void errorDialog(Shell shell, String title, String message,
85 // if the 'message' resource string and the IStatus' message are the
87 // don't show both in the dialog
88 if (s != null && message.equals(s.getMessage())) {
91 ErrorDialog.openError(shell, title, message, s);
95 * Utility method with conventions
97 public static void errorDialog(Shell shell, String title, String message,
100 if (t instanceof CoreException) {
101 status = ((CoreException) t).getStatus();
102 // if the 'message' resource string and the IStatus' message are the
104 // don't show both in the dialog
105 if (status != null && message.equals(status.getMessage())) {
109 status = new Status(IStatus.ERROR, getUniqueIdentifier(),
110 IStatus.ERROR, "Error within Debug UI: ", t); //$NON-NLS-1$
113 ErrorDialog.openError(shell, title, message, status);
117 * Logs the specified status with this plug-in's log.
122 public static void log(IStatus status) {
123 getDefault().getLog().log(status);
127 * Logs an internal error with the specified throwable
130 * the exception to be logged
132 public static void log(Throwable e) {
133 log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR,
134 "Internal Error", e));
138 * Returns the standard display to be used. The method first checks, if the
139 * thread calling this method has an associated display. If so, this display
140 * is returned. Otherwise the method returns the default display.
142 public static Display getStandardDisplay() {
144 display = Display.getCurrent();
146 display = Display.getDefault();
150 public static String getString(String key) {
152 return RESOURCE_BUNDLE.getString(key);
153 } catch (MissingResourceException e) {
154 return '!' + key + '!';