diff options
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/PromptingDialog.java')
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/PromptingDialog.java | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/PromptingDialog.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/PromptingDialog.java deleted file mode 100644 index 87d1630f6..000000000 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/PromptingDialog.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v0.5 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v05.html - * - * Contributors: - * IBM - Initial implementation - ******************************************************************************/ -package org.eclipse.team.internal.ui; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Shell; - -/** - * A confirmation dialog helper that will either show a 'yes/no/yes to all/cancel' - * dialog to confirm an action performed on several resources or if only one - * resource is specified 'ok/cancel' will be shown. - */ -public class PromptingDialog { - private IResource[] resources; - private Shell shell; - private String[] buttons; - private boolean confirmOverwrite = true; - private IPromptCondition condition; - private String title; - private boolean hasMultipleResources; - - /** - * Prompt for the given resources using the specific condition. The prompt dialog will - * have the title specified. - */ - public PromptingDialog(Shell shell, IResource[] resources, IPromptCondition condition, String title) { - this.condition = condition; - this.resources = resources; - this.title = title; - this.shell = shell; - this.hasMultipleResources = resources.length > 1; - if (hasMultipleResources) { - buttons = new String[] { - IDialogConstants.YES_LABEL, - IDialogConstants.YES_TO_ALL_LABEL, - IDialogConstants.NO_LABEL, - IDialogConstants.CANCEL_LABEL}; - } else { - buttons = new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}; - } - } - - /** - * Call to calculate and show prompt. If no resources satisfy the prompt condition - * a dialog won't be shown. The resources for which the user confirmed the action - * are returned. - */ - public IResource[] promptForMultiple() throws InterruptedException { - List targetResources = new ArrayList(); - for (int i = 0; i < resources.length; i++) { - IResource resource = resources[i]; - if (condition.needsPrompt(resource) && confirmOverwrite) { - if (confirmOverwrite(condition.promptMessage(resource))) { - targetResources.add(resource); - } - } else { - targetResources.add(resource); - } - } - return (IResource[]) targetResources.toArray(new IResource[targetResources.size()]); - } - - /** - * Opens the confirmation dialog based on the prompt condition settings. - */ - private boolean confirmOverwrite(String msg) throws InterruptedException { - if (!confirmOverwrite) { - return true; - } - final MessageDialog dialog = - new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0); - - // run in syncExec because callback is from an operation, - // which is probably not running in the UI thread. - shell.getDisplay().syncExec( - new Runnable() { - public void run() { - dialog.open(); - } - }); - if (hasMultipleResources) { - switch (dialog.getReturnCode()) { - case 0://Yes - return true; - case 1://Yes to all - confirmOverwrite = false; - return true; - case 2://No - return false; - case 3://Cancel - default: - throw new InterruptedException(); - } - } else { - return dialog.getReturnCode() == 0; - } - } -} |