KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.HelpCtx;
23 import org.openide.util.actions.*;
24 import org.openide.nodes.*;
25 import org.netbeans.modules.form.*;
26
27 /** CustomizeLayout action - enabled on RADContainerNodes and RADLayoutNodes.
28  *
29  * @author Ian Formanek
30  */

31
32 public class CustomizeLayoutAction extends CookieAction {
33
34     private static String JavaDoc name;
35
36     /** @return the mode of action. Possible values are disjunctions of MODE_XXX
37      * constants. */

38     protected int mode() {
39         return MODE_EXACTLY_ONE;
40     }
41
42     /** Creates new set of classes that are tested by the cookie.
43      *
44      * @return list of classes the that the cookie tests
45      */

46     protected Class JavaDoc[] cookieClasses() {
47         return new Class JavaDoc[] { RADComponentCookie.class };
48     }
49
50     protected boolean asynchronous() {
51         return false;
52     }
53
54     /** Human presentable name of the action. This should be
55      * presented as an item in a menu.
56      * @return the name of the action
57      */

58     public String JavaDoc getName() {
59         if (name == null)
60             name = org.openide.util.NbBundle.getBundle(CustomizeLayoutAction.class)
61                      .getString("ACT_CustomizeLayout"); // NOI18N
62
return name;
63     }
64
65     /** Help context where to find more about the action.
66      * @return the help context for this action
67      */

68     public HelpCtx getHelpCtx() {
69         return HelpCtx.DEFAULT_HELP;
70     }
71
72     /**
73      * Standard perform action extended by actually activated nodes.
74      *
75      * @param activatedNodes gives array of actually activated nodes.
76      */

77     protected void performAction(Node[] activatedNodes) {
78         RADComponentCookie radCookie = (RADComponentCookie)
79             activatedNodes[0].getCookie(RADComponentCookie.class);
80         if (radCookie != null) {
81             RADComponent metacomp = radCookie.getRADComponent();
82             if (metacomp instanceof RADVisualContainer) {
83                 Node layoutNode = ((RADVisualContainer)metacomp)
84                                       .getLayoutNodeReference();
85                 if (layoutNode != null && layoutNode.hasCustomizer())
86                     NodeOperation.getDefault().customize(layoutNode);
87             }
88         }
89     }
90
91     /*
92      * In this method the enable / disable action logic can be defined.
93      *
94      * @param activatedNodes gives array of actually activated nodes.
95      */

96     protected boolean enable(Node[] activatedNodes) {
97         if (super.enable(activatedNodes)) {
98             RADComponentCookie radCookie = (RADComponentCookie)
99                 activatedNodes[0].getCookie(RADComponentCookie.class);
100             if (radCookie != null) {
101                 RADComponent metacomp = radCookie.getRADComponent();
102                 if (metacomp instanceof RADVisualContainer) {
103                     Node layoutNode = ((RADVisualContainer)metacomp)
104                                       .getLayoutNodeReference();
105                     return layoutNode != null && layoutNode.hasCustomizer();
106                 }
107             }
108         }
109         return false;
110     }
111 }
112
Popular Tags