1 11 package org.eclipse.team.internal.core.subscribers; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.team.core.diff.IDiff; 16 import org.eclipse.team.core.mapping.IResourceDiffTree; 17 import org.eclipse.team.core.mapping.provider.ResourceDiffTree; 18 19 public class DiffChangeSet extends ChangeSet { 20 21 private final ResourceDiffTree tree = new ResourceDiffTree(); 22 23 public DiffChangeSet() { 24 super(); 25 } 26 27 public DiffChangeSet(String name) { 28 super(name); 29 } 30 31 35 public IResourceDiffTree getDiffTree() { 36 return tree; 37 } 38 39 protected ResourceDiffTree internalGetDiffTree() { 40 return tree; 41 } 42 43 47 public IResource[] getResources() { 48 return tree.getAffectedResources(); 49 } 50 51 55 public boolean isEmpty() { 56 return tree.isEmpty(); 57 } 58 59 64 public boolean contains(IResource local) { 65 return tree.getDiff(local) != null; 66 } 67 68 73 public void add(IDiff diff) { 74 if (isValidChange(diff)) { 75 tree.add(diff); 76 } 77 } 78 79 86 protected boolean isValidChange(IDiff diff) { 87 return (diff != null); 88 } 89 90 95 public void add(IDiff[] diffs) { 96 try { 97 tree.beginInput(); 98 for (int i = 0; i < diffs.length; i++) { 99 IDiff diff = diffs[i]; 100 add(diff); 101 } 102 } finally { 103 tree.endInput(null); 104 } 105 } 106 107 111 public void remove(IResource resource) { 112 if (contains(resource)) { 113 tree.remove(resource); 114 } 115 } 116 117 123 public void rootRemoved(IResource resource, int depth) { 124 IDiff[] diffs = tree.getDiffs(resource, depth); 125 if (diffs.length > 0) { 126 try { 127 tree.beginInput(); 128 for (int i = 0; i < diffs.length; i++) { 129 IDiff diff = diffs[i]; 130 IResource r = tree.getResource(diff); 131 if (r != null) 132 tree.remove(r); 133 } 134 } finally { 135 tree.endInput(null); 136 } 137 } 138 } 139 140 public boolean contains(IPath path) { 141 return getDiffTree().getDiff(path) != null; 142 } 143 144 public boolean containsChildren(IResource resource, int depth) { 145 return getDiffTree().getDiffs(resource, depth).length > 0; 146 } 147 148 public void remove(IPath[] paths) { 149 try { 150 tree.beginInput(); 151 for (int i = 0; i < paths.length; i++) { 152 IPath path = paths[i]; 153 tree.remove(path); 154 } 155 } finally { 156 tree.endInput(null); 157 } 158 } 159 160 public void remove(IResource[] resources) { 161 try { 162 tree.beginInput(); 163 for (int i = 0; i < resources.length; i++) { 164 IResource resource = resources[i]; 165 tree.remove(resource); 166 } 167 } finally { 168 tree.endInput(null); 169 } 170 } 171 172 public String getComment() { 173 return null; 174 } 175 176 } 177 | Popular Tags |