Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 44d4ee26bff2e66cd72b2814e50a73b591506c48 (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
/*******************************************************************************
 * Copyright (c) 2010, 2013 SAP AG 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:
 *    Mathias Kinzler (SAP AG) - initial implementation
 *******************************************************************************/
package org.eclipse.egit.ui.internal.repository.tree.command;

import java.util.List;
import java.util.Map;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.branch.BranchOperationUI;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

/**
 * Implements "Checkout"
 */
public class CheckoutCommand extends
		RepositoriesViewCommandHandler<RepositoryTreeNode> implements
		IElementUpdater {
	@Override
	public Object execute(final ExecutionEvent event) throws ExecutionException {
		final RepositoryTreeNode node = getSelectedNodes(event).get(0);
		if (!(node.getObject() instanceof Ref))
			return null;

		final Ref ref = (Ref) node.getObject();
		Repository repo = node.getRepository();

		BranchOperationUI op = BranchOperationUI.checkout(repo, ref.getName());
		op.start();

		return null;
	}

	@Override
	public void updateElement(UIElement element, Map parameters) {
		List<RepositoryTreeNode> nodes = getSelectedNodes();
		if (!nodes.isEmpty()) {
			RepositoryTreeNode node = nodes.get(0);
			if (node.getObject() instanceof Ref) {
				Ref ref = (Ref) node.getObject();
				if (BranchOperationUI.checkoutWillShowQuestionDialog(ref
						.getName())) {
					element.setText(UIText.CheckoutCommand_CheckoutLabelWithQuestion);
					return;
				}
			}
		}
		element.setText(UIText.CheckoutCommand_CheckoutLabel);
	}
}

Back to the top