KickJava   Java API By Example, From Geeks To Geeks.

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


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 starts in-place editing of selected component in FormDesigner.
30  */

31 public class InPlaceEditAction 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) {
50                 FormDesigner designer = FormEditor.getFormDesigner(metacomp.getFormModel());
51                 if (designer != null)
52                     designer.startInPlaceEditing(metacomp);
53             }
54         }
55     }
56
57     protected boolean asynchronous() {
58         return false;
59     }
60
61     /**
62     * Test whether the action should be enabled based
63     * on the currently activated nodes.
64     *
65     * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
66     * @return <code>true</code> to be enabled, <code>false</code> to be disabled
67     */

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

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

99     public HelpCtx getHelpCtx() {
100         return new HelpCtx("gui.quickref"); // NOI18N
101
}
102 }
103
Popular Tags