]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/Activator.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / Activator.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.structural.ui;\r
13 \r
14 import org.eclipse.jface.resource.ImageDescriptor;\r
15 import org.eclipse.jface.resource.JFaceResources;\r
16 import org.eclipse.jface.resource.LocalResourceManager;\r
17 import org.eclipse.jface.resource.ResourceManager;\r
18 import org.eclipse.swt.widgets.Display;\r
19 import org.eclipse.ui.plugin.AbstractUIPlugin;\r
20 import org.osgi.framework.Bundle;\r
21 import org.osgi.framework.BundleContext;\r
22 \r
23 /**\r
24  * The activator class controls the plug-in life cycle\r
25  */\r
26 public class Activator extends AbstractUIPlugin {\r
27 \r
28     // The plug-in ID\r
29     public static final String PLUGIN_ID = "org.simantics.structural.ui";\r
30 \r
31     // The shared instance\r
32     private static Activator plugin;\r
33 \r
34     private static LocalResourceManager resourceManager;\r
35 \r
36     public static ImageDescriptor SYNCED_ICON;\r
37     public static ImageDescriptor SHOW_ALL_CHILDREN_ICON;\r
38     public static ImageDescriptor LOCK;\r
39 \r
40     /**\r
41      * The constructor\r
42      */\r
43     public Activator() {\r
44     }\r
45 \r
46     /*\r
47      * (non-Javadoc)\r
48      * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)\r
49      */\r
50     @Override\r
51     public void start(BundleContext context) throws Exception {\r
52         super.start(context);\r
53         plugin = this;\r
54 \r
55         Bundle bundle = context.getBundle();\r
56 \r
57         SYNCED_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/synced.gif"));\r
58         SHOW_ALL_CHILDREN_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/text_linespacing.png"));\r
59         LOCK = ImageDescriptor.createFromURL(bundle.getResource("icons/lock.png"));\r
60     }\r
61 \r
62     /*\r
63      * (non-Javadoc)\r
64      * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)\r
65      */\r
66     @Override\r
67     public void stop(BundleContext context) throws Exception {\r
68         if (resourceManager != null) {\r
69             resourceManager.dispose();\r
70             resourceManager = null;\r
71         }\r
72 \r
73         plugin = null;\r
74         super.stop(context);\r
75     }\r
76 \r
77     /**\r
78      * Returns the shared instance\r
79      *\r
80      * @return the shared instance\r
81      */\r
82     public static Activator getDefault() {\r
83         return plugin;\r
84     }\r
85 \r
86     public static ResourceManager initializeResourceManager(Display display) {\r
87         if (resourceManager == null) {\r
88             resourceManager = new LocalResourceManager(JFaceResources.getResources(display));\r
89         }\r
90         return resourceManager;\r
91     }\r
92 \r
93     public static ResourceManager getResources() {\r
94         if (resourceManager == null)\r
95             throw new IllegalStateException("ResourceManager of bundle '" + PLUGIN_ID + "' is not initialized.");\r
96         return resourceManager;\r
97     }\r
98 \r
99 }\r