KickJava   Java API By Example, From Geeks To Geeks.

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


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 UseBean implements ActiveEditorDrop {
32
33     private static final int BEAN_DEFAULT = -1;
34
35     public static final String JavaDoc[] scopes = new String JavaDoc[] { "page", "request", "session", "application" }; // NOI18N
36
public static final int SCOPE_DEFAULT = 0;
37     
38     private int beanIndex = BEAN_DEFAULT;
39     private String JavaDoc bean = "";
40     private String JavaDoc clazz = "";
41     private int scopeIndex = SCOPE_DEFAULT;
42     
43     private String JavaDoc[] beans;
44    
45     public UseBean() {
46         beans = findBeans();
47         if (beans.length > 0)
48             beanIndex = 0;
49     }
50
51     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
52
53         UseBeanCustomizer c = new UseBeanCustomizer(this, targetComponent);
54         boolean accept = c.showDialog();
55         if (accept) {
56             String JavaDoc body = createBody();
57             try {
58                 JSPPaletteUtilities.insert(body, targetComponent);
59             } catch (BadLocationException JavaDoc ble) {
60                 accept = false;
61             }
62         }
63         
64         return accept;
65     }
66
67     private String JavaDoc createBody() {
68         
69         String JavaDoc strBean = " id=\"\""; // NOI18N
70
if (beanIndex == -1)
71             strBean = " id=\"" + bean + "\""; // NOI18N
72
else
73             strBean = " id=\"" + beans[beanIndex] + "\""; // NOI18N
74

75         String JavaDoc strClass = " class=\"" + clazz + "\""; // NOI18N
76

77         String JavaDoc strScope = " scope=\"" + scopes[scopeIndex] + "\""; // NOI18N
78

79         String JavaDoc ub = "<jsp:useBean" + strBean + strScope + strClass + " />"; // NOI18N
80

81         return ub;
82     }
83         
84     private String JavaDoc[] findBeans() {
85          
86         //TODO retrieve existing beans
87
String JavaDoc[] beans = new String JavaDoc[] {};
88         
89         return beans;
90     }
91
92     public int getBeanIndex() {
93         return beanIndex;
94     }
95
96     public void setBeanIndex(int beanIndex) {
97         this.beanIndex = beanIndex;
98     }
99
100     public String JavaDoc getBean() {
101         return bean;
102     }
103
104     public void setBean(String JavaDoc bean) {
105         this.bean = bean;
106     }
107
108     public String JavaDoc getClazz() {
109         return clazz;
110     }
111
112     public void setClazz(String JavaDoc clazz) {
113         this.clazz = clazz;
114     }
115
116     public int getScopeIndex() {
117         return scopeIndex;
118     }
119
120     public void setScopeIndex(int scopeIndex) {
121         this.scopeIndex = scopeIndex;
122     }
123
124     public String JavaDoc[] getBeans() {
125         return beans;
126     }
127
128     public void setBeans(String JavaDoc[] beans) {
129         this.beans = beans;
130     }
131     
132 }
133
Popular Tags