1 11 package org.eclipse.team.internal.ui; 12 13 14 import java.lang.reflect.InvocationTargetException ; 15 import java.net.URL ; 16 import java.util.*; 17 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.core.runtime.jobs.Job; 20 import org.eclipse.core.runtime.preferences.InstanceScope; 21 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 22 import org.eclipse.jface.operation.IRunnableWithProgress; 23 import org.eclipse.jface.preference.IPreferenceStore; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.util.IPropertyChangeListener; 26 import org.eclipse.jface.util.PropertyChangeEvent; 27 import org.eclipse.swt.custom.BusyIndicator; 28 import org.eclipse.swt.graphics.Image; 29 import org.eclipse.swt.widgets.Display; 30 import org.eclipse.team.core.RepositoryProviderType; 31 import org.eclipse.team.core.subscribers.Subscriber; 32 import org.eclipse.team.internal.ui.mapping.StreamMergerDelegate; 33 import org.eclipse.team.internal.ui.mapping.WorkspaceTeamStateProvider; 34 import org.eclipse.team.internal.ui.synchronize.SynchronizeManager; 35 import org.eclipse.team.internal.ui.synchronize.TeamSynchronizingPerspective; 36 import org.eclipse.team.internal.ui.synchronize.actions.GlobalRefreshAction; 37 import org.eclipse.team.ui.ISharedImages; 38 import org.eclipse.team.ui.mapping.ITeamStateProvider; 39 import org.eclipse.team.ui.synchronize.*; 40 import org.eclipse.ui.*; 41 import org.eclipse.ui.plugin.AbstractUIPlugin; 42 import org.osgi.framework.Bundle; 43 import org.osgi.framework.BundleContext; 44 45 49 public class TeamUIPlugin extends AbstractUIPlugin { 50 51 private static TeamUIPlugin instance; 52 53 public static final String ICON_PATH = "$nl$/icons/full/"; 56 public static final String ID = "org.eclipse.team.ui"; 58 public static final String PLUGIN_ID = "org.eclipse.team.ui"; 61 public static final String TRIGGER_POINT_ID = "org.eclipse.team.ui.activityTriggerPoint"; 63 private static List propertyChangeListeners = new ArrayList(5); 64 65 private Hashtable imageDescriptors = new Hashtable(20); 66 67 private WorkspaceTeamStateProvider provider; 68 69 private Map decoratedStateProviders = new HashMap(); 70 71 private SynchronizeManager synchronizeManager; 73 74 77 public TeamUIPlugin() { 78 super(); 79 instance = this; 80 } 81 82 91 public static Object createExtension(final IConfigurationElement element, final String classAttribute) throws CoreException { 92 Bundle bundle = Platform.getBundle(element.getNamespace()); 95 if (bundle.getState() == org.osgi.framework.Bundle.ACTIVE) { 96 return element.createExecutableExtension(classAttribute); 97 } else { 98 final Object [] ret = new Object [1]; 99 final CoreException [] exc = new CoreException[1]; 100 BusyIndicator.showWhile(null, new Runnable () { 101 public void run() { 102 try { 103 ret[0] = element.createExecutableExtension(classAttribute); 104 } catch (CoreException e) { 105 exc[0] = e; 106 } 107 } 108 }); 109 if (exc[0] != null) 110 throw exc[0]; 111 else 112 return ret[0]; 113 } 114 } 115 116 124 public static IWorkbenchPage getActivePage() { 125 IWorkbenchWindow window = getPlugin().getWorkbench().getActiveWorkbenchWindow(); 126 if (window == null) return null; 127 return window.getActivePage(); 128 } 129 130 135 public static TeamUIPlugin getPlugin() { 136 return instance; 137 } 138 141 protected void initializeDefaultPluginPreferences() { 142 IPreferenceStore store = getPreferenceStore(); 143 store.setDefault(IPreferenceIds.SYNCVIEW_VIEW_SYNCINFO_IN_LABEL, false); 144 store.setDefault(IPreferenceIds.SHOW_AUTHOR_IN_COMPARE_EDITOR, false); 145 store.setDefault(IPreferenceIds.MAKE_FILE_WRITTABLE_IF_CONTEXT_MISSING, false); 146 store.setDefault(IPreferenceIds.REUSE_OPEN_COMPARE_EDITOR, true); 147 store.setDefault(IPreferenceIds.RUN_IMPORT_IN_BACKGROUND, false); 148 store.setDefault(IPreferenceIds.SYNCVIEW_COMPRESS_FOLDERS, true); 149 store.setDefault(IPreferenceIds.SYNCVIEW_DEFAULT_LAYOUT, IPreferenceIds.COMPRESSED_LAYOUT); 150 store.setDefault(IPreferenceIds.SYNCVIEW_DEFAULT_PERSPECTIVE, TeamSynchronizingPerspective.ID); 151 store.setDefault(IPreferenceIds.SYNCHRONIZING_DEFAULT_PARTICIPANT, GlobalRefreshAction.NO_DEFAULT_PARTICPANT); 152 store.setDefault(IPreferenceIds.SYNCHRONIZING_DEFAULT_PARTICIPANT_SEC_ID, GlobalRefreshAction.NO_DEFAULT_PARTICPANT); 153 store.setDefault(IPreferenceIds.SYNCHRONIZING_COMPLETE_PERSPECTIVE, MessageDialogWithToggle.PROMPT); 154 store.setDefault(IPreferenceIds.SYNCVIEW_REMOVE_FROM_VIEW_NO_PROMPT, false); 155 store.setDefault(IPreferenceIds.PREF_WORKSPACE_FIRST_TIME, true); 156 157 if (!store.isDefault(IPreferenceIds.SYNCVIEW_COMPRESS_FOLDERS) && !store.getBoolean(IPreferenceIds.SYNCVIEW_COMPRESS_FOLDERS)) { 159 store.setToDefault(IPreferenceIds.SYNCVIEW_COMPRESS_FOLDERS); 162 store.setDefault(IPreferenceIds.SYNCVIEW_DEFAULT_LAYOUT, IPreferenceIds.TREE_LAYOUT); 164 } 165 } 166 167 172 public static void log(IStatus status) { 173 getPlugin().getLog().log(status); 174 } 175 176 181 public static void log(CoreException e) { 182 IStatus status = e.getStatus(); 183 log (status.getSeverity(), status.getMessage(), e); 184 } 185 186 189 public static void log(int severity, String message, Throwable e) { 190 log(new Status(severity, ID, 0, message, e)); 191 } 192 193 196 public void start(BundleContext context) throws Exception { 197 super.start(context); 198 199 initializeImages(this); 200 201 IPreferenceStore store = getPreferenceStore(); 207 if (store.getBoolean(IPreferenceIds.PREF_WORKSPACE_FIRST_TIME)) { 208 Job capabilityInitializer = new Job("") { protected IStatus run(IProgressMonitor monitor) { 210 TeamCapabilityHelper.getInstance(); 211 getPreferenceStore().setValue(IPreferenceIds.PREF_WORKSPACE_FIRST_TIME, false); 212 return Status.OK_STATUS; 213 } 214 public boolean shouldRun() { 215 return PlatformUI.isWorkbenchRunning(); 217 } 218 }; 219 capabilityInitializer.setSystem(true); 220 capabilityInitializer.setPriority(Job.DECORATE); 221 capabilityInitializer.schedule(1000); 222 } 223 224 StreamMergerDelegate.start(); 225 } 226 227 230 public void stop(BundleContext context) throws Exception { 231 try { 232 if (synchronizeManager != null) 233 synchronizeManager.dispose(); 234 } finally { 235 super.stop(context); 236 } 237 if (provider != null) { 238 provider.dispose(); 239 } 240 for (Iterator iter = decoratedStateProviders.values().iterator(); iter.hasNext();) { 241 SubscriberTeamStateProvider sdsp = (SubscriberTeamStateProvider) iter.next(); 242 sdsp.dispose(); 243 } 244 } 245 246 249 public static void addPropertyChangeListener(IPropertyChangeListener listener) { 250 propertyChangeListeners.add(listener); 251 } 252 253 256 public static void removePropertyChangeListener(IPropertyChangeListener listener) { 257 propertyChangeListeners.remove(listener); 258 } 259 260 263 public static void broadcastPropertyChange(PropertyChangeEvent event) { 264 for (Iterator it = propertyChangeListeners.iterator(); it.hasNext();) { 265 IPropertyChangeListener listener = (IPropertyChangeListener)it.next(); 266 listener.propertyChange(event); 267 } 268 } 269 270 276 private static void createImageDescriptor(TeamUIPlugin plugin, String id) { 277 plugin.privateCreateImageDescriptor(id); 279 } 280 private void privateCreateImageDescriptor(String id) { 281 ImageDescriptor desc = ImageDescriptor.createFromURL(getImageUrl(id)); 282 imageDescriptors.put(id, desc); 283 } 284 285 292 public static ImageDescriptor getImageDescriptor(String id) { 293 return getPlugin().privateGetImageDescriptor(id); 295 } 296 private ImageDescriptor privateGetImageDescriptor(String id) { 297 if(! imageDescriptors.containsKey(id)) { 298 createImageDescriptor(getPlugin(), id); 299 } 300 return (ImageDescriptor)imageDescriptors.get(id); 301 } 302 303 310 public static ImageDescriptor getImageDescriptorFromExtension(IExtension extension, String subdirectoryAndFilename) { 311 URL fullPathString = Platform.find(Platform.getBundle(extension.getNamespace()), new Path(subdirectoryAndFilename)); 312 return ImageDescriptor.createFromURL(fullPathString); 313 } 314 320 private void initializeImages(TeamUIPlugin plugin) { 321 createImageDescriptor(plugin, ISharedImages.IMG_DIRTY_OVR); 323 createImageDescriptor(plugin, ISharedImages.IMG_CONFLICT_OVR); 324 createImageDescriptor(plugin, ISharedImages.IMG_CHECKEDIN_OVR); 325 createImageDescriptor(plugin, ISharedImages.IMG_CHECKEDOUT_OVR); 326 createImageDescriptor(plugin, ISharedImages.IMG_ERROR_OVR); 327 createImageDescriptor(plugin, ISharedImages.IMG_WARNING_OVR); 328 createImageDescriptor(plugin, ISharedImages.IMG_HOURGLASS_OVR); 329 330 createImageDescriptor(plugin, ITeamUIImages.IMG_SITE_ELEMENT); 332 333 createImageDescriptor(plugin, ITeamUIImages.IMG_DLG_SYNC_INCOMING); 335 createImageDescriptor(plugin, ITeamUIImages.IMG_DLG_SYNC_OUTGOING); 336 createImageDescriptor(plugin, ITeamUIImages.IMG_DLG_SYNC_CONFLICTING); 337 createImageDescriptor(plugin, ITeamUIImages.IMG_REFRESH); 338 createImageDescriptor(plugin, ITeamUIImages.IMG_CHANGE_FILTER); 339 createImageDescriptor(plugin, ITeamUIImages.IMG_IGNORE_WHITESPACE); 340 createImageDescriptor(plugin, ITeamUIImages.IMG_COLLAPSE_ALL); 341 createImageDescriptor(plugin, ITeamUIImages.IMG_COLLAPSE_ALL_ENABLED); 342 343 createImageDescriptor(plugin, ITeamUIImages.IMG_DLG_SYNC_INCOMING_DISABLED); 344 createImageDescriptor(plugin, ITeamUIImages.IMG_DLG_SYNC_OUTGOING_DISABLED); 345 createImageDescriptor(plugin, ITeamUIImages.IMG_DLG_SYNC_CONFLICTING_DISABLED); 346 createImageDescriptor(plugin, ITeamUIImages.IMG_REFRESH_DISABLED); 347 createImageDescriptor(plugin, ITeamUIImages.IMG_IGNORE_WHITESPACE_DISABLED); 348 349 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_CATCHUP); 350 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_RELEASE); 351 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_FREE); 352 353 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_CATCHUP_DISABLED); 354 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_RELEASE_DISABLED); 355 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_FREE_DISABLED); 356 357 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_CATCHUP_ENABLED); 358 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_RELEASE_ENABLED); 359 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_MODE_FREE_ENABLED); 360 361 createImageDescriptor(plugin, ITeamUIImages.IMG_PROJECTSET_IMPORT_BANNER); 363 createImageDescriptor(plugin, ITeamUIImages.IMG_PROJECTSET_EXPORT_BANNER); 364 createImageDescriptor(plugin, ITeamUIImages.IMG_WIZBAN_SHARE); 365 366 createImageDescriptor(plugin, ITeamUIImages.IMG_COMPRESSED_FOLDER); 368 createImageDescriptor(plugin, ITeamUIImages.IMG_SYNC_VIEW); 369 createImageDescriptor(plugin, ITeamUIImages.IMG_HIERARCHICAL); 370 371 createImageDescriptor(plugin, ITeamUIImages.IMG_DATES_CATEGORY); 373 createImageDescriptor(plugin, ITeamUIImages.IMG_COMPARE_VIEW); 374 createImageDescriptor(plugin, ITeamUIImages.IMG_LOCALREVISION_TABLE); 375 } 376 377 private URL getImageUrl(String relative) { 378 return Platform.find(Platform.getBundle(PLUGIN_ID), new Path(ICON_PATH + relative)); 379 } 380 381 386 public static Display getStandardDisplay() { 387 Display display= Display.getCurrent(); 388 if (display == null) { 389 display= Display.getDefault(); 390 } 391 return display; 392 } 393 394 public Image getImage(String key) { 395 Image image = getImageRegistry().get(key); 396 if(image == null) { 397 ImageDescriptor d = getImageDescriptor(key); 398 image = d.createImage(); 399 getImageRegistry().put(key, image); 400 } 401 return image; 402 } 403 404 public static void run(IRunnableWithProgress runnable) { 405 try { 406 PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, runnable); 407 } catch (InvocationTargetException e) { 408 Utils.handleError(getStandardDisplay().getActiveShell(), e, null, null); 409 } catch (InterruptedException e2) { 410 } 412 } 413 414 public org.osgi.service.prefs.Preferences getInstancePreferences() { 415 return new InstanceScope().getNode(getBundle().getSymbolicName()); 416 } 417 418 public synchronized TeamStateProvider getDecoratedStateProvider(RepositoryProviderType rpt) { 419 TeamStateProvider provider = (TeamStateProvider)decoratedStateProviders.get(rpt.getID()); 420 if (provider != null) 421 return provider; 422 Subscriber subscriber = rpt.getSubscriber(); 423 if (subscriber != null) { 424 provider = new SubscriberTeamStateProvider(subscriber); 425 decoratedStateProviders.put(rpt.getID(), provider); 426 return provider; 427 } 428 return null; 429 } 430 431 437 public synchronized ITeamStateProvider getDecoratedStateProvider() { 438 if (provider == null) 439 provider = new WorkspaceTeamStateProvider(); 440 return provider; 441 } 442 443 public ISynchronizeManager getSynchronizeManager() { 444 if (synchronizeManager == null) { 445 synchronizeManager = new SynchronizeManager(); 446 } 447 return synchronizeManager; 448 } 449 } 450 | Popular Tags |