KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > subscribers > DiffChangeSet


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc name) {
28         super(name);
29     }
30     
31     /**
32      * Return the diff tree that contains the resources that belong to this change set.
33      * @return the diff tree that contains the resources that belong to this change set
34      */

35     public IResourceDiffTree getDiffTree() {
36         return tree;
37     }
38     
39     protected ResourceDiffTree internalGetDiffTree() {
40         return tree;
41     }
42
43     /**
44      * Return the resources that are contained in this set.
45      * @return the resources that are contained in this set
46      */

47     public IResource[] getResources() {
48         return tree.getAffectedResources();
49     }
50     
51     /**
52      * Return whether the set contains any files.
53      * @return whether the set contains any files
54      */

55     public boolean isEmpty() {
56         return tree.isEmpty();
57     }
58
59     /**
60      * Return true if the given file is included in this set.
61      * @param local a local file
62      * @return true if the given file is included in this set
63      */

64     public boolean contains(IResource local) {
65         return tree.getDiff(local) != null;
66     }
67     
68     /**
69      * Add the resource to this set if it is modified
70      * w.r.t. the subscriber.
71      * @param diff the diff to be added
72      */

73     public void add(IDiff diff) {
74         if (isValidChange(diff)) {
75             tree.add(diff);
76         }
77     }
78     
79     /**
80      * Return whether the given sync info is a valid change
81      * and can be included in this set. This method is used
82      * by the <code>add</code> method to filter set additions.
83      * @param diff a diff
84      * @return whether the sync info is a valid member of this set
85      */

86     protected boolean isValidChange(IDiff diff) {
87         return (diff != null);
88     }
89
90     /**
91      * Add the resources to this set if they are modified
92      * w.r.t. the subscriber.
93      * @param diffs the resources to be added.
94      */

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     /**
108      * Remove the resource from the set.
109      * @param resource the resource to be removed
110      */

111     public void remove(IResource resource) {
112         if (contains(resource)) {
113             tree.remove(resource);
114         }
115     }
116     
117     /**
118      * Remove the resource and it's descendants to the given depth.
119      * @param resource the resource to be removed
120      * @param depth the depth of the removal (one of
121      * <code>IResource.DEPTH_ZERO, IResource.DEPTH_ONE, IResource.DEPTH_INFINITE)</code>
122      */

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 JavaDoc getComment() {
173         return null;
174     }
175
176 }
177
Popular Tags