KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > palette > items > GetProperty


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.palette.items;
21 import javax.swing.text.BadLocationException JavaDoc;
22 import javax.swing.text.JTextComponent JavaDoc;
23 import org.netbeans.modules.web.core.palette.JSPPaletteUtilities;
24 import org.openide.text.ActiveEditorDrop;
25
26
27 /**
28  *
29  * @author Libor Kotouc
30  */

31 public class GetProperty implements ActiveEditorDrop {
32
33     public static final String JavaDoc[] implicitBeans = new String JavaDoc[] { // NOI18N
34
"request",
35         "response",
36         "pageContext",
37         "session",
38         "application",
39         "out",
40         "config",
41         "page",
42         "exception"
43     };
44     public static final int BEAN_DEFAULT = -1;
45     public static final String JavaDoc[] implicitTypes = new String JavaDoc[] { // NOI18N
46
"javax.servlet.http.HttpServletRequest",
47         "javax.servlet.http.HttpServletResponse",
48         "javax.servlet.jsp.PageContext",
49         "javax.servlet.http.HttpSession",
50         "javax.servlet.ServletContext",
51         "javax.servlet.jsp.JspWriter",
52         "javax.servlet.ServletConfig",
53         "java.lang.Object",
54         "java.lang.Throwable"
55     };
56
57     private int beanIndex = BEAN_DEFAULT;
58     private String JavaDoc bean = "";
59     private String JavaDoc property = "";
60     
61     public GetProperty() {
62     }
63
64     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
65
66         GetPropertyCustomizer c = new GetPropertyCustomizer(this, targetComponent);
67         boolean accept = c.showDialog();
68         if (accept) {
69             String JavaDoc body = createBody();
70             try {
71                 JSPPaletteUtilities.insert(body, targetComponent);
72             } catch (BadLocationException JavaDoc ble) {
73                 accept = false;
74             }
75         }
76         
77         return accept;
78     }
79
80     private String JavaDoc createBody() {
81         
82         String JavaDoc strBean = " name=\"\""; // NOI18N
83
if (beanIndex == -1)
84             strBean = " name=\"" + bean + "\""; // NOI18N
85
else
86             strBean = " name=\"" + implicitBeans[beanIndex] + "\""; // NOI18N
87

88         String JavaDoc strProperty = " property=\"" + property + "\""; // NOI18N
89

90         String JavaDoc gp = "<jsp:getProperty" + strBean + strProperty + " />"; // NOI18N
91

92         return gp;
93     }
94
95     public int getBeanIndex() {
96         return beanIndex;
97     }
98
99     public void setBeanIndex(int beanIndex) {
100         this.beanIndex = beanIndex;
101     }
102
103     public String JavaDoc getBean() {
104         return bean;
105     }
106
107     public void setBean(String JavaDoc bean) {
108         this.bean = bean;
109     }
110
111     public String JavaDoc getProperty() {
112         return property;
113     }
114
115     public void setProperty(String JavaDoc property) {
116         this.property = property;
117     }
118         
119 }
120
Popular Tags