KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > pmd > EditRulesAction


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.pmd;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import org.openide.DialogDescriptor;
25 import org.openide.DialogDisplayer;
26 import org.openide.NotifyDescriptor;
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
32 import org.openide.explorer.propertysheet.*;
33 import org.netbeans.modules.tasklist.client.Suggestion;
34
35 import pmd.config.PMDOptionsSettings;
36 import pmd.config.ui.RuleEditor;
37
38 /**
39  * Edit the set of PMD rules used by the rule violation provider.
40  * <p>
41  *
42  * @author Tor Norbye
43  */

44
45 public class EditRulesAction extends NodeAction {
46
47     private static final long serialVersionUID = 1;
48
49     protected boolean asynchronous() {
50         return false;
51     }
52     
53     protected boolean enable(Node[] node) {
54         if ((node == null) || (node.length != 1)) {
55             return false;
56         }
57         Suggestion s = (Suggestion)node[0].getCookie(Suggestion.class);
58         if (s == null) {
59             return false;
60         }
61         return true;
62     }
63
64     protected void performAction(Node[] node) {
65         PMDOptionsSettings settings = PMDOptionsSettings.getDefault();
66         String JavaDoc rules = settings.getRules();
67         RuleEditor editor = new RuleEditor();
68         editor.setValue(rules);
69         Component JavaDoc customizer = editor.getCustomEditor();
70
71         DialogDescriptor d = new DialogDescriptor(customizer,
72                     NbBundle.getMessage(EditRulesAction.class,
73                     "TITLE_editRules")); // NOI18N
74
d.setModal(true);
75         d.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
76         d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
77         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(d);
78         dlg.pack();
79         dlg.show();
80         if (d.getValue() == NotifyDescriptor.OK_OPTION) {
81             Object JavaDoc value = editor.getValue();
82             settings.setRules(value.toString());
83             Suggestion s = (Suggestion)node[0].getCookie(Suggestion.class);
84             if (s != null) {
85                 Object JavaDoc seed = s.getSeed();
86                 if (seed instanceof ViolationProvider) {
87                     // TODO invalidate the suggestion instead
88
//((ViolationProvider)seed).rescan();
89
}
90             }
91         }
92     }
93     
94     public String JavaDoc getName() {
95         return NbBundle.getMessage(EditRulesAction.class,
96                                    "EditRules"); // NOI18N
97
}
98
99     /*
100     protected String iconResource() {
101         return "org/netbeans/modules/tasklist/pmd/editRules.gif"; // NOI18N
102     }
103     */

104     
105     public HelpCtx getHelpCtx() {
106         return HelpCtx.DEFAULT_HELP;
107         // If you will provide context help then use:
108
// return new HelpCtx (NewTodoItemAction.class);
109
}
110     
111 }
112
Popular Tags