KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > actions > EditFormAction


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.form.actions;
21
22 import org.openide.nodes.Node;
23 import org.openide.util.actions.*;
24 import org.openide.util.HelpCtx;
25
26 import org.netbeans.modules.form.*;
27
28
29 /** Action that sets form top container to be edited in FormDesigner.
30  */

31 public class EditFormAction extends NodeAction {
32
33     private static String JavaDoc name;
34
35     /**
36     * Perform the action based on the currently activated nodes.
37     * Note that if the source of the event triggering this action was itself
38     * a node, that node will be the sole argument to this method, rather
39     * than the activated nodes.
40     *
41     * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
42     */

43     protected void performAction(Node[] activatedNodes) {
44         if (activatedNodes != null && activatedNodes.length == 1) {
45             RADComponentCookie radCookie = (RADComponentCookie)activatedNodes[0]
46                                             .getCookie(RADComponentCookie.class);
47             RADComponent metacomp = radCookie == null ? null :
48                                       radCookie.getRADComponent();
49             if (metacomp != null) { //instanceof RADVisualContainer
50
FormDesigner designer = FormEditor.getFormDesigner(metacomp.getFormModel());
51                 if (designer != null) {
52                     designer.resetTopDesignComponent(true);
53                     designer.requestActive();
54                 }
55             }
56         }
57     }
58
59     protected boolean asynchronous() {
60         return false;
61     }
62
63     /**
64     * Test whether the action should be enabled based
65     * on the currently activated nodes.
66     *
67     * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
68     * @return <code>true</code> to be enabled, <code>false</code> to be disabled
69     */

70     protected boolean enable(Node[] activatedNodes) {
71         if (activatedNodes != null && activatedNodes.length == 1) {
72             RADComponentCookie radCookie = (RADComponentCookie)activatedNodes[0]
73                                             .getCookie(RADComponentCookie.class);
74             RADComponent metacomp = radCookie == null ? null :
75                                       radCookie.getRADComponent();
76             if (metacomp instanceof RADVisualContainer) {
77                 FormModel formModel = metacomp.getFormModel();
78                 FormDesigner designer = FormEditor.getFormDesigner(formModel);
79                 return designer != null
80                        && designer.getTopDesignComponent() != formModel.getTopRADComponent();
81             }
82         }
83         return false;
84     }
85
86     /**
87      * human presentable name of the action. This should be
88      * presented as an item in a menu.
89      * @return the name of the action
90      */

91     public String JavaDoc getName() {
92         if (name == null)
93             name = org.openide.util.NbBundle.getBundle(EditFormAction.class)
94                      .getString("ACT_EditForm"); // NOI18N
95
return name;
96     }
97
98     /**
99      * Help context where to find more about the action.
100      * @return the help context for this action
101      */

102     public HelpCtx getHelpCtx() {
103         return new HelpCtx("gui.containers.designing"); // NOI18N
104
}
105 }
106
Popular Tags