KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > IDEWorkbenchPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.ide;
13
14 import com.ibm.icu.text.MessageFormat;
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.core.resources.IWorkspace;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IBundleGroup;
22 import org.eclipse.core.runtime.IBundleGroupProvider;
23 import org.eclipse.core.runtime.IConfigurationElement;
24 import org.eclipse.core.runtime.IProduct;
25 import org.eclipse.core.runtime.IStatus;
26 import org.eclipse.core.runtime.Platform;
27 import org.eclipse.jface.resource.ImageDescriptor;
28 import org.eclipse.swt.custom.BusyIndicator;
29 import org.eclipse.ui.internal.ide.registry.MarkerImageProviderRegistry;
30 import org.eclipse.ui.internal.ide.registry.ProjectImageRegistry;
31 import org.eclipse.ui.plugin.AbstractUIPlugin;
32 import org.osgi.framework.Bundle;
33
34 /**
35  * This internal class represents the top of the IDE workbench.
36  *
37  * This class is responsible for tracking various registries
38  * font, preference, graphics, dialog store.
39  *
40  * This class is explicitly referenced by the
41  * IDE workbench plug-in's "plugin.xml"
42  *
43  * @since 3.0
44  */

45 public class IDEWorkbenchPlugin extends AbstractUIPlugin {
46     // Default instance of the receiver
47
private static IDEWorkbenchPlugin inst;
48
49     // Global workbench ui plugin flag. Only workbench implementation is allowed to use this flag
50
// All other plugins, examples, or test cases must *not* use this flag.
51
public static boolean DEBUG = false;
52
53     /**
54      * The IDE workbench plugin ID.
55      */

56     public static final String JavaDoc IDE_WORKBENCH = "org.eclipse.ui.ide"; //$NON-NLS-1$
57

58     /**
59      * The ID of the default text editor.
60      * This must correspond to EditorsUI.DEFAULT_TEXT_EDITOR_ID.
61      */

62     public static final String JavaDoc DEFAULT_TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
63

64     // IDE workbench extension point names
65
public static final String JavaDoc PL_MARKER_IMAGE_PROVIDER = "markerImageProviders"; //$NON-NLS-1$
66

67     public static final String JavaDoc PL_MARKER_HELP = "markerHelp"; //$NON-NLS-1$
68

69     public static final String JavaDoc PL_MARKER_RESOLUTION = "markerResolution"; //$NON-NLS-1$
70

71     public static final String JavaDoc PL_CAPABILITIES = "capabilities"; //$NON-NLS-1$
72

73     public static final String JavaDoc PL_PROJECT_NATURE_IMAGES = "projectNatureImages"; //$NON-NLS-1$
74

75     private final static String JavaDoc ICONS_PATH = "$nl$/icons/full/";//$NON-NLS-1$
76

77     /**
78      * Project image registry; lazily initialized.
79      */

80     private ProjectImageRegistry projectImageRegistry = null;
81
82     /**
83      * Marker image registry; lazily initialized.
84      */

85     private MarkerImageProviderRegistry markerImageProviderRegistry = null;
86
87     /**
88      * Create an instance of the receiver.
89      */

90     public IDEWorkbenchPlugin() {
91         super();
92         inst = this;
93     }
94     /**
95      * Creates an extension. If the extension plugin has not
96      * been loaded a busy cursor will be activated during the duration of
97      * the load.
98      *
99      * @param element the config element defining the extension
100      * @param classAttribute the name of the attribute carrying the class
101      * @return Object the extension object
102      * @throws CoreException
103      */

104     public static Object JavaDoc createExtension(final IConfigurationElement element,
105             final String JavaDoc classAttribute) throws CoreException {
106         // If plugin has been loaded create extension.
107
// Otherwise, show busy cursor then create extension.
108
Bundle plugin = Platform.getBundle(element.getNamespace());
109         if (plugin.getState() == Bundle.ACTIVE) {
110             return element.createExecutableExtension(classAttribute);
111         } else {
112             final Object JavaDoc[] ret = new Object JavaDoc[1];
113             final CoreException[] exc = new CoreException[1];
114             BusyIndicator.showWhile(null, new Runnable JavaDoc() {
115                 public void run() {
116                     try {
117                         ret[0] = element
118                                 .createExecutableExtension(classAttribute);
119                     } catch (CoreException e) {
120                         exc[0] = e;
121                     }
122                 }
123             });
124             if (exc[0] != null) {
125                 throw exc[0];
126             } else {
127                 return ret[0];
128             }
129         }
130     }
131
132     /* Return the default instance of the receiver. This represents the runtime plugin.
133      *
134      * @see AbstractPlugin for the typical implementation pattern for plugin classes.
135      */

136     public static IDEWorkbenchPlugin getDefault() {
137         return inst;
138     }
139
140     /**
141      * Return the workspace used by the workbench
142      *
143      * This method is internal to the workbench and must not be called
144      * by any plugins.
145      */

146     public static IWorkspace getPluginWorkspace() {
147         return ResourcesPlugin.getWorkspace();
148     }
149
150     /**
151      * Logs the given message to the platform log.
152      *
153      * If you have an exception in hand, call log(String, Throwable) instead.
154      *
155      * If you have a status object in hand call log(String, IStatus) instead.
156      *
157      * This convenience method is for internal use by the IDE Workbench only and
158      * must not be called outside the IDE Workbench.
159      *
160      * @param message
161      * A high level UI message describing when the problem happened.
162      */

163     public static void log(String JavaDoc message) {
164         getDefault().getLog().log(
165                 StatusUtil.newStatus(IStatus.ERROR, message, null));
166     }
167
168     /**
169      * Logs the given message and throwable to the platform log.
170      *
171      * If you have a status object in hand call log(String, IStatus) instead.
172      *
173      * This convenience method is for internal use by the IDE Workbench only and
174      * must not be called outside the IDE Workbench.
175      *
176      * @param message
177      * A high level UI message describing when the problem happened.
178      * @param t
179      * The throwable from where the problem actually occurred.
180      */

181     public static void log(String JavaDoc message, Throwable JavaDoc t) {
182         IStatus status = StatusUtil.newStatus(IStatus.ERROR, message, t);
183         log(message, status);
184     }
185     
186     /**
187      * Logs the given throwable to the platform log, indicating the class and
188      * method from where it is being logged (this is not necessarily where it
189      * occurred).
190      *
191      * This convenience method is for internal use by the IDE Workbench only and
192      * must not be called outside the IDE Workbench.
193      *
194      * @param clazz
195      * The calling class.
196      * @param methodName
197      * The calling method name.
198      * @param t
199      * The throwable from where the problem actually occurred.
200      */

201     public static void log(Class JavaDoc clazz, String JavaDoc methodName, Throwable JavaDoc t) {
202         String JavaDoc msg = MessageFormat.format("Exception in {0}.{1}: {2}", //$NON-NLS-1$
203
new Object JavaDoc[] { clazz.getName(), methodName, t });
204         log(msg, t);
205     }
206     
207     /**
208      * Logs the given message and status to the platform log.
209      *
210      * This convenience method is for internal use by the IDE Workbench only and
211      * must not be called outside the IDE Workbench.
212      *
213      * @param message
214      * A high level UI message describing when the problem happened.
215      * May be <code>null</code>.
216      * @param status
217      * The status describing the problem. Must not be null.
218      */

219     public static void log(String JavaDoc message, IStatus status) {
220
221         //1FTUHE0: ITPCORE:ALL - API - Status & logging - loss of semantic info
222

223         if (message != null) {
224             getDefault().getLog().log(
225                     StatusUtil.newStatus(IStatus.ERROR, message, null));
226         }
227
228         getDefault().getLog().log(status);
229     }
230
231     /* (non-javadoc)
232      * Method declared on AbstractUIPlugin
233      */

234     protected void refreshPluginActions() {
235         // do nothing
236
}
237
238
239     /**
240      * Return the manager that maps project nature ids to images.
241      */

242     public ProjectImageRegistry getProjectImageRegistry() {
243         if (projectImageRegistry == null) {
244             projectImageRegistry = new ProjectImageRegistry();
245             projectImageRegistry.load();
246         }
247         return projectImageRegistry;
248     }
249
250     /**
251      * Returns the marker image provider registry for the workbench.
252      *
253      * @return the marker image provider registry
254      */

255     public MarkerImageProviderRegistry getMarkerImageProviderRegistry() {
256         if (markerImageProviderRegistry == null) {
257             markerImageProviderRegistry = new MarkerImageProviderRegistry();
258         }
259         return markerImageProviderRegistry;
260     }
261
262
263     /**
264      * Returns the about information of all known features,
265      * omitting any features which are missing this information.
266      *
267      * @return a possibly empty list of about infos
268      */

269     public AboutInfo[] getFeatureInfos() {
270         // cannot be cached since bundle groups come and go
271
List JavaDoc infos = new ArrayList JavaDoc();
272
273         // add an entry for each bundle group
274
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
275         if (providers != null) {
276             for (int i = 0; i < providers.length; ++i) {
277                 IBundleGroup[] bundleGroups = providers[i].getBundleGroups();
278                 for (int j = 0; j < bundleGroups.length; ++j) {
279                     infos.add(new AboutInfo(bundleGroups[j]));
280                 }
281             }
282         }
283
284         return (AboutInfo[]) infos.toArray(new AboutInfo[infos.size()]);
285     }
286
287     /**
288      * Returns the about information of the primary feature.
289      *
290      * @return info about the primary feature, or <code>null</code> if there
291      * is no primary feature or if this information is unavailable
292      */

293     public AboutInfo getPrimaryInfo() {
294         IProduct product = Platform.getProduct();
295         return product == null ? null : new AboutInfo(product);
296     }
297     
298     /**
299      * Get the workbench image with the given path relative to
300      * ICON_PATH.
301      * @param relativePath
302      * @return ImageDescriptor
303      */

304     public static ImageDescriptor getIDEImageDescriptor(String JavaDoc relativePath){
305         return imageDescriptorFromPlugin(IDE_WORKBENCH, ICONS_PATH + relativePath);
306     }
307     
308     
309 }
310
Popular Tags