001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form.actions;
043:
044: import org.openide.nodes.Node;
045: import org.openide.util.actions.*;
046: import org.openide.util.*;
047:
048: import org.netbeans.modules.form.*;
049:
050: /**
051: * Makes the entire form selected in designer - if the current designed
052: * container is a sub-container and also the current selected node.
053: * This action is not presented visually anywhere, it is used as one of the
054: * component default actions ensuring that when a designed container is double
055: * clicked, the whole form is brought back to design.
056: *
057: * @author Tomas Pavek
058: */
059: public class EditFormAction extends NodeAction {
060:
061: protected boolean enable(Node[] nodes) {
062: boolean ret = false;
063: if (nodes != null && nodes.length == 1) {
064: RADComponentCookie radCookie = nodes[0]
065: .getCookie(RADComponentCookie.class);
066: RADComponent comp = (radCookie != null) ? radCookie
067: .getRADComponent() : null;
068: if (comp != null) {
069: RADComponent topComp = comp.getFormModel()
070: .getTopRADComponent();
071: if (comp != topComp
072: && EditContainerAction
073: .isEditableComponent(topComp)) {
074: FormDesigner designer = getDesigner(comp);
075: if (designer != null
076: && comp == designer.getTopDesignComponent()) {
077: ret = true;
078: }
079: }
080: }
081: }
082: return ret;
083: }
084:
085: static void reenable(Node[] nodes) {
086: SystemAction.get(EditFormAction.class).reenable0(nodes);
087: }
088:
089: private void reenable0(Node[] nodes) {
090: setEnabled(enable(nodes));
091: }
092:
093: protected void performAction(Node[] nodes) {
094: if (nodes != null && nodes.length == 1) {
095: RADComponentCookie radCookie = nodes[0]
096: .getCookie(RADComponentCookie.class);
097: RADComponent comp = (radCookie != null) ? radCookie
098: .getRADComponent() : null;
099: if (comp != null) {
100: RADComponent topComp = comp.getFormModel()
101: .getTopRADComponent();
102: if (topComp != comp
103: && EditContainerAction
104: .isEditableComponent(topComp)) {
105: FormDesigner designer = getDesigner(topComp);
106: if (designer != null
107: && topComp != designer
108: .getTopDesignComponent()) {
109: designer.setTopDesignComponent(
110: (RADVisualComponent) topComp, true);
111: designer.requestActive();
112:
113: // NodeAction is quite unreliable in enabling, do it ourselves for sure
114: Node[] n = new Node[] { topComp
115: .getNodeReference() };
116: if (n[0] != null) {
117: EditContainerAction.reenable(n);
118: DesignParentAction.reenable(n);
119: EditFormAction.reenable(n);
120: }
121: }
122: }
123: }
124: }
125: }
126:
127: private static FormDesigner getDesigner(RADComponent comp) {
128: return FormEditor.getFormDesigner(comp.getFormModel());
129: }
130:
131: @Override
132: protected boolean asynchronous() {
133: return false;
134: }
135:
136: public String getName() {
137: return ""; // NOI18N
138: }
139:
140: public HelpCtx getHelpCtx() {
141: return HelpCtx.DEFAULT_HELP;
142: }
143:
144: }
|