remove task from progress view after finish
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / ImageResources.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.model;
11
12 import java.net.MalformedURLException;
13 import java.net.URI;
14 import java.net.URL;
15
16 import org.eclipse.core.runtime.FileLocator;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.jface.resource.DeviceResourceException;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.jface.resource.ImageRegistry;
22 import org.eclipse.swt.graphics.Image;
23
24 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
25
26 /**
27 * <p>ImageResources class.</p>
28 *
29 * @author n.hoffmann
30 * @created 24.03.2009
31 * @version 1.0
32 */
33 public class ImageResources {
34
35 private static ImageResources instance;
36
37 /**
38 * <p>Getter for the field <code>instance</code>.</p>
39 *
40 * @return a {@link eu.etaxonomy.taxeditor.model.ImageResources} object.
41 */
42 public static ImageResources getInstance(){
43 if(instance == null){
44 instance = new ImageResources();
45 }
46 return instance;
47 }
48
49
50 /* ***************************************************************************************
51 ICONS
52 ************************************************************************************** */
53 /** Constant <code>ADD_ICON="add_icon"</code> */
54 public static final String ADD_ICON = "add_icon";
55 public static final String ADD_ICON_GREEN = "add_icon_green";
56 public static final String MIN_ICON = "min_icon";
57 public static final String ADD_EDIT = "add_edit";
58 /** Constant <code>TRASH_ICON="trash_icon"</code> */
59 public static final String TRASH_ICON = "trash_icon";
60 /** Constant <code>BROWSE_ICON="browse_icon"</code> */
61 public static final String BROWSE_ICON = "browse_icon";
62 /** Constant <code>EDIT_ICON="edit_icon"</code> */
63 public static final String EDIT_ICON = "edit_icon";
64 /** Constant <code>EDIT_LOGO_ICON="edit_logo_icon"</code> */
65 public static final String EDIT_LOGO_ICON = "edit_logo_icon";
66 /** Constant <code>WARNING_ICON="warning_icon"</code> */
67 public static final String WARNING_ICON = "warning_icon";
68 /** Constant <code>BLACK_SQUARE_ICON="black_square_icon"</code> */
69 public static final String BLACK_SQUARE_ICON = "black_square_icon";
70 /** Constant <code>HOMOTYPIC_SYN_ICON="homotypic_syn_icon"</code> */
71 public static final String HOMOTYPIC_SYN_ICON = "homotypic_syn_icon";
72 /** Constant <code>HOMOTYPIC_SYN_ORIGINAL_ICON="homotypic_syn_original_icon"</code> */
73 public static final String HOMOTYPIC_SYN_ORIGINAL_ICON = "homotypic_syn_original_icon";
74 /** Constant <code>HETEROTYPIC_SYN_ICON="heterotypic_syn_icon"</code> */
75 public static final String HETEROTYPIC_SYN_ICON = "heterotypic_syn_icon";
76 public static final String NOM_INVAL_NUD_SYN_ICON = "nom_inval_nud_syn_icon";
77 public static final String HOMOTYPIC_SYNONYM_IN_HETEROTYPIC_GROUP_ICON = "homotypic_synonym_in_heterotypic_group_icon";
78 /** Constant <code>HETEROTYPIC_SYN_ORIGINAL_ICON="heterotypic_syn_original_icon"</code> */
79 public static final String HETEROTYPIC_SYN_ORIGINAL_ICON = "heterotypic_syn_original_icon";
80 /** Constant <code>MISAPPLIED_NAME_ICON="misapplied_icon"</code> */
81 public static final String MISAPPLIED_NAME_ICON = "misapplied_icon";
82 /** Constant <code>PRO_PARTE_SYNONYM_ICON="pro_parte_synonym_icon"</code> */
83 public static final String PRO_PARTE_SYNONYM_ICON = "proparte_syn_icon";
84 /** Constant <code>PRO_PARTE_SYNONYM_ICON="pro_parte_synonym_icon"</code> */
85 public static final String PARTIAL_SYNONYM_ICON = "partial_syn_icon";
86 /** Constant <code>CONCEPT_ICON="concept_icon"</code> */
87 public static final String CONCEPT_ICON = "concept_icon";
88 /** Constant <code>AUTONYM_ICON="autonym_icon"</code> */
89 public static final String AUTONYM_ICON = "autonym_icon";
90 /** Constant <code>BASIONYM_ICON="basionym_icon"</code> */
91 public static final String BASIONYM_ICON = "basionym_icon";
92 /** Constant <code>ORTHOGRAPHIC_VARIANT_ICON="orthographic_variants_icon"</code> */
93 public static final String ORTHOGRAPHIC_VARIANT_ICON = "orthographic_variants_icon";
94 /** Constant <code>DB_ICON="db_icon"</code> */
95 public static final String DB_ICON = "db_icon";
96 /** Constant <code>MOVE_ICON="move_icon"</code> */
97 public static final String MOVE_ICON = "move_icon";
98 /** Constant <code>ACTIVE_DELETE_ICON="active_delete_icon"</code> */
99 public static final String ACTIVE_DELETE_ICON = "active_delete_icon";
100 /** Constant <code>SYNONYM_TO_TAXON_ICON="synoynm_to_taxon_icon"</code> */
101 public static final String SYNONYM_TO_TAXON_ICON = "synoynm_to_taxon_icon";
102 /** Constant <code>OPEN_TAXON_ICON="open_taxon_icon"</code> */
103 public static final String OPEN_TAXON_ICON = "open_taxon_icon";
104 /** Constant <code>ADD_CHILD_TAXON_ICON="add_taxon_icon"</code> */
105 public static final String ADD_CHILD_TAXON_ICON = "add_taxon_icon";
106 /** Constant <code>SWAP_SYNONYM_AND_TAXON_ICON="swap_syn_and_tax_icon"</code> */
107 public static final String SWAP_SYNONYM_AND_TAXON_ICON = "swap_syn_and_tax_icon";
108 /** Constant <code>QUICK_ADD_ICON="quick_add_icon"</code> */
109 public static final String QUICK_ADD_ICON = "quick_add_icon";
110 /** Constant <code>TAXON_TO_SYNONYM_ICON="tax_to_syn_icon"</code> */
111 public static final String TAXON_TO_SYNONYM_ICON = "tax_to_syn_icon";
112 /** Constant <code>ERROR_ANNOTATION_ICON="error_annotation_icon"</code> */
113 public static final String ERROR_ANNOTATION_ICON = "error_annotation_icon";
114 /** Constant <code>EDIT_BITMAP_ICON="edit_bitmap_icon"</code> */
115 public static final String EDIT_BITMAP_ICON = "edit_bitmap_icon";
116 /** Constant <code>IMG_DATASOURCE_CONNECTED="IMG_DATASOURCE_CONNECTED"</code> */
117 public static final String IMG_DATASOURCE_CONNECTED = "IMG_DATASOURCE_CONNECTED";
118 /** Constant <code>IMG_DATASOURCE_DISCONNECTED="IMG_DATASOURCE_DISCONNECTED"</code> */
119 public static final String IMG_DATASOURCE_DISCONNECTED = "IMG_DATASOURCE_DISCONNECTED";
120 /** Constant <code>IMG_NOT_FOUND="IMG_NOT_FOUND"</code> */
121 public static final String IMG_NOT_FOUND = "IMG_NOT_FOUND";
122 /** Constant <code>WARNING_ANNOTATION_ICON="warning"</code> */
123 public static final String WARNING_ANNOTATION_ICON = "warning";
124
125 /** Constant <code>LOCK_ICON="locked"</code> */
126 public static final String LOCK_ICON = "lock";
127
128 public static final String SYNCED = "synced";
129 public static final String REFRESH = "refresh";
130
131 /** Constant <code>LOCK_OPEN_ICON="lock_open"</code> */
132 public static final String LOCK_OPEN_ICON = "lock_open";
133
134 /** Constant <code>THREE_PRONGED_EQUAL="3_pronged_equal"</code> */
135 public static final String THREE_PRONGED_EQUAL = "3_pronged_equal";
136 /** Constant <code>TWO_PRONGED_EQUAL="2_pronged_equal"</code> */
137 public static final String TWO_PRONGED_EQUAL = "2_pronged_equal";
138 /** Constant <code>MISAPPLIED_NAME="misapplied_name"</code> */
139 public static final String MISAPPLIED_NAME = "misapplied_name";
140 /** Constant <code>ORPHANED_TAXON="orphaned_taxon"</code> */
141 public static final String ORPHANED_TAXON = "orphaned_taxon";
142 /** Constant <code>EXPAND_ALL="expand_all"</code> */
143 public static final String EXPAND_ALL = "expand_all";
144 /** Constant <code>COLLAPSE_ALL="collapse_all"</code> */
145 public static final String COLLAPSE_ALL = "collapse_all";
146
147 public static final String SWITCH_VIEW_TYPE = "switch_view_type";
148 public static final String SETTINGS = "settings";
149 public static final String EXPORT = "export";
150
151 //derivative icons
152 public static final String TISSUE_SAMPLE_DERIVATE = "tissue_sample_derivate";
153 public static final String TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA = "tissue_sample_derivate_character_data";
154 public static final String DNA_SAMPLE_DERIVATE = "dna_sample_derivate";
155 public static final String DNA_SAMPLE_DERIVATE_CHARACTER_DATA = "dna_sample_derivate_character_data";
156 public static final String FIELD_UNIT = "field_unit";
157 public static final String FIELD_UNIT_CHARACTER_DATA = "field_unit_character_data";
158 public static final String SPECIMEN_DERIVATE = "specimen_derivate";
159 public static final String SPECIMEN_DERIVATE_TYPE = "specimen_derivate_type";
160 public static final String SPECIMEN_DERIVATE_CHARACTER_DATA = "specimen_derivate_character_data";
161 public static final String ARTWORK_DERIVATE = "artwork_derivate";
162 public static final String ARTWORK_DERIVATE_CHARACTER_DATA = "artwork_derivate_character_data";
163 public static final String SPECIMEN_SCAN_DERIVATE = "specimen_scan_derivate";
164 public static final String SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA = "specimen_scan_derivate_character_data";
165 public static final String LIVING_PLANT_PHOTO_DERIVATE = "living_plant_photo_derivate";
166 public static final String LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA = "living_plant_photo_derivate_character_data";
167 public static final String DETAIL_IMAGE_DERIVATE = "detail_image_derivate";
168 public static final String DETAIL_IMAGE_DERIVATE_CHARACTER_DATA = "detail_image_derivate_character_data";
169 public static final String SEQUENCE_DERIVATE = "sequence_derivate";
170 public static final String AMPLIFICATION_DERIVATE = "amplification_derivate";
171 public static final String SINGLE_READ_DERIVATE = "single_read_derivate";
172 public static final String SINGLE_READ_DERIVATE_MULTILINK = "single_read_derivate_multilink";
173 public static final String DEFAULT_DERIVATIVE = "default_derivate";
174
175 public static final String CHARACTER_DATA_DERIVATE = "character_data_derivate";
176
177 public static final String WEB = "web";
178 public static final String DATE = "dates";
179
180 public static final String FLAT = "flat";
181 public static final String HIERARCHICAL = "hierarchical";
182
183
184 /***************************************************************************
185 * IMAGE REGISTRY
186 **************************************************************************/
187 private ImageRegistry imageRegistry;
188
189 /**
190 * <p>getImageDescriptor</p>
191 *
192 * @param key a {@link java.lang.String} object.
193 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
194 */
195 public static ImageDescriptor getImageDescriptor(String key) {
196 return getInstance().getImageRegistry().getDescriptor(key);
197 }
198
199 /**
200 * <p>getImage</p>
201 *
202 * @param key a {@link java.lang.String} object.
203 * @return a {@link org.eclipse.swt.graphics.Image} object.
204 */
205 public static Image getImage(String key) {
206 return getInstance().getImageRegistry().get(key);
207 }
208
209 /**
210 * Gets an image for the given URL. Adds the image to the registry as needed.
211 *
212 * @param uri a {@link java.net.URI} object.
213 * @return a {@link org.eclipse.swt.graphics.Image} object.
214 */
215 public static Image getImage(URI uri) {
216
217 String key = uri.toString();
218 ImageRegistry registry = getInstance().getImageRegistry();
219
220 Image image = registry.get(key);
221
222 if (image == null) {
223 ImageDescriptor desc;
224 try {
225 desc = ImageDescriptor.createFromURL(new URL(key));
226 registry.put(key, desc);
227 image = registry.get(key);
228 } catch (DeviceResourceException e) {
229 return getImageNotFound();
230 } catch (MalformedURLException e) {
231 // should never happen
232 } catch (Exception e) {
233 MessagingUtils.error(ImageResources.class, e);
234 }
235
236 // logger.warn(ImageDescriptor.getMissingImageDescriptor().getClass());
237 // logger.warn(desc.getClass());
238 //
239 // if (ImageDescriptor.getMissingImageDescriptor().equals(desc)) {
240 // logger.warn("img not found");
241 // }
242
243 }
244
245 return image;
246 }
247
248 /**
249 * <p>getImageNotFound</p>
250 *
251 * @return a {@link org.eclipse.swt.graphics.Image} object.
252 */
253 public static Image getImageNotFound() {
254 return getImage(ImageResources.IMG_NOT_FOUND);
255 }
256
257 /**
258 * <p>Getter for the field <code>imageRegistry</code>.</p>
259 *
260 * @return a {@link org.eclipse.jface.resource.ImageRegistry} object.
261 */
262 public ImageRegistry getImageRegistry() {
263 if (imageRegistry == null) {
264 imageRegistry = TaxeditorStorePlugin.getDefault().createImageRegistry();
265 initializeImageRegistry(imageRegistry);
266 }
267 return imageRegistry;
268 }
269
270 /**
271 * <p>initializeImageRegistry</p>
272 *
273 * @param registry a {@link org.eclipse.jface.resource.ImageRegistry} object.
274 */
275 protected void initializeImageRegistry(ImageRegistry registry) {
276 registerImage(registry, ADD_ICON,
277 "add_no_bg.gif");
278 registerImage(registry, ADD_ICON_GREEN,
279 "add.gif");
280 registerImage(registry, MIN_ICON,
281 "min.gif");
282 registerImage(registry, ADD_EDIT,
283 "add_edit.gif");
284 registerImage(registry, TRASH_ICON,
285 "trash.gif");
286 registerImage(registry, EDIT_ICON,
287 "text.gif");
288 registerImage(registry, EDIT_LOGO_ICON,
289 "edit_16x16.ico");
290 registerImage(registry, WARNING_ICON,
291 "warn_tsk.gif");
292 registerImage(registry, BLACK_SQUARE_ICON,
293 "accepted_small.gif");
294 registerImage(registry, HOMOTYPIC_SYN_ICON,
295 "homosyn_no_bg.gif");
296 registerImage(registry, HOMOTYPIC_SYN_ORIGINAL_ICON,
297 "homosyn_original_no_bg.gif");
298 registerImage(registry, HETEROTYPIC_SYN_ICON,
299 "heterosyn_no_bg.gif");
300 registerImage(registry, NOM_INVAL_NUD_SYN_ICON,
301 "nominval_nud_no_bg.gif");
302 registerImage(registry, HETEROTYPIC_SYN_ORIGINAL_ICON,
303 "heterosyn_original_no_bg.gif");
304 registerImage(registry, HOMOTYPIC_SYNONYM_IN_HETEROTYPIC_GROUP_ICON,
305 "homotypic_syn_hetero_group.gif");
306 registerImage(registry, MISAPPLIED_NAME_ICON,
307 "misapplied_no_bg.gif");
308 registerImage(registry, PRO_PARTE_SYNONYM_ICON,
309 "proparte-bright.gif");
310 registerImage(registry, PARTIAL_SYNONYM_ICON,
311 "proparte-dark.gif");
312 registerImage(registry, CONCEPT_ICON,
313 "concept_no_bg.gif");
314 registerImage(registry, AUTONYM_ICON,
315 "autonym_no_bg.gif");
316 registerImage(registry, BASIONYM_ICON,
317 "basionym_no_bg.gif");
318 registerImage(registry, ORTHOGRAPHIC_VARIANT_ICON,
319 "orthovariant_no_bg.gif");
320 registerImage(registry, DB_ICON,
321 "db.gif");
322 registerImage(registry, MOVE_ICON,
323 "correction_change.gif");
324 registerImage(registry, ACTIVE_DELETE_ICON,
325 "delete_edit.gif");
326 registerImage(registry, SYNONYM_TO_TAXON_ICON,
327 "change.gif");
328 registerImage(registry, OPEN_TAXON_ICON,
329 "open.gif");
330 registerImage(registry, ADD_CHILD_TAXON_ICON,
331 "new_child.gif");
332 registerImage(registry,
333 SWAP_SYNONYM_AND_TAXON_ICON, "swap2.gif");
334 registerImage(registry, QUICK_ADD_ICON,
335 "quick_add.gif");
336 registerImage(registry, TAXON_TO_SYNONYM_ICON,
337 "tax_to_syn.gif");
338 registerImage(registry, ERROR_ANNOTATION_ICON,
339 "error_co.gif");
340 registerImage(registry, EDIT_BITMAP_ICON,
341 "256color_16x16.bmp");
342 registerImage(registry, IMG_DATASOURCE_CONNECTED,
343 "prj_obj.gif");
344 registerImage(registry, IMG_DATASOURCE_DISCONNECTED,
345 "cprj_obj.gif");
346 registerImage(registry, IMG_NOT_FOUND,
347 "pic_not_found.PNG");
348 registerImage(registry, WARNING_ANNOTATION_ICON,
349 "warning_co.gif");
350 registerImage(registry, THREE_PRONGED_EQUAL,
351 "3_pronged_equal_small.GIF");
352 registerImage(registry, TWO_PRONGED_EQUAL,
353 "2_pronged_equal_small.GIF");
354 registerImage(registry, MISAPPLIED_NAME,
355 "ma_12x12.gif");
356 registerImage(registry, ORPHANED_TAXON,
357 "orphaned.gif");
358 registerImage(registry, EXPAND_ALL,
359 "expandAll.jpg");
360 registerImage(registry, COLLAPSE_ALL,
361 "collapseall.gif");
362 registerImage(registry, BROWSE_ICON,
363 "prj_obj.gif");
364 registerImage(registry, LOCK_ICON,
365 "lock.png");
366 registerImage(registry, SYNCED,
367 "synced.gif");
368 registerImage(registry, REFRESH,
369 "refresh.gif");
370 registerImage(registry, LOCK_OPEN_ICON,
371 "lock_open.png");
372 registerImage(registry, SWITCH_VIEW_TYPE,
373 "switch_view_type-16x16-32.png");
374 registerImage(registry, SETTINGS,
375 "settings.gif");
376 registerImage(registry, DNA_SAMPLE_DERIVATE,
377 "dna_derivate-16x16-32.png");
378 registerImage(registry, DNA_SAMPLE_DERIVATE_CHARACTER_DATA,
379 "dna_derivate_data-16x16-32.png");
380 registerImage(registry, FIELD_UNIT,
381 "fieldunit-16x16-32.png");
382 registerImage(registry, FIELD_UNIT_CHARACTER_DATA,
383 "fieldunit_data-16x16-32.png");
384 registerImage(registry, SPECIMEN_DERIVATE,
385 "specimen_derivate-16x16-32.png");
386 registerImage(registry, SPECIMEN_DERIVATE_TYPE,
387 "specimen_derivate_type-16x16-32.png");
388 registerImage(registry, SPECIMEN_DERIVATE_CHARACTER_DATA,
389 "specimen_derivate_data-16x16-32.png");
390 registerImage(registry, ARTWORK_DERIVATE,
391 "artwork_derivate-16x16-32.png");
392 registerImage(registry, ARTWORK_DERIVATE_CHARACTER_DATA,
393 "artwork_derivate_data-16x16-32.png");
394 registerImage(registry, SPECIMEN_SCAN_DERIVATE,
395 "specimen_scan_derivate-16x16-32.png");
396 registerImage(registry, SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA,
397 "specimen_scan_derivate_data-16x16-32.png");
398 registerImage(registry, LIVING_PLANT_PHOTO_DERIVATE,
399 "living_plant_photo_derivate-16x16-32.png");
400 registerImage(registry, LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA,
401 "living_plant_photo_derivate_data-16x16-32.png");
402 registerImage(registry, DETAIL_IMAGE_DERIVATE,
403 "detail_image_derivate-16x16-32.png");
404 registerImage(registry, DETAIL_IMAGE_DERIVATE_CHARACTER_DATA,
405 "detail_image_derivate_data-16x16-32.png");
406 registerImage(registry, TISSUE_SAMPLE_DERIVATE,
407 "tissue_sample-16x16-32.png");
408 registerImage(registry, TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA,
409 "tissue_sample_data-16x16-32.png");
410 registerImage(registry, SEQUENCE_DERIVATE,
411 "sequence_derivate-16x16-32.png");
412 registerImage(registry, AMPLIFICATION_DERIVATE,
413 "amplification_derivate-16x16-32.png");
414 registerImage(registry, SINGLE_READ_DERIVATE,
415 "single_read_derivate-16x16-32.png");
416 registerImage(registry, SINGLE_READ_DERIVATE_MULTILINK,
417 "single_read_derivate_multilink-16x16-32.png");
418 registerImage(registry, CHARACTER_DATA_DERIVATE,
419 "character_data_derivate-16x16-32.png");
420 registerImage(registry, DEFAULT_DERIVATIVE,
421 "default_derivate-16x16-32.png");
422 registerImage(registry, EXPORT,
423 "export.gif");
424
425 registerImage(registry, WEB,
426 "web.gif");
427 registerImage(registry, DATE,
428 "dates.gif");
429
430 registerImage(registry, FLAT,
431 "flat.gif");
432 registerImage(registry, HIERARCHICAL,
433 "hierarchical.gif");
434
435 }
436
437 private void registerImage(ImageRegistry registry, String key,
438 String fileName) {
439 try {
440 IPath path = new Path("icons/" + fileName); //$NON-NLS-1$
441 URL url = FileLocator.find(TaxeditorStorePlugin.getDefault().getBundle(), path, null);
442 if (url != null) {
443 ImageDescriptor desc = ImageDescriptor.createFromURL(url);
444 registry.put(key, desc);
445 }
446 } catch (Exception e) {
447 }
448 }
449 }