1 11 package org.eclipse.team.ui.synchronize; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.compare.structuremergeviewer.IDiffElement; 17 import org.eclipse.core.runtime.jobs.IJobChangeEvent; 18 import org.eclipse.jface.operation.IRunnableContext; 19 import org.eclipse.team.core.synchronize.SyncInfo; 20 import org.eclipse.team.core.synchronize.SyncInfoSet; 21 import org.eclipse.team.internal.ui.synchronize.SyncInfoModelElement; 22 import org.eclipse.team.ui.TeamOperation; 23 import org.eclipse.ui.IWorkbenchPart; 24 25 36 public abstract class SynchronizeModelOperation extends TeamOperation { 37 38 private IDiffElement[] elements; 39 40 43 private static IWorkbenchPart getPart(ISynchronizePageConfiguration configuration) { 44 if (configuration != null) { 45 ISynchronizePageSite site = configuration.getSite(); 46 if (site != null) { 47 return site.getPart(); 48 } 49 } 50 return null; 51 } 52 53 56 private static IRunnableContext getRunnableContext(ISynchronizePageConfiguration configuration) { 57 if (configuration != null) { 58 return configuration.getRunnableContext(); 59 } 60 return null; 61 } 62 63 70 protected SynchronizeModelOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { 71 super(getPart(configuration), getRunnableContext(configuration)); 72 this.elements = elements; 73 } 74 75 82 protected SyncInfoSet getSyncInfoSet() { 83 return makeSyncInfoSetFromSelection(getSyncInfos()); 84 } 85 86 89 public void scheduled(IJobChangeEvent event) { 90 super.scheduled(event); 91 markBusy(elements, true); 92 } 93 94 97 public void done(IJobChangeEvent event) { 98 markBusy(elements, false); 99 super.done(event); 100 } 101 102 private void markBusy(IDiffElement[] elements, boolean isBusy) { 103 for (int i = 0; i < elements.length; i++) { 104 IDiffElement element = elements[i]; 105 if (element instanceof ISynchronizeModelElement) { 106 ((ISynchronizeModelElement)element).setPropertyToRoot(ISynchronizeModelElement.BUSY_PROPERTY, isBusy); 107 } 108 } 109 } 110 111 116 private SyncInfo[] getSyncInfos() { 117 List filtered = new ArrayList (); 118 for (int i = 0; i < elements.length; i++) { 119 IDiffElement e = elements[i]; 120 if (e instanceof SyncInfoModelElement) { 121 filtered.add(((SyncInfoModelElement)e).getSyncInfo()); 122 } 123 } 124 return (SyncInfo[]) filtered.toArray(new SyncInfo[filtered.size()]); 125 } 126 127 130 private SyncInfoSet makeSyncInfoSetFromSelection(SyncInfo[] infos) { 131 return new SyncInfoSet(infos); 132 } 133 } 134 | Popular Tags |