blob: 54eb63a0987c3f06c3ad0ce44b8791a4561ceca0 (
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
|
/*******************************************************************************
* Copyright (C) 2012, 2016 Mathias Kinzler <mathias.kinzler@sap.com>
* and other copyright owners as documented in the project's IP log.
*
* 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
**/
package org.eclipse.egit.ui.internal.actions;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.dialogs.CommitSelectDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jgit.revwalk.RevCommit;
/**
* Replace with previous revision action handler.
*/
public class ReplaceWithPreviousActionHandler extends
DiscardChangesActionHandler {
@Override
protected String gatherRevision(ExecutionEvent event)
throws ExecutionException {
IResource[] resources = getSelectedResources(event);
try {
List<RevCommit> pcs = findPreviousCommits(Arrays.asList(resources));
int parentCount = pcs.size();
if (parentCount == 0) {
final String resourceNames = CommonUtils
.getResourceNames(Arrays.asList(resources));
MessageDialog
.openError(
getShell(event),
UIText.ReplaceWithPreviousActionHandler_NoParentCommitDialogTitle,
MessageFormat
.format(UIText.ReplaceWithPreviousActionHandler_NoParentCommitDialogMessage,
resourceNames));
throw new OperationCanceledException();
} else if (parentCount > 1) {
CommitSelectDialog dlg = new CommitSelectDialog(
getShell(event), pcs);
if (dlg.open() == Window.OK)
return dlg.getSelectedCommit().getName();
else
throw new OperationCanceledException();
} else
return pcs.get(0).getName();
} catch (IOException e) {
throw new ExecutionException(e.getMessage(), e);
}
}
@Override
public boolean isEnabled() {
IStructuredSelection selection = getSelection();
return super.isEnabled() && selection.size() == 1
&& selectionMapsToSingleRepository();
}
}
|