KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 java.util.Date JavaDoc;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.team.core.synchronize.SyncInfo;
17 import org.eclipse.team.core.synchronize.SyncInfoTree;
18
19 /**
20  * A checked-in change set represents a group of resource
21  * changes that were previously checked into a repository
22  * as a single logical change.
23  * <p>
24  * A previously checked-in set of changes may not apply directly
25  * to the local versions of the resources involved. However,
26  * a <code>SyncInfo</code> is still used to represent each change.
27  * The base and remote slots of the <code>SyncInfo</code> identify
28  * the state before and after the resources were checked-in.
29  * @since 3.1
30  */

31 public abstract class CheckedInChangeSet extends ChangeSet {
32     
33     private final SyncInfoTree set = new SyncInfoTree();
34     
35     public abstract String JavaDoc getAuthor();
36     
37     public abstract Date JavaDoc getDate();
38     
39     /**
40      * Return the SyncInfoSet that contains the resources that belong to this change set.
41      * @return the SyncInfoSet that contains the resources that belong to this change set
42      */

43     public SyncInfoTree getSyncInfoSet() {
44         return set;
45     }
46
47     /**
48      * Return the resources that are contained in this set.
49      * @return the resources that are contained in this set
50      */

51     public IResource[] getResources() {
52         return set.getResources();
53     }
54     
55     /**
56      * Return whether the set contains any files.
57      * @return whether the set contains any files
58      */

59     public boolean isEmpty() {
60         return set.isEmpty();
61     }
62
63     /**
64      * Return true if the given file is included in this set.
65      * @param local a local file
66      * @return true if the given file is included in this set
67      */

68     public boolean contains(IResource local) {
69         return set.getSyncInfo(local) != null;
70     }
71     
72     /**
73      * Add the resource to this set if it is modified
74      * w.r.t. the subscriber.
75      * @param info
76      */

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

90     protected boolean isValidChange(SyncInfo info) {
91         return (info != null);
92     }
93
94     /**
95      * Add the resources to this set if they are modified
96      * w.r.t. the subscriber.
97      * @param infos the resources to be added.
98      */

99     public void add(SyncInfo[] infos) {
100        try {
101            set.beginInput();
102            for (int i = 0; i < infos.length; i++) {
103               SyncInfo info = infos[i];
104               add(info);
105            }
106        } finally {
107            set.endInput(null);
108        }
109     }
110     
111     /**
112      * Remove the resource from the set.
113      * @param resource the resource to be removed
114      */

115     public void remove(IResource resource) {
116         if (contains(resource)) {
117             set.remove(resource);
118         }
119     }
120     
121     /**
122      * Remove the resources from the set.
123      * @param resources the resources to be removed
124      */

125     public void remove(IResource[] resources) {
126         for (int i = 0; i < resources.length; i++) {
127             IResource resource = resources[i];
128             remove(resource);
129         }
130     }
131     
132     /**
133      * Remove the resource and it's descendants to the given depth.
134      * @param resource the resource to be removed
135      * @param depth the depth of the removal (one of
136      * <code>IResource.DEPTH_ZERO, IResource.DEPTH_ONE, IResource.DEPTH_INFINITE)</code>
137      */

138     public void rootRemoved(IResource resource, int depth) {
139         SyncInfo[] infos = set.getSyncInfos(resource, depth);
140         if (infos.length > 0) {
141             IResource[] resources = new IResource[infos.length];
142             for (int i = 0; i < resources.length; i++) {
143                 resources[i] = infos[i].getLocal();
144             }
145             set.removeAll(resources);
146         }
147     }
148     
149     public boolean containsChildren(IResource resource, int depth) {
150         return set.getSyncInfos(resource, depth).length > 0;
151     }
152 }
153
Popular Tags