CVS test
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.ui / src / net / sourceforge / phpeclipse / js / ui / JSUIPlugin.java
1 /*
2  * Copyright (c) 2002-2004 Adrian Dinu and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Adrian Dinu - initial implementation
10  * 
11  * $Id: JSUIPlugin.java,v 1.1 2004-09-02 18:23:57 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.js.ui;
15
16 import java.util.LinkedList;
17 import java.util.List;
18 import java.util.MissingResourceException;
19 import java.util.ResourceBundle;
20
21 import net.sourceforge.phpeclipse.js.ui.editors.JSImages;
22 import net.sourceforge.phpeclipse.js.ui.model.JSModelAdapterFactory;
23 import net.sourceforge.phpeclipse.js.ui.preferences.PreferenceNames;
24
25 import org.eclipse.core.resources.IWorkspace;
26 import org.eclipse.core.resources.ResourcesPlugin;
27 import org.eclipse.core.runtime.Platform;
28 import org.eclipse.jface.preference.IPreferenceStore;
29 import org.eclipse.jface.resource.ImageRegistry;
30 import org.eclipse.ui.plugin.AbstractUIPlugin;
31 import org.osgi.framework.BundleContext;
32
33 /**
34  * The main plugin class to be used in the desktop.
35  */
36 public class JSUIPlugin extends AbstractUIPlugin {
37
38         /** The shared instance. */
39         private static JSUIPlugin plugin;
40
41         /** Resource bundle. */
42         private ResourceBundle resourceBundle;
43
44         /** The current func list. */
45         private List currentFunctions = new LinkedList();
46
47         /**
48          * The constructor.
49          * 
50          * @param descriptor the plugin descriptors
51          */
52         public JSUIPlugin() {
53                 plugin = this;
54
55                 try {
56                         resourceBundle = ResourceBundle.getBundle(
57                                 "net.sourceforge.phpeclipse.js.ui.jseditorPluginResources"); //$NON-NLS-1$
58                 } catch (MissingResourceException e) {
59                         resourceBundle = null;
60                 }
61         }
62
63         /**
64          * Returns the shared instance.
65          * @return
66          */
67         public static JSUIPlugin getDefault() {
68                 return plugin;
69         }
70
71         /**
72          * Returns the workspace instance.
73          * @return
74          */
75         public static IWorkspace getWorkspace() {
76                 return ResourcesPlugin.getWorkspace();
77         }
78
79         /**
80          * Returns the string from the plugin's resource bundle, or 'key' if not
81          * found.
82          * 
83          * @param key
84          * 
85          * @return
86          */
87         public static String getResourceString(String key) {
88                 ResourceBundle bundle = JSUIPlugin.getDefault().getResourceBundle();
89                 try {
90                         return bundle.getString(key);
91                 } catch(MissingResourceException e) {
92                         return key;
93                 }
94         }
95
96         /**
97          * Returns the plugin's resource bundle,
98          * @return
99          */
100         public ResourceBundle getResourceBundle() {
101                 return resourceBundle;
102         }
103
104         /**
105          * Returns the list of current functions.
106          * 
107          * @return the current functions
108          */
109         public List getCurrentFunctions() {
110                 return currentFunctions;
111         }
112
113         /**
114          * Sets the current list of functions.
115          * 
116          * @param currentFunctions The functions to set
117          */
118         public void setCurrentFunctions(List currentFunctions) {
119                 this.currentFunctions = currentFunctions;
120         }
121
122         /*
123          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
124          */
125         public void start(BundleContext context) throws Exception {
126                 super.start(context);
127                 JSModelAdapterFactory.register(Platform.getAdapterManager());
128         }
129         
130         /* 
131          * @see AbstractUIPlugin#initializeDefaultPreferences(IPreferenceStore)
132          */
133         protected void initializeDefaultPreferences(IPreferenceStore store) {
134                 store.setDefault(PreferenceNames.P_AUTO_OUTLINE, true);
135                 // TODO Use PreferenceConverter for color/string conversion
136                 store.setDefault(PreferenceNames.P_COMMENT_COLOR, "63,127,95");
137                 store.setDefault(PreferenceNames.P_STRING_COLOR, "42,0,255");
138                 store.setDefault(PreferenceNames.P_KEYWORD_COLOR, "127,0,85");
139                 store.setDefault(PreferenceNames.P_DEFAULT_COLOR, "0,0,0");
140         }
141
142         /* 
143          * @see AbstractUIPlugin#initializeImageRegistry(ImageRegistry)
144          */
145         protected void initializeImageRegistry(ImageRegistry reg) {
146                 JSImages.initializeRegistry(reg);
147         }
148 }