1 11 package org.eclipse.core.internal.refresh; 12 13 import org.eclipse.core.internal.resources.IManager; 14 import org.eclipse.core.internal.utils.Policy; 15 import org.eclipse.core.resources.*; 16 import org.eclipse.core.resources.refresh.IRefreshMonitor; 17 import org.eclipse.core.resources.refresh.IRefreshResult; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.Preferences; 20 import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; 21 22 29 public class RefreshManager implements IRefreshResult, IManager, Preferences.IPropertyChangeListener { 30 public static boolean DEBUG = Policy.DEBUG_AUTO_REFRESH; 31 public static final String DEBUG_PREFIX = "Auto-refresh: "; MonitorManager monitors; 33 private RefreshJob refreshJob; 34 35 38 private IWorkspace workspace; 39 40 public RefreshManager(IWorkspace workspace) { 41 this.workspace = workspace; 42 } 43 44 47 protected void manageAutoRefresh(boolean enabled) { 48 if (refreshJob == null) 50 return; 51 if (enabled) { 52 refreshJob.start(); 53 monitors.start(); 54 } else { 55 refreshJob.stop(); 56 monitors.stop(); 57 } 58 } 59 60 63 public void monitorFailed(IRefreshMonitor monitor, IResource resource) { 64 monitors.monitorFailed(monitor, resource); 65 } 66 67 71 public void propertyChange(PropertyChangeEvent event) { 72 String property = event.getProperty(); 73 if (ResourcesPlugin.PREF_AUTO_REFRESH.equals(property)) { 74 Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences(); 75 boolean autoRefresh = preferences.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH); 76 manageAutoRefresh(autoRefresh); 77 } 78 } 79 80 83 public void refresh(IResource resource) { 84 if (refreshJob != null) 86 refreshJob.refresh(resource); 87 } 88 89 93 public void shutdown(IProgressMonitor monitor) { 94 ResourcesPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this); 95 if (monitors != null) { 96 monitors.stop(); 97 monitors = null; 98 } 99 if (refreshJob != null) { 100 refreshJob.stop(); 101 refreshJob = null; 102 } 103 } 104 105 109 public void startup(IProgressMonitor monitor) { 110 Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences(); 111 preferences.addPropertyChangeListener(this); 112 113 refreshJob = new RefreshJob(); 114 monitors = new MonitorManager(workspace, this); 115 boolean autoRefresh = preferences.getBoolean(ResourcesPlugin.PREF_AUTO_REFRESH); 116 if (autoRefresh) 117 manageAutoRefresh(autoRefresh); 118 } 119 } 120 | Popular Tags |