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-2007 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: package org.netbeans.modules.visualweb.insync.live;
042:
043: import java.awt.event.ActionEvent;
044: import javax.swing.Action;
045: import javax.swing.AbstractAction;
046:
047: import org.openide.nodes.Node;
048: import org.openide.util.HelpCtx;
049: import org.openide.util.Lookup;
050: import org.openide.util.NbBundle;
051: import org.openide.util.actions.NodeAction;
052:
053: import com.sun.rave.designtime.Customizer2;
054:
055: /**
056: *
057: * @author Carl Quinn
058: */
059: public class CustomizeAction extends NodeAction {
060:
061: /**
062: *
063: */
064: private static final long serialVersionUID = 3256440300644742713L;
065:
066: protected boolean enable(Node[] nodes) {
067: // only enable when a single node is selected
068: if (nodes.length > 1) {
069: return false;
070: } else {
071: return true;
072: }
073: }
074:
075: public HelpCtx getHelpCtx() {
076: return HelpCtx.DEFAULT_HELP;
077: // If you will provide context help then use:
078: // return new AddServerAction.class);
079: }
080:
081: public String getName() {
082: return NbBundle.getMessage(CustomizeAction.class, "Customize"); // NOI18N
083: }
084:
085: public Action createContextAwareInstance(Lookup context) {
086: Action a = super .createContextAwareInstance(context);
087:
088: // XXX Trying to change the name according to the liveCustomizer.
089: Node node = (Node) context.lookup(Node.class);
090: if (node instanceof DesignBeanNode) {
091: Customizer2 liveCustomizer = ((DesignBeanNode) node).liveCustomizer;
092:
093: if (liveCustomizer != null) {
094: // XXX Using the hacked action.. since the a.putValue is
095: // overlapped in Node.DelegateAction.
096: a = new DelegateAction(a, liveCustomizer
097: .getDisplayName());
098: }
099: }
100: return a;
101: }
102:
103: protected void performAction(Node[] nodes) {
104: if (nodes.length > 0 && nodes[0] instanceof DesignBeanNode) {
105: DesignBeanNode lbn = (DesignBeanNode) nodes[0];
106: Customizer2 liveCustomizer = lbn.getCustomizer2();
107: if (liveCustomizer != null) {
108: lbn.invokeCustomizer();
109: }
110: }
111: }
112:
113: protected boolean asynchronous() {
114: return false;
115: }
116:
117: // XXX Dont use this anywhere else.
118: // Hack to be able change the Node.DelegateAction display name.
119: // It should be allowed by the NB NodeAction implementation.
120: private static class DelegateAction extends AbstractAction {
121: /**
122: *
123: */
124: private static final long serialVersionUID = 3617015264743471412L;
125: private final Action delegate;
126:
127: public DelegateAction(Action delegate, String dispName) {
128: this .delegate = delegate;
129: putValue(Action.NAME, dispName);
130: }
131:
132: public Object getValue(String key) {
133: if (Action.NAME.equals(key)) {
134: return super .getValue(key);
135: } else {
136: return delegate.getValue(key);
137: }
138: }
139:
140: public void actionPerformed(ActionEvent evt) {
141: delegate.actionPerformed(evt);
142: }
143:
144: public boolean isEnabled() {
145: return delegate.isEnabled();
146: }
147: }
148: }
|