KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.resources.mapping.ResourceMapping;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.team.core.diff.*;
20 import org.eclipse.team.core.mapping.IResourceDiffTree;
21 import org.eclipse.team.core.mapping.ISynchronizationContext;
22 import org.eclipse.team.internal.core.mapping.GroupProgressMonitor;
23 import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
24 import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
25
26 public class RefreshModelParticipantJob extends RefreshParticipantJob {
27
28     private final ResourceMapping[] mappings;
29     private IProgressMonitor group;
30     private int groupTicks;
31
32     public class ChangeDescription implements IChangeDescription, IDiffChangeListener {
33         Map JavaDoc changes = new HashMap JavaDoc();
34         
35         public int getChangeCount() {
36             return changes.size();
37         }
38
39         public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) {
40             IDiff[] additions = event.getAdditions();
41             for (int i = 0; i < additions.length; i++) {
42                 IDiff node = additions[i];
43                 changes.put(node.getPath(), node);
44             }
45             IDiff[] changed = event.getChanges();
46             for (int i = 0; i < changed.length; i++) {
47                 IDiff node = changed[i];
48                 changes.put(node.getPath(), node);
49             }
50         }
51         
52         public void propertyChanged(IDiffTree tree, int property, IPath[] paths) {
53             // Do nothing
54
}
55     }
56     
57     public RefreshModelParticipantJob(ISynchronizeParticipant participant, String JavaDoc jobName, String JavaDoc taskName, ResourceMapping[] mappings, IRefreshSubscriberListener listener) {
58         super(participant, jobName, taskName, listener);
59         this.mappings = mappings;
60     }
61
62     protected void doRefresh(IChangeDescription changeListener,
63             IProgressMonitor monitor) throws CoreException {
64         ISynchronizationContext context = ((ModelSynchronizeParticipant)getParticipant()).getContext();
65         try {
66             context.getDiffTree().addDiffChangeListener((ChangeDescription)changeListener);
67             // TODO: finer grained refresh
68
context.refresh(mappings, monitor);
69             // Wait for any asynchronous updating to complete
70
try {
71                 Platform.getJobManager().join(context, monitor);
72             } catch (InterruptedException JavaDoc e) {
73                 // Ignore
74
}
75         } finally {
76             context.getDiffTree().removeDiffChangeListener((ChangeDescription)changeListener);
77         }
78     }
79
80     protected int getChangeCount() {
81         return ((ModelSynchronizeParticipant)getParticipant()).getContext().getDiffTree().size();
82     }
83
84     protected int getIncomingChangeCount() {
85       IResourceDiffTree diffTree = ((ModelSynchronizeParticipant)getParticipant()).getContext().getDiffTree();
86       return (int) diffTree.countFor(IThreeWayDiff.INCOMING, IThreeWayDiff.DIRECTION_MASK);
87     }
88     
89     protected int getOutgoingChangeCount() {
90       IResourceDiffTree diffTree = ((ModelSynchronizeParticipant)getParticipant()).getContext().getDiffTree();
91       return (int) diffTree.countFor(IThreeWayDiff.OUTGOING, IThreeWayDiff.DIRECTION_MASK);
92     }
93     
94     protected void handleProgressGroupSet(IProgressMonitor group, int ticks) {
95         this.group = group;
96         this.groupTicks = ticks;
97     }
98
99     protected IChangeDescription createChangeDescription() {
100         return new ChangeDescription();
101     }
102     
103     public boolean belongsTo(Object JavaDoc family) {
104         if (family instanceof RefreshModelParticipantJob) {
105             RefreshModelParticipantJob rmpj = (RefreshModelParticipantJob) family;
106             return rmpj.getParticipant() == getParticipant();
107         }
108         if (family == getParticipant())
109             return true;
110         return super.belongsTo(family);
111     }
112     
113     public IStatus run(IProgressMonitor monitor) {
114         if (group != null)
115             monitor = wrapMonitorWithGroup(monitor);
116         return super.run(monitor);
117     }
118
119     private IProgressMonitor wrapMonitorWithGroup(IProgressMonitor monitor) {
120         return new GroupProgressMonitor(monitor, group, groupTicks);
121     }
122
123 }
124
Popular Tags