1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.resources.mapping.ResourceMapping; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.team.core.mapping.provider.SynchronizationContext; 20 import org.eclipse.team.core.subscribers.SubscriberScopeManager; 21 import org.eclipse.team.internal.ccvs.core.*; 22 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 23 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants; 24 import org.eclipse.team.internal.ccvs.ui.mappings.*; 25 import org.eclipse.team.internal.ccvs.ui.subscriber.CompareParticipant; 26 import org.eclipse.team.internal.ccvs.ui.tags.TagSelectionDialog; 27 import org.eclipse.team.internal.ccvs.ui.tags.TagSource; 28 import org.eclipse.team.ui.TeamUI; 29 import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; 30 31 public class CompareWithTagAction extends WorkspaceTraversalAction { 32 33 private static boolean isOpenEditorForSingleFile() { 34 return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_OPEN_COMPARE_EDITOR_FOR_SINGLE_FILE); 35 } 36 37 public void execute(IAction action) throws InvocationTargetException , InterruptedException { 38 39 IResource[] resources = getSelectedResources(); 41 CVSTag tag = promptForTag(resources); 42 if (tag == null) 43 return; 44 45 if (isOpenEditorForSingleFile()) { 46 IFile file = getSelectedFile(); 47 if (file != null && SyncAction.isOKToShowSingleFile(file)) { 48 CVSCompareSubscriber compareSubscriber = new CVSCompareSubscriber(resources, tag); 49 SyncAction.showSingleFileComparison(getShell(), compareSubscriber, file, getTargetPage()); 50 compareSubscriber.dispose(); 51 return; 52 } 53 } 54 55 if (isShowModelSync()) { 57 final CVSCompareSubscriber compareSubscriber = new CVSCompareSubscriber(getProjects(resources), tag); 58 ResourceMapping[] mappings = getCVSResourceMappings(); 59 try { 60 compareSubscriber.primeRemoteTree(); 62 } catch(CVSException e) { 63 } 65 SubscriberScopeManager manager = new SubscriberScopeManager(compareSubscriber.getName(), mappings, compareSubscriber, true){ 66 public void dispose() { 67 compareSubscriber.dispose(); 68 super.dispose(); 69 } 70 }; 71 SynchronizationContext context = CompareSubscriberContext.createContext(manager, compareSubscriber); 72 ModelCompareParticipant participant = new ModelCompareParticipant(context); 73 TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant}); 74 participant.run(getTargetPart()); 75 } else { 76 CVSCompareSubscriber compareSubscriber = new CVSCompareSubscriber(getProjects(resources), tag); 77 ResourceMapping[] resourceMappings = getCVSResourceMappings(); 78 if (isLogicalModel(resourceMappings)) { 79 compareSubscriber = new CVSCompareSubscriber(getProjects(resources), tag); 80 resources = getResourcesToCompare(compareSubscriber); 81 compareSubscriber.dispose(); 82 } 83 compareSubscriber = new CVSCompareSubscriber(resources, tag); 85 try { 86 compareSubscriber.primeRemoteTree(); 87 } catch(CVSException e) { 88 } 90 CompareParticipant participant = CompareParticipant.getMatchingParticipant(resources, tag); 92 if (participant == null) { 93 CVSCompareSubscriber s = compareSubscriber; 94 participant = new CompareParticipant(s); 95 TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant}); 96 } 97 participant.refresh(resources, null, null, null); 98 } 99 } 100 101 private boolean isShowModelSync() { 102 return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_ENABLE_MODEL_SYNC); 103 } 104 105 protected CVSTag promptForTag(IResource[] resources) { 106 CVSTag tag = TagSelectionDialog.getTagToCompareWith(getShell(), TagSource.create(resources), TagSelectionDialog.INCLUDE_ALL_TAGS); 107 return tag; 108 } 109 110 113 protected boolean isEnabledForNonExistantResources() { 114 return true; 115 } 116 } 117 | Popular Tags |