stack frame bugs fixed
[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
32 /**
33  * External tools plug-in class
34  */
35 public final class ExternalToolsPlugin { // extends AbstractUIPlugin {
36         /**
37          * Status representing no problems encountered during operation.
38          */ 
39         public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
40
41         private static ExternalToolsPlugin plugin;
42
43         private RefreshScopeVariableRegistry refreshVarRegistry;
44         private PathLocationVariableRegistry fileLocVarRegistry;
45         private PathLocationVariableRegistry dirLocVarRegistry;
46         private ArgumentVariableRegistry argumentVarRegistry;
47
48         /**
49          * Create an instance of the External Tools plug-in.
50          */
51         public ExternalToolsPlugin() { // IPluginDescriptor descriptor) {
52                 // super(descriptor);
53                 plugin = this;
54         }
55
56         /**
57          * Returns the default instance of the receiver.
58          * This represents the runtime plugin.
59          */
60         public static ExternalToolsPlugin getDefault() {
61                 return plugin;
62         }
63
64         /**
65          * Returns a new <code>IStatus</code> for this plug-in
66          */
67         public static IStatus newErrorStatus(String message, Throwable exception) {
68                 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
69         }
70
71         /**
72          * Returns a new <code>CoreException</code> for this plug-in
73          */
74         public static CoreException newError(String message, Throwable exception) {
75                 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
76         }
77
78         /**
79          * Returns the registry of refresh scope variables.
80          */
81         public ArgumentVariableRegistry getArgumentVariableRegistry() {
82                 if (argumentVarRegistry == null)
83                         argumentVarRegistry = new ArgumentVariableRegistry();
84                 return argumentVarRegistry;
85         }
86
87         /**
88          * Returns the registry of directory location variables.
89          */
90         public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
91                 if (dirLocVarRegistry == null)
92                         dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
93                 return dirLocVarRegistry;
94         }
95
96         /**
97          * Returns the registry of file location variables.
98          */
99         public PathLocationVariableRegistry getFileLocationVariableRegistry() {
100                 if (fileLocVarRegistry == null)
101                         fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
102                 return fileLocVarRegistry;
103         }
104
105         /**
106          * Returns the registry of refresh scope variables.
107          */
108         public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
109                 if (refreshVarRegistry == null)
110                         refreshVarRegistry = new RefreshScopeVariableRegistry();
111                 return refreshVarRegistry;
112         }
113
114         /**
115          * Writes the message to the plug-in's log
116          * 
117          * @param message the text to write to the log
118          */
119         public void log(String message, Throwable exception) {
120                 IStatus status = newErrorStatus(message, exception);
121         //      getLog().log(status);
122                 PHPeclipsePlugin.log(status);
123         }
124
125         /**
126          * Returns the ImageDescriptor for the icon with the given path
127          * 
128          * @return the ImageDescriptor object
129          */
130         public ImageDescriptor getImageDescriptor(String path) {
131                 try {
132                         URL installURL = PHPeclipsePlugin.getDefault().getDescriptor().getInstallURL();
133                         URL url = new URL(installURL, path);
134                         return ImageDescriptor.createFromURL(url);
135                 } catch (MalformedURLException e) {
136                         return null;
137                 }
138         }
139
140         /* (non-Javadoc)
141          * Method declared in AbstractUIPlugin.
142          */
143         public void initializeDefaultPreferences(IPreferenceStore prefs) {
144                 prefs.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
145                 
146                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as debug Consol
147                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
148                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
149                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
150                 PreferenceConverter.setDefault(prefs, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
151         }
152
153         public static IWorkbenchWindow getActiveWorkbenchWindow() {
154                 return PHPeclipsePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
155         }
156
157         /**
158          * Returns the standard display to be used. The method first checks, if
159          * the thread calling this method has an associated display. If so, this
160          * display is returned. Otherwise the method returns the default display.
161          */
162 //      public static Display getStandardDisplay() {
163 //              Display display = Display.getCurrent();
164 //              if (display == null) {
165 //                      display = Display.getDefault();
166 //              }
167 //              return display;
168 //      }
169
170         /**
171          * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
172          */
173         protected ImageRegistry createImageRegistry() {
174                 return ExternalToolsImages.initializeImageRegistry();
175         }
176
177         /**
178          * @see org.eclipse.core.runtime.Plugin#startup()
179          */
180 //      public void startup() throws CoreException {
181 ////            super.startup();
182 //              getStandardDisplay().asyncExec(
183 //                      new Runnable() {
184 //                              public void run() {
185 //                                      //initialize the variable context manager
186 //                                      VariableContextManager.getDefault();
187 //                              }
188 //                      });     
189 //      }
190 //
191 //      /**
192 //       * @see org.eclipse.core.runtime.Plugin#shutdown()
193 //       */
194 //      public void shutdown() throws CoreException {
195 //      //      super.shutdown();
196 //              ColorManager.getDefault().dispose();
197 //      }
198
199         /**
200          * Returns the preference color, identified by the given preference.
201          */
202         public static Color getPreferenceColor(String pref) {
203                 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(PHPeclipsePlugin.getDefault().getPreferenceStore(), pref));
204         }
205 }