1 12 package org.eclipse.ant.internal.ui; 13 14 15 import java.util.Locale ; 16 17 import org.eclipse.ant.internal.ui.editor.DecayCodeCompletionDataStructuresThread; 18 import org.eclipse.ant.internal.ui.editor.text.AntEditorDocumentProvider; 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.widgets.Display; 26 import org.eclipse.ui.IWorkbenchPage; 27 import org.eclipse.ui.IWorkbenchWindow; 28 import org.eclipse.ui.editors.text.EditorsUI; 29 import org.eclipse.ui.plugin.AbstractUIPlugin; 30 import org.eclipse.ui.texteditor.ChainedPreferenceStore; 31 import org.eclipse.ui.texteditor.IDocumentProvider; 32 import org.osgi.framework.BundleContext; 33 34 37 public class AntUIPlugin extends AbstractUIPlugin { 38 39 43 public static final int INTERNAL_ERROR = 120; 44 45 48 private static AntUIPlugin plugin; 49 50 54 public static final String PI_ANTUI = "org.eclipse.ant.ui"; 56 private static final String EMPTY_STRING= ""; 58 62 private IPreferenceStore fCombinedPreferenceStore; 63 64 private IDocumentProvider fDocumentProvider; 65 66 74 public AntUIPlugin() { 75 super(); 76 plugin = this; 77 } 78 79 82 public void stop(BundleContext context) throws Exception { 83 try { 84 AntUIImages.disposeImageDescriptorRegistry(); 85 DecayCodeCompletionDataStructuresThread.cancel(); 86 } finally { 87 super.stop(context); 88 } 89 } 90 91 96 public static AntUIPlugin getDefault() { 97 return plugin; 98 } 99 100 103 public static String getUniqueIdentifier() { 104 return PI_ANTUI; 105 } 106 107 112 public static void log(Throwable t) { 113 IStatus status= new Status(IStatus.ERROR, PI_ANTUI, INTERNAL_ERROR, "Error logged from Ant UI: ", t); log(status); 115 } 116 117 122 public static void log(IStatus status) { 123 getDefault().getLog().log(status); 124 } 125 126 131 public static void log(String message, Throwable exception) { 132 IStatus status = newErrorStatus(message, exception); 133 log(status); 134 } 135 136 139 public static IStatus newErrorStatus(String message, Throwable exception) { 140 if (message == null) { 141 message= EMPTY_STRING; 142 } 143 return new Status(IStatus.ERROR, IAntUIConstants.PLUGIN_ID, 0, message, exception); 144 } 145 146 151 public static Display getStandardDisplay() { 152 Display display = Display.getCurrent(); 153 if (display == null) { 154 display = Display.getDefault(); 155 } 156 return display; 157 } 158 159 162 protected ImageRegistry createImageRegistry() { 163 return AntUIImages.initializeImageRegistry(); 164 } 165 166 169 public static Color getPreferenceColor(String pref) { 170 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(getDefault().getCombinedPreferenceStore(), pref)); 171 } 172 173 176 public static IWorkbenchPage getActivePage() { 177 IWorkbenchWindow window= getActiveWorkbenchWindow(); 178 if (window != null) { 179 return window.getActivePage(); 180 } 181 return null; 182 } 183 184 187 public static IWorkbenchWindow getActiveWorkbenchWindow() { 188 return getDefault().getWorkbench().getActiveWorkbenchWindow(); 189 } 190 191 194 public static boolean isMacOS() { 195 String osname= System.getProperty("os.name").toLowerCase(Locale.US); return osname.indexOf("mac") != -1; } 198 199 206 public IPreferenceStore getCombinedPreferenceStore() { 207 if (fCombinedPreferenceStore == null) { 208 IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore(); 209 fCombinedPreferenceStore= new ChainedPreferenceStore(new IPreferenceStore[] { getPreferenceStore(), generalTextStore }); 210 } 211 return fCombinedPreferenceStore; 212 } 213 214 221 public synchronized IDocumentProvider getDocumentProvider() { 222 if (fDocumentProvider == null) 223 fDocumentProvider= new AntEditorDocumentProvider(); 224 return fDocumentProvider; 225 } 226 } 227 | Popular Tags |