1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.loader; 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 NewLoaderIterator.DataModel data; 43 44 45 public NameAndLocationPanel(final WizardDescriptor setting, final NewLoaderIterator.DataModel data) { 46 super(setting); 47 this.data = data; 48 initComponents(); 49 initAccessibility(); 50 putClientProperty("NewFileWizard_Title", getMessage("LBL_LoaderWizardTitle")); 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.setIconPath(icon.length() == 0 ? (String )null : icon); 76 data.setPrefix(txtPrefix.getText().trim()); 77 NewLoaderIterator.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 protected void readFromDataModel() { 90 if (data.getPackageName() != null) { 91 comPackageName.setSelectedItem(data.getPackageName()); 92 } 93 txtPrefix.setText(data.getPrefix()); 94 txtIcon.setText(data.getPrefix()); 95 checkValidity(); 96 } 97 98 protected String getPanelName() { 99 return getMessage("LBL_NameLocation_Title"); 100 } 101 102 private boolean checkValidity() { 103 if (txtPrefix.getText().trim().length() == 0) { 104 setError(getMessage("ERR_Name_Prefix_Empty")); 105 return false; 106 } 107 if (!Utilities.isJavaIdentifier(txtPrefix.getText().trim())) { 108 setError(getMessage("ERR_Name_Prefix_Invalid")); 109 return false; 110 } 111 String path = txtIcon.getText().trim(); 112 if (path.length() != 0) { 113 File fil = new File (path); 114 if (!fil.exists()) { 115 setError(NbBundle.getMessage(getClass(), "ERR_Icon_Invalid")); 116 return false; 117 } 118 } 119 String packageName = comPackageName.getEditor().getItem().toString().trim(); 120 121 if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) { setError(NbBundle.getMessage(getClass(), "ERR_Package_Invalid")); 123 return false; 124 } 125 126 File icon = (path.length() == 0) ? null : new File (path); 127 if (icon == null || !icon.exists()) { 128 setWarning(UIUtil.getNoIconSelectedWarning(16,16)); 129 } else if (!UIUtil.isValidIcon(icon,16,16)) { 130 setWarning(UIUtil.getIconDimensionWarning(icon,16,16)); 131 } else { 132 markValid(); 133 } 134 return true; 135 } 136 137 protected HelpCtx getHelp() { 138 return new HelpCtx(NameAndLocationPanel.class); 139 } 140 141 private static String getMessage(String key) { 142 return NbBundle.getMessage(NameAndLocationPanel.class, key); 143 } 144 145 150 private void initComponents() { 152 java.awt.GridBagConstraints gridBagConstraints; 153 154 lblPrefix = new javax.swing.JLabel (); 155 txtPrefix = new javax.swing.JTextField (); 156 lblIcon = new javax.swing.JLabel (); 157 txtIcon = new javax.swing.JTextField (); 158 btnIcon = new javax.swing.JButton (); 159 lblProjectName = new javax.swing.JLabel (); 160 txtProjectName = new JTextField (ProjectUtils.getInformation(this.data.getProject()).getDisplayName()); 161 lblPackageName = new javax.swing.JLabel (); 162 comPackageName = UIUtil.createPackageComboBox(data.getSourceRootGroup()); 163 createdFiles = new javax.swing.JLabel (); 164 modifiedFiles = new javax.swing.JLabel (); 165 filler = new javax.swing.JLabel (); 166 createdFilesValue = new javax.swing.JTextArea (); 167 modifiedFilesValue = new javax.swing.JTextArea (); 168 169 setLayout(new java.awt.GridBagLayout ()); 170 171 lblPrefix.setLabelFor(txtPrefix); 172 org.openide.awt.Mnemonics.setLocalizedText(lblPrefix, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Prefix")); 173 gridBagConstraints = new java.awt.GridBagConstraints (); 174 gridBagConstraints.gridx = 0; 175 gridBagConstraints.gridy = 0; 176 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 177 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 12); 178 add(lblPrefix, gridBagConstraints); 179 180 gridBagConstraints = new java.awt.GridBagConstraints (); 181 gridBagConstraints.gridx = 1; 182 gridBagConstraints.gridy = 0; 183 gridBagConstraints.gridwidth = 2; 184 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 185 gridBagConstraints.weightx = 1.0; 186 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 0); 187 add(txtPrefix, gridBagConstraints); 188 189 lblIcon.setLabelFor(txtIcon); 190 org.openide.awt.Mnemonics.setLocalizedText(lblIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon")); 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.gridx = 0; 193 gridBagConstraints.gridy = 1; 194 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 195 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 196 add(lblIcon, gridBagConstraints); 197 198 gridBagConstraints = new java.awt.GridBagConstraints (); 199 gridBagConstraints.gridx = 1; 200 gridBagConstraints.gridy = 1; 201 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 202 gridBagConstraints.weightx = 1.0; 203 add(txtIcon, gridBagConstraints); 204 205 org.openide.awt.Mnemonics.setLocalizedText(btnIcon, org.openide.util.NbBundle.getMessage(NameAndLocationPanel.class, "LBL_Icon_Browse")); 206 btnIcon.addActionListener(new java.awt.event.ActionListener () { 207 public void actionPerformed(java.awt.event.ActionEvent evt) { 208 btnIconActionPerformed(evt); 209 } 210 }); 211 212 gridBagConstraints = new java.awt.GridBagConstraints (); 213 gridBagConstraints.gridx = 2; 214 gridBagConstraints.gridy = 1; 215 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 216 add(btnIcon, gridBagConstraints); 217 218 lblProjectName.setLabelFor(txtProjectName); 219 org.openide.awt.Mnemonics.setLocalizedText(lblProjectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ProjectName")); 220 gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.gridx = 0; 222 gridBagConstraints.gridy = 2; 223 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 224 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 12); 225 add(lblProjectName, gridBagConstraints); 226 227 txtProjectName.setEditable(false); 228 gridBagConstraints = new java.awt.GridBagConstraints (); 229 gridBagConstraints.gridx = 1; 230 gridBagConstraints.gridy = 2; 231 gridBagConstraints.gridwidth = 2; 232 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 233 gridBagConstraints.weightx = 1.0; 234 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 0); 235 add(txtProjectName, gridBagConstraints); 236 237 lblPackageName.setLabelFor(comPackageName); 238 org.openide.awt.Mnemonics.setLocalizedText(lblPackageName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_PackageName")); 239 gridBagConstraints = new java.awt.GridBagConstraints (); 240 gridBagConstraints.gridx = 0; 241 gridBagConstraints.gridy = 3; 242 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 243 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 244 add(lblPackageName, gridBagConstraints); 245 246 comPackageName.setEditable(true); 247 gridBagConstraints = new java.awt.GridBagConstraints (); 248 gridBagConstraints.gridx = 1; 249 gridBagConstraints.gridy = 3; 250 gridBagConstraints.gridwidth = 2; 251 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 252 gridBagConstraints.weightx = 1.0; 253 add(comPackageName, gridBagConstraints); 254 255 createdFiles.setLabelFor(createdFilesValue); 256 org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_CreatedFiles")); 257 gridBagConstraints = new java.awt.GridBagConstraints (); 258 gridBagConstraints.gridx = 0; 259 gridBagConstraints.gridy = 4; 260 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 261 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 262 gridBagConstraints.insets = new java.awt.Insets (36, 0, 6, 12); 263 add(createdFiles, gridBagConstraints); 264 265 modifiedFiles.setLabelFor(modifiedFilesValue); 266 org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ModifiedFiles")); 267 gridBagConstraints = new java.awt.GridBagConstraints (); 268 gridBagConstraints.gridx = 0; 269 gridBagConstraints.gridy = 5; 270 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 271 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 272 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 273 add(modifiedFiles, gridBagConstraints); 274 275 gridBagConstraints = new java.awt.GridBagConstraints (); 276 gridBagConstraints.gridx = 0; 277 gridBagConstraints.gridy = 6; 278 gridBagConstraints.gridwidth = 3; 279 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 280 gridBagConstraints.weightx = 1.0; 281 gridBagConstraints.weighty = 1.0; 282 add(filler, gridBagConstraints); 283 284 createdFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 285 createdFilesValue.setColumns(20); 286 createdFilesValue.setEditable(false); 287 createdFilesValue.setRows(5); 288 createdFilesValue.setBorder(null); 289 gridBagConstraints = new java.awt.GridBagConstraints (); 290 gridBagConstraints.gridx = 1; 291 gridBagConstraints.gridy = 4; 292 gridBagConstraints.gridwidth = 2; 293 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 294 gridBagConstraints.weightx = 1.0; 295 gridBagConstraints.insets = new java.awt.Insets (36, 0, 6, 0); 296 add(createdFilesValue, gridBagConstraints); 297 298 modifiedFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 299 modifiedFilesValue.setColumns(20); 300 modifiedFilesValue.setEditable(false); 301 modifiedFilesValue.setRows(5); 302 modifiedFilesValue.setToolTipText("modifiedFilesValue"); 303 modifiedFilesValue.setBorder(null); 304 gridBagConstraints = new java.awt.GridBagConstraints (); 305 gridBagConstraints.gridx = 1; 306 gridBagConstraints.gridy = 5; 307 gridBagConstraints.gridwidth = 2; 308 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 309 gridBagConstraints.weightx = 1.0; 310 add(modifiedFilesValue, gridBagConstraints); 311 312 } 313 315 private void btnIconActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = UIUtil.getIconFileChooser(txtIcon.getText()); 317 int ret = chooser.showDialog(this, getMessage("LBL_Select")); if (ret == JFileChooser.APPROVE_OPTION) { 319 File file = chooser.getSelectedFile(); 320 txtIcon.setText(file.getAbsolutePath()); 321 } 322 } 324 private javax.swing.JButton btnIcon; 326 private javax.swing.JComboBox comPackageName; 327 private javax.swing.JLabel createdFiles; 328 private javax.swing.JTextArea createdFilesValue; 329 private javax.swing.JLabel filler; 330 private javax.swing.JLabel lblIcon; 331 private javax.swing.JLabel lblPackageName; 332 private javax.swing.JLabel lblPrefix; 333 private javax.swing.JLabel lblProjectName; 334 private javax.swing.JLabel modifiedFiles; 335 private javax.swing.JTextArea modifiedFilesValue; 336 private javax.swing.JTextField txtIcon; 337 private javax.swing.JTextField txtPrefix; 338 private javax.swing.JTextField txtProjectName; 339 341 private void initAccessibility() { 342 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameAndLocationPanel")); 343 comPackageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName")); 344 txtIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Icon")); 345 txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Prefix")); 346 btnIcon.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton")); 347 txtProjectName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName")); 348 createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue")); 349 modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue")); 350 } 351 352 } | Popular Tags |