KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > loskutov > bco > BytecodeOutlinePlugin


1 /*****************************************************************************************
2  * Copyright (c) 2004 Andrei Loskutov. All rights reserved. This program and the
3  * accompanying materials are made available under the terms of the BSD License which
4  * accompanies this distribution, and is available at
5  * http://www.opensource.org/licenses/bsd-license.php Contributor: Andrei Loskutov -
6  * initial API and implementation
7  ****************************************************************************************/

8 package de.loskutov.bco;
9
10 import java.util.MissingResourceException JavaDoc;
11 import java.util.ResourceBundle JavaDoc;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.ui.plugin.AbstractUIPlugin;
18 import org.osgi.framework.BundleContext;
19
20 /**
21  * The main plugin class to be used in the desktop.
22  */

23 public class BytecodeOutlinePlugin extends AbstractUIPlugin {
24     //The shared instance.
25
private static BytecodeOutlinePlugin plugin;
26     //Resource bundle.
27
private ResourceBundle JavaDoc resourceBundle;
28
29     /**
30      * The constructor.
31      */

32     public BytecodeOutlinePlugin() {
33         super();
34         plugin = this;
35         try {
36             resourceBundle = ResourceBundle
37                 .getBundle("de.loskutov.bco.BytecodeOutlinePluginResources"); //$NON-NLS-1$
38
} catch (MissingResourceException JavaDoc x) {
39             resourceBundle = null;
40         }
41     }
42
43     /**
44      * This method is called upon plug-in activation
45      * @param context
46      * @throws Exception
47      */

48     public void start(BundleContext context) throws Exception JavaDoc {
49         super.start(context);
50     }
51
52     /**
53      * This method is called when the plug-in is stopped
54      * @param context
55      * @throws Exception
56      */

57     public void stop(BundleContext context) throws Exception JavaDoc {
58         super.stop(context);
59     }
60
61     /**
62      * Returns the shared instance.
63      * @return plugin
64      */

65     public static BytecodeOutlinePlugin getDefault() {
66         return plugin;
67     }
68
69     /**
70      * Returns the string from the plugin's resource bundle, or 'key' if not found.
71      * @param key
72      * @return translation
73      */

74     public static String JavaDoc getResourceString(String JavaDoc key) {
75         ResourceBundle JavaDoc bundle = BytecodeOutlinePlugin.getDefault()
76             .getResourceBundle();
77         try {
78             return (bundle != null)
79                 ? bundle.getString(key)
80                 : key;
81         } catch (MissingResourceException JavaDoc e) {
82             return key;
83         }
84     }
85
86     /**
87      * Returns the plugin's resource bundle,
88      */

89     public ResourceBundle JavaDoc getResourceBundle() {
90         return resourceBundle;
91     }
92
93     /**
94      * Returns the workspace instance.
95      * @return shell object
96      */

97     public static Shell getShell() {
98         return getDefault().getWorkbench().getActiveWorkbenchWindow()
99             .getShell();
100     }
101
102     /**
103      * @param messageID
104      * @param error
105      */

106     public static void error(String JavaDoc messageID, Throwable JavaDoc error) {
107         Shell shell = getShell();
108         String JavaDoc message = getResourceString("BytecodeOutline.Error"); //$NON-NLS-1$
109
if (messageID != null) {
110             message = getResourceString(messageID);
111         }
112         message = message + " " + error.getMessage();//$NON-NLS-1$
113
MessageDialog.openError(
114             shell, getResourceString("BytecodeOutline.Title"), //$NON-NLS-1$
115
message);
116
117         getDefault().getLog().log(
118             new Status(IStatus.ERROR, "BytecodeOutline", 0, message, error)); //$NON-NLS-1$
119
}
120
121     /**
122      * @param statusID one of IStatus. constants like IStatus.ERROR etc
123      * @param error
124      */

125     public static void log(Throwable JavaDoc error, int statusID) {
126         String JavaDoc message = error.getMessage();
127         if(message == null){
128             message = error.toString();
129         }
130         getDefault().getLog()
131             .log(
132                 new Status(
133                     statusID,
134                     "BytecodeOutline", 0, message, error)); //$NON-NLS-1$
135
}
136
137
138 }
Popular Tags