1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.librarydescriptor; 21 22 import javax.swing.JTextField ; 23 import javax.swing.event.DocumentEvent ; 24 import javax.swing.event.DocumentListener ; 25 import org.netbeans.api.project.ProjectUtils; 26 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles; 27 import org.netbeans.modules.apisupport.project.ui.UIUtil; 28 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator; 29 import org.openide.WizardDescriptor; 30 import org.openide.util.HelpCtx; 31 import org.openide.util.NbBundle; 32 33 38 final class NameAndLocationPanel extends BasicWizardIterator.Panel { 39 40 private NewLibraryDescriptor.DataModel data; 41 42 43 public NameAndLocationPanel(final WizardDescriptor setting, final NewLibraryDescriptor.DataModel data) { 44 super(setting); 45 this.data = data; 46 initComponents(); 47 initAccessibility(); 48 putClientProperty("NewFileWizard_Title", NbBundle.getMessage(NameAndLocationPanel.class,"LBL_LibraryWizardTitle")); 51 DocumentListener dListener = new UIUtil.DocumentAdapter() { 52 public void insertUpdate(DocumentEvent e) { 53 NewLibraryDescriptor.DataModel _data = getTemporaryDataModel(); 54 setEnabledForFilesInfo(checkValidity(_data)); 55 setFilesInfoIntoTextAreas(_data); 56 } 57 }; 58 libraryNameVale.getDocument().addDocumentListener(dListener); 59 libraryDisplayNameValue.getDocument().addDocumentListener(dListener); 60 } 61 62 private static String getMessage(String key) { 63 return NbBundle.getMessage(NameAndLocationPanel.class, key); 64 } 65 66 private void initAccessibility() { 67 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NameIconLocationPanel")); 68 createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_CreatedFiles")); 69 modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_ModifiedFiles")); 70 libraryDisplayNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_DisplayName")); 71 libraryNameVale.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_Name")); 72 projectNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_ProjectName")); 73 } 74 75 protected void storeToDataModel() { 76 NewLibraryDescriptor.DataModel _temp = getTemporaryDataModel(); 77 data.setLibraryName(_temp.getLibraryName()); 78 data.setLibraryDisplayName(_temp.getLibraryDisplayName()); 79 data.setCreatedModifiedFiles(_temp.getCreatedModifiedFiles()); 80 } 81 82 private NewLibraryDescriptor.DataModel getTemporaryDataModel() { 83 NewLibraryDescriptor.DataModel _temp = data.cloneMe(getSettings()); 84 _temp.setLibraryName(libraryNameVale.getText()); 85 _temp.setLibraryDisplayName(libraryDisplayNameValue.getText()); 86 if (_temp.isValidLibraryDisplayName() && _temp.isValidLibraryName()) { 87 CreatedModifiedFiles files = CreatedModifiedFilesProvider.createInstance(_temp); 88 _temp.setCreatedModifiedFiles(files); 89 } 90 return _temp; 91 } 92 93 private void setEnabledForFilesInfo(boolean enabled) { 94 createdFilesValue.setEnabled(enabled); 95 modifiedFilesValue.setEnabled(enabled); 96 } 97 98 private void setFilesInfoIntoTextAreas(final NewLibraryDescriptor.DataModel _temp) { 99 if (_temp.getCreatedModifiedFiles() != null) { 100 createdFilesValue.setText(UIUtil.generateTextAreaContent( 101 _temp.getCreatedModifiedFiles().getCreatedPaths())); 102 modifiedFilesValue.setText(UIUtil.generateTextAreaContent( 103 _temp.getCreatedModifiedFiles().getModifiedPaths())); 104 } 105 } 106 107 protected void readFromDataModel() { 108 libraryNameVale.setText(this.data.getLibrary().getName()); 109 libraryDisplayNameValue.setText(this.data.getLibrary().getDisplayName()); 110 checkValidity(getTemporaryDataModel()); 111 } 112 113 protected String getPanelName() { 114 return NbBundle.getMessage(NameAndLocationPanel.class,"LBL_NameAndLocation_Title"); } 116 117 118 private boolean checkValidity(final NewLibraryDescriptor.DataModel _data) { 119 if (!_data.isValidLibraryName()) { 120 setError(NbBundle.getMessage(NameAndLocationPanel.class,"ERR_EmptyName")); return false; 122 } else if (!_data.isValidLibraryDisplayName()) { 123 setError(NbBundle.getMessage(NameAndLocationPanel.class,"ERR_EmptyDescName")); return false; 125 }else if (_data.libraryAlreadyExists()) { 126 setError(NbBundle.getMessage(NameAndLocationPanel.class, 127 "ERR_LibraryExists", _data.getLibraryName())); 128 return false; 129 } 130 markValid(); 131 return true; 132 } 133 134 protected HelpCtx getHelp() { 135 return new HelpCtx(NameAndLocationPanel.class); 136 } 137 138 public void addNotify() { 139 super.addNotify(); 140 checkValidity(getTemporaryDataModel()); 141 } 142 143 148 private void initComponents() { 150 java.awt.GridBagConstraints gridBagConstraints; 151 152 libraryName = new javax.swing.JLabel (); 153 libraryNameVale = new javax.swing.JTextField (); 154 libraryDisplayName = new javax.swing.JLabel (); 155 libraryDisplayNameValue = new javax.swing.JTextField (); 156 projectName = new javax.swing.JLabel (); 157 projectNameValue = new JTextField (ProjectUtils.getInformation(this.data.getProject()).getDisplayName()); 158 createdFiles = new javax.swing.JLabel (); 159 modifiedFiles = new javax.swing.JLabel (); 160 createdFilesValueS = new javax.swing.JScrollPane (); 161 createdFilesValue = new javax.swing.JTextArea (); 162 modifiedFilesValueS = new javax.swing.JScrollPane (); 163 modifiedFilesValue = new javax.swing.JTextArea (); 164 165 setLayout(new java.awt.GridBagLayout ()); 166 167 libraryName.setLabelFor(libraryNameVale); 168 org.openide.awt.Mnemonics.setLocalizedText(libraryName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_LibraryName")); 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 0; 171 gridBagConstraints.gridy = 0; 172 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 173 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 12); 174 add(libraryName, gridBagConstraints); 175 176 gridBagConstraints = new java.awt.GridBagConstraints (); 177 gridBagConstraints.gridx = 1; 178 gridBagConstraints.gridy = 0; 179 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 180 gridBagConstraints.weightx = 1.0; 181 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 0); 182 add(libraryNameVale, gridBagConstraints); 183 184 libraryDisplayName.setLabelFor(libraryDisplayNameValue); 185 org.openide.awt.Mnemonics.setLocalizedText(libraryDisplayName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_LibraryDisplayName")); 186 gridBagConstraints = new java.awt.GridBagConstraints (); 187 gridBagConstraints.gridx = 0; 188 gridBagConstraints.gridy = 1; 189 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 190 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 191 add(libraryDisplayName, gridBagConstraints); 192 193 gridBagConstraints = new java.awt.GridBagConstraints (); 194 gridBagConstraints.gridx = 1; 195 gridBagConstraints.gridy = 1; 196 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 197 gridBagConstraints.weightx = 1.0; 198 add(libraryDisplayNameValue, gridBagConstraints); 199 200 projectName.setLabelFor(projectNameValue); 201 org.openide.awt.Mnemonics.setLocalizedText(projectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ProjectName")); 202 gridBagConstraints = new java.awt.GridBagConstraints (); 203 gridBagConstraints.gridx = 0; 204 gridBagConstraints.gridy = 2; 205 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 206 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 12); 207 add(projectName, gridBagConstraints); 208 209 projectNameValue.setEditable(false); 210 gridBagConstraints = new java.awt.GridBagConstraints (); 211 gridBagConstraints.gridx = 1; 212 gridBagConstraints.gridy = 2; 213 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 214 gridBagConstraints.weightx = 1.0; 215 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 0); 216 add(projectNameValue, gridBagConstraints); 217 218 createdFiles.setLabelFor(createdFilesValue); 219 org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_CreatedFiles")); 220 gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.gridx = 0; 222 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 223 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 224 gridBagConstraints.insets = new java.awt.Insets (36, 0, 6, 12); 225 add(createdFiles, gridBagConstraints); 226 227 modifiedFiles.setLabelFor(modifiedFilesValue); 228 org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/librarydescriptor/Bundle").getString("LBL_ModifiedFiles")); 229 gridBagConstraints = new java.awt.GridBagConstraints (); 230 gridBagConstraints.gridx = 0; 231 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 232 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 233 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 234 add(modifiedFiles, gridBagConstraints); 235 236 createdFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 237 createdFilesValue.setColumns(20); 238 createdFilesValue.setEditable(false); 239 createdFilesValue.setRows(5); 240 createdFilesValue.setBorder(null); 241 createdFilesValueS.setViewportView(createdFilesValue); 242 243 gridBagConstraints = new java.awt.GridBagConstraints (); 244 gridBagConstraints.gridx = 1; 245 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 246 gridBagConstraints.weightx = 1.0; 247 gridBagConstraints.weighty = 1.0; 248 gridBagConstraints.insets = new java.awt.Insets (36, 0, 6, 0); 249 add(createdFilesValueS, gridBagConstraints); 250 251 modifiedFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 252 modifiedFilesValue.setColumns(20); 253 modifiedFilesValue.setEditable(false); 254 modifiedFilesValue.setRows(5); 255 modifiedFilesValue.setToolTipText("modifiedFilesValue"); 256 modifiedFilesValue.setBorder(null); 257 modifiedFilesValueS.setViewportView(modifiedFilesValue); 258 259 gridBagConstraints = new java.awt.GridBagConstraints (); 260 gridBagConstraints.gridx = 1; 261 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 262 gridBagConstraints.weightx = 1.0; 263 add(modifiedFilesValueS, gridBagConstraints); 264 265 } 267 private javax.swing.JLabel createdFiles; 269 private javax.swing.JTextArea createdFilesValue; 270 private javax.swing.JScrollPane createdFilesValueS; 271 private javax.swing.JLabel libraryDisplayName; 272 private javax.swing.JTextField libraryDisplayNameValue; 273 private javax.swing.JLabel libraryName; 274 private javax.swing.JTextField libraryNameVale; 275 private javax.swing.JLabel modifiedFiles; 276 private javax.swing.JTextArea modifiedFilesValue; 277 private javax.swing.JScrollPane modifiedFilesValueS; 278 private javax.swing.JLabel projectName; 279 private javax.swing.JTextField projectNameValue; 280 282 } 283 | Popular Tags |