Git Repositories View: Simple fetch and push
[egit.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / actions / DiscardChangesAction.java
blobc2ca63efb635fab7d3127b7a5ddcd9dadbbbcfac
1 /*******************************************************************************
2 * Copyright (C) 2010, Roland Grunberg <rgrunber@redhat.com>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org.eclipse.egit.ui.internal.actions;
11 import org.eclipse.core.resources.IProject;
12 import org.eclipse.core.resources.IResource;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.core.runtime.jobs.Job;
18 import org.eclipse.egit.core.op.DiscardChangesOperation;
19 import org.eclipse.egit.ui.Activator;
20 import org.eclipse.egit.ui.UIText;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.dialogs.MessageDialog;
23 import org.eclipse.jgit.lib.Repository;
24 import org.eclipse.jgit.lib.RepositoryState;
26 /**
27 * Checkout all selected dirty files.
29 public class DiscardChangesAction extends RepositoryAction {
31 @Override
32 public void execute(IAction action) {
34 boolean performAction = MessageDialog.openConfirm(getShell(),
35 UIText.DiscardChangesAction_confirmActionTitle,
36 UIText.DiscardChangesAction_confirmActionMessage);
37 if (!performAction)
38 return;
39 final DiscardChangesOperation operation = new DiscardChangesOperation(
40 getSelectedResources());
41 String jobname = UIText.DiscardChangesAction_discardChanges;
42 Job job = new Job(jobname) {
43 @Override
44 protected IStatus run(IProgressMonitor monitor) {
45 try {
46 operation.execute(monitor);
47 } catch (CoreException e) {
48 return Activator.createErrorStatus(e.getStatus()
49 .getMessage(), e);
51 return Status.OK_STATUS;
54 job.setUser(true);
55 job.setRule(operation.getSchedulingRule());
56 job.schedule();
59 @Override
60 public boolean isEnabled() {
61 for (IResource res : getSelectedResources()) {
62 IProject[] proj = new IProject[] { res.getProject() };
63 Repository repository = getRepositoriesFor(proj)[0];
64 if (!repository.getRepositoryState().equals(RepositoryState.SAFE)) {
65 return false;
68 return true;