]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/Activator.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.structural.ui / src / org / simantics / structural / ui / Activator.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 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.structural.ui;
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.jface.resource.JFaceResources;
16 import org.eclipse.jface.resource.LocalResourceManager;
17 import org.eclipse.jface.resource.ResourceManager;
18 import org.eclipse.swt.widgets.Display;
19 import org.eclipse.ui.plugin.AbstractUIPlugin;
20 import org.osgi.framework.Bundle;
21 import org.osgi.framework.BundleContext;
22
23 /**
24  * The activator class controls the plug-in life cycle
25  */
26 public class Activator extends AbstractUIPlugin {
27
28     // The plug-in ID
29     public static final String PLUGIN_ID = "org.simantics.structural.ui";
30
31     // The shared instance
32     private static Activator plugin;
33
34     private static LocalResourceManager resourceManager;
35
36     public static ImageDescriptor SYNCED_ICON;
37     public static ImageDescriptor SHOW_ALL_CHILDREN_ICON;
38     public static ImageDescriptor LOCK;
39
40     /**
41      * The constructor
42      */
43     public Activator() {
44     }
45
46     /*
47      * (non-Javadoc)
48      * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
49      */
50     @Override
51     public void start(BundleContext context) throws Exception {
52         super.start(context);
53         plugin = this;
54
55         Bundle bundle = context.getBundle();
56
57         SYNCED_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/synced.gif"));
58         SHOW_ALL_CHILDREN_ICON = ImageDescriptor.createFromURL(bundle.getResource("icons/text_linespacing.png"));
59         LOCK = ImageDescriptor.createFromURL(bundle.getResource("icons/lock.png"));
60     }
61
62     /*
63      * (non-Javadoc)
64      * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
65      */
66     @Override
67     public void stop(BundleContext context) throws Exception {
68         if (resourceManager != null) {
69             resourceManager.dispose();
70             resourceManager = null;
71         }
72
73         plugin = null;
74         super.stop(context);
75     }
76
77     /**
78      * Returns the shared instance
79      *
80      * @return the shared instance
81      */
82     public static Activator getDefault() {
83         return plugin;
84     }
85
86     public static ResourceManager initializeResourceManager(Display display) {
87         if (resourceManager == null) {
88             resourceManager = new LocalResourceManager(JFaceResources.getResources(display));
89         }
90         return resourceManager;
91     }
92
93     public static ResourceManager getResources() {
94         if (resourceManager == null)
95             throw new IllegalStateException("ResourceManager of bundle '" + PLUGIN_ID + "' is not initialized.");
96         return resourceManager;
97     }
98
99 }