diff --git a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java index 73dfa6ba35d..e6e50eb8a6e 100644 --- a/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java +++ b/resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/localstore/FileSystemResourceManager.java @@ -72,16 +72,16 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; import org.eclipse.core.runtime.SubMonitor; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.osgi.util.NLS; import org.xml.sax.InputSource; /** * Manages the synchronization between the workspace's view and the file system. */ -public class FileSystemResourceManager implements ICoreConstants, IManager, Preferences.IPropertyChangeListener { +public class FileSystemResourceManager implements ICoreConstants, IManager { /** * The history store is initialized lazily - always use the accessor method @@ -91,6 +91,13 @@ public class FileSystemResourceManager implements ICoreConstants, IManager, Pref private volatile boolean lightweightAutoRefreshEnabled; + private IPreferenceChangeListener lightweightAutoRefreshPrefListener = event -> { + if (ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH.equals(event.getKey())) { + lightweightAutoRefreshEnabled = Platform.getPreferencesService().getBoolean(ResourcesPlugin.PI_RESOURCES, + ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, false, null); + } + }; + public FileSystemResourceManager(Workspace workspace) { this.workspace = workspace; } @@ -864,13 +871,6 @@ public void move(IResource source, IFileStore destination, int flags, IProgressM getStore(source).move(destination, EFS.NONE, monitor); } - @Deprecated - @Override - public void propertyChange(PropertyChangeEvent event) { - if (ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH.equals(event.getProperty())) - lightweightAutoRefreshEnabled = Boolean.parseBoolean(event.getNewValue().toString()); - } - public InputStream read(IFile target, boolean force, IProgressMonitor monitor) throws CoreException { IFileStore store = getStore(target); if (lightweightAutoRefreshEnabled || !force) { @@ -1124,14 +1124,16 @@ public void setResourceAttributes(IResource resource, ResourceAttributes attribu public void shutdown(IProgressMonitor monitor) throws CoreException { if (_historyStore != null) _historyStore.shutdown(monitor); - ResourcesPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this); + InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES) + .removePreferenceChangeListener(lightweightAutoRefreshPrefListener); } @Override public void startup(IProgressMonitor monitor) { - Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences(); - preferences.addPropertyChangeListener(this); - lightweightAutoRefreshEnabled = preferences.getBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH); + InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES) + .addPreferenceChangeListener(lightweightAutoRefreshPrefListener); + lightweightAutoRefreshEnabled = Platform.getPreferencesService().getBoolean(ResourcesPlugin.PI_RESOURCES, + ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, false, null); } /** diff --git a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java index 9e254b48bdf..596c2569534 100644 --- a/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java +++ b/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/internal/localstore/FileSystemResourceManagerTest.java @@ -39,6 +39,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.tests.internal.filesystem.bug440110.Bug440110FileSystem; import org.junit.Test; @@ -400,6 +401,17 @@ public void testBug547691() throws CoreException { assertEquals("Expected location of project to not change after delete", location, locationAfterDelete); } + @Test + public void testLightweightAutoRefreshPrefChange() { + FileSystemResourceManager manager = ((Workspace) getWorkspace()).getFileSystemManager(); + InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES) + .putBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, false); + assertFalse(manager.isLightweightAutoRefreshEnabled()); + InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES) + .putBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, true); + assertTrue(manager.isLightweightAutoRefreshEnabled()); + } + protected void write(final IFile file, final InputStream contents, final boolean force, IProgressMonitor monitor) throws CoreException { try {