1 11 package org.eclipse.core.internal.resources; 12 13 import org.eclipse.core.resources.*; 14 import org.eclipse.core.runtime.*; 15 16 public class SaveContext implements ISaveContext { 17 protected Plugin plugin; 18 protected int kind; 19 protected boolean needDelta; 20 protected boolean needSaveNumber; 21 protected SafeFileTable fileTable; 22 protected int previousSaveNumber; 23 protected IProject project; 24 25 protected SaveContext(Plugin plugin, int kind, IProject project) throws CoreException { 26 this.plugin = plugin; 27 this.kind = kind; 28 this.project = project; 29 needDelta = false; 30 needSaveNumber = false; 31 String pluginId = plugin.getBundle().getSymbolicName(); 32 fileTable = new SafeFileTable(pluginId); 33 previousSaveNumber = getWorkspace().getSaveManager().getSaveNumber(pluginId); 34 } 35 36 public void commit() throws CoreException { 37 if (needSaveNumber) { 38 String pluginId = plugin.getBundle().getSymbolicName(); 39 IPath oldLocation = getWorkspace().getMetaArea().getSafeTableLocationFor(pluginId); 40 getWorkspace().getSaveManager().setSaveNumber(pluginId, getSaveNumber()); 41 fileTable.setLocation(getWorkspace().getMetaArea().getSafeTableLocationFor(pluginId)); 42 fileTable.save(); 43 oldLocation.toFile().delete(); 44 } 45 } 46 47 50 public IPath[] getFiles() { 51 return getFileTable().getFiles(); 52 } 53 54 protected SafeFileTable getFileTable() { 55 return fileTable; 56 } 57 58 61 public int getKind() { 62 return kind; 63 } 64 65 68 public Plugin getPlugin() { 69 return plugin; 70 } 71 72 75 public int getPreviousSaveNumber() { 76 return previousSaveNumber; 77 } 78 79 82 public IProject getProject() { 83 return project; 84 } 85 86 89 public int getSaveNumber() { 90 int result = getPreviousSaveNumber() + 1; 91 return result > 0 ? result : 1; 92 } 93 94 protected Workspace getWorkspace() { 95 return (Workspace) ResourcesPlugin.getWorkspace(); 96 } 97 98 public boolean isDeltaNeeded() { 99 return needDelta; 100 } 101 102 105 public IPath lookup(IPath file) { 106 return getFileTable().lookup(file); 107 } 108 109 112 public void map(IPath file, IPath location) { 113 getFileTable().map(file, location); 114 } 115 116 119 public void needDelta() { 120 needDelta = true; 121 } 122 123 126 public void needSaveNumber() { 127 needSaveNumber = true; 128 } 129 } 130 | Popular Tags |