KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.Dialog JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import javax.swing.DefaultComboBoxModel JavaDoc;
25 import javax.swing.text.JTextComponent JavaDoc;
26 import org.openide.DialogDescriptor;
27 import org.openide.DialogDisplayer;
28 import org.openide.util.NbBundle;
29
30
31
32
33
34 /**
35  *
36  * @author Libor Kotouc
37  */

38 public class UseBeanCustomizer extends javax.swing.JPanel JavaDoc {
39
40     private Dialog JavaDoc dialog = null;
41     private DialogDescriptor descriptor = null;
42     private boolean dialogOK = false;
43
44     UseBean useBean;
45     JTextComponent JavaDoc target;
46             
47     /** Creates new form TABLECustomizerPanel */
48     public UseBeanCustomizer(UseBean useBean, JTextComponent JavaDoc target) {
49         this.useBean = useBean;
50         this.target = target;
51         
52         initComponents();
53
54         jComboBox1.setModel(new DefaultComboBoxModel JavaDoc(useBean.getBeans()));
55         if (useBean.getBeanIndex() > -1)
56             jComboBox1.setSelectedIndex(useBean.getBeanIndex());
57         
58         jComboBox2.setModel(new DefaultComboBoxModel JavaDoc(UseBean.scopes));
59         jComboBox2.setSelectedIndex(useBean.getScopeIndex());
60         
61     }
62     
63     public boolean showDialog() {
64         
65         dialogOK = false;
66         
67         String JavaDoc displayName = "";
68         try {
69             displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-UseBean"); // NOI18N
70
}
71         catch (Exception JavaDoc e) {}
72         
73         descriptor = new DialogDescriptor
74                 (this, NbBundle.getMessage(UseBeanCustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true,
75                  DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
76                  new ActionListener JavaDoc() {
77                      public void actionPerformed(ActionEvent JavaDoc e) {
78                         if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
79                             evaluateInput();
80                             dialogOK = true;
81                         }
82                         dialog.dispose();
83              }
84          }
85                 );
86         
87         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
88         dialog.setVisible(true);
89         repaint();
90         
91         return dialogOK;
92     }
93     
94     private void evaluateInput() {
95         
96         int beanIndex = jComboBox1.getSelectedIndex();
97         useBean.setBeanIndex(beanIndex);
98         if (beanIndex == -1 && jComboBox1.getSelectedItem() != null) // new or no value selected
99
useBean.setBean(jComboBox1.getSelectedItem().toString());
100         
101         String JavaDoc clazz = jTextField1.getText();
102         useBean.setClazz(clazz);
103         
104         int scopeIndex = jComboBox2.getSelectedIndex();
105         useBean.setScopeIndex(scopeIndex);
106         
107     }
108     
109     /** This method is called from within the constructor to
110      * initialize the form.
111      * WARNING: Do NOT modify this code. The content of this method is
112      * always regenerated by the Form Editor.
113      */

114     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
115
private void initComponents() {
116         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
117
118         jFileChooser1 = new javax.swing.JFileChooser JavaDoc();
119         jLabel4 = new javax.swing.JLabel JavaDoc();
120         jTextField1 = new javax.swing.JTextField JavaDoc();
121         jLabel1 = new javax.swing.JLabel JavaDoc();
122         jLabel2 = new javax.swing.JLabel JavaDoc();
123         jComboBox1 = new javax.swing.JComboBox JavaDoc();
124         jComboBox2 = new javax.swing.JComboBox JavaDoc();
125
126         jFileChooser1.setCurrentDirectory(null);
127
128         setLayout(new java.awt.GridBagLayout JavaDoc());
129
130         jLabel4.setLabelFor(jComboBox2);
131         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "LBL_UseBean_Scope"));
132         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
133         gridBagConstraints.gridx = 0;
134         gridBagConstraints.gridy = 2;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
137         gridBagConstraints.weighty = 1.0;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 0);
139         add(jLabel4, gridBagConstraints);
140         jLabel4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "ACSN_UseBean_Scope"));
141         jLabel4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "ACSD_UseBean_Scope"));
142
143         jTextField1.setColumns(35);
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 1;
146         gridBagConstraints.gridy = 1;
147         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
150         add(jTextField1, gridBagConstraints);
151
152         jLabel1.setLabelFor(jComboBox1);
153         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "LBL_UseBean_ID"));
154         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
155         gridBagConstraints.gridx = 0;
156         gridBagConstraints.gridy = 0;
157         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
158         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
160         add(jLabel1, gridBagConstraints);
161         jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "ACSN_UseBean_ID"));
162         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "ACSD_UseBean_ID"));
163
164         jLabel2.setLabelFor(jTextField1);
165         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "LBL_UseBean_Class"));
166         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridx = 0;
168         gridBagConstraints.gridy = 1;
169         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
170         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
171         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
172         add(jLabel2, gridBagConstraints);
173         jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "ACSN_UseBean_Class"));
174         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(UseBeanCustomizer.class, "ACSD_UseBean_Class"));
175
176         jComboBox1.setEditable(true);
177         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
178         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
180         add(jComboBox1, gridBagConstraints);
181
182         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
183         gridBagConstraints.gridx = 1;
184         gridBagConstraints.gridy = 2;
185         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
187         gridBagConstraints.weightx = 1.0;
188         gridBagConstraints.weighty = 1.0;
189         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 12);
190         add(jComboBox2, gridBagConstraints);
191
192     }// </editor-fold>//GEN-END:initComponents
193

194     
195     // Variables declaration - do not modify//GEN-BEGIN:variables
196
private javax.swing.JComboBox JavaDoc jComboBox1;
197     private javax.swing.JComboBox JavaDoc jComboBox2;
198     private javax.swing.JFileChooser JavaDoc jFileChooser1;
199     private javax.swing.JLabel JavaDoc jLabel1;
200     private javax.swing.JLabel JavaDoc jLabel2;
201     private javax.swing.JLabel JavaDoc jLabel4;
202     private javax.swing.JTextField JavaDoc jTextField1;
203     // End of variables declaration//GEN-END:variables
204

205 }
206
Popular Tags