Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0bb9ae7088ce76f48e0651c259c922887445dee6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.actions;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.jface.action.IAction;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
import org.eclipse.team.internal.ccvs.ui.mappings.ModelCompareOperation;
import org.eclipse.team.internal.ccvs.ui.subscriber.CompareParticipant;
import org.eclipse.team.internal.ccvs.ui.tags.TagSelectionDialog;
import org.eclipse.team.internal.ccvs.ui.tags.TagSource;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;

public class CompareWithTagAction extends WorkspaceTraversalAction {

	public void execute(IAction action) throws InvocationTargetException, InterruptedException {
        
        // First, determine the tag to compare with
		IResource[] resources = getSelectedResources();
		CVSTag tag = promptForTag(resources);
		if (tag == null)
			return;
		
		IFile file = getSelectedFile();
		if (file != null) {
			CVSCompareSubscriber compareSubscriber = new CVSCompareSubscriber(resources, tag);
			SyncAction.showSingleFileComparison(getShell(), compareSubscriber, file, getTargetPage());
			compareSubscriber.dispose();
			return;
		}
		
        // Create a subscriber that can cover all projects invlived
        CVSCompareSubscriber compareSubscriber = new CVSCompareSubscriber(getProjects(resources), tag);
		if (isShowModelSync()) {
			try {
				ResourceMapping[] mappings = getCVSResourceMappings();
				try {
					// TODO: Only prime the area covered by the mappings
					compareSubscriber.primeRemoteTree();
				} catch(CVSException e) {
					// ignore, the compare will fail if there is a real problem.
				}
				new ModelCompareOperation(getTargetPart(), mappings, compareSubscriber).run();
			} catch (InterruptedException e) {
				// Ignore
			}
		} else {
	        ResourceMapping[] resourceMappings = getCVSResourceMappings();
			if (isLogicalModel(resourceMappings)) {
	            compareSubscriber = new CVSCompareSubscriber(getProjects(resources), tag);
	            resources = getResourcesToCompare(compareSubscriber);
	            compareSubscriber.dispose();
	        }
			// create a subscriber specifically for the resources for display to the user
			compareSubscriber = new CVSCompareSubscriber(resources, tag);
			try {
				compareSubscriber.primeRemoteTree();
			} catch(CVSException e) {
				// ignore, the compare will fail if there is a real problem.
			}
			//	First check if there is an existing matching participant, if so then re-use it
			CompareParticipant participant = CompareParticipant.getMatchingParticipant(resources, tag);
			if (participant == null) {
				CVSCompareSubscriber s = compareSubscriber;
				participant = new CompareParticipant(s);
				TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant});
			}
			participant.refresh(resources, null, null, null); 
		}
	}

    private boolean isShowModelSync() {
		return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_ENABLE_MODEL_SYNC);
	}
    
    protected CVSTag promptForTag(IResource[] resources) {
		CVSTag tag = TagSelectionDialog.getTagToCompareWith(getShell(), TagSource.create(resources), TagSelectionDialog.INCLUDE_ALL_TAGS);
		return tag;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources()
	 */
	protected boolean isEnabledForNonExistantResources() {
		return true;
    }
}

Back to the top