1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.issues.ui.internal;
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;
27 public class Activator extends AbstractUIPlugin {
29 public static final String PLUGIN_ID = "org.simantics.issues.ui";
31 static Activator instance;
32 ServiceTracker messageScheme;
34 public static ImageDescriptor HIDE_ICON;
35 public static ImageDescriptor UNHIDE_ICON;
36 public static ImageDescriptor RESOLVE_ICON;
37 public static ImageDescriptor UNRESOLVE_ICON;
39 public static ImageDescriptor PURGE_ICON;
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;
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;
55 public void start(BundleContext context) throws Exception {
58 messageScheme = new ServiceTracker(context, IMessageSchemeManager.class.getName(), null);
60 Bundle bundle = context.getBundle();
62 HIDE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/hide.png"));
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"));
68 UNRESOLVE_ICON = AlphaAdjustmentImageDescriptor.adjustAlpha(HSVAdjustmentImageDescriptor.adjust(
69 RESOLVE_ICON, 0f, 0f, 1f), 96);
71 PURGE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/purge.gif"));
73 FATAL_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/fatal.png"));
74 ERROR_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/error.png"));
75 WARNING_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/warning.png"));
76 INFO_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/information.png"));
77 NOTE_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/note.png"));
78 OK_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/noissue.png"));
80 FATAL_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/fatal_decoration.png"));
81 ERROR_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/error_decoration.png"));
82 WARNING_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/warning_decoration.png"));
83 INFO_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/information_decoration.png"));
84 NOTE_DECORATION_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/note_decoration.png"));
88 protected ImageRegistry createImageRegistry() {
89 return super.createImageRegistry();
93 protected void initializeImageRegistry(ImageRegistry reg) {
94 reg.put(Severity.FATAL.toString()+"-full", FATAL_ICON);
95 reg.put(Severity.ERROR.toString()+"-full", ERROR_ICON);
96 reg.put(Severity.WARNING.toString()+"-full", WARNING_ICON);
97 reg.put(Severity.INFO.toString()+"-full", INFO_ICON);
98 reg.put(Severity.NOTE.toString()+"-full", NOTE_ICON);
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);
107 public void stop(BundleContext context) throws Exception {
108 messageScheme.close();
114 * Returns the shared instance
116 * @return the shared instance
118 public static Activator getDefault() {
122 public static ImageDescriptor getImageDescriptor(String path) {
123 return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
126 public static URL getDefaultResource(String name) {
127 Activator plugin = getDefault();
128 if(plugin == null) throw new IllegalStateException("The plugin is not active.");
129 Bundle bundle = plugin.getBundle();
130 return bundle.getResource(name);