KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > EditQueryStringAction


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.web.core;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.web.core.jsploader.JspLoader;
24 import org.netbeans.modules.web.core.jsploader.JspDataObject;
25
26 import org.openide.util.HelpCtx;
27 import org.openide.util.NbBundle;
28 import org.openide.util.actions.CookieAction;
29 import org.openide.nodes.Node;
30 import org.openide.loaders.DataObject;
31 import org.openide.NotifyDescriptor;
32
33 import org.openide.DialogDisplayer;
34 import org.openide.ErrorManager;
35
36 /**
37 * EditQueryStringAction.
38 *
39 * @author Petr Jiricka
40 */

41 public class EditQueryStringAction extends CookieAction {
42     /** generated Serialized Version UID */
43     static final long serialVersionUID = -8487176709444303658L;
44
45     /** Actually performs the SwitchOn action.
46     * @param activatedNodes Currently activated nodes.
47     */

48     public void performAction (final Node[] activatedNodes) {
49         if (activatedNodes.length == 0) {
50             return;
51         }
52         DataObject dObj = (DataObject)(activatedNodes[0]).getCookie(DataObject.class);
53         QueryStringCookie qsc = (QueryStringCookie)activatedNodes[0].getCookie(QueryStringCookie.class);
54
55         NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
56                                              NbBundle.getBundle(EditQueryStringAction.class).getString("CTL_QueryStringLabel"),
57                                              NbBundle.getBundle(EditQueryStringAction.class).getString("CTL_QueryStringTitle"));
58
59         dlg.setInputText(WebExecSupport.getQueryString(dObj.getPrimaryFile()));
60
61         if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
62             try {
63                 // WebExecSupport.setQueryString(dObj.getPrimaryFile(), dlg.getInputText());
64
qsc.setQueryString (dlg.getInputText());
65             }
66             catch (IOException JavaDoc e) {
67                 ErrorManager.getDefault().notify(e);
68             }
69         }
70     }
71
72     /**
73     * Returns MODE_EXACTLY_ONE.
74     */

75     protected int mode () {
76         return MODE_EXACTLY_ONE;
77     }
78
79     protected boolean enable (Node[] activatedNodes){
80         if (activatedNodes.length == 0) {
81             return false;
82         }
83         for (int i = 0; i < activatedNodes.length; i++){
84             DataObject dObj = (DataObject)(activatedNodes[i]).getCookie(DataObject.class);
85             QueryStringCookie qsc = (QueryStringCookie)activatedNodes[i].getCookie(QueryStringCookie.class);
86
87             if (qsc == null || dObj == null)
88                 return false;
89             
90             if (dObj instanceof JspDataObject){
91                 String JavaDoc ext = dObj.getPrimaryFile().getExt();
92                 if (ext.equals(JspLoader.TAGF_FILE_EXTENSION)
93                     || ext.equals(JspLoader.TAGX_FILE_EXTENSION)
94                     || ext.equals(JspLoader.TAG_FILE_EXTENSION))
95                         return false;
96             }
97         }
98         return true;
99     }
100     /**
101     * Returns QueryStringCookie
102     */

103     protected Class JavaDoc[] cookieClasses () {
104         return new Class JavaDoc [] {
105                    // ExecCookie.class, DataObject.class
106
QueryStringCookie.class
107                };
108     }
109
110     /** @return the action's icon */
111     public String JavaDoc getName() {
112         return NbBundle.getBundle (EditQueryStringAction.class).getString ("LBL_EditQueryString");
113     }
114
115     /** @return the action's help context */
116     public HelpCtx getHelpCtx() {
117         return new HelpCtx (EditQueryStringAction.class);
118     }
119 }
120
121
Popular Tags