KickJava   Java API By Example, From Geeks To Geeks.

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


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 SetPropertyCustomizer extends javax.swing.JPanel JavaDoc {
39
40     private Dialog JavaDoc dialog = null;
41     private DialogDescriptor descriptor = null;
42     private boolean dialogOK = false;
43
44     SetProperty setProperty;
45     JTextComponent JavaDoc target;
46     
47     public SetPropertyCustomizer(SetProperty setProperty, JTextComponent JavaDoc target) {
48         this.setProperty = setProperty;
49         this.target = target;
50
51         initComponents();
52
53         jComboBox1.setModel(new DefaultComboBoxModel JavaDoc(SetProperty.implicitBeans));
54         jComboBox1.setSelectedIndex(setProperty.getBeanIndex());
55     }
56     
57     private void setClassName() {
58         
59         int beanIndex = jComboBox1.getSelectedIndex();
60         if (beanIndex == -1)
61             jTextField1.setText("");
62         else if (beanIndex < GetProperty.implicitBeans.length)
63             jTextField1.setText(GetProperty.implicitTypes[beanIndex]);
64         else {
65             //TODO get class name for the "explicit" bean
66
}
67     }
68             
69     public boolean showDialog() {
70         
71         dialogOK = false;
72         
73         String JavaDoc displayName = "";
74         try {
75             displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-SetProperty"); // NOI18N
76
}
77         catch (Exception JavaDoc e) {}
78         
79         descriptor = new DialogDescriptor
80                 (this, NbBundle.getMessage(SetPropertyCustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true,
81                  DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
82                  new ActionListener JavaDoc() {
83                      public void actionPerformed(ActionEvent JavaDoc e) {
84                         if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
85                             evaluateInput();
86                             dialogOK = true;
87                         }
88                         dialog.dispose();
89              }
90          }
91                 );
92         
93         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
94         dialog.setVisible(true);
95         repaint();
96         
97         return dialogOK;
98     }
99     
100     private void evaluateInput() {
101         
102         int beanIndex = jComboBox1.getSelectedIndex();
103         setProperty.setBeanIndex(beanIndex);
104         if (beanIndex == -1) { // new or no value selected
105
Object JavaDoc item = jComboBox1.getSelectedItem();
106             if (item != null)
107                 setProperty.setBean(item.toString());
108         }
109
110         String JavaDoc property = jTextField2.getText();
111         setProperty.setProperty(property);
112         
113         String JavaDoc value = jTextField3.getText();
114         setProperty.setValue(value);
115         
116     }
117     
118     /** This method is called from within the constructor to
119      * initialize the form.
120      * WARNING: Do NOT modify this code. The content of this method is
121      * always regenerated by the Form Editor.
122      */

123     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
124
private void initComponents() {
125         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
126
127         jTextField1 = new javax.swing.JTextField JavaDoc();
128         jLabel1 = new javax.swing.JLabel JavaDoc();
129         jLabel2 = new javax.swing.JLabel JavaDoc();
130         jComboBox1 = new javax.swing.JComboBox JavaDoc();
131         jLabel3 = new javax.swing.JLabel JavaDoc();
132         jTextField2 = new javax.swing.JTextField JavaDoc();
133         jLabel4 = new javax.swing.JLabel JavaDoc();
134         jTextField3 = new javax.swing.JTextField JavaDoc();
135
136         setLayout(new java.awt.GridBagLayout JavaDoc());
137
138         jTextField1.setColumns(35);
139         jTextField1.setEditable(false);
140         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
141         gridBagConstraints.gridx = 1;
142         gridBagConstraints.gridy = 1;
143         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
144         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
145         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
146         add(jTextField1, gridBagConstraints);
147
148         jLabel1.setLabelFor(jComboBox1);
149         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "LBL_SetProperty_Bean"));
150         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
151         gridBagConstraints.gridx = 0;
152         gridBagConstraints.gridy = 0;
153         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
154         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
155         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
156         add(jLabel1, gridBagConstraints);
157         jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSN_SetProperty_Bean"));
158         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSD_SetProperty_Bean"));
159
160         jLabel2.setLabelFor(jTextField1);
161         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "LBL_SetProperty_Class"));
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 1;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
168         add(jLabel2, gridBagConstraints);
169         jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSN_SetProperty_Class"));
170         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSD_SetProperty_Class"));
171
172         jComboBox1.setEditable(true);
173         jComboBox1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
174             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
175                 jComboBox1ActionPerformed(evt);
176             }
177         });
178
179         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
180         gridBagConstraints.gridx = 1;
181         gridBagConstraints.gridy = 0;
182         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
183         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
184         add(jComboBox1, gridBagConstraints);
185
186         jLabel3.setLabelFor(jTextField2);
187         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "LBL_SetProperty_PropertyName"));
188         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
189         gridBagConstraints.gridx = 0;
190         gridBagConstraints.gridy = 2;
191         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
193         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
194         add(jLabel3, gridBagConstraints);
195         jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSN_SetProperty_PropertyName"));
196         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSD_SetProperty_PropertyName"));
197
198         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
199         gridBagConstraints.gridx = 1;
200         gridBagConstraints.gridy = 2;
201         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
202         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
203         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
204         add(jTextField2, gridBagConstraints);
205
206         jLabel4.setLabelFor(jTextField3);
207         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "LBL_SetProperty_PropertyValue"));
208         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints.gridx = 0;
210         gridBagConstraints.gridy = 3;
211         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
212         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 0);
214         add(jLabel4, gridBagConstraints);
215         jLabel4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSN_SetProperty_PropertyValue"));
216         jLabel4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SetPropertyCustomizer.class, "ACSD_SetProperty_PropertyValue"));
217
218         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
219         gridBagConstraints.gridx = 1;
220         gridBagConstraints.gridy = 3;
221         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
222         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
223         gridBagConstraints.weightx = 1.0;
224         gridBagConstraints.weighty = 1.0;
225         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 12);
226         add(jTextField3, gridBagConstraints);
227
228     }// </editor-fold>//GEN-END:initComponents
229

230     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
231
setClassName();
232     }//GEN-LAST:event_jComboBox1ActionPerformed
233

234     
235     // Variables declaration - do not modify//GEN-BEGIN:variables
236
private javax.swing.JComboBox JavaDoc jComboBox1;
237     private javax.swing.JLabel JavaDoc jLabel1;
238     private javax.swing.JLabel JavaDoc jLabel2;
239     private javax.swing.JLabel JavaDoc jLabel3;
240     private javax.swing.JLabel JavaDoc jLabel4;
241     private javax.swing.JTextField JavaDoc jTextField1;
242     private javax.swing.JTextField JavaDoc jTextField2;
243     private javax.swing.JTextField JavaDoc jTextField3;
244     // End of variables declaration//GEN-END:variables
245

246 }
247
Popular Tags