KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > examples > jet > article2 > TypesafeEnumPlugin


1 package org.eclipse.emf.examples.jet.article2;
2
3
4 import java.net.MalformedURLException JavaDoc;
5 import java.net.URL JavaDoc;
6
7 import org.eclipse.core.runtime.IStatus;
8 import org.eclipse.core.runtime.Status;
9 import org.eclipse.jface.resource.ImageDescriptor;
10 import org.eclipse.swt.widgets.Shell;
11 import org.eclipse.ui.IWorkbench;
12 import org.eclipse.ui.IWorkbenchPage;
13 import org.eclipse.ui.IWorkbenchWindow;
14 import org.eclipse.ui.plugin.AbstractUIPlugin;
15
16
17 /**
18  * The plug-in runtime class for the TypesafeEnum plug-in.
19  *
20  * @author Remko Popma
21  * @version $Revision: 1.1 $ ($Date: 2004/06/01 16:17:41 $)
22  */

23 public class TypesafeEnumPlugin extends AbstractUIPlugin
24 {
25
26   /**
27    * The single instance of this plug-in runtime class.
28    */

29   private static TypesafeEnumPlugin sPlugin = null;
30
31   /**
32    * @param descriptor
33    */

34   public TypesafeEnumPlugin()
35   {
36     sPlugin = this;
37   }
38
39   public static ImageDescriptor getImageDescriptor(String JavaDoc name)
40   {
41     try
42     {
43       String JavaDoc base = getDefault().getBundle().getEntry("/").toString();
44       String JavaDoc uri = base + name;
45       return ImageDescriptor.createFromURL(new URL JavaDoc(uri));
46
47     }
48     catch (MalformedURLException JavaDoc e)
49     {
50       return ImageDescriptor.getMissingImageDescriptor();
51     }
52   }
53
54   public static TypesafeEnumPlugin getDefault()
55   {
56     return sPlugin;
57   }
58
59   public static Shell getActiveWorkbenchShell()
60   {
61     IWorkbenchWindow workBenchWindow = getActiveWorkbenchWindow();
62     if (workBenchWindow == null)
63     {
64       return null;
65     }
66     return workBenchWindow.getShell();
67   }
68
69   /**
70    * Returns the active workbench window
71    *
72    * @return the active workbench window
73    */

74   public static IWorkbenchWindow getActiveWorkbenchWindow()
75   {
76     if (sPlugin == null)
77     {
78       return null;
79     }
80     IWorkbench workBench = sPlugin.getWorkbench();
81     if (workBench == null)
82     {
83       return null;
84     }
85     return workBench.getActiveWorkbenchWindow();
86   }
87
88   public static IWorkbenchPage getActivePage()
89   {
90     IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
91     if (activeWorkbenchWindow == null)
92     {
93       return null;
94     }
95     return activeWorkbenchWindow.getActivePage();
96   }
97
98   public static String JavaDoc getPluginId()
99   {
100     return getDefault().getBundle().getSymbolicName();
101   }
102
103   public static void log(Throwable JavaDoc e)
104   {
105     log(new Status(IStatus.ERROR, getPluginId(), IStatus.ERROR, "Error", e)); //$NON-NLS-1$
106
}
107
108   public static void log(IStatus status)
109   {
110     getDefault().getLog().log(status);
111   }
112 }
Popular Tags