61 plugin = this; |
62 plugin = this; |
62 } |
63 } |
63 |
64 |
64 /* |
65 /* |
65 * (non-Javadoc) |
66 * (non-Javadoc) |
66 * |
67 * |
67 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
68 * @see |
|
69 * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext |
|
70 * ) |
68 */ |
71 */ |
69 @Override |
72 @Override |
70 public final void start(final BundleContext context) { |
73 public final void start(final BundleContext context) { |
71 try { |
74 try { |
72 super.start(context); |
75 super.start(context); |
73 |
76 |
74 } catch (Exception e) { |
77 } catch (Exception e) { |
75 e.printStackTrace(); |
78 e.printStackTrace(); |
76 } |
79 } |
77 |
|
78 } |
80 } |
79 |
81 |
80 /* |
82 /* |
81 * (non-Javadoc) |
83 * (non-Javadoc) |
82 * |
84 * |
83 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
85 * @see |
|
86 * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext |
|
87 * ) |
84 */ |
88 */ |
85 @Override |
89 @Override |
86 public final void stop(final BundleContext context) { |
90 public final void stop(final BundleContext context) { |
87 try { |
91 try { |
88 plugin = null; |
92 plugin = null; |
89 super.stop(context); |
93 super.stop(context); |
90 } catch (Exception e) { |
94 } catch (Exception e) { |
91 e.printStackTrace(); |
95 e.printStackTrace(); |
92 } |
96 } |
93 |
|
94 } |
97 } |
95 |
98 |
96 /** |
99 /** |
97 * Returns the shared instance. |
100 * Returns the shared instance. |
98 * |
101 * |
99 * @return the shared instance |
102 * @return the shared instance |
100 */ |
103 */ |
101 public static Activator getDefault() { |
104 public static Activator getDefault() { |
102 return plugin; |
105 return plugin; |
103 } |
106 } |
104 |
107 |
105 /** |
108 /** |
106 * Returns an image descriptor for the image file at the given |
109 * Returns an image descriptor for the image file at the given plug-in |
107 * plug-in relative path. |
110 * relative path. |
108 * |
111 * |
109 * @param path |
112 * @param path |
110 * the path |
113 * the path |
111 * @return the image descriptor |
114 * @return the image descriptor |
112 */ |
115 */ |
113 public static ImageDescriptor getImageDescriptor(final String path) { |
116 public static ImageDescriptor getImageDescriptor(final String path) { |
114 return imageDescriptorFromPlugin(PLUGIN_ID, path); |
117 return imageDescriptorFromPlugin(PLUGIN_ID, path); |
115 } |
118 } |
116 |
119 |
117 /** |
120 /** |
118 * Returns AnalyzeTool used preference store. |
121 * Returns AnalyzeTool used preference store. |
119 * |
122 * |
120 * @return Preference store |
123 * @return Preference store |
121 */ |
124 */ |
122 public static IPreferenceStore getPreferences() { |
125 public static IPreferenceStore getPreferences() { |
123 |
126 |
124 // if preference store not yet created => create it |
127 // if preference store not yet created => create it |
125 if (preferenceStore == null) { |
128 if (preferenceStore == null) { |
126 preferenceStore = getDefault().getPreferenceStore(); |
129 preferenceStore = getDefault().getPreferenceStore(); |
127 } |
130 } |
128 |
|
129 return preferenceStore; |
131 return preferenceStore; |
130 } |
132 } |
131 |
133 |
132 /** |
134 /** |
133 * Add action listener class. |
135 * Add action listener class. |
134 * |
136 * |
135 * @param listener |
137 * @param listener |
136 * Action listener |
138 * Action listener |
137 */ |
139 */ |
138 public static void setActionListener(final IActionListener listener) { |
140 public static void setActionListener(final IActionListener listener) { |
139 actionListener = listener; |
141 actionListener = listener; |
140 } |
142 } |
141 |
143 |
142 /** |
144 /** |
143 * Gets action listener. |
145 * Gets action listener. |
144 * |
146 * |
145 * @return ActionListener Action listener |
147 * @return ActionListener Action listener |
146 */ |
148 */ |
147 public static IActionListener getActionListener() { |
149 public static IActionListener getActionListener() { |
148 return actionListener; |
150 return actionListener; |
149 } |
151 } |
150 |
152 |
151 /** |
153 /** |
152 * Returns a File corresponding to the given bundle relative path. |
154 * Returns a File corresponding to the given bundle relative path. |
153 * @param path the bundle relative path to resource to locate |
155 * |
|
156 * @param path |
|
157 * the bundle relative path to resource to locate |
154 * @return the File corresponding to the given bundle relative path, or null |
158 * @return the File corresponding to the given bundle relative path, or null |
155 * @throws IOException |
159 * @throws IOException |
156 */ |
160 */ |
157 public File locateFileInBundle(final String path) throws IOException { |
161 public File locateFileInBundle(final String path) throws IOException { |
158 Bundle myBundle= getDefault().getBundle(); |
162 Bundle myBundle = getDefault().getBundle(); |
159 IPath ppath= new Path(path); |
163 IPath ppath = new Path(path); |
160 ppath= ppath.makeRelative(); |
164 ppath = ppath.makeRelative(); |
161 URL[] urls= FileLocator.findEntries(myBundle, ppath); |
165 URL[] urls = FileLocator.findEntries(myBundle, ppath); |
162 if(urls.length != 1) { |
166 if (urls.length != 1) { |
163 return null; |
167 return null; |
164 } |
168 } |
165 return new File(FileLocator.toFileURL(urls[0]).getFile()); |
169 return new File(FileLocator.toFileURL(urls[0]).getFile()); |
166 } |
170 } |
167 |
171 |
168 /** |
172 /** |
169 * Logs information to the eclipse .log file |
173 * Logs information to the eclipse .log file |
170 * @param severity Message severity |
174 * |
171 * @param code Message code |
175 * @param severity |
172 * @param message Message content |
176 * Message severity |
|
177 * @param code |
|
178 * Message code |
|
179 * @param message |
|
180 * Message content |
173 */ |
181 */ |
174 public void logInfo(int severity, int code, String message) { |
182 public void logInfo(int severity, int code, String message) { |
175 IStatus status = new Status(severity, PLUGIN_ID, code, message, (Throwable) null); |
183 IStatus status = new Status(severity, PLUGIN_ID, code, message, |
|
184 (Throwable) null); |
176 getDefault().getLog().log(status); |
185 getDefault().getLog().log(status); |
177 } |
186 } |
|
187 |
178 /** |
188 /** |
179 * Logs the given message with the given severity and the given exception to |
189 * Logs the given message with the given severity and the given exception to |
180 * this plug-in's log. |
190 * this plug-in's log. |
|
191 * |
181 * @param aSeverity |
192 * @param aSeverity |
182 * the severity; one of the <strong>IStatus</strong> severity |
193 * the severity; one of the <strong>IStatus</strong> severity |
183 * constants: OK, ERROR, INFO, WARNING, or CANCEL |
194 * constants: OK, ERROR, INFO, WARNING, or CANCEL |
184 * @param aMessage |
195 * @param aMessage |
185 * a human-readable message, localised to the current locale |
196 * a human-readable message, localized to the current locale |
186 * @param aException |
197 * @param aException |
187 * a low-level exception, or null if not applicable |
198 * a low-level exception, or null if not applicable |
188 */ |
199 */ |
189 public void log(final int aSeverity, final String aMessage, |
200 public void log(final int aSeverity, final String aMessage, |
190 final Exception aException) |
201 final Exception aException) { |
191 { |
202 getLog().log( |
192 getLog().log(new Status(aSeverity, PLUGIN_ID, IStatus.OK, aMessage, aException)); |
203 new Status(aSeverity, PLUGIN_ID, IStatus.OK, aMessage, |
193 } |
204 aException)); |
194 |
205 } |
|
206 |
195 /** |
207 /** |
196 * Creates and returns an Image for the file at the given plug-in relative |
208 * Creates and returns an Image for the file at the given plug-in relative |
197 * path. The Image is cached in the #ImageRegistry. |
209 * path. The Image is cached in the #ImageRegistry. |
198 * @param aPath the plug-in relative path to the image file |
210 * |
|
211 * @param aPath |
|
212 * the plug-in relative path to the image file |
199 * @return the requested Image |
213 * @return the requested Image |
200 */ |
214 */ |
201 public Image getImage(final String aPath) |
215 public Image getImage(final String aPath) { |
202 { |
|
203 Image cachedImage = getImageRegistry().get(aPath); |
216 Image cachedImage = getImageRegistry().get(aPath); |
204 if (null == cachedImage) |
217 if (null == cachedImage) { |
205 { |
|
206 cachedImage = getImageDescriptor(aPath).createImage(); |
218 cachedImage = getImageDescriptor(aPath).createImage(); |
207 getImageRegistry().put(aPath, cachedImage); |
219 getImageRegistry().put(aPath, cachedImage); |
208 } |
220 } |
209 return cachedImage; |
221 return cachedImage; |
210 } |
222 } |
211 |
|
212 } |
223 } |