Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetMenu.java22
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommandConfirmation.java53
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java5
3 files changed, 56 insertions, 24 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetMenu.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetMenu.java
index 27ce7593f..10b033d40 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetMenu.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ResetMenu.java
@@ -11,20 +11,16 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
-import java.text.MessageFormat;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.egit.core.internal.job.JobUtil;
import org.eclipse.egit.core.op.ResetOperation;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
-import org.eclipse.egit.ui.internal.branch.LaunchFinder;
+import org.eclipse.egit.ui.internal.dialogs.CommandConfirmation;
import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
@@ -93,21 +89,7 @@ public class ResetMenu {
final String jobName;
switch (resetType) {
case HARD:
- String question = UIText.ResetTargetSelectionDialog_ResetConfirmQuestion;
- ILaunchConfiguration launch = LaunchFinder
- .getRunningLaunchConfiguration(Collections.singleton(repo),
- null);
- if (launch != null) {
- question = MessageFormat.format(question,
- "\n\n" + MessageFormat.format( //$NON-NLS-1$
- UIText.LaunchFinder_RunningLaunchMessage,
- launch.getName()));
- } else {
- question = MessageFormat.format(question, ""); //$NON-NLS-1$
- }
- if (!MessageDialog.openQuestion(shell,
- UIText.ResetTargetSelectionDialog_ResetQuestion,
- question)) {
+ if (!CommandConfirmation.confirmHardReset(shell, repo)) {
return;
}
jobName = UIText.HardResetToRevisionAction_hardReset;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommandConfirmation.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommandConfirmation.java
new file mode 100644
index 000000000..c01ca363c
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommandConfirmation.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2016, Matthias Sohn <matthias.sohn@sap.com> 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:
+ * Stefan Lay (SAP AG) - initial implementation
+ * Mathias Kinzler (SAP AG) - use the abstract super class
+ * Thomas Wolf <thomas.wolf@paranor.ch> - Bug 477248
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.dialogs;
+
+import java.text.MessageFormat;
+import java.util.Collections;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.egit.ui.internal.UIText;
+import org.eclipse.egit.ui.internal.branch.LaunchFinder;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Dialog to confirm a potentially destructive command
+ */
+public class CommandConfirmation {
+ /**
+ * Ask the user to confirm hard reset. Warns the user if a running launch
+ * could be affected by the reset.
+ *
+ * @param shell
+ * @param repo
+ * @return {@code true} if the user confirmed hard reset
+ */
+ public static boolean confirmHardReset(Shell shell, final Repository repo) {
+ String question = UIText.ResetTargetSelectionDialog_ResetConfirmQuestion;
+ ILaunchConfiguration launch = LaunchFinder
+ .getRunningLaunchConfiguration(Collections.singleton(repo),
+ null);
+ if (launch != null) {
+ question = MessageFormat.format(question,
+ "\n\n" + MessageFormat.format( //$NON-NLS-1$
+ UIText.LaunchFinder_RunningLaunchMessage,
+ launch.getName()));
+ } else {
+ question = MessageFormat.format(question, ""); //$NON-NLS-1$
+ }
+ return MessageDialog.openQuestion(shell,
+ UIText.ResetTargetSelectionDialog_ResetQuestion, question);
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java
index 782431c08..f316f55b2 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/ResetTargetSelectionDialog.java
@@ -19,7 +19,6 @@ import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -261,9 +260,7 @@ public class ResetTargetSelectionDialog extends AbstractBranchSelectionDialog {
@Override
protected void okPressed() {
if (resetType == ResetType.HARD) {
- if (!MessageDialog.openQuestion(getShell(),
- UIText.ResetTargetSelectionDialog_ResetQuestion,
- UIText.ResetTargetSelectionDialog_ResetConfirmQuestion)) {
+ if (!CommandConfirmation.confirmHardReset(getShell(), repo)) {
return;
}
}

Back to the top