KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > mapping > DiffChangeEvent


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.mapping;
12
13 import java.util.*;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.team.core.diff.*;
18
19 /**
20  * Implementation of {@link IDiffChangeEvent}
21  */

22 public class DiffChangeEvent implements IDiffChangeEvent {
23
24     private final IDiffTree tree;
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     /**
37      * Create a diff change event
38      * @param tree the originating tree
39      */

40     public DiffChangeEvent(IDiffTree tree) {
41         this.tree = tree;
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.team.core.delta.ISyncDeltaChangeEvent#getTree()
46      */

47     public IDiffTree getTree() {
48         return tree;
49     }
50
51     /* (non-Javadoc)
52      * @see org.eclipse.team.core.delta.ISyncDeltaChangeEvent#getAdditions()
53      */

54     public IDiff[] getAdditions() {
55         return (IDiff[]) addedResources.values().toArray(new IDiff[addedResources.size()]);
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.team.core.delta.ISyncDeltaChangeEvent#getRemovals()
60      */

61     public IPath[] getRemovals() {
62         return (IPath[]) removedResources.toArray(new IPath[removedResources.size()]);
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.team.core.delta.ISyncDeltaChangeEvent#getChanges()
67      */

68     public IDiff[] getChanges() {
69         return (IDiff[]) changedResources.values().toArray(new IDiff[changedResources.size()]);
70     }
71     
72     public void added(IDiff delta) {
73         if (removedResources.contains(delta.getPath())) {
74             // A removal followed by an addition is treated as a change
75
removedResources.remove(delta.getPath());
76             changed(delta);
77         } else {
78             addedResources.put(delta.getPath(), delta);
79         }
80     }
81     
82     public void removed(IPath path, IDiff delta) {
83         if (changedResources.containsKey(path)) {
84             // No use in reporting the change since it has subsequently been removed
85
changedResources.remove(path);
86         } else if (addedResources.containsKey(path)) {
87             // An addition followed by a removal can be dropped
88
addedResources.remove(path);
89             return;
90         }
91         removedResources.add(path);
92     }
93     
94     public void changed(IDiff delta) {
95         if (addedResources.containsKey(delta.getPath())) {
96             // An addition followed by a change is an addition
97
addedResources.put(delta.getPath(), delta);
98             return;
99         }
100         changedResources.put(delta.getPath(), delta);
101     }
102
103     public void reset() {
104         reset = true;
105     }
106     
107     public boolean isReset() {
108         return reset;
109     }
110     
111     public boolean isEmpty() {
112         return changedResources.isEmpty() && removedResources.isEmpty() && addedResources.isEmpty();
113     }
114
115     public void errorOccurred(IStatus status) {
116         errors .add(status);
117     }
118
119     public IStatus[] getErrors() {
120         return (IStatus[]) errors.toArray(new IStatus[errors.size()]);
121     }
122
123 }
124
Popular Tags