(no commit message)
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / Activator.java
1 package eu.etaxonomy.taxeditor;
2
3 import java.net.URL;
4 import java.util.MissingResourceException;
5 import java.util.ResourceBundle;
6
7 import org.eclipse.core.runtime.IPath;
8 import org.eclipse.core.runtime.Path;
9 import org.eclipse.jface.resource.ImageDescriptor;
10 import org.eclipse.jface.resource.ImageRegistry;
11 import org.eclipse.swt.graphics.Image;
12 import org.eclipse.swt.widgets.Display;
13 import org.eclipse.ui.forms.FormColors;
14 import org.eclipse.ui.plugin.AbstractUIPlugin;
15 import org.osgi.framework.BundleContext;
16
17 /**
18 * The activator class controls the plug-in life cycle
19 */
20 public class Activator extends AbstractUIPlugin {
21
22 // The plug-in ID
23 public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor";
24
25 // The shared instance
26 private static Activator plugin;
27
28 /**
29 * The constructor
30 */
31 public Activator() {
32 }
33
34 /*
35 * (non-Javadoc)
36 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
37 */
38 public void start(BundleContext context) throws Exception {
39 super.start(context);
40 plugin = this;
41 }
42
43 /*
44 * (non-Javadoc)
45 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
46 */
47 /*public void stop(BundleContext context) throws Exception {
48 plugin = null;
49 super.stop(context);
50 }*/
51
52 /**
53 * Returns the shared instance
54 *
55 * @return the shared instance
56 */
57 public static Activator getDefault() {
58 return plugin;
59 }
60
61 /**
62 * Returns an image descriptor for the image file at the given
63 * plug-in relative path
64 *
65 * @param path the path
66 * @return the image descriptor
67 */
68 public static ImageDescriptor getImageDescriptorOrig(String path) {
69 return imageDescriptorFromPlugin(PLUGIN_ID, path);
70 }
71
72 /**
73 * EVERYTHING BELOW HERE WAS PASTED FROM FORMARTICLEPLUGIN.JAVA
74 **/
75 //Resource bundle.
76 private ResourceBundle resourceBundle;
77 private FormColors formColors;
78 public static final String IMG_FORM_BG = "formBg"; //$NON-NLS-1$
79 public static final String IMG_LARGE = "large"; //$NON-NLS-1$
80 public static final String IMG_HORIZONTAL = "horizontal"; //$NON-NLS-1$
81 public static final String IMG_VERTICAL = "vertical"; //$NON-NLS-1$
82 public static final String IMG_SAMPLE = "sample"; //$NON-NLS-1$
83 public static final String IMG_WIZBAN = "wizban"; //$NON-NLS-1$
84 public static final String IMG_LINKTO_HELP = "linkto_help"; //$NON-NLS-1$
85 public static final String IMG_HELP_TOPIC = "help_topic"; //$NON-NLS-1$
86 public static final String IMG_CLOSE = "close"; //$NON-NLS-1$
87
88 protected void initializeImageRegistry(ImageRegistry registry) {
89 registerImage(registry, IMG_FORM_BG, "form_banner.gif"); //$NON-NLS-1$
90 registerImage(registry, IMG_LARGE, "large_image.gif"); //$NON-NLS-1$
91 registerImage(registry, IMG_HORIZONTAL, "th_horizontal.gif"); //$NON-NLS-1$
92 registerImage(registry, IMG_VERTICAL, "th_vertical.gif"); //$NON-NLS-1$
93 registerImage(registry, IMG_SAMPLE, "sample.gif"); //$NON-NLS-1$
94 registerImage(registry, IMG_WIZBAN, "newprj_wiz.gif"); //$NON-NLS-1$
95 registerImage(registry, IMG_LINKTO_HELP, "linkto_help.gif"); //$NON-NLS-1$
96 registerImage(registry, IMG_HELP_TOPIC, "help_topic.gif"); //$NON-NLS-1$
97 registerImage(registry, IMG_CLOSE, "close_view.gif"); //$NON-NLS-1$
98 }
99
100 private void registerImage(ImageRegistry registry, String key,
101 String fileName) {
102 try {
103 IPath path = new Path("icons/" + fileName); //$NON-NLS-1$
104 URL url = find(path);
105 if (url!=null) {
106 ImageDescriptor desc = ImageDescriptor.createFromURL(url);
107 registry.put(key, desc);
108 }
109 } catch (Exception e) {
110 }
111 }
112
113 public FormColors getFormColors(Display display) {
114 if (formColors == null) {
115 formColors = new FormColors(display);
116 formColors.markShared();
117 }
118 return formColors;
119 }
120 /**
121 * Returns the workspace instance.
122 */
123 /* public static IWorkspace getWorkspace() {
124 return ResourcesPlugin.getWorkspace();
125 }*/
126 /**
127 * Returns the string from the plugin's resource bundle, or 'key' if not
128 * found.
129 */
130 public static String getResourceString(String key) {
131 ResourceBundle bundle = Activator.getDefault().getResourceBundle();
132 try {
133 return (bundle != null ? bundle.getString(key) : key);
134 } catch (MissingResourceException e) {
135 return key;
136 }
137 }
138 /**
139 * Returns the plugin's resource bundle,
140 */
141 public ResourceBundle getResourceBundle() {
142 return resourceBundle;
143 }
144 public void stop(BundleContext context) throws Exception {
145 plugin = null;
146 try {
147 if (formColors != null) {
148 formColors.dispose();
149 formColors = null;
150 }
151 } finally {
152 super.stop(context);
153 }
154 }
155 public Image getImage(String key) {
156 return getImageRegistry().get(key);
157 }
158 public ImageDescriptor getImageDescriptor(String key) {
159 return getImageRegistry().getDescriptor(key);
160 }
161
162 }