KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > actions > CompareWithTagAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 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  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.actions;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
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 JavaDoc, InterruptedException JavaDoc {
38         
39         // First, determine the tag to compare with
40
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         // Create a subscriber that can cover all projects involved
56
if (isShowModelSync()) {
57             final CVSCompareSubscriber compareSubscriber = new CVSCompareSubscriber(getProjects(resources), tag);
58             ResourceMapping[] mappings = getCVSResourceMappings();
59             try {
60                 // TODO: Only prime the area covered by the mappings
61
compareSubscriber.primeRemoteTree();
62             } catch(CVSException e) {
63                 // ignore, the compare will fail if there is a real problem.
64
}
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             // create a subscriber specifically for the resources for display to the user
84
compareSubscriber = new CVSCompareSubscriber(resources, tag);
85             try {
86                 compareSubscriber.primeRemoteTree();
87             } catch(CVSException e) {
88                 // ignore, the compare will fail if there is a real problem.
89
}
90             // First check if there is an existing matching participant, if so then re-use it
91
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     /* (non-Javadoc)
111      * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources()
112      */

113     protected boolean isEnabledForNonExistantResources() {
114         return true;
115     }
116 }
117
Popular Tags