1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.options; 21 22 import java.awt.Component ; 23 import javax.swing.JTextField ; 24 import javax.swing.event.DocumentEvent ; 25 import javax.swing.event.DocumentListener ; 26 import javax.swing.text.JTextComponent ; 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.netbeans.modules.apisupport.project.ui.wizard.options.NewOptionsIterator.DataModel; 31 import org.openide.WizardDescriptor; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 35 38 final class OptionsPanel extends BasicWizardIterator.Panel { 39 40 private final DataModel data; 41 private DocumentListener updateListener; 42 43 44 public OptionsPanel(final WizardDescriptor setting, final DataModel data) { 45 super(setting); 46 this.data = data; 47 initComponents(); 48 initAccessibility(); 49 if (data.getPackageName() != null) { 50 packageName.setSelectedItem(data.getPackageName()); 51 } 52 putClientProperty("NewFileWizard_Title", getMessage("LBL_OptionsWizardTitle")); 53 54 } 55 56 private void addListeners() { 57 if (updateListener == null) { 58 updateListener = new UIUtil.DocumentAdapter() { 59 public void insertUpdate(DocumentEvent e) { 60 updateData(); 61 } 62 }; 63 64 txtPrefix.getDocument().addDocumentListener(updateListener); 65 Component editorComp = packageName.getEditor().getEditorComponent(); 66 if (editorComp instanceof JTextComponent ) { 67 ((JTextComponent ) editorComp).getDocument().addDocumentListener(updateListener); 68 } 69 } 70 } 71 72 private void removeListeners() { 73 if (updateListener != null) { 74 txtPrefix.getDocument().removeDocumentListener(updateListener); 75 Component editorComp = packageName.getEditor().getEditorComponent(); 76 if (editorComp instanceof JTextComponent ) { 77 ((JTextComponent ) editorComp).getDocument().removeDocumentListener(updateListener); 78 } 79 updateListener = null; 80 } 81 } 82 83 protected void storeToDataModel() { 84 removeListeners(); 85 updateData(); 86 } 87 88 protected void readFromDataModel() { 89 addListeners(); 90 txtPrefix.setText(data.getClassNamePrefix()); 91 } 92 93 public void removeNotify() { 94 super.removeNotify(); 95 removeListeners(); 96 } 97 98 public void addNotify() { 99 super.addNotify(); 100 addListeners(); 101 updateData(); 102 } 103 104 private void updateData() { 105 int errCode = data.setPackageAndPrefix( 106 packageName.getEditor().getItem().toString(),txtPrefix.getText()); 107 data.getCreatedModifiedFiles(); 108 createdFilesValue.setText(UIUtil.generateTextAreaContent( 109 data.getCreatedModifiedFiles().getCreatedPaths())); 110 modifiedFilesValue.setText(UIUtil.generateTextAreaContent( 111 data.getCreatedModifiedFiles().getModifiedPaths())); 112 113 String [] invalid = data.getCreatedModifiedFiles().getInvalidPaths(); 115 if (data.isErrorCode(errCode)) { 116 setError(data.getErrorMessage(errCode)); } else if (invalid.length > 0) { 118 setError(NbBundle.getMessage(OptionsPanel.class, "ERR_ToBeCreateFileExists", invalid[0])); } else if (data.isSuccessCode(errCode)) { 120 markValid(); 121 } 122 } 123 124 125 protected String getPanelName() { 126 return getMessage("LBL_OptionsPanel1_Title"); 127 } 128 129 protected HelpCtx getHelp() { 130 return new HelpCtx(OptionsPanel.class); 131 } 132 133 private static String getMessage(String key) { 134 return NbBundle.getMessage(OptionsPanel.class, key); 135 } 136 137 private void initAccessibility() { 138 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_OptionsPanel")); 139 projectNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ProjectName")); 140 packageName.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_PackageName")); 141 createdFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CreatedFilesValue")); 142 modifiedFilesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ModifiedFilesValue")); 143 txtPrefix.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL__ClassNamePrefix")); 144 } 145 146 151 private void initComponents() { 153 java.awt.GridBagConstraints gridBagConstraints; 154 155 projectName = new javax.swing.JLabel (); 156 projectNameValue = new JTextField (ProjectUtils.getInformation(this.data.getProject()).getDisplayName()); 157 createdFiles = new javax.swing.JLabel (); 158 modifiedFiles = new javax.swing.JLabel (); 159 createdFilesValueS = new javax.swing.JScrollPane (); 160 createdFilesValue = new javax.swing.JTextArea (); 161 modifiedFilesValueS = new javax.swing.JScrollPane (); 162 modifiedFilesValue = new javax.swing.JTextArea (); 163 packageName = UIUtil.createPackageComboBox(data.getSourceRootGroup()); 164 packageNameTxt = new javax.swing.JLabel (); 165 lblPrefix = new javax.swing.JLabel (); 166 txtPrefix = new javax.swing.JTextField (); 167 168 setLayout(new java.awt.GridBagLayout ()); 169 170 projectName.setLabelFor(projectNameValue); 171 org.openide.awt.Mnemonics.setLocalizedText(projectName, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_ProjectName")); 172 gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 0; 174 gridBagConstraints.gridy = 0; 175 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 176 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 12); 177 add(projectName, gridBagConstraints); 178 179 projectNameValue.setEditable(false); 180 gridBagConstraints = new java.awt.GridBagConstraints (); 181 gridBagConstraints.gridx = 1; 182 gridBagConstraints.gridy = 0; 183 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 184 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 185 gridBagConstraints.weightx = 1.0; 186 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 187 add(projectNameValue, gridBagConstraints); 188 189 createdFiles.setLabelFor(createdFilesValue); 190 org.openide.awt.Mnemonics.setLocalizedText(createdFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_CreatedFiles")); 191 gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.gridx = 0; 193 gridBagConstraints.gridy = 3; 194 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 195 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 196 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 12); 197 add(createdFiles, gridBagConstraints); 198 199 modifiedFiles.setLabelFor(modifiedFilesValue); 200 org.openide.awt.Mnemonics.setLocalizedText(modifiedFiles, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_ModifiedFiles")); 201 gridBagConstraints = new java.awt.GridBagConstraints (); 202 gridBagConstraints.gridx = 0; 203 gridBagConstraints.gridy = 4; 204 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 205 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 206 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 207 add(modifiedFiles, gridBagConstraints); 208 209 createdFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 210 createdFilesValue.setColumns(20); 211 createdFilesValue.setEditable(false); 212 createdFilesValue.setRows(5); 213 createdFilesValue.setBorder(null); 214 createdFilesValueS.setViewportView(createdFilesValue); 215 216 gridBagConstraints = new java.awt.GridBagConstraints (); 217 gridBagConstraints.gridx = 1; 218 gridBagConstraints.gridy = 3; 219 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 220 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 221 gridBagConstraints.weightx = 1.0; 222 gridBagConstraints.weighty = 0.5; 223 gridBagConstraints.insets = new java.awt.Insets (18, 0, 6, 0); 224 add(createdFilesValueS, gridBagConstraints); 225 226 modifiedFilesValue.setBackground(javax.swing.UIManager.getDefaults().getColor("Label.background")); 227 modifiedFilesValue.setColumns(20); 228 modifiedFilesValue.setEditable(false); 229 modifiedFilesValue.setRows(5); 230 modifiedFilesValue.setToolTipText("modifiedFilesValue"); 231 modifiedFilesValue.setBorder(null); 232 modifiedFilesValueS.setViewportView(modifiedFilesValue); 233 234 gridBagConstraints = new java.awt.GridBagConstraints (); 235 gridBagConstraints.gridx = 1; 236 gridBagConstraints.gridy = 4; 237 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 238 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 239 gridBagConstraints.weightx = 1.0; 240 gridBagConstraints.weighty = 0.5; 241 add(modifiedFilesValueS, gridBagConstraints); 242 243 packageName.setEditable(true); 244 gridBagConstraints = new java.awt.GridBagConstraints (); 245 gridBagConstraints.gridx = 1; 246 gridBagConstraints.gridy = 2; 247 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 248 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 249 gridBagConstraints.weightx = 1.0; 250 add(packageName, gridBagConstraints); 251 252 packageNameTxt.setLabelFor(packageName); 253 org.openide.awt.Mnemonics.setLocalizedText(packageNameTxt, org.openide.util.NbBundle.getMessage(OptionsPanel.class, "LBL_PackageName")); 254 gridBagConstraints = new java.awt.GridBagConstraints (); 255 gridBagConstraints.gridx = 0; 256 gridBagConstraints.gridy = 2; 257 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 258 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 259 add(packageNameTxt, gridBagConstraints); 260 261 lblPrefix.setLabelFor(txtPrefix); 262 org.openide.awt.Mnemonics.setLocalizedText(lblPrefix, org.openide.util.NbBundle.getMessage(OptionsPanel.class, "LBL_Prefix")); 263 gridBagConstraints = new java.awt.GridBagConstraints (); 264 gridBagConstraints.gridx = 0; 265 gridBagConstraints.gridy = 1; 266 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 267 gridBagConstraints.insets = new java.awt.Insets (12, 0, 6, 12); 268 add(lblPrefix, gridBagConstraints); 269 270 gridBagConstraints = new java.awt.GridBagConstraints (); 271 gridBagConstraints.gridx = 1; 272 gridBagConstraints.gridy = 1; 273 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 274 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 275 gridBagConstraints.weightx = 1.0; 276 gridBagConstraints.insets = new java.awt.Insets (12, 0, 6, 0); 277 add(txtPrefix, gridBagConstraints); 278 279 } 281 private javax.swing.JLabel createdFiles; 283 private javax.swing.JTextArea createdFilesValue; 284 private javax.swing.JScrollPane createdFilesValueS; 285 private javax.swing.JLabel lblPrefix; 286 private javax.swing.JLabel modifiedFiles; 287 private javax.swing.JTextArea modifiedFilesValue; 288 private javax.swing.JScrollPane modifiedFilesValueS; 289 private javax.swing.JComboBox packageName; 290 private javax.swing.JLabel packageNameTxt; 291 private javax.swing.JLabel projectName; 292 private javax.swing.JTextField projectNameValue; 293 private javax.swing.JTextField txtPrefix; 294 296 } 297 | Popular Tags |