Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 540cfc05b88e8f9c05470040e84f82db4407967e (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*******************************************************************************
 * Copyright (c) 2000, 2010 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.actions;
 
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.operations.ReplaceOperation;

/**
 * Action for replace with tag.
 */
public abstract class ReplaceWithTagAction extends WorkspaceTraversalAction {
    
	/*
	 * Method declared on IActionDelegate.
	 */
	@Override
	public void execute(IAction action) throws InterruptedException, InvocationTargetException {
		final ReplaceOperation replaceOperation= createReplaceOperation();
		if (hasOutgoingChanges(replaceOperation)) {
			final boolean[] keepGoing = new boolean[] { true };
			Display.getDefault().syncExec(() -> {
				OutgoingChangesDialog dialog = new OutgoingChangesDialog(getShell(), replaceOperation.getScopeManager(),
						CVSUIMessages.ReplaceWithTagAction_2, CVSUIMessages.ReplaceWithTagAction_0,
						CVSUIMessages.ReplaceWithTagAction_1);
				dialog.setHelpContextId(IHelpContextIds.REPLACE_OUTGOING_CHANGES_DIALOG);
				int result = dialog.open();
				keepGoing[0] = result == Window.OK;
			});
			if (!keepGoing[0])
				return;
		}

		// Setup the tag holder
		final CVSTag[] tag= new CVSTag[] { null };

		// Show a busy cursor while display the tag selection dialog
		run((IRunnableWithProgress) monitor -> {
			monitor = Policy.monitorFor(monitor);
			tag[0] = getTag(replaceOperation);

			// finish, when tag can't be obtained
			if (tag[0] == null)
				return;

			// For non-projects determine if the tag being loaded is the same as the
			// resource's parent
			// If it's not, warn the user that they will have strange sync behavior
			try {
				if (!CVSAction.checkForMixingTags(getShell(), replaceOperation.getScope().getRoots(), tag[0])) {
					tag[0] = null;
					return;
				}
			} catch (CoreException e) {
				throw new InvocationTargetException(e);
			}
		}, false /* cancelable */, PROGRESS_BUSYCURSOR);			 
		
		if (tag[0] == null) return;
		
		// Perform the replace in the background
		replaceOperation.setTag(tag[0]);
		replaceOperation.run();
	}

	/**
	 * Creates and returns a new <code>ReplaceOperation</code>.
	 * 
	 * @return the created replace operation
	 */
	protected ReplaceOperation createReplaceOperation() {
		return new ReplaceOperation(getTargetPart(), getCVSResourceMappings(), null);
	}

	/**
	 * @see org.eclipse.team.internal.ccvs.ui.actions.CVSAction#getErrorTitle()
	 */
	@Override
	protected String getErrorTitle() {
		return CVSUIMessages.ReplaceWithTagAction_replace; 
	}

	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.actions.WorkspaceAction#isEnabledForNonExistantResources()
	 */
	@Override
	protected boolean isEnabledForNonExistantResources() {
		return true;
	}
	
	/**
	 * This function should obtain a tag which user wants to load.
	 * @param replaceOperation 
	 *    replaceOperation is an operation for which the tag is obtained
	 * @return tag
	 * 		marks the resources revision the user wants to load
	 */
	abstract protected CVSTag getTag(final ReplaceOperation replaceOperation);
	
}

Back to the top