1 11 package org.eclipse.team.ui.mapping; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.mapping.ResourceTraversal; 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.core.runtime.jobs.*; 18 import org.eclipse.team.core.diff.IDiff; 19 import org.eclipse.team.core.mapping.*; 20 import org.eclipse.team.internal.ui.*; 21 import org.eclipse.team.ui.TeamOperation; 22 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 23 import org.eclipse.team.ui.synchronize.ISynchronizePageSite; 24 import org.eclipse.ui.IWorkbenchPart; 25 26 38 public abstract class SynchronizationOperation extends TeamOperation { 39 40 private final ISynchronizePageConfiguration configuration; 41 private final Object [] elements; 42 43 46 private static IWorkbenchPart getPart(ISynchronizePageConfiguration configuration) { 47 if (configuration != null) { 48 ISynchronizePageSite site = configuration.getSite(); 49 if (site != null) { 50 return site.getPart(); 51 } 52 } 53 return null; 54 } 55 56 61 protected SynchronizationOperation(ISynchronizePageConfiguration configuration, Object [] elements) { 62 super(getPart(configuration), configuration.getRunnableContext()); 63 this.configuration = configuration; 64 this.elements = elements; 65 } 66 67 73 public ISynchronizePageConfiguration getConfiguration() { 74 return configuration; 75 } 76 77 81 protected ISynchronizationContext getContext() { 82 return (ISynchronizationContext)getConfiguration().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT); 83 } 84 85 89 public Object [] getElements() { 90 return elements; 91 } 92 93 97 public boolean shouldRun() { 98 return super.shouldRun(); 99 } 100 101 109 public SaveableComparison getSaveable() { 110 return null; 111 } 112 113 116 public final void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 117 try { 118 monitor.beginTask(null, 100); 119 setContextBusy(Policy.subMonitorFor(monitor, 5)); 120 execute(Policy.subMonitorFor(monitor, 90)); 121 } finally { 122 clearContextBusy(Policy.subMonitorFor(monitor, 5)); 123 monitor.done(); 124 } 125 } 126 127 private void clearContextBusy(final IProgressMonitor monitor) { 128 final IJobManager jobManager = Platform.getJobManager(); 131 final IJobChangeListener listener = new JobChangeAdapter() { 132 public void done(IJobChangeEvent event) { 133 Job[] jobs = jobManager.find(getContext()); 134 if (jobs.length == 0) { 135 final IResourceDiffTree diffTree = getContext().getDiffTree(); 136 diffTree.clearBusy(null); 137 jobManager.removeJobChangeListener(this); 138 } 139 } 140 }; 141 jobManager.addJobChangeListener(listener); 142 } 143 144 private void setContextBusy(final IProgressMonitor monitor) { 145 try { 146 ResourceTraversal[] traversals = Utils.getTraversals(getElements()); 148 final IResourceDiffTree diffTree = getContext().getDiffTree(); 149 IDiff[] diffs = diffTree.getDiffs(traversals); 150 diffTree.setBusy(diffs, monitor); 151 } catch (CoreException e) { 152 TeamUIPlugin.log(e); 153 } 154 } 155 156 164 protected abstract void execute(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException ; 165 166 } 167 | Popular Tags |