1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.winsys; 21 22 import java.io.File ; 23 import javax.swing.JFileChooser ; 24 import javax.swing.JTextField ; 25 import javax.swing.event.DocumentEvent ; 26 import javax.swing.event.DocumentListener ; 27 import org.netbeans.api.project.ProjectUtils; 28 import org.netbeans.modules.apisupport.project.ui.UIUtil; 29 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator; 30 import org.openide.WizardDescriptor; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.NbBundle; 33 import org.openide.util.Utilities; 34 35 40 final class NameAndLocationPanel extends BasicWizardIterator.Panel { 41 42 private NewTCIterator.DataModel data; 43 44 45 public NameAndLocationPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) { 46 super(setting); 47 this.data = data; 48 initComponents(); 49 initAccessibility(); 50 putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle")); 51 52 DocumentListener dListener = new UIUtil.DocumentAdapter() { 53 public void insertUpdate(DocumentEvent e) { 54 if (checkValidity()) { 55 updateData(); 56 } 57 } 58 }; 59 txtPrefix.getDocument().addDocumentListener(dListener); 60 txtIcon.getDocument().addDocumentListener(dListener); 61 62 if (comPackageName.getEditor().getEditorComponent() instanceof JTextField ) { 63 JTextField txt = (JTextField )comPackageName.getEditor().getEditorComponent(); 64 txt.getDocument().addDocumentListener(dListener); 65 } 66 } 67 68 protected void storeToDataModel() { 69 updateData(); 70 } 71 72 private void updateData() { 73 data.setPackageName(comPackageName.getEditor().getItem().toString()); 74 String icon = txtIcon.getText().trim(); 75 data.setIcon(icon.length() == 0 ? (String )null : icon); 76 data.setName(txtPrefix.getText().trim()); 77 NewTCIterator.generateFileChanges(data); 78 createdFilesValue.setText(UIUtil.generateTextAreaContent( 79 data.getCreatedModifiedFiles().getCreatedPaths())); 80 modifiedFilesValue.setText(UIUtil.generateTextAreaContent( 81 data.getCreatedModifiedFiles().getModifiedPaths())); 82 String [] invalid = data.getCreatedModifiedFiles().getInvalidPaths(); 84 if (invalid.length > 0) { 85 setError(NbBundle.getMessage(NameAndLocationPanel.class, "ERR_ToBeCreateFileExists", invalid[0])); 86 } 87 88 } 89 90 protected void readFromDataModel() { 91 txtPrefix.setText(data.getName()); 92 txtIcon.setText(data.getIcon()); 93 if (data.getPackageName() != null) { 94 comPackageName.setSelectedItem(data.getPackageName()); 95 } 96 checkValidity(); 97 } 98 99 protected String getPanelName() { 100 return getMessage("LBL_NameLocation_Title"); 101 } 102 103 private boolean checkValidity() { 104 if (txtPrefix.getText().trim().length() == 0) { 105 setError(getMessage("ERR_Name_Prefix_Empty")); 106 return false; 107 } 108 if (!Utilities.isJavaIdentifier(txtPrefix.getText().trim())) { 109 setError(getMessage("ERR_Name_Prefix_Invalid")); 110 return false; 111 } 112 String path = txtIcon.getText().trim(); 113 if (path.length() != 0) { 114 File fil = new File (path); 115 if (!fil.exists()) { 116 setError(NbBundle.getMessage(getClass(), "ERR_Icon_Invalid")); 117 return false; 118 } 119 } 120 String packageName = comPackageName.getEditor().getItem().toString().trim(); 121 if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) { 122 setError(NbBundle.getMessage(getClass(), "ERR_Package_Invalid")); 123 return false; 124 } 125 126 markValid(); 127 return true; 128 } 129 130 protected HelpCtx getHelp() { 131 return new HelpCtx(NameAndLocationPanel.class); 132 } 133 134 private static String getMessage(String key) { 135 return NbBundle.getMessage(NameAndLocationPanel.class, key); 136 } 137 138 143 private void initComponents() { 145 java.awt.GridBagConstraints gridBagConstraints; 146 147 lblPrefix = new javax.swing.JLabel (); 148 txtPrefix = new javax.swing.JTextField (); 149 lblIcon = new javax.swing.JLabel (); 150 txtIcon = new javax.swing.JTextField (); 151 btnIcon = new javax.swing.JButton (); 152 lblProjectName = new javax.swing.JLabel (); 153 txtProjectName = new JTextField (ProjectUtils.getInformation(this.data.getProject()).getDisplayName()); 154 lblPackageName = new javax.swing.JLabel (); 155 comPackageName = UIUtil.createPackageComboBox(data.getSourceRootGroup()); 156 createdFiles = new javax.swing.JLabel (); 157 modifiedFiles = new javax.swing.JLabel (); 158 filler = new javax.swing.JLabel (); 159 createdFilesValue = new javax.swing.JTextArea (); 160 modifiedFilesValue = new javax.swing.JTextArea (); 161 162 setLayout(new java.awt.GridBagLayout ()); 163 164 lblPrefix.setLabelFor(txtPrefix); 165 org.openide.awt.Mnemonics.setLocalizedText(lblPrefix, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Prefix")); 166 gridBagConstraints = new java.awt.GridBagConstraints (); 167 gridBagConstraints.gridx = 0; 168 gridBagConstraints.gridy = 0; 169 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 170 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 12); 171 add(lblPrefix, gridBagConstraints); 172 173 gridBagConstraints = new java.awt.GridBagConstraints (); 174 gridBagConstraints.gridx = 1; 175 gridBagConstraints.gridy = 0; 176 gridBagConstraints.gridwidth = 2; 177 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 178 gridBagConstraints.weightx = 1.0; 179 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 0); 180 add(txtPrefix, gridBagConstraints); 181 182 lblIcon.setLabelFor(txtIcon); 183 org.openide.awt.Mnemonics.setLocalizedText(lblIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon")); 184 gridBagConstraints = new java.awt.GridBagConstraints (); 185 gridBagConstraints.gridx = 0; 186 gridBagConstraints.gridy = 1; 187 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 188 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 189 add(lblIcon, gridBagConstraints); 190 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.gridx = 1; 193 gridBagConstraints.gridy = 1; 194 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 195 gridBagConstraints.weightx = 1.0; 196 add(txtIcon, gridBagConstraints); 197 198 org.openide.awt.Mnemonics.setLocalizedText(btnIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon_Browse")); 199 btnIcon.addActionListener(new java.awt.event.ActionListener () { 200 public void actionPerformed(java.awt.event.ActionEvent evt) { 201 btnIconActionPerformed(evt); 202 } 203 }); 204 205 gridBagConstraints = new java.awt.GridBagConstraints (); 206 gridBagConstraints.gridx = 2; 207 gridBagConstraints.gridy = 1; 208 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 209 add(btnIcon, gridBagConstraints); 210 211 lblProjectName.setLabelFor(txtProjectName); 212 org.openide.awt.Mnemonics.setLocalizedText(lblProjectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ProjectName")); 213 gridBagConstraints = new java.awt.GridBagConstraints (); 214 gridBagConstraints.gridx = 0; 215 gridBagConstraints.gridy = 2; 216 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 217 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 12); 218 add(lblProjectName, gridBagConstraints); 219 220 txtProjectName.setEditable(false); 221 gridBagConstraints = new java.awt.GridBagConstraints (); 222 gridBagConstraints.gridx = 1; 223 gridBagConstraints.gridy = 2; 224 gridBagConstraints.gridwidth = 2; 225 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 226 gridBagConstraints.weightx = 1.0; 227 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 0); 228 add(txtProjectName, gridBagConstraints); 229 230 lblPackageName.setLabelFor(comPackageName); 231 org.openide.awt.Mnemonics.setLocalizedText(lblPackageName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_PackageName")); 232 gridBagConstraints = new java.awt.GridBagConstraints (); 233 gridBagConstraints.gridx = 0; 234 gridBagConstraints.gridy = 3; 235 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 236 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 237 add(lblPackageName, gridBagConstraints); 238 239 comPackageName.setEditable(true); 240 gridBagConstraints = new java.awt.GridBagConstraints (); 241 gridBagConstraints.gridx = 1; 242 gridBagConstraints.gridy = 3; 243 gridBagConstraints.gridwidth = 2; 244 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 245 gridBagConstraints.weightx = 1.0; 246 add(comPackageName, gridBagConstraints); 247 248 createdFiles.setLabelFor(createdFilesValue); 249 org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_CreatedFiles")); 250 gridBagConstraints = new java.awt.GridBagConstraints (); 251 gridBagConstraints.gridx = 0; 252 gridBagConstraints.gridy = 4; 253 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 254 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 255 gridBagConstraints.insets = new java.awt.Insets (36, 0, 6, 12); 256 add(createdFiles, gridBagConstraints); 257 258 modifiedFiles.setLabelFor(modifiedFilesValue); 259 org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ModifiedFiles")); 260 gridBagConstraints = new java.awt.GridBagConstraints (); 261 gridBagConstraints.gridx = 0; 262 gridBagConstraints.gridy = 5; 263 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 264 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 265 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 266 add(modifiedFiles, gridBagConstraints); 267 268 gridBagConstraints = new java.awt.GridBagConstraints (); 269 gridBagConstraints.gridx = 0; 270 gridBagConstraints.gridy = 6; 271 gridBagConstraints.gridwidth = 3; 272 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 273 gridBagConstraints.weightx = 1.0; 274 gridBagConstraints.weighty = 1.0; 275 add(filler, gridBagConstraints); 276 277 createdFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 278 createdFilesValue.setColumns(20); 279 createdFilesValue.setEditable(false); 280 createdFilesValue.setRows(5); 281 createdFilesValue.setBorder(null); 282 gridBagConstraints = new java.awt.GridBagConstraints (); 283 gridBagConstraints.gridx = 1; 284 gridBagConstraints.gridy = 4; 285 gridBagConstraints.gridwidth = 2; 286 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 287 gridBagConstraints.weightx = 1.0; 288 gridBagConstraints.insets = new java.awt.Insets (36, 0, 6, 0); 289 add(createdFilesValue, gridBagConstraints); 290 291 modifiedFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 292 modifiedFilesValue.setColumns(20); 293 modifiedFilesValue.setEditable(false); 294 modifiedFilesValue.setRows(5); 295 modifiedFilesValue.setToolTipText("modifiedFilesValue"); 296 modifiedFilesValue.setBorder(null); 297 gridBagConstraints = new java.awt.GridBagConstraints (); 298 gridBagConstraints.gridx = 1; 299 gridBagConstraints.gridy = 5; 300 gridBagConstraints.gridwidth = 2; 301 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 302 gridBagConstraints.weightx = 1.0; 303 add(modifiedFilesValue, gridBagConstraints); 304 305 } 306 308 private void initAccessibility() { 309 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameAndLocationPanel")); 310 comPackageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName")); 311 txtIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Icon")); 312 txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Prefix")); 313 btnIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton")); 314 txtProjectName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName")); 315 createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue")); 316 modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue")); 317 } 318 319 private void btnIconActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = UIUtil.getIconFileChooser(txtIcon.getText()); 321 int ret = chooser.showDialog(this, getMessage("LBL_Select")); if (ret == JFileChooser.APPROVE_OPTION) { 323 File file = chooser.getSelectedFile(); 324 txtIcon.setText(file.getAbsolutePath()); 325 } 326 } 328 private javax.swing.JButton btnIcon; 330 private javax.swing.JComboBox comPackageName; 331 private javax.swing.JLabel createdFiles; 332 private javax.swing.JTextArea createdFilesValue; 333 private javax.swing.JLabel filler; 334 private javax.swing.JLabel lblIcon; 335 private javax.swing.JLabel lblPackageName; 336 private javax.swing.JLabel lblPrefix; 337 private javax.swing.JLabel lblProjectName; 338 private javax.swing.JLabel modifiedFiles; 339 private javax.swing.JTextArea modifiedFilesValue; 340 private javax.swing.JTextField txtIcon; 341 private javax.swing.JTextField txtPrefix; 342 private javax.swing.JTextField txtProjectName; 343 345 } | Popular Tags |