Merged "Open PHP Declaration" and "Open Include File" into one action "Open Declarati...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / internal / model / ExternalToolsPlugin.java
1 package net.sourceforge.phpdt.externaltools.internal.model;
2
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8  
9 Contributors:
10 **********************************************************************/
11
12 import java.net.MalformedURLException;
13 import java.net.URL;
14
15 import net.sourceforge.phpdt.externaltools.internal.registry.ArgumentVariableRegistry;
16 import net.sourceforge.phpdt.externaltools.internal.registry.PathLocationVariableRegistry;
17 import net.sourceforge.phpdt.externaltools.internal.registry.RefreshScopeVariableRegistry;
18 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Status;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.preference.PreferenceConverter;
26 import org.eclipse.jface.resource.ImageDescriptor;
27 import org.eclipse.jface.resource.ImageRegistry;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.graphics.RGB;
30 import org.eclipse.ui.IWorkbenchWindow;
31 import org.osgi.framework.Bundle;
32
33 /**
34  * External tools plug-in class
35  */
36 public final class ExternalToolsPlugin { // extends AbstractUIPlugin {
37         /**
38          * Status representing no problems encountered during operation.
39          */ 
40         public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
41
42         private static ExternalToolsPlugin plugin;
43
44         private RefreshScopeVariableRegistry refreshVarRegistry;
45         private PathLocationVariableRegistry fileLocVarRegistry;
46         private PathLocationVariableRegistry dirLocVarRegistry;
47         private ArgumentVariableRegistry argumentVarRegistry;
48
49         /**
50          * Create an instance of the External Tools plug-in.
51          */
52         public ExternalToolsPlugin() { // IPluginDescriptor descriptor) {
53                 // super(descriptor);
54                 plugin = this;
55         }
56
57         /**
58          * Returns the default instance of the receiver.
59          * This represents the runtime plugin.
60          */
61         public static ExternalToolsPlugin getDefault() {
62                 return plugin;
63         }
64
65         /**
66          * Returns a new <code>IStatus</code> for this plug-in
67          */
68         public static IStatus newErrorStatus(String message, Throwable exception) {
69                 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
70         }
71
72         /**
73          * Returns a new <code>CoreException</code> for this plug-in
74          */
75         public static CoreException newError(String message, Throwable exception) {
76                 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
77         }
78
79         /**
80          * Returns the registry of refresh scope variables.
81          */
82         public ArgumentVariableRegistry getArgumentVariableRegistry() {
83                 if (argumentVarRegistry == null)
84                         argumentVarRegistry = new ArgumentVariableRegistry();
85                 return argumentVarRegistry;
86         }
87
88         /**
89          * Returns the registry of directory location variables.
90          */
91         public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
92                 if (dirLocVarRegistry == null)
93                         dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
94                 return dirLocVarRegistry;
95         }
96
97         /**
98          * Returns the registry of file location variables.
99          */
100         public PathLocationVariableRegistry getFileLocationVariableRegistry() {
101                 if (fileLocVarRegistry == null)
102                         fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
103                 return fileLocVarRegistry;
104         }
105
106         /**
107          * Returns the registry of refresh scope variables.
108          */
109         public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
110                 if (refreshVarRegistry == null)
111                         refreshVarRegistry = new RefreshScopeVariableRegistry();
112                 return refreshVarRegistry;
113         }
114
115         /**
116          * Writes the message to the plug-in's log
117          * 
118          * @param message the text to write to the log
119          */
120         public void log(String message, Throwable exception) {
121                 IStatus status = newErrorStatus(message, exception);
122         //      getLog().log(status);
123                 PHPeclipsePlugin.log(status);
124         }
125
126         /**
127          * Returns the ImageDescriptor for the icon with the given path
128          * 
129          * @return the ImageDescriptor object
130          */
131         public ImageDescriptor getImageDescriptor(String path) {
132                 try {
133                         Bundle bundle= PHPeclipsePlugin.getDefault().getBundle();
134                         URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
135                         URL url = new URL(installURL, path);
136                         return ImageDescriptor.createFromURL(url);
137                 } catch (MalformedURLException e) {
138                         return null;
139                 }
140         }
141
142         /* (non-Javadoc)
143          * Method declared in AbstractUIPlugin.
144          */
145         public void initializeDefaultPreferences(IPreferenceStore prefs) {
146                 prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
147                 
148                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as debug Consol
149                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
150                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
151                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
152                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
153         }
154
155         public static IWorkbenchWindow getActiveWorkbenchWindow() {
156                 return PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
157         }
158
159         /**
160          * Returns the standard display to be used. The method first checks, if
161          * the thread calling this method has an associated display. If so, this
162          * display is returned. Otherwise the method returns the default display.
163          */
164 //      public static Display getStandardDisplay() {
165 //              Display display = Display.getCurrent();
166 //              if (display == null) {
167 //                      display = Display.getDefault();
168 //              }
169 //              return display;
170 //      }
171
172         /**
173          * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
174          */
175         protected ImageRegistry createImageRegistry() {
176                 return ExternalToolsImages.initializeImageRegistry();
177         }
178
179         /**
180          * @see org.eclipse.core.runtime.Plugin#startup()
181          */
182 //      public void startup() throws CoreException {
183 ////            super.startup();
184 //              getStandardDisplay().asyncExec(
185 //                      new Runnable() {
186 //                              public void run() {
187 //                                      //initialize the variable context manager
188 //                                      VariableContextManager.getDefault();
189 //                              }
190 //                      });     
191 //      }
192 //
193 //      /**
194 //       * @see org.eclipse.core.runtime.Plugin#shutdown()
195 //       */
196 //      public void shutdown() throws CoreException {
197 //      //      super.shutdown();
198 //              ColorManager.getDefault().dispose();
199 //      }
200
201         /**
202          * Returns the preference color, identified by the given preference.
203          */
204         public static Color getPreferenceColor(String pref) {
205                 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(PHPeclipsePlugin.getDefault().getPreferenceStore(), pref));
206         }
207 }