KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.team.core.ITeamStatus;
17 import org.eclipse.team.core.synchronize.*;
18
19 /**
20  * This event keeps track of the changes in a sync set
21  */

22 public class SyncSetChangedEvent implements ISyncInfoSetChangeEvent {
23     
24     private SyncInfoSet set;
25     
26     // List that accumulate changes
27
// SyncInfo
28
private Map changedResources = new HashMap();
29     private Set removedResources = new HashSet();
30     private Map addedResources = new HashMap();
31     
32     private boolean reset = false;
33
34     private List errors = new ArrayList();
35
36     public SyncSetChangedEvent(SyncInfoSet set) {
37         super();
38         this.set = set;
39     }
40
41     public void added(SyncInfo info) {
42         if (removedResources.contains(info.getLocal())) {
43             // A removal followed by an addition is treated as a change
44
removedResources.remove(info.getLocal());
45             changed(info);
46         } else {
47             addedResources.put(info.getLocal(), info);
48         }
49     }
50     
51     public void removed(IResource resource, SyncInfo info) {
52         if (changedResources.containsKey(resource)) {
53             // No use in reporting the change since it has subsequently been removed
54
changedResources.remove(resource);
55         } else if (addedResources.containsKey(resource)) {
56             // An addition followed by a removal can be dropped
57
addedResources.remove(resource);
58             return;
59         }
60         removedResources.add(resource);
61     }
62     
63     public void changed(SyncInfo info) {
64         IResource resource = info.getLocal();
65         if (addedResources.containsKey(resource)) {
66             // An addition followed by a change is an addition
67
addedResources.put(resource, info);
68             return;
69         }
70         changedResources.put(resource, info);
71     }
72     
73     public SyncInfo[] getAddedResources() {
74         return (SyncInfo[]) addedResources.values().toArray(new SyncInfo[addedResources.size()]);
75     }
76
77     public SyncInfo[] getChangedResources() {
78         return (SyncInfo[]) changedResources.values().toArray(new SyncInfo[changedResources.size()]);
79     }
80
81     public IResource[] getRemovedResources() {
82         return (IResource[]) removedResources.toArray(new IResource[removedResources.size()]);
83     }
84
85     public SyncInfoSet getSet() {
86         return set;
87     }
88
89     public void reset() {
90         reset = true;
91     }
92     
93     public boolean isReset() {
94         return reset;
95     }
96     
97     public boolean isEmpty() {
98         return changedResources.isEmpty() && removedResources.isEmpty() && addedResources.isEmpty() && errors.isEmpty();
99     }
100
101     public void errorOccurred(ITeamStatus status) {
102         errors.add(status);
103     }
104     
105     public ITeamStatus[] getErrors() {
106         return (ITeamStatus[]) errors.toArray(new ITeamStatus[errors.size()]);
107     }
108 }
109
Popular Tags