Introduce a bundle for Rap Workbench
[gpl/argeo-suite.git] / org.argeo.suite.workbench.rap / src / org / argeo / suite / workbench / AsUiPlugin.java
diff --git a/org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/AsUiPlugin.java b/org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/AsUiPlugin.java
new file mode 100644 (file)
index 0000000..60663a6
--- /dev/null
@@ -0,0 +1,73 @@
+package org.argeo.suite.workbench;
+
+import java.net.URL;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/** The activator class controls the plug-in life cycle */
+public class AsUiPlugin extends AbstractUIPlugin {
+
+       public static final String PLUGIN_ID = "org.argeo.suite.workbench";
+
+       // The shared instance
+       private static AsUiPlugin plugin;
+
+       private BundleContext bundleContext;
+
+       /** Default constructor */
+       public AsUiPlugin() {
+       }
+
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+               this.bundleContext = context;
+               plugin = this;
+       }
+
+       public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        * 
+        * @return the shared instance
+        */
+       public static AsUiPlugin getDefault() {
+               return plugin;
+       }
+
+       /** Creates the image */
+       public static Image img(String path) {
+               return getImageDescriptor(path).createImage();
+       }
+
+       /**
+        * Returns an image descriptor for the image file at the given plug-in
+        * relative path
+        * 
+        * @param path
+        *            the path
+        * @return the image descriptor
+        */
+       public static ImageDescriptor getImageDescriptor(String path) {
+               return imageDescriptorFromPlugin(PLUGIN_ID, path);
+       }
+
+       public URL imageUrl(String path) {
+               return bundleContext.getBundle().getResource(path);
+       }
+
+       @Override
+       protected void initializeImageRegistry(ImageRegistry reg) {
+       }
+
+       public BundleContext getBundleContext() {
+               return bundleContext;
+       }
+}