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