1 package net.sourceforge.phpeclipse.xdebug.ui;
3 import java.util.MissingResourceException;
4 import java.util.ResourceBundle;
6 import org.eclipse.swt.widgets.Display;
7 import org.eclipse.swt.widgets.Shell;
8 import org.eclipse.ui.plugin.*;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.core.runtime.IStatus;
11 import org.eclipse.core.runtime.Status;
12 import org.eclipse.jface.dialogs.ErrorDialog;
13 import org.eclipse.jface.resource.ImageDescriptor;
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";
29 //The shared instance.
30 private static XDebugUIPlugin plugin;
35 public XDebugUIPlugin() {
40 * This method is called upon plug-in activation
42 public void start(BundleContext context) throws Exception {
47 * This method is called when the plug-in is stopped
49 public void stop(BundleContext context) throws Exception {
55 * Returns the shared instance.
57 public static XDebugUIPlugin getDefault() {
62 * Returns an image descriptor for the image file at the given
63 * plug-in relative path.
65 * @param path the path
66 * @return the image descriptor
68 public static ImageDescriptor getImageDescriptor(String path) {
69 return AbstractUIPlugin.imageDescriptorFromPlugin("net.sourceforge.phpeclipse.xdebug.ui", path);
73 * Convenience method which returns the unique identifier of this plugin.
75 public static String getUniqueIdentifier() {
80 * Utility method with conventions
82 public static void errorDialog(Shell shell, String title, String message, IStatus s) {
83 // if the 'message' resource string and the IStatus' message are the same,
84 // don't show both in the dialog
85 if (s != null && message.equals(s.getMessage())) {
88 ErrorDialog.openError(shell, title, message, s);
93 * Utility method with conventions
95 public static void errorDialog(Shell shell, String title, String message, Throwable t) {
97 if (t instanceof CoreException) {
98 status= ((CoreException)t).getStatus();
99 // if the 'message' resource string and the IStatus' message are the same,
100 // don't show both in the dialog
101 if (status != null && message.equals(status.getMessage())) {
105 status= new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, "Error within Debug UI: ", t); //$NON-NLS-1$
108 ErrorDialog.openError(shell, title, message, status);
112 * Logs the specified status with this plug-in's log.
114 * @param status status to log
116 public static void log(IStatus status) {
117 getDefault().getLog().log(status);
121 * Logs an internal error with the specified throwable
123 * @param e the exception to be logged
125 public static void log(Throwable e) {
126 log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, "Internal Error", e));
130 * Returns the standard display to be used. The method first checks, if
131 * the thread calling this method has an associated display. If so, this
132 * display is returned. Otherwise the method returns the default display.
134 public static Display getStandardDisplay() {
136 display= Display.getCurrent();
138 display= Display.getDefault();
142 public static String getString(String key) {
144 return RESOURCE_BUNDLE.getString(key);
145 } catch (MissingResourceException e) {
146 return '!' + key + '!';