KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > dialogs > PromptingDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.dialogs;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.jface.window.IShellProvider;
18 import org.eclipse.swt.widgets.Shell;
19
20 /**
21  * A confirmation dialog helper that will either show a 'yes/no/yes to all/cancel'
22  * dialog to confirm an action performed on several resources or if only one
23  * resource is specified 'ok/cancel' will be shown.
24  */

25 public class PromptingDialog extends MultipleYesNoPrompter {
26     private IPromptCondition condition;
27     private IResource[] resources;
28     /**
29      * Prompt for the given resources using the specific condition. The prompt dialog will
30      * have the title specified.
31      * @param shell
32      * @param resources
33      * @param condition
34      * @param title
35      */

36     public PromptingDialog(Shell shell, IResource[] resources, IPromptCondition condition, String JavaDoc title) {
37         this(shell, resources, condition, title, false /* all or nothing */);
38     }
39     
40     public PromptingDialog(final Shell shell, IResource[] resources, IPromptCondition condition, String JavaDoc title, boolean allOrNothing) {
41         super(new IShellProvider() {
42             public Shell getShell() {
43                 return shell;
44             }
45         }, title, resources.length > 1, allOrNothing);
46         this.resources = resources;
47         this.condition = condition;
48     }
49     /**
50      * Call to calculate and show prompt. If no resources satisfy the prompt
51      * condition a dialog won't be shown. The resources for which the user
52      * confirmed the action are returned.
53      * @return the resources
54      *
55      * @throws InterruptedException
56      * if the user choose to cancel on the prompt dialog
57      */

58     public IResource[] promptForMultiple() throws InterruptedException JavaDoc {
59         List JavaDoc targetResources = new ArrayList JavaDoc();
60         for (int i = 0; i < resources.length; i++) {
61             IResource resource = resources[i];
62             if (!condition.needsPrompt(resource) || shouldInclude(condition.promptMessage(resource))) {
63                 targetResources.add(resource);
64             }
65         }
66         return (IResource[]) targetResources.toArray(new IResource[targetResources.size()]);
67     }
68 }
69
Popular Tags