KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * TABLECustomizerPanel.java
3  *
4  * Created on July 20, 2005, 10:32 AM
5  */

6
7 package org.netbeans.modules.web.core.palette.items;
8 import java.awt.Dialog JavaDoc;
9 import java.awt.event.ActionEvent JavaDoc;
10 import java.awt.event.ActionListener JavaDoc;
11 import javax.swing.DefaultComboBoxModel JavaDoc;
12 import javax.swing.text.JTextComponent JavaDoc;
13 import org.openide.DialogDescriptor;
14 import org.openide.DialogDisplayer;
15 import org.openide.util.NbBundle;
16
17
18
19
20
21 /**
22  *
23  * @author Libor Kotouc
24  */

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

107     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
108
private void initComponents() {
109         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
110
111         jTextField1 = new javax.swing.JTextField JavaDoc();
112         jLabel1 = new javax.swing.JLabel JavaDoc();
113         jLabel2 = new javax.swing.JLabel JavaDoc();
114         jComboBox1 = new javax.swing.JComboBox JavaDoc();
115         jLabel3 = new javax.swing.JLabel JavaDoc();
116         jTextField2 = new javax.swing.JTextField JavaDoc();
117
118         setLayout(new java.awt.GridBagLayout JavaDoc());
119
120         jTextField1.setColumns(35);
121         jTextField1.setEditable(false);
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridx = 1;
124         gridBagConstraints.gridy = 1;
125         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
126         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
127         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
128         add(jTextField1, gridBagConstraints);
129
130         jLabel1.setLabelFor(jComboBox1);
131         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "LBL_GetProperty_Bean"));
132         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
133         gridBagConstraints.gridx = 0;
134         gridBagConstraints.gridy = 0;
135         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
136         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
137         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
138         add(jLabel1, gridBagConstraints);
139         jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "ACSN_GetProperty_Bean"));
140         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "ACSD_GetProperty_Bean"));
141
142         jLabel2.setLabelFor(jTextField1);
143         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "LBL_GetProperty_Class"));
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 0;
146         gridBagConstraints.gridy = 1;
147         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
148         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
150         add(jLabel2, gridBagConstraints);
151         jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "ACSN_GetProperty_Class"));
152         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "ACSD_GetProperty_Class"));
153
154         jComboBox1.setEditable(true);
155         jComboBox1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
156             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
157                 jComboBox1ActionPerformed(evt);
158             }
159         });
160
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
162         gridBagConstraints.gridx = 1;
163         gridBagConstraints.gridy = 0;
164         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
166         add(jComboBox1, gridBagConstraints);
167
168         jLabel3.setLabelFor(jTextField2);
169         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "LBL_GetProperty_Property"));
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridx = 0;
172         gridBagConstraints.gridy = 2;
173         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
174         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
175         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 0);
176         add(jLabel3, gridBagConstraints);
177         jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "ACSN_GetProperty_Property"));
178         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GetPropertyCustomizer.class, "ACSD_GetProperty_Property"));
179
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 1;
182         gridBagConstraints.gridy = 2;
183         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
184         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
185         gridBagConstraints.weightx = 1.0;
186         gridBagConstraints.weighty = 1.0;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 12);
188         add(jTextField2, gridBagConstraints);
189
190     }// </editor-fold>//GEN-END:initComponents
191

192     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
193
setClassName();
194     }//GEN-LAST:event_jComboBox1ActionPerformed
195

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

206 }
207
Popular Tags