1 11 package org.eclipse.core.internal.resources; 12 13 import org.eclipse.core.internal.events.ResourceDelta; 14 import org.eclipse.core.internal.events.ResourceDeltaFactory; 15 import org.eclipse.core.internal.utils.Policy; 16 import org.eclipse.core.internal.watson.ElementTree; 17 import org.eclipse.core.resources.*; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.core.runtime.jobs.ISchedulingRule; 20 21 24 public class SavedState implements ISavedState { 25 ElementTree oldTree; 26 ElementTree newTree; 27 SafeFileTable fileTable; 28 String pluginId; 29 Workspace workspace; 30 31 SavedState(Workspace workspace, String pluginId, ElementTree oldTree, ElementTree newTree) throws CoreException { 32 this.workspace = workspace; 33 this.pluginId = pluginId; 34 this.newTree = newTree; 35 this.oldTree = oldTree; 36 this.fileTable = restoreFileTable(); 37 } 38 39 void forgetTrees() { 40 newTree = null; 41 oldTree = null; 42 workspace.saveManager.clearDeltaExpiration(pluginId); 43 } 44 45 public int getSaveNumber() { 46 return workspace.getSaveManager().getSaveNumber(pluginId); 47 } 48 49 protected SafeFileTable getFileTable() { 50 return fileTable; 51 } 52 53 protected SafeFileTable restoreFileTable() throws CoreException { 54 if (fileTable == null) 55 fileTable = new SafeFileTable(pluginId); 56 return fileTable; 57 } 58 59 public IPath lookup(IPath file) { 60 return getFileTable().lookup(file); 61 } 62 63 public IPath[] getFiles() { 64 return getFileTable().getFiles(); 65 } 66 67 public void processResourceChangeEvents(IResourceChangeListener listener) { 68 try { 69 final ISchedulingRule rule = workspace.getRoot(); 70 try { 71 workspace.prepareOperation(rule, null); 72 if (oldTree == null || newTree == null) 73 return; 74 workspace.beginOperation(true); 75 ResourceDelta delta = ResourceDeltaFactory.computeDelta(workspace, oldTree, newTree, Path.ROOT, -1); 76 forgetTrees(); workspace.getNotificationManager().broadcastChanges(listener, IResourceChangeEvent.POST_BUILD, delta); 78 } finally { 79 workspace.endOperation(rule, false, null); 80 } 81 } catch (CoreException e) { 82 Policy.log(e); 84 } 85 } 86 } 87 | Popular Tags |