KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > suggestions > ui > DisableAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.suggestions.ui;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import org.netbeans.modules.tasklist.client.SuggestionManager;
25 import org.netbeans.modules.tasklist.core.TaskNode;
26 import org.netbeans.modules.tasklist.suggestions.*;
27 import org.openide.nodes.Node;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30 import org.openide.util.actions.NodeAction;
31 import org.openide.DialogDisplayer;
32 import org.openide.NotifyDescriptor;
33
34
35 /**
36  * Disables selected category.
37  *
38  * @author Tor Norbye
39  */

40
41 public final class DisableAction extends NodeAction {
42
43     private static final long serialVersionUID = 1;
44
45     protected boolean asynchronous() {
46         return false;
47     }
48
49     protected boolean enable(Node[] node) {
50         return true;
51     }
52     
53     protected void performAction(Node[] node) {
54         if (node == null) {
55             return;
56         }
57
58         // Remove suggestion when we've performed it
59
SuggestionManagerImpl manager =
60             (SuggestionManagerImpl)SuggestionManager.getDefault();
61
62         HashSet JavaDoc set = new HashSet JavaDoc(10);
63
64         // Compute the set of types we're disabling
65
for (int i = 0; i < node.length; i++) {
66             SuggestionImpl s = (SuggestionImpl)TaskNode.getTask(node[i]);
67             SuggestionType type = s.getSType();
68             String JavaDoc message = NbBundle.getMessage(DisableAction.class,
69                 "ConfirmDisable", type.getLocalizedName()); // NOI18N
70
String JavaDoc title = NbBundle.getMessage(DisableAction.class,
71                 "ConfirmDisableTitle"); // NOI18N
72
NotifyDescriptor desc = new NotifyDescriptor.Confirmation(
73                  message, title, NotifyDescriptor.YES_NO_OPTION);
74             if (!NotifyDescriptor.YES_OPTION.equals(
75                DialogDisplayer.getDefault().notify(desc))) {
76                 continue;
77             }
78             set.add(s.getSType());
79         }
80         // Disable each type
81
Iterator JavaDoc it = set.iterator();
82         while (it.hasNext()) {
83             SuggestionType type = (SuggestionType)it.next();
84             manager.setEnabled(type.getName(), false, false);
85         }
86     }
87     
88     public String JavaDoc getName() {
89         return NbBundle.getMessage(DisableAction.class, "LBL_Disable"); // NOI18N
90
}
91
92     protected String JavaDoc iconResource() {
93         return "org/netbeans/modules/tasklist/suggestions/disableAction.gif"; // NOI18N
94
}
95
96     public HelpCtx getHelpCtx() {
97         return HelpCtx.DEFAULT_HELP;
98         // If you will provide context help then use:
99
// return new HelpCtx(DisableAction.class);
100
}
101     
102 }
103
Popular Tags