KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > synchronize > RefreshSubscriberParticipantJob


1 /*******************************************************************************
2  * Copyright (c) 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  * Eugene Kuleshov (eu@md.pp.ru) - Bug 138152 Improve sync job status reporting
11  *******************************************************************************/

12 package org.eclipse.team.internal.ui.synchronize;
13
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.team.core.TeamException;
17 import org.eclipse.team.core.subscribers.Subscriber;
18 import org.eclipse.team.core.synchronize.SyncInfo;
19 import org.eclipse.team.core.synchronize.SyncInfoTree;
20 import org.eclipse.team.internal.core.subscribers.SubscriberSyncInfoCollector;
21 import org.eclipse.team.ui.synchronize.SubscriberParticipant;
22
23 public class RefreshSubscriberParticipantJob extends RefreshParticipantJob {
24
25     private final IResource[] resources;
26
27     public RefreshSubscriberParticipantJob(SubscriberParticipant participant, String JavaDoc jobName, String JavaDoc taskName, IResource[] resources, IRefreshSubscriberListener listener) {
28         super(participant, jobName, taskName, listener);
29         this.resources = resources;
30     }
31
32     /* (non-Javadoc)
33      * @see org.eclipse.team.internal.ui.synchronize.RefreshSubscriberJob#getSubscriber()
34      */

35     protected Subscriber getSubscriber() {
36         return ((SubscriberParticipant)getParticipant()).getSubscriber();
37     }
38     
39     private SubscriberSyncInfoCollector getCollector() {
40         return ((SubscriberParticipant)getParticipant()).getSubscriberSyncInfoCollector();
41     }
42     
43     protected int getChangeCount() {
44         int numChanges = 0;
45         SubscriberSyncInfoCollector collector = getCollector();
46         if (collector != null) {
47             SyncInfoTree set = collector.getSyncInfoSet();
48             for (int i = 0; i < resources.length; i++) {
49                 IResource resource = resources[i];
50                 SyncInfo[] infos = set.getSyncInfos(resource, IResource.DEPTH_INFINITE);
51                 if(infos != null && infos.length > 0) {
52                     numChanges += infos.length;
53                 }
54             }
55         }
56         return numChanges;
57     }
58     
59     protected int getIncomingChangeCount() {
60       return getChangesInMode(SyncInfo.INCOMING);
61     }
62     
63     protected int getOutgoingChangeCount() {
64       return getChangesInMode(SyncInfo.OUTGOING);
65     }
66     
67     private int getChangesInMode(int kind) {
68         int numChanges = 0;
69         SubscriberSyncInfoCollector collector = getCollector();
70         if (collector != null) {
71             SyncInfoTree set = collector.getSyncInfoSet();
72             for (int i = 0; i < resources.length; i++) {
73                 IResource resource = resources[i];
74                 SyncInfo[] infos = set.getSyncInfos(resource, IResource.DEPTH_INFINITE);
75                 if(infos != null && infos.length > 0) {
76                     for(int j = 0; j < infos.length; j++) {
77                         if((infos[ j].getKind() | kind)>0) {
78                           numChanges++;
79                         }
80                     }
81                 }
82             }
83         }
84         return numChanges;
85     }
86     
87     protected RefreshParticipantJob.IChangeDescription createChangeDescription() {
88         return new RefreshChangeListener(resources, getCollector());
89     }
90     
91     protected void handleProgressGroupSet(IProgressMonitor group, int ticks) {
92         getCollector().setProgressGroup(group, ticks);
93     }
94     
95     /**
96      * If a collector is available then run the refresh and the background event processing
97      * within the same progess group.
98      */

99     public boolean shouldRun() {
100         // Ensure that any progress shown as a result of this refresh occurs hidden in a progress group.
101
return getSubscriber() != null && getCollector().getSyncInfoSet() != null;
102     }
103     
104     public boolean belongsTo(Object JavaDoc family) {
105         if(family instanceof RefreshSubscriberParticipantJob) {
106             return ((RefreshSubscriberParticipantJob)family).getSubscriber() == getSubscriber();
107         }
108         return super.belongsTo(family);
109     }
110     
111     protected void doRefresh(IChangeDescription changeListener, IProgressMonitor monitor) throws TeamException {
112         Subscriber subscriber = getSubscriber();
113         if (subscriber != null) {
114             try {
115                 subscriber.addListener((RefreshChangeListener)changeListener);
116                 subscriber.refresh(resources, IResource.DEPTH_INFINITE, monitor);
117                 getCollector().waitForCollector(monitor);
118             } finally {
119                 subscriber.removeListener((RefreshChangeListener)changeListener);
120             }
121         }
122     }
123 }
124
Popular Tags