KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.team.core.ITeamStatus;
16 import org.eclipse.team.core.synchronize.*;
17 import org.eclipse.team.internal.core.Policy;
18
19 /**
20  * Ths class uses the contents of one sync set as the input of another.
21  */

22 public class SyncSetInputFromSyncSet extends SyncSetInput implements ISyncInfoSetChangeListener {
23
24     SubscriberSyncInfoSet inputSyncSet;
25
26     public SyncSetInputFromSyncSet(SubscriberSyncInfoSet set, SubscriberEventHandler handler) {
27         super(handler);
28         this.inputSyncSet = set;
29         inputSyncSet.addSyncSetChangedListener(this);
30     }
31     
32     public void disconnect() {
33         if (inputSyncSet == null) return;
34         inputSyncSet.removeSyncSetChangedListener(this);
35         inputSyncSet = null;
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.team.ccvs.syncviews.views.AbstractSyncSet#initialize(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
40      */

41     protected void fetchInput(IProgressMonitor monitor) {
42         if (inputSyncSet == null) return;
43         SyncInfo[] infos = inputSyncSet.getSyncInfos();
44         for (int i = 0; i < infos.length; i++) {
45             collect(infos[i], monitor);
46         }
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.team.ccvs.syncviews.views.ISyncSetChangedListener#syncSetChanged(org.eclipse.team.ccvs.syncviews.views.SyncSetChangedEvent)
51      */

52     public void syncInfoChanged(ISyncInfoSetChangeEvent event, IProgressMonitor monitor) {
53         SyncInfoSet syncSet = getSyncSet();
54         try {
55             syncSet.beginInput();
56             monitor.beginTask(null, 105);
57             syncSetChanged(event.getChangedResources(), Policy.subMonitorFor(monitor, 50));
58             syncSetChanged(event.getAddedResources(), Policy.subMonitorFor(monitor, 50));
59             remove(event.getRemovedResources());
60         } finally {
61             syncSet.endInput(Policy.subMonitorFor(monitor, 5));
62         }
63     }
64
65     private void syncSetChanged(SyncInfo[] infos, IProgressMonitor monitor) {
66         for (int i = 0; i < infos.length; i++) {
67             collect(infos[i], monitor);
68         }
69     }
70     
71     private void remove(IResource[] resources) {
72         for (int i = 0; i < resources.length; i++) {
73             remove(resources[i]);
74         }
75     }
76     
77     public void reset() {
78         inputSyncSet.connect(this);
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.team.core.subscribers.ISyncInfoSetChangeListener#syncInfoSetReset(org.eclipse.team.core.subscribers.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor)
83      */

84     public void syncInfoSetReset(SyncInfoSet set, IProgressMonitor monitor) {
85         if(inputSyncSet == null) {
86             set.removeSyncSetChangedListener(this);
87         } else {
88             SyncInfoSet syncSet = getSyncSet();
89             try {
90                 syncSet.beginInput();
91                 monitor.beginTask(null, 100);
92                 syncSet.clear();
93                 fetchInput(Policy.subMonitorFor(monitor, 95));
94             } finally {
95                 syncSet.endInput(Policy.subMonitorFor(monitor, 5));
96                 monitor.done();
97             }
98         }
99     }
100
101     /* (non-Javadoc)
102      * @see org.eclipse.team.core.subscribers.ISyncInfoSetChangeListener#syncInfoSetError(org.eclipse.team.core.subscribers.SyncInfoSet, org.eclipse.team.core.ITeamStatus[], org.eclipse.core.runtime.IProgressMonitor)
103      */

104     public void syncInfoSetErrors(SyncInfoSet set, ITeamStatus[] errors, IProgressMonitor monitor) {
105         SubscriberSyncInfoSet syncSet = getSyncSet();
106         try {
107             syncSet.beginInput();
108             for (int i = 0; i < errors.length; i++) {
109                 ITeamStatus status = errors[i];
110                 syncSet.addError(status);
111             }
112         } finally {
113             syncSet.endInput(monitor);
114         }
115     }
116 }
117
Popular Tags