1 12 package org.eclipse.ant.internal.ui.model; 13 14 15 import java.util.Locale ; 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 36 public class AntUIPlugin extends AbstractUIPlugin { 37 38 42 public static final int INTERNAL_ERROR = 120; 43 44 47 private static AntUIPlugin plugin; 48 49 53 public static final String PI_ANTUI = "org.eclipse.ant.ui"; 55 private static final String EMPTY_STRING= ""; 57 65 public AntUIPlugin() { 66 super(); 67 plugin = this; 68 } 69 70 73 public void stop(BundleContext context) throws Exception { 74 try { 75 AntUIImages.disposeImageDescriptorRegistry(); 76 } finally { 77 super.stop(context); 78 } 79 } 80 81 86 public static AntUIPlugin getDefault() { 87 return plugin; 88 } 89 90 93 public static String getUniqueIdentifier() { 94 return PI_ANTUI; 95 } 96 97 102 public static void log(Throwable t) { 103 IStatus status= new Status(IStatus.ERROR, PI_ANTUI, INTERNAL_ERROR, "Error logged from Ant UI: ", t); log(status); 105 } 106 107 112 public static void log(IStatus status) { 113 getDefault().getLog().log(status); 114 } 115 116 121 public static void log(String message, Throwable exception) { 122 IStatus status = newErrorStatus(message, exception); 123 log(status); 124 } 125 126 129 public static IStatus newErrorStatus(String message, Throwable 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 139 protected void initializeDefaultPreferences(IPreferenceStore prefs) { 140 prefs.setDefault(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, "build.xml"); EditorsUI.useAnnotationsPreferencePage(prefs); 142 EditorsUI.useQuickDiffPreferencePage(prefs); 143 if (isMacOS()) { 144 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 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)); PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_WARNING_COLOR, new RGB(250, 100, 0)); PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_INFO_COLOR, new RGB(0, 0, 255)); PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_VERBOSE_COLOR, new RGB(0, 200, 125)); PreferenceConverter.setDefault(prefs, IAntUIPreferenceConstants.CONSOLE_DEBUG_COLOR, new RGB(0, 0, 0)); 170 AntEditorPreferenceConstants.initializeDefaultValues(prefs); 171 } 172 173 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 189 protected ImageRegistry createImageRegistry() { 190 return AntUIImages.initializeImageRegistry(); 191 } 192 193 196 public static Color getPreferenceColor(String pref) { 197 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(getDefault().getPreferenceStore(), pref)); 198 } 199 200 203 public static IWorkbenchPage getActivePage() { 204 IWorkbenchWindow window= getActiveWorkbenchWindow(); 205 if (window != null) { 206 return window.getActivePage(); 207 } 208 return null; 209 } 210 211 214 public static IWorkbenchWindow getActiveWorkbenchWindow() { 215 return getDefault().getWorkbench().getActiveWorkbenchWindow(); 216 } 217 218 221 public static boolean isMacOS() { 222 String osname= System.getProperty("os.name").toLowerCase(Locale.US); return osname.indexOf("mac") != -1; } 225 } | Popular Tags |