1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.io.File ; 23 import javax.swing.JFileChooser ; 24 import javax.swing.event.DocumentEvent ; 25 import org.netbeans.modules.apisupport.project.ui.UIUtil; 26 import org.netbeans.spi.project.support.ant.PropertyUtils; 27 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 28 import org.openide.util.NbBundle; 29 30 35 final class CustomizerPackaging extends NbPropertyPanel.Single { 36 private ProjectCustomizer.Category cat; 37 38 CustomizerPackaging(final SingleModuleProperties props, ProjectCustomizer.Category cat) { 39 super(props, CustomizerPackaging.class); 40 this.cat = cat; 41 initComponents(); 42 initAccesibility(); 43 refresh(); 44 if (!getProperties().isNetBeansOrg()) { 45 licenseValue.getDocument().addDocumentListener(new UIUtil.DocumentAdapter() { 46 public void insertUpdate(DocumentEvent e) { 47 checkValidity(); 48 } 49 }); 50 } else { 51 license.setEnabled(false); 52 licenseValue.setEnabled(false); 53 browseLicense.setEnabled(false); 54 } 55 checkValidity(); 56 } 57 58 59 private void checkValidity() { 60 File currentLicenceF = getCurrentLicenceFile(); 61 if (currentLicenceF != null && !currentLicenceF.isFile()) { 62 cat.setErrorMessage(NbBundle.getMessage(CustomizerPackaging.class, "MSG_LicenceFileDoesNotExist")); 63 cat.setValid(false); 64 } else { 65 cat.setErrorMessage(null); 66 cat.setValid(true); 67 } 68 } 69 70 void refresh() { 71 UIUtil.setText(jarFileValue, getProperties().getJarFile()); 72 needsRestart.setSelected(getBooleanProperty(SingleModuleProperties.NBM_NEEDS_RESTART)); 73 UIUtil.setText(homePageValue, getProperty(SingleModuleProperties.NBM_HOMEPAGE)); 74 UIUtil.setText(authorValue, getProperty(SingleModuleProperties.NBM_MODULE_AUTHOR)); 75 if (!getProperties().isNetBeansOrg()) { 76 UIUtil.setText(licenseValue, getProperty(SingleModuleProperties.LICENSE_FILE)); 77 } 78 } 79 80 public void store() { 81 setBooleanProperty(SingleModuleProperties.NBM_NEEDS_RESTART, needsRestart.isSelected()); 82 setProperty(SingleModuleProperties.NBM_HOMEPAGE, homePageValue.getText()); 83 setProperty(SingleModuleProperties.NBM_MODULE_AUTHOR, authorValue.getText()); 84 if (!getProperties().isNetBeansOrg()) { 85 setProperty(SingleModuleProperties.LICENSE_FILE, licenseValue.getText()); 86 } 87 } 88 89 private String getCurrentLicence() { 90 return licenseValue.getText().trim(); 91 } 92 93 private File getCurrentLicenceFile() { 94 File file = null; 95 String currentLicence = getCurrentLicence(); 96 if (!currentLicence.equals("")) { 97 file = getProperties().evaluateFile(currentLicence); 98 } 99 return file; 100 } 101 102 107 private void initComponents() { 109 java.awt.GridBagConstraints gridBagConstraints; 110 111 license = new javax.swing.JLabel (); 112 licenseValue = new javax.swing.JTextField (); 113 homePage = new javax.swing.JLabel (); 114 homePageValue = new javax.swing.JTextField (); 115 nbmPkgMetadata = new javax.swing.JLabel (); 116 author = new javax.swing.JLabel (); 117 authorValue = new javax.swing.JTextField (); 118 jarFile = new javax.swing.JLabel (); 119 jarFileValue = new javax.swing.JTextField (); 120 sep1 = new javax.swing.JSeparator (); 121 needsRestart = new javax.swing.JCheckBox (); 122 filler = new javax.swing.JLabel (); 123 browseLicense = new javax.swing.JButton (); 124 125 setLayout(new java.awt.GridBagLayout ()); 126 127 license.setLabelFor(licenseValue); 128 org.openide.awt.Mnemonics.setLocalizedText(license, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_License")); gridBagConstraints = new java.awt.GridBagConstraints (); 130 gridBagConstraints.gridx = 0; 131 gridBagConstraints.gridy = 5; 132 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 133 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 6); 134 add(license, gridBagConstraints); 135 136 gridBagConstraints = new java.awt.GridBagConstraints (); 137 gridBagConstraints.gridx = 1; 138 gridBagConstraints.gridy = 5; 139 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 140 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 141 gridBagConstraints.weightx = 1.0; 142 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 143 add(licenseValue, gridBagConstraints); 144 145 homePage.setLabelFor(homePageValue); 146 org.openide.awt.Mnemonics.setLocalizedText(homePage, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_HomePage")); gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridx = 0; 149 gridBagConstraints.gridy = 6; 150 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 151 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 152 add(homePage, gridBagConstraints); 153 154 gridBagConstraints = new java.awt.GridBagConstraints (); 155 gridBagConstraints.gridx = 1; 156 gridBagConstraints.gridy = 6; 157 gridBagConstraints.gridwidth = 2; 158 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 159 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 160 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 161 add(homePageValue, gridBagConstraints); 162 163 org.openide.awt.Mnemonics.setLocalizedText(nbmPkgMetadata, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_NBMPackageMetadata")); gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.gridx = 0; 166 gridBagConstraints.gridy = 1; 167 gridBagConstraints.gridwidth = 3; 168 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 169 gridBagConstraints.insets = new java.awt.Insets (18, 0, 0, 0); 170 add(nbmPkgMetadata, gridBagConstraints); 171 172 author.setLabelFor(authorValue); 173 org.openide.awt.Mnemonics.setLocalizedText(author, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_Author")); gridBagConstraints = new java.awt.GridBagConstraints (); 175 gridBagConstraints.gridx = 0; 176 gridBagConstraints.gridy = 7; 177 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 178 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 179 add(author, gridBagConstraints); 180 181 gridBagConstraints = new java.awt.GridBagConstraints (); 182 gridBagConstraints.gridx = 1; 183 gridBagConstraints.gridy = 7; 184 gridBagConstraints.gridwidth = 2; 185 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 186 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 187 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 188 add(authorValue, gridBagConstraints); 189 190 jarFile.setLabelFor(jarFileValue); 191 org.openide.awt.Mnemonics.setLocalizedText(jarFile, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_JarFile")); gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridx = 0; 194 gridBagConstraints.gridy = 0; 195 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 196 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 197 add(jarFile, gridBagConstraints); 198 199 jarFileValue.setEditable(false); 200 gridBagConstraints = new java.awt.GridBagConstraints (); 201 gridBagConstraints.gridx = 1; 202 gridBagConstraints.gridy = 0; 203 gridBagConstraints.gridwidth = 2; 204 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 205 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 206 add(jarFileValue, gridBagConstraints); 207 208 gridBagConstraints = new java.awt.GridBagConstraints (); 209 gridBagConstraints.gridx = 0; 210 gridBagConstraints.gridy = 2; 211 gridBagConstraints.gridwidth = 3; 212 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 213 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 214 add(sep1, gridBagConstraints); 215 216 org.openide.awt.Mnemonics.setLocalizedText(needsRestart, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "CTL_NeedsRestartOnInstall")); gridBagConstraints = new java.awt.GridBagConstraints (); 218 gridBagConstraints.gridx = 0; 219 gridBagConstraints.gridy = 3; 220 gridBagConstraints.gridwidth = 3; 221 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 222 add(needsRestart, gridBagConstraints); 223 224 gridBagConstraints = new java.awt.GridBagConstraints (); 225 gridBagConstraints.gridx = 0; 226 gridBagConstraints.gridy = 8; 227 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 228 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 229 gridBagConstraints.weighty = 1.0; 230 add(filler, gridBagConstraints); 231 232 org.openide.awt.Mnemonics.setLocalizedText(browseLicense, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "CTL_BrowseButton")); browseLicense.addActionListener(new java.awt.event.ActionListener () { 234 public void actionPerformed(java.awt.event.ActionEvent evt) { 235 browseLicense(evt); 236 } 237 }); 238 239 gridBagConstraints = new java.awt.GridBagConstraints (); 240 gridBagConstraints.gridx = 2; 241 gridBagConstraints.gridy = 5; 242 gridBagConstraints.insets = new java.awt.Insets (6, 12, 6, 0); 243 add(browseLicense, gridBagConstraints); 244 245 } 247 private void browseLicense(java.awt.event.ActionEvent evt) { String startDir; 249 File currentLicenceF = getCurrentLicenceFile(); 250 if (currentLicenceF != null && currentLicenceF.exists() && currentLicenceF.getParent() != null) { 251 startDir = currentLicenceF.getParent(); 252 } else { 253 startDir = getProperties().getProjectDirectory(); 254 } 255 JFileChooser chooser = new JFileChooser (startDir); 256 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 257 int ret = chooser.showOpenDialog(this); 258 if (ret == JFileChooser.APPROVE_OPTION) { 259 String relPath = PropertyUtils.relativizeFile( 260 getProperties().getProjectDirectoryFile(), chooser.getSelectedFile()); 261 licenseValue.setText(relPath); 262 } 263 } 265 private javax.swing.JLabel author; 267 private javax.swing.JTextField authorValue; 268 private javax.swing.JButton browseLicense; 269 private javax.swing.JLabel filler; 270 private javax.swing.JLabel homePage; 271 private javax.swing.JTextField homePageValue; 272 private javax.swing.JLabel jarFile; 273 private javax.swing.JTextField jarFileValue; 274 private javax.swing.JLabel license; 275 private javax.swing.JTextField licenseValue; 276 private javax.swing.JLabel nbmPkgMetadata; 277 private javax.swing.JCheckBox needsRestart; 278 private javax.swing.JSeparator sep1; 279 281 private static String getMessage(String key) { 282 return NbBundle.getMessage(CustomizerPackaging.class, key); 283 } 284 285 private void initAccesibility() { 286 browseLicense.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_BrowseLicense")); 287 needsRestart.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_NeedsRestart")); 288 authorValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_AuthorValue")); 289 homePageValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_HomePageValue")); 290 jarFileValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_JarFileValue")); 291 licenseValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_LicenseValue")); 292 } 293 294 } 295 | Popular Tags |