1 6 7 package org.netbeans.modules.web.core.palette.items; 8 import java.awt.Dialog ; 9 import java.awt.event.ActionEvent ; 10 import java.awt.event.ActionListener ; 11 import javax.swing.DefaultComboBoxModel ; 12 import javax.swing.text.JTextComponent ; 13 import org.openide.DialogDescriptor; 14 import org.openide.DialogDisplayer; 15 import org.openide.util.NbBundle; 16 17 18 19 20 21 25 public class GetPropertyCustomizer extends javax.swing.JPanel { 26 27 private Dialog dialog = null; 28 private DialogDescriptor descriptor = null; 29 private boolean dialogOK = false; 30 31 GetProperty getProperty; 32 JTextComponent target; 33 34 public GetPropertyCustomizer(GetProperty getProperty, JTextComponent target) { 35 this.getProperty = getProperty; 36 this.target = target; 37 38 initComponents(); 39 40 jComboBox1.setModel(new DefaultComboBoxModel (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 } 54 } 55 56 public boolean showDialog() { 57 58 dialogOK = false; 59 60 String displayName = ""; 61 try { 62 displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-GetProperty"); } 64 catch (Exception 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 () { 70 public void actionPerformed(ActionEvent 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) { Object item = jComboBox1.getSelectedItem(); 93 if (item != null) 94 getProperty.setBean(item.toString()); 95 } 96 97 String property = jTextField2.getText(); 98 getProperty.setProperty(property); 99 100 } 101 102 107 private void initComponents() { 109 java.awt.GridBagConstraints gridBagConstraints; 110 111 jTextField1 = new javax.swing.JTextField (); 112 jLabel1 = new javax.swing.JLabel (); 113 jLabel2 = new javax.swing.JLabel (); 114 jComboBox1 = new javax.swing.JComboBox (); 115 jLabel3 = new javax.swing.JLabel (); 116 jTextField2 = new javax.swing.JTextField (); 117 118 setLayout(new java.awt.GridBagLayout ()); 119 120 jTextField1.setColumns(35); 121 jTextField1.setEditable(false); 122 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 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 (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 (); 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 (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 () { 156 public void actionPerformed(java.awt.event.ActionEvent evt) { 157 jComboBox1ActionPerformed(evt); 158 } 159 }); 160 161 gridBagConstraints = new java.awt.GridBagConstraints (); 162 gridBagConstraints.gridx = 1; 163 gridBagConstraints.gridy = 0; 164 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 165 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (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 (); 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 (12, 12, 12, 12); 188 add(jTextField2, gridBagConstraints); 189 190 } 192 private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { setClassName(); 194 } 196 197 private javax.swing.JComboBox jComboBox1; 199 private javax.swing.JLabel jLabel1; 200 private javax.swing.JLabel jLabel2; 201 private javax.swing.JLabel jLabel3; 202 private javax.swing.JTextField jTextField1; 203 private javax.swing.JTextField jTextField2; 204 206 } 207 | Popular Tags |