]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/internal/Activator.java
Externalize strings
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / internal / Activator.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.issues.ui.internal;
13
14 import java.net.URL;
15
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.jface.resource.ImageRegistry;
18 import org.eclipse.ui.plugin.AbstractUIPlugin;
19 import org.osgi.framework.Bundle;
20 import org.osgi.framework.BundleContext;
21 import org.osgi.util.tracker.ServiceTracker;
22 import org.simantics.issues.Severity;
23 import org.simantics.message.IMessageSchemeManager;
24 import org.simantics.utils.ui.gfx.AlphaAdjustmentImageDescriptor;
25 import org.simantics.utils.ui.gfx.HSVAdjustmentImageDescriptor;
26
27 public class Activator extends AbstractUIPlugin {
28
29     public static final String PLUGIN_ID = "org.simantics.issues.ui"; //$NON-NLS-1$
30     
31     static Activator instance;
32     ServiceTracker   messageScheme;
33
34     public static ImageDescriptor HIDE_ICON;
35     public static ImageDescriptor UNHIDE_ICON;
36     public static ImageDescriptor RESOLVE_ICON;
37     public static ImageDescriptor UNRESOLVE_ICON;
38
39     public static ImageDescriptor PURGE_ICON;
40
41     public static ImageDescriptor FATAL_ICON;
42     public static ImageDescriptor ERROR_ICON;
43     public static ImageDescriptor WARNING_ICON;
44     public static ImageDescriptor INFO_ICON;
45     public static ImageDescriptor NOTE_ICON;
46     public static ImageDescriptor OK_ICON;
47
48     public static ImageDescriptor FATAL_DECORATION_ICON;
49     public static ImageDescriptor ERROR_DECORATION_ICON;
50     public static ImageDescriptor WARNING_DECORATION_ICON;
51     public static ImageDescriptor INFO_DECORATION_ICON;
52     public static ImageDescriptor NOTE_DECORATION_ICON;
53
54     @Override
55     public void start(BundleContext context) throws Exception {
56         super.start(context);
57         instance = this;
58         messageScheme = new ServiceTracker(context, IMessageSchemeManager.class.getName(), null);
59
60         Bundle bundle = context.getBundle();
61
62         HIDE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/hide.png")); //$NON-NLS-1$
63         UNHIDE_ICON = AlphaAdjustmentImageDescriptor.adjustAlpha(HSVAdjustmentImageDescriptor.adjust(
64                 HIDE_ICON, 0f, 0f, 1f), 96);
65         //RESOLVE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/lightbulb.png"));
66         //UNRESOLVE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/lightbulb_off.png"));
67         RESOLVE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/tick.png")); //$NON-NLS-1$
68         UNRESOLVE_ICON = AlphaAdjustmentImageDescriptor.adjustAlpha(HSVAdjustmentImageDescriptor.adjust(
69                 RESOLVE_ICON, 0f, 0f, 1f), 96);
70
71         PURGE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/purge.gif")); //$NON-NLS-1$
72
73         FATAL_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/fatal.png")); //$NON-NLS-1$
74         ERROR_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/error.png")); //$NON-NLS-1$
75         WARNING_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/warning.png")); //$NON-NLS-1$
76         INFO_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/information.png")); //$NON-NLS-1$
77         NOTE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/note.png")); //$NON-NLS-1$
78         OK_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/noissue.png")); //$NON-NLS-1$
79
80         FATAL_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/fatal_decoration.png")); //$NON-NLS-1$
81         ERROR_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/error_decoration.png")); //$NON-NLS-1$
82         WARNING_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/warning_decoration.png")); //$NON-NLS-1$
83         INFO_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/information_decoration.png")); //$NON-NLS-1$
84         NOTE_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/note_decoration.png")); //$NON-NLS-1$
85     }
86
87     @Override
88     protected ImageRegistry createImageRegistry() {
89         return super.createImageRegistry();
90     }
91
92     @Override
93     protected void initializeImageRegistry(ImageRegistry reg) {
94         reg.put(Severity.FATAL.toString()+"-full", FATAL_ICON); //$NON-NLS-1$
95         reg.put(Severity.ERROR.toString()+"-full", ERROR_ICON); //$NON-NLS-1$
96         reg.put(Severity.WARNING.toString()+"-full", WARNING_ICON); //$NON-NLS-1$
97         reg.put(Severity.INFO.toString()+"-full", INFO_ICON); //$NON-NLS-1$
98         reg.put(Severity.NOTE.toString()+"-full", NOTE_ICON); //$NON-NLS-1$
99         reg.put(Severity.FATAL.toString(), FATAL_DECORATION_ICON);
100         reg.put(Severity.ERROR.toString(), ERROR_DECORATION_ICON);
101         reg.put(Severity.WARNING.toString(), WARNING_DECORATION_ICON);
102         reg.put(Severity.INFO.toString(), INFO_DECORATION_ICON);
103         reg.put(Severity.NOTE.toString(), NOTE_DECORATION_ICON);
104     }
105
106     @Override
107     public void stop(BundleContext context) throws Exception {
108         messageScheme.close();
109         instance = null;
110         super.stop(context);
111     }
112
113     /**
114      * Returns the shared instance
115      *
116      * @return the shared instance
117      */
118     public static Activator getDefault() {
119         return instance;
120     }
121
122     public static ImageDescriptor getImageDescriptor(String path) {
123         return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
124     }
125
126     public static URL getDefaultResource(String name) {
127         Activator plugin = getDefault();
128         if(plugin == null) throw new IllegalStateException("The plugin is not active."); //$NON-NLS-1$
129         Bundle bundle = plugin.getBundle(); 
130         return bundle.getResource(name);
131     }
132
133 }