KickJava   Java API By Example, From Geeks To Geeks.

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


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 SetProperty 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     private String JavaDoc value = "";
61     
62     public SetProperty() {
63     }
64
65     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
66
67         SetPropertyCustomizer c = new SetPropertyCustomizer(this, targetComponent);
68         boolean accept = c.showDialog();
69         if (accept) {
70             String JavaDoc body = createBody();
71             try {
72                 JSPPaletteUtilities.insert(body, targetComponent);
73             } catch (BadLocationException JavaDoc ble) {
74                 accept = false;
75             }
76         }
77         
78         return accept;
79     }
80     
81     private String JavaDoc createBody() {
82         
83         String JavaDoc strBean = " name=\"\""; // NOI18N
84
if (beanIndex == -1)
85             strBean = " name=\"" + bean + "\""; // NOI18N
86
else
87             strBean = " name=\"" + implicitBeans[beanIndex] + "\""; // NOI18N
88

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

91         String JavaDoc strValue = " value=\"" + value + "\""; // NOI18N
92

93         String JavaDoc sp = "<jsp:setProperty" + strBean + strProperty + strValue + " />"; // NOI18N
94

95         return sp;
96     }
97
98     public int getBeanIndex() {
99         return beanIndex;
100     }
101
102     public void setBeanIndex(int beanIndex) {
103         this.beanIndex = beanIndex;
104     }
105
106     public String JavaDoc getBean() {
107         return bean;
108     }
109
110     public void setBean(String JavaDoc bean) {
111         this.bean = bean;
112     }
113
114     public String JavaDoc getProperty() {
115         return property;
116     }
117
118     public void setProperty(String JavaDoc property) {
119         this.property = property;
120     }
121
122     public String JavaDoc getValue() {
123         return value;
124     }
125
126     public void setValue(String JavaDoc value) {
127         this.value = value;
128     }
129         
130 }
131
Popular Tags