Remove System.out.println from RevWalkFilterTest
[jgit.git] / org.spearce.egit.ui / src / org / spearce / egit / ui / internal / actions / BranchAction.java
blob38ee3d81950ae2d6c7e1c44996524bcb99bbda62
1 /*******************************************************************************
2 * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
3 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
4 * Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org>
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * See LICENSE for the full license text, also available.
9 *******************************************************************************/
10 package org.spearce.egit.ui.internal.actions;
12 import java.lang.reflect.InvocationTargetException;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.swt.widgets.Display;
21 import org.spearce.egit.core.op.BranchOperation;
22 import org.spearce.egit.ui.internal.decorators.GitLightweightDecorator;
23 import org.spearce.egit.ui.internal.dialogs.BranchSelectionDialog;
24 import org.spearce.jgit.lib.Repository;
26 /**
27 * Action for selecting a branch and checking it out.
29 * @see BranchOperation
31 public class BranchAction extends RepositoryAction {
32 @Override
33 public void run(IAction action) {
34 final Repository repository = getRepository(true);
35 if (repository == null)
36 return;
38 if (!repository.getRepositoryState().canCheckout()) {
39 MessageDialog.openError(getShell(), "Cannot checkout now",
40 "Repository state:"
41 + repository.getRepositoryState().getDescription());
42 return;
45 BranchSelectionDialog dialog = new BranchSelectionDialog(getShell(), repository);
46 dialog.setShowResetType(false);
47 if (dialog.open() != IDialogConstants.OK_ID) {
48 return;
51 final String refName = dialog.getRefName();
52 try {
53 getTargetPart().getSite().getWorkbenchWindow().run(true, false,
54 new IRunnableWithProgress() {
55 public void run(final IProgressMonitor monitor)
56 throws InvocationTargetException {
57 try {
58 new BranchOperation(repository, refName).run(monitor);
59 GitLightweightDecorator.refresh();
60 } catch (final CoreException ce) {
61 ce.printStackTrace();
62 Display.getDefault().asyncExec(new Runnable() {
63 public void run() {
64 handle(ce, "Error while switching branches", "Unable to switch branches");
66 });
69 });
70 } catch (InvocationTargetException e) {
71 e.printStackTrace();
72 } catch (InterruptedException e) {
73 e.printStackTrace();
77 @Override
78 public boolean isEnabled() {
79 return getRepository(false) != null;