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.web.core;
043:
044: import java.io.IOException;
045: import org.netbeans.modules.web.core.jsploader.JspLoader;
046: import org.netbeans.modules.web.core.jsploader.JspDataObject;
047:
048: import org.openide.util.HelpCtx;
049: import org.openide.util.NbBundle;
050: import org.openide.util.actions.CookieAction;
051: import org.openide.nodes.Node;
052: import org.openide.loaders.DataObject;
053: import org.openide.NotifyDescriptor;
054:
055: import org.openide.DialogDisplayer;
056: import org.openide.util.Exceptions;
057:
058: /**
059: * EditQueryStringAction.
060: *
061: * @author Petr Jiricka
062: */
063: public class EditQueryStringAction extends CookieAction {
064: /** generated Serialized Version UID */
065: static final long serialVersionUID = -8487176709444303658L;
066:
067: /** Actually performs the SwitchOn action.
068: * @param activatedNodes Currently activated nodes.
069: */
070: public void performAction(final Node[] activatedNodes) {
071: if (activatedNodes.length == 0) {
072: return;
073: }
074: DataObject dObj = (DataObject) (activatedNodes[0])
075: .getCookie(DataObject.class);
076: QueryStringCookie qsc = (QueryStringCookie) activatedNodes[0]
077: .getCookie(QueryStringCookie.class);
078:
079: NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
080: NbBundle.getBundle(EditQueryStringAction.class)
081: .getString("CTL_QueryStringLabel"), NbBundle
082: .getBundle(EditQueryStringAction.class)
083: .getString("CTL_QueryStringTitle"));
084:
085: dlg.setInputText(WebExecSupport.getQueryString(dObj
086: .getPrimaryFile()));
087:
088: if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer
089: .getDefault().notify(dlg))) {
090: try {
091: // WebExecSupport.setQueryString(dObj.getPrimaryFile(), dlg.getInputText());
092: qsc.setQueryString(dlg.getInputText());
093: } catch (IOException e) {
094: Exceptions.printStackTrace(e);
095: }
096: }
097: }
098:
099: /**
100: * Returns MODE_EXACTLY_ONE.
101: */
102: protected int mode() {
103: return MODE_EXACTLY_ONE;
104: }
105:
106: protected boolean enable(Node[] activatedNodes) {
107: if (activatedNodes.length == 0) {
108: return false;
109: }
110: for (int i = 0; i < activatedNodes.length; i++) {
111: DataObject dObj = (DataObject) (activatedNodes[i])
112: .getCookie(DataObject.class);
113: QueryStringCookie qsc = (QueryStringCookie) activatedNodes[i]
114: .getCookie(QueryStringCookie.class);
115:
116: if (qsc == null || dObj == null)
117: return false;
118:
119: if (dObj instanceof JspDataObject) {
120: String ext = dObj.getPrimaryFile().getExt();
121: if (ext.equals(JspLoader.TAGF_FILE_EXTENSION)
122: || ext.equals(JspLoader.TAGX_FILE_EXTENSION)
123: || ext.equals(JspLoader.TAG_FILE_EXTENSION))
124: return false;
125: }
126: }
127: return true;
128: }
129:
130: /**
131: * Returns QueryStringCookie
132: */
133: protected Class[] cookieClasses() {
134: return new Class[] {
135: // ExecCookie.class, DataObject.class
136: QueryStringCookie.class };
137: }
138:
139: /** @return the action's icon */
140: public String getName() {
141: return NbBundle.getBundle(EditQueryStringAction.class)
142: .getString("LBL_EditQueryString");
143: }
144:
145: /** @return the action's help context */
146: public HelpCtx getHelpCtx() {
147: return new HelpCtx(EditQueryStringAction.class);
148: }
149: }
|