KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > AntUIPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  * John-Mason P. Shackelford (john-mason.shackelford@pearson.com) - bug 53547
11  *******************************************************************************/

12 package org.eclipse.ant.internal.ui.model;
13
14
15 import java.util.Locale JavaDoc;
16
17 import org.eclipse.ant.internal.ui.editor.text.IAntEditorColorConstants;
18 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.jface.preference.IPreferenceStore;
22 import org.eclipse.jface.preference.PreferenceConverter;
23 import org.eclipse.jface.resource.ImageRegistry;
24 import org.eclipse.swt.graphics.Color;
25 import org.eclipse.swt.graphics.RGB;
26 import org.eclipse.swt.widgets.Display;
27 import org.eclipse.ui.IWorkbenchPage;
28 import org.eclipse.ui.IWorkbenchWindow;
29 import org.eclipse.ui.editors.text.EditorsUI;
30 import org.eclipse.ui.plugin.AbstractUIPlugin;
31 import org.osgi.framework.BundleContext;
32
33 /**
34  * The plug-in runtime class for the Ant Core plug-in.
35  */

36 public class AntUIPlugin extends AbstractUIPlugin {
37
38     /**
39      * Status code indicating an unexpected internal error.
40      * @since 2.1
41      */

42     public static final int INTERNAL_ERROR = 120;
43     
44     /**
45      * The single instance of this plug-in runtime class.
46      */

47     private static AntUIPlugin plugin;
48
49     /**
50      * Unique identifier constant (value <code>"org.eclipse.ant.ui"</code>)
51      * for the Ant UI plug-in.
52      */

53     public static final String JavaDoc PI_ANTUI = "org.eclipse.ant.ui"; //$NON-NLS-1$
54

55     private static final String JavaDoc EMPTY_STRING= ""; //$NON-NLS-1$
56

57     /**
58      * Constructs an instance of this plug-in runtime class.
59      * <p>
60      * An instance of this plug-in runtime class is automatically created
61      * when the facilities provided by the Ant Core plug-in are required.
62      * <b>Clients must never explicitly instantiate a plug-in runtime class.</b>
63      * </p>
64      */

65     public AntUIPlugin() {
66         super();
67         plugin = this;
68     }
69
70     /* (non-Javadoc)
71      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
72      */

73     public void stop(BundleContext context) throws Exception JavaDoc {
74         try {
75             AntUIImages.disposeImageDescriptorRegistry();
76         } finally {
77             super.stop(context);
78         }
79     }
80
81     /**
82      * Returns this plug-in instance.
83      *
84      * @return the single instance of this plug-in runtime class
85      */

86     public static AntUIPlugin getDefault() {
87         return plugin;
88     }
89     
90     /**
91      * Convenience method which returns the unique identifier of this plugin.
92      */

93     public static String JavaDoc getUniqueIdentifier() {
94         return PI_ANTUI;
95     }
96     
97     /**
98      * Logs the specified throwable with this plug-in's log.
99      *
100      * @param t throwable to log
101      */

102     public static void log(Throwable JavaDoc t) {
103         IStatus status= new Status(IStatus.ERROR, PI_ANTUI, INTERNAL_ERROR, "Error logged from Ant UI: ", t); //$NON-NLS-1$
104
log(status);
105     }
106     
107     /**
108      * Logs the specified status with this plug-in's log.
109      *
110      * @param status status
111      */

112     public static void log(IStatus status) {
113         getDefault().getLog().log(status);
114     }
115     
116     /**
117      * Writes the message to the plug-in's log
118      *
119      * @param message the text to write to the log
120      */

121     public static void log(String JavaDoc message, Throwable JavaDoc exception) {
122         IStatus status = newErrorStatus(message, exception);
123         log(status);
124     }
125     
126     /**
127      * Returns a new <code>IStatus</code> for this plug-in
128      */

129     public static IStatus newErrorStatus(String JavaDoc message, Throwable JavaDoc exception) {
130         if (message == null) {
131             message= EMPTY_STRING;
132         }
133         return new Status(IStatus.ERROR, IAntUIConstants.PLUGIN_ID, 0, message, exception);
134     }
135     
136     /* (non-Javadoc)
137      * Method declared in AbstractUIPlugin.
138      */

139     protected void initializeDefaultPreferences(IPreferenceStore prefs) {
140         prefs.setDefault(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, "build.xml"); //$NON-NLS-1$
141
EditorsUI.useAnnotationsPreferencePage(prefs);
142         EditorsUI.useQuickDiffPreferencePage(prefs);
143         if (isMacOS()) {
144             //the mac does not have a tools.jar Bug 40778
145
prefs.setDefault(IAntUIPreferenceConstants.ANT_TOOLS_JAR_WARNING, false);
146         } else {
147             prefs.setDefault(IAntUIPreferenceConstants.ANT_TOOLS_JAR_WARNING, true);
148         }
149         
150         prefs.setDefault(IAntUIPreferenceConstants.ANT_ERROR_DIALOG, true);
151         
152         prefs.setDefault(IAntUIPreferenceConstants.ANTEDITOR_FILTER_INTERNAL_TARGETS, false);
153         prefs.setDefault(IAntUIPreferenceConstants.ANTEDITOR_FILTER_IMPORTED_ELEMENTS, false);
154         prefs.setDefault(IAntUIPreferenceConstants.ANTEDITOR_FILTER_PROPERTIES, false);
155         prefs.setDefault(IAntUIPreferenceConstants.ANTEDITOR_FILTER_TOP_LEVEL, false);
156
157         // Ant Editor color preferences
158
PreferenceConverter.setDefault(prefs, IAntEditorColorConstants.TEXT_COLOR, IAntEditorColorConstants.DEFAULT);
159         PreferenceConverter.setDefault(prefs, IAntEditorColorConstants.PROCESSING_INSTRUCTIONS_COLOR, IAntEditorColorConstants.PROC_INSTR);
160         PreferenceConverter.setDefault(prefs, IAntEditorColorConstants.STRING_COLOR, IAntEditorColorConstants.STRING);
161         PreferenceConverter.setDefault(prefs, IAntEditorColorConstants.TAG_COLOR, IAntEditorColorConstants.TAG);
162         PreferenceConverter.setDefault(prefs, IAntEditorColorConstants.XML_COMMENT_COLOR, IAntEditorColorConstants.XML_COMMENT);
163         
164         PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_ERROR_COLOR, new RGB(255, 0, 0)); // red - exactly the same as debug Console
165
PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR, new RGB(250, 100, 0)); // orange
166
PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_INFO_COLOR, new RGB(0, 0, 255)); // blue
167
PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_VERBOSE_COLOR, new RGB(0, 200, 125)); // green
168
PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_DEBUG_COLOR, new RGB(0, 0, 0)); // black
169

170         AntEditorPreferenceConstants.initializeDefaultValues(prefs);
171     }
172     
173     /**
174      * Returns the standard display to be used. The method first checks, if
175      * the thread calling this method has an associated display. If so, this
176      * display is returned. Otherwise the method returns the default display.
177      */

178     public static Display getStandardDisplay() {
179         Display display = Display.getCurrent();
180         if (display == null) {
181             display = Display.getDefault();
182         }
183         return display;
184     }
185     
186     /* (non-Javadoc)
187      * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
188      */

189     protected ImageRegistry createImageRegistry() {
190         return AntUIImages.initializeImageRegistry();
191     }
192     
193     /**
194      * Returns the preference color, identified by the given preference.
195      */

196     public static Color getPreferenceColor(String JavaDoc pref) {
197         return ColorManager.getDefault().getColor(PreferenceConverter.getColor(getDefault().getPreferenceStore(), pref));
198     }
199     
200     /**
201     * Returns the active workbench page or <code>null</code> if none.
202     */

203    public static IWorkbenchPage getActivePage() {
204        IWorkbenchWindow window= getActiveWorkbenchWindow();
205        if (window != null) {
206            return window.getActivePage();
207        }
208        return null;
209    }
210
211    /**
212     * Returns the active workbench window or <code>null</code> if none
213     */

214    public static IWorkbenchWindow getActiveWorkbenchWindow() {
215        return getDefault().getWorkbench().getActiveWorkbenchWindow();
216    }
217    
218    /**
219     * Returns whether the current OS claims to be Mac
220     */

221    public static boolean isMacOS() {
222         String JavaDoc osname= System.getProperty("os.name").toLowerCase(Locale.US); //$NON-NLS-1$
223
return osname.indexOf("mac") != -1; //$NON-NLS-1$
224
}
225 }
Popular Tags