1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Iterator ; 25 import javax.swing.event.DocumentEvent ; 26 import javax.swing.event.DocumentListener ; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.api.project.ProjectManager; 29 import org.netbeans.api.project.ProjectUtils; 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.customizer.SuiteUtils; 33 import org.openide.ErrorManager; 34 import org.openide.filesystems.FileObject; 35 import org.openide.filesystems.FileUtil; 36 import org.openide.util.NbBundle; 37 38 52 final class BasicConfVisualPanel extends BasicVisualPanel.NewTemplatePanel { 53 54 static final String EXAMPLE_BASE_NAME = "org.yourorghere."; 56 private boolean wasLayerUpdated; 57 private boolean wasBundleUpdated; 58 59 private boolean listenersAttached; 60 private final DocumentListener cnbDL; 61 private final DocumentListener layerDL; 62 private final DocumentListener bundleDL; 63 64 public BasicConfVisualPanel(final NewModuleProjectData data) { 65 super(data); 66 initComponents(); 67 initAccessibility(); 68 cnbDL = new UIUtil.DocumentAdapter() { 69 public void insertUpdate(DocumentEvent e) { checkCodeNameBase(); } 70 }; 71 if (isLibraryWizard()) { 72 layer.setVisible(false); 74 layerValue.setVisible(false); 75 layerDL = null; 76 } else { 77 layerDL = new UIUtil.DocumentAdapter() { 78 public void insertUpdate(DocumentEvent e) { wasLayerUpdated = true; checkLayer(); } 79 }; 80 } 81 bundleDL = new UIUtil.DocumentAdapter() { 82 public void insertUpdate(DocumentEvent e) { wasBundleUpdated = true; checkBundle(); } 83 }; 84 } 85 86 private void initAccessibility() { 87 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_BasicConfVisualPanel")); 88 bundleValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_BundleValue")); 89 codeNameBaseValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CodeNameBaseValue")); 90 displayNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_DisplayNameValue")); 91 layerValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_LayerValue")); 92 } 93 94 private void checkCodeNameBase() { 95 if (!Util.isValidJavaFQN(getCodeNameBaseValue())) { 96 setError(getMessage("MSG_InvalidCNB")); 97 } else if (getData().isSuiteComponent() && cnbIsAlreadyInSuite(getData().getSuiteRoot(), getCodeNameBaseValue())) { 98 setError(NbBundle.getMessage(BasicConfVisualPanel.class, "MSG_ComponentWithSuchCNBAlreadyInSuite", 99 getCodeNameBaseValue())); 100 } else { 101 markValid(); 102 String dotName = getCodeNameBaseValue(); 104 String slashName = dotName.replace('.', '/'); 105 if (!wasBundleUpdated) { 106 bundleValue.setText(slashName + "/Bundle.properties"); wasBundleUpdated = false; 108 } 109 if (!wasLayerUpdated && !isLibraryWizard()) { 110 layerValue.setText(slashName + "/layer.xml"); wasLayerUpdated = false; 112 } 113 } 114 } 115 116 private void checkBundle() { 117 checkEntry(getBundleValue(), "bundle", ".properties"); } 119 120 private void checkLayer() { 121 checkEntry(getLayerValue(), "layer", ".xml"); } 123 124 125 private void checkEntry(String path, String resName, String extension) { 126 if (path.length() == 0) { 127 setError(NbBundle.getMessage(BasicConfVisualPanel.class, "BasicConfVisualPanel_err_" + resName + "_empty")); 128 return; 129 } 130 if (path.indexOf('/') == -1) { 131 setError(NbBundle.getMessage(BasicConfVisualPanel.class, "BasicConfVisualPanel_err_" + resName + "_def_pkg")); 132 return; 133 } 134 if (!path.endsWith(extension)) { 135 setError(NbBundle.getMessage(BasicConfVisualPanel.class, "BasicConfVisualPanel_err_" + resName + "_ext", extension)); 136 return; 137 } 138 markValid(); 139 } 140 141 void refreshData() { 142 String cnb = getData().getCodeNameBase(); 143 codeNameBaseValue.setText(cnb); 144 if (cnb.startsWith(EXAMPLE_BASE_NAME)) { 145 codeNameBaseValue.select(0, EXAMPLE_BASE_NAME.length() - 1); 146 } 147 String dn = getData().getProjectDisplayName(); 148 displayNameValue.setText(dn); 149 checkCodeNameBase(); 150 } 151 152 153 void storeData() { 154 getData().setCodeNameBase(getCodeNameBaseValue()); 156 getData().setProjectDisplayName(displayNameValue.getText()); 157 getData().setBundle(getBundleValue()); 158 if (!isLibraryWizard()) { 159 getData().setLayer(getLayerValue()); 160 } 161 } 162 163 private String getCodeNameBaseValue() { 164 return codeNameBaseValue.getText().trim(); 165 } 166 167 private String getBundleValue() { 168 return bundleValue.getText().trim(); 169 } 170 171 private String getLayerValue() { 172 return layerValue.getText().trim(); 173 } 174 175 private boolean cnbIsAlreadyInSuite(String suiteDir, String cnb) { 176 boolean result = false; 177 FileObject suiteDirFO = FileUtil.toFileObject(new File (suiteDir)); 178 try { 179 Project suite = ProjectManager.getDefault().findProject(suiteDirFO); 180 for (Iterator it = SuiteUtils.getSubProjects(suite).iterator(); it.hasNext();) { 181 Project p = (Project) it.next(); 182 if (ProjectUtils.getInformation(p).getName().equals(cnb)) { 183 result = true; 184 break; 185 } 186 } 187 } catch (IOException e) { 188 Util.err.notify(ErrorManager.INFORMATIONAL, e); 189 } 190 return result; 191 } 192 193 public void addNotify() { 194 super.addNotify(); 195 attachDocumentListeners(); 196 } 197 198 public void removeNotify() { 199 removeDocumentListeners(); 201 super.removeNotify(); 202 } 203 204 private void attachDocumentListeners() { 205 if (!listenersAttached) { 206 codeNameBaseValue.getDocument().addDocumentListener(cnbDL); 207 bundleValue.getDocument().addDocumentListener(bundleDL); 208 if (!isLibraryWizard()) { 209 layerValue.getDocument().addDocumentListener(layerDL); 210 } 211 listenersAttached = true; 212 } 213 } 214 215 private void removeDocumentListeners() { 216 if (listenersAttached) { 217 codeNameBaseValue.getDocument().removeDocumentListener(cnbDL); 218 bundleValue.getDocument().removeDocumentListener(bundleDL); 219 if (!isLibraryWizard()) { 220 layerValue.getDocument().removeDocumentListener(layerDL); 221 } 222 listenersAttached = false; 223 } 224 } 225 226 private static String getMessage(String key) { 227 return NbBundle.getMessage(BasicConfVisualPanel.class, key); 228 } 229 230 235 private void initComponents() { 237 java.awt.GridBagConstraints gridBagConstraints; 238 239 confPanel = new javax.swing.JPanel (); 240 codeNameBase = new javax.swing.JLabel (); 241 displayName = new javax.swing.JLabel (); 242 bundle = new javax.swing.JLabel (); 243 layer = new javax.swing.JLabel (); 244 codeNameBaseValue = new javax.swing.JTextField (); 245 displayNameValue = new javax.swing.JTextField (); 246 bundleValue = new javax.swing.JTextField (); 247 layerValue = new javax.swing.JTextField (); 248 filler = new javax.swing.JLabel (); 249 250 setLayout(new java.awt.GridBagLayout ()); 251 252 confPanel.setLayout(new java.awt.GridBagLayout ()); 253 254 codeNameBase.setLabelFor(codeNameBaseValue); 255 org.openide.awt.Mnemonics.setLocalizedText(codeNameBase, org.openide.util.NbBundle.getMessage(BasicConfVisualPanel.class, "LBL_CodeNameBase")); 256 gridBagConstraints = new java.awt.GridBagConstraints (); 257 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 258 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 12); 259 confPanel.add(codeNameBase, gridBagConstraints); 260 261 displayName.setLabelFor(displayNameValue); 262 org.openide.awt.Mnemonics.setLocalizedText(displayName, org.openide.util.NbBundle.getMessage(BasicConfVisualPanel.class, "LBL_ModuleDisplayName")); 263 gridBagConstraints = new java.awt.GridBagConstraints (); 264 gridBagConstraints.gridx = 0; 265 gridBagConstraints.gridy = 1; 266 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 267 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 268 confPanel.add(displayName, gridBagConstraints); 269 270 bundle.setLabelFor(bundleValue); 271 org.openide.awt.Mnemonics.setLocalizedText(bundle, org.openide.util.NbBundle.getMessage(BasicConfVisualPanel.class, "LBL_LocalizingBundle")); 272 gridBagConstraints = new java.awt.GridBagConstraints (); 273 gridBagConstraints.gridx = 0; 274 gridBagConstraints.gridy = 2; 275 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 276 gridBagConstraints.insets = new java.awt.Insets (18, 0, 0, 12); 277 confPanel.add(bundle, gridBagConstraints); 278 279 layer.setLabelFor(layerValue); 280 org.openide.awt.Mnemonics.setLocalizedText(layer, org.openide.util.NbBundle.getMessage(BasicConfVisualPanel.class, "LBL_XMLLayer")); 281 gridBagConstraints = new java.awt.GridBagConstraints (); 282 gridBagConstraints.gridx = 0; 283 gridBagConstraints.gridy = 3; 284 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 285 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 12); 286 confPanel.add(layer, gridBagConstraints); 287 288 gridBagConstraints = new java.awt.GridBagConstraints (); 289 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 290 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 291 gridBagConstraints.weightx = 1.0; 292 gridBagConstraints.insets = new java.awt.Insets (1, 0, 6, 0); 293 confPanel.add(codeNameBaseValue, gridBagConstraints); 294 295 gridBagConstraints = new java.awt.GridBagConstraints (); 296 gridBagConstraints.gridx = 1; 297 gridBagConstraints.gridy = 1; 298 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 299 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 300 confPanel.add(displayNameValue, gridBagConstraints); 301 302 gridBagConstraints = new java.awt.GridBagConstraints (); 303 gridBagConstraints.gridx = 1; 304 gridBagConstraints.gridy = 2; 305 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 306 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 307 gridBagConstraints.insets = new java.awt.Insets (18, 0, 0, 0); 308 confPanel.add(bundleValue, gridBagConstraints); 309 310 gridBagConstraints = new java.awt.GridBagConstraints (); 311 gridBagConstraints.gridx = 1; 312 gridBagConstraints.gridy = 3; 313 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 314 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 315 gridBagConstraints.insets = new java.awt.Insets (6, 0, 0, 0); 316 confPanel.add(layerValue, gridBagConstraints); 317 318 gridBagConstraints = new java.awt.GridBagConstraints (); 319 gridBagConstraints.gridx = 0; 320 gridBagConstraints.gridy = 4; 321 gridBagConstraints.gridwidth = 2; 322 gridBagConstraints.weighty = 1.0; 323 confPanel.add(filler, gridBagConstraints); 324 325 gridBagConstraints = new java.awt.GridBagConstraints (); 326 gridBagConstraints.gridx = 0; 327 gridBagConstraints.gridy = 0; 328 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 329 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 330 gridBagConstraints.weightx = 1.0; 331 gridBagConstraints.weighty = 1.0; 332 gridBagConstraints.insets = new java.awt.Insets (4, 0, 4, 0); 333 add(confPanel, gridBagConstraints); 334 335 } 336 338 private javax.swing.JLabel bundle; 340 private javax.swing.JTextField bundleValue; 341 private javax.swing.JLabel codeNameBase; 342 private javax.swing.JTextField codeNameBaseValue; 343 private javax.swing.JPanel confPanel; 344 private javax.swing.JLabel displayName; 345 private javax.swing.JTextField displayNameValue; 346 private javax.swing.JLabel filler; 347 private javax.swing.JLabel layer; 348 private javax.swing.JTextField layerValue; 349 351 } 352 | Popular Tags |