001: /*****************************************************************************************
002: * Copyright (c) 2004 Andrei Loskutov. All rights reserved. This program and the
003: * accompanying materials are made available under the terms of the BSD License which
004: * accompanies this distribution, and is available at
005: * http://www.opensource.org/licenses/bsd-license.php Contributor: Andrei Loskutov -
006: * initial API and implementation
007: ****************************************************************************************/package de.loskutov.bco;
008:
009: import java.util.MissingResourceException;
010: import java.util.ResourceBundle;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.core.runtime.Status;
014: import org.eclipse.jface.dialogs.MessageDialog;
015: import org.eclipse.swt.widgets.Shell;
016: import org.eclipse.ui.plugin.AbstractUIPlugin;
017: import org.osgi.framework.BundleContext;
018:
019: /**
020: * The main plugin class to be used in the desktop.
021: */
022: public class BytecodeOutlinePlugin extends AbstractUIPlugin {
023: //The shared instance.
024: private static BytecodeOutlinePlugin plugin;
025: //Resource bundle.
026: private ResourceBundle resourceBundle;
027:
028: /**
029: * The constructor.
030: */
031: public BytecodeOutlinePlugin() {
032: super ();
033: plugin = this ;
034: try {
035: resourceBundle = ResourceBundle
036: .getBundle("de.loskutov.bco.BytecodeOutlinePluginResources"); //$NON-NLS-1$
037: } catch (MissingResourceException x) {
038: resourceBundle = null;
039: }
040: }
041:
042: /**
043: * This method is called upon plug-in activation
044: * @param context
045: * @throws Exception
046: */
047: public void start(BundleContext context) throws Exception {
048: super .start(context);
049: }
050:
051: /**
052: * This method is called when the plug-in is stopped
053: * @param context
054: * @throws Exception
055: */
056: public void stop(BundleContext context) throws Exception {
057: super .stop(context);
058: }
059:
060: /**
061: * Returns the shared instance.
062: * @return plugin
063: */
064: public static BytecodeOutlinePlugin getDefault() {
065: return plugin;
066: }
067:
068: /**
069: * Returns the string from the plugin's resource bundle, or 'key' if not found.
070: * @param key
071: * @return translation
072: */
073: public static String getResourceString(String key) {
074: ResourceBundle bundle = BytecodeOutlinePlugin.getDefault()
075: .getResourceBundle();
076: try {
077: return (bundle != null) ? bundle.getString(key) : key;
078: } catch (MissingResourceException e) {
079: return key;
080: }
081: }
082:
083: /**
084: * Returns the plugin's resource bundle,
085: */
086: public ResourceBundle getResourceBundle() {
087: return resourceBundle;
088: }
089:
090: /**
091: * Returns the workspace instance.
092: * @return shell object
093: */
094: public static Shell getShell() {
095: return getDefault().getWorkbench().getActiveWorkbenchWindow()
096: .getShell();
097: }
098:
099: /**
100: * @param messageID
101: * @param error
102: */
103: public static void error(String messageID, Throwable error) {
104: Shell shell = getShell();
105: String message = getResourceString("BytecodeOutline.Error"); //$NON-NLS-1$
106: if (messageID != null) {
107: message = getResourceString(messageID);
108: }
109: message = message + " " + error.getMessage();//$NON-NLS-1$
110: MessageDialog.openError(shell,
111: getResourceString("BytecodeOutline.Title"), //$NON-NLS-1$
112: message);
113:
114: getDefault().getLog().log(
115: new Status(IStatus.ERROR,
116: "BytecodeOutline", 0, message, error)); //$NON-NLS-1$
117: }
118:
119: /**
120: * @param statusID one of IStatus. constants like IStatus.ERROR etc
121: * @param error
122: */
123: public static void log(Throwable error, int statusID) {
124: String message = error.getMessage();
125: if (message == null) {
126: message = error.toString();
127: }
128: getDefault().getLog().log(
129: new Status(statusID,
130: "BytecodeOutline", 0, message, error)); //$NON-NLS-1$
131: }
132:
133: }
|