001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.ui.customizer;
043:
044: import java.io.File;
045: import javax.swing.JFileChooser;
046: import javax.swing.event.DocumentEvent;
047: import org.netbeans.modules.apisupport.project.ui.UIUtil;
048: import org.netbeans.spi.project.support.ant.PropertyUtils;
049: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
050: import org.openide.util.NbBundle;
051:
052: /**
053: * Represents <em>Packaging</em> panel in Netbeans Module customizer.
054: *
055: * @author Martin Krauskopf
056: */
057: final class CustomizerPackaging extends NbPropertyPanel.Single {
058: /** Creates new form CustomizerPackaging */
059: CustomizerPackaging(final SingleModuleProperties props,
060: ProjectCustomizer.Category cat) {
061: super (props, CustomizerPackaging.class, cat);
062: initComponents();
063: initAccesibility();
064: refresh();
065: if (!getProperties().isNetBeansOrg()) {
066: licenseValue.getDocument().addDocumentListener(
067: new UIUtil.DocumentAdapter() {
068: public void insertUpdate(DocumentEvent e) {
069: checkValidity();
070: }
071: });
072: } else {
073: license.setEnabled(false);
074: licenseValue.setEnabled(false);
075: browseLicense.setEnabled(false);
076: }
077: checkValidity();
078: }
079:
080: private void checkValidity() {
081: File currentLicenceF = getCurrentLicenceFile();
082: if (currentLicenceF != null && !currentLicenceF.isFile()) {
083: category.setErrorMessage(NbBundle.getMessage(
084: CustomizerPackaging.class,
085: "MSG_LicenceFileDoesNotExist"));
086: category.setValid(false);
087: } else {
088: category.setErrorMessage(null);
089: category.setValid(true);
090: }
091: }
092:
093: void refresh() {
094: UIUtil.setText(jarFileValue, getProperties().getJarFile());
095: needsRestart
096: .setSelected(getBooleanProperty(SingleModuleProperties.NBM_NEEDS_RESTART));
097: UIUtil.setText(homePageValue,
098: getProperty(SingleModuleProperties.NBM_HOMEPAGE));
099: UIUtil.setText(authorValue,
100: getProperty(SingleModuleProperties.NBM_MODULE_AUTHOR));
101: if (!getProperties().isNetBeansOrg()) {
102: UIUtil.setText(licenseValue,
103: getProperty(SingleModuleProperties.LICENSE_FILE));
104: }
105: }
106:
107: @Override
108: public void store() {
109: setBooleanProperty(SingleModuleProperties.NBM_NEEDS_RESTART,
110: needsRestart.isSelected());
111: setProperty(SingleModuleProperties.NBM_HOMEPAGE, homePageValue
112: .getText());
113: setProperty(SingleModuleProperties.NBM_MODULE_AUTHOR,
114: authorValue.getText());
115: if (!getProperties().isNetBeansOrg()) {
116: setProperty(SingleModuleProperties.LICENSE_FILE,
117: licenseValue.getText());
118: }
119: }
120:
121: private String getCurrentLicence() {
122: return licenseValue.getText().trim();
123: }
124:
125: private File getCurrentLicenceFile() {
126: File file = null;
127: String currentLicence = getCurrentLicence();
128: if (!currentLicence.equals("")) {
129: file = getProperties().evaluateFile(currentLicence);
130: }
131: return file;
132: }
133:
134: /** This method is called from within the constructor to
135: * initialize the form.
136: * WARNING: Do NOT modify this code. The content of this method is
137: * always regenerated by the Form Editor.
138: */
139: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
140: private void initComponents() {
141: java.awt.GridBagConstraints gridBagConstraints;
142:
143: license = new javax.swing.JLabel();
144: licenseValue = new javax.swing.JTextField();
145: homePage = new javax.swing.JLabel();
146: homePageValue = new javax.swing.JTextField();
147: nbmPkgMetadata = new javax.swing.JLabel();
148: author = new javax.swing.JLabel();
149: authorValue = new javax.swing.JTextField();
150: jarFile = new javax.swing.JLabel();
151: jarFileValue = new javax.swing.JTextField();
152: sep1 = new javax.swing.JSeparator();
153: needsRestart = new javax.swing.JCheckBox();
154: filler = new javax.swing.JLabel();
155: browseLicense = new javax.swing.JButton();
156:
157: setLayout(new java.awt.GridBagLayout());
158:
159: license.setLabelFor(licenseValue);
160: org.openide.awt.Mnemonics.setLocalizedText(license,
161: org.openide.util.NbBundle.getMessage(
162: CustomizerPackaging.class, "LBL_License")); // NOI18N
163: gridBagConstraints = new java.awt.GridBagConstraints();
164: gridBagConstraints.gridx = 0;
165: gridBagConstraints.gridy = 5;
166: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
167: gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 6);
168: add(license, gridBagConstraints);
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.gridx = 1;
171: gridBagConstraints.gridy = 5;
172: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
174: gridBagConstraints.weightx = 1.0;
175: gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
176: add(licenseValue, gridBagConstraints);
177:
178: homePage.setLabelFor(homePageValue);
179: org.openide.awt.Mnemonics.setLocalizedText(homePage,
180: org.openide.util.NbBundle.getMessage(
181: CustomizerPackaging.class, "LBL_HomePage")); // NOI18N
182: gridBagConstraints = new java.awt.GridBagConstraints();
183: gridBagConstraints.gridx = 0;
184: gridBagConstraints.gridy = 6;
185: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
186: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
187: add(homePage, gridBagConstraints);
188: gridBagConstraints = new java.awt.GridBagConstraints();
189: gridBagConstraints.gridx = 1;
190: gridBagConstraints.gridy = 6;
191: gridBagConstraints.gridwidth = 2;
192: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
194: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
195: add(homePageValue, gridBagConstraints);
196:
197: org.openide.awt.Mnemonics.setLocalizedText(nbmPkgMetadata,
198: org.openide.util.NbBundle.getMessage(
199: CustomizerPackaging.class,
200: "LBL_NBMPackageMetadata")); // NOI18N
201: gridBagConstraints = new java.awt.GridBagConstraints();
202: gridBagConstraints.gridx = 0;
203: gridBagConstraints.gridy = 1;
204: gridBagConstraints.gridwidth = 3;
205: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
206: gridBagConstraints.insets = new java.awt.Insets(18, 0, 0, 0);
207: add(nbmPkgMetadata, gridBagConstraints);
208:
209: author.setLabelFor(authorValue);
210: org.openide.awt.Mnemonics.setLocalizedText(author,
211: org.openide.util.NbBundle.getMessage(
212: CustomizerPackaging.class, "LBL_Author")); // NOI18N
213: gridBagConstraints = new java.awt.GridBagConstraints();
214: gridBagConstraints.gridx = 0;
215: gridBagConstraints.gridy = 7;
216: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
217: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
218: add(author, gridBagConstraints);
219: gridBagConstraints = new java.awt.GridBagConstraints();
220: gridBagConstraints.gridx = 1;
221: gridBagConstraints.gridy = 7;
222: gridBagConstraints.gridwidth = 2;
223: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
224: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
225: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
226: add(authorValue, gridBagConstraints);
227:
228: jarFile.setLabelFor(jarFileValue);
229: org.openide.awt.Mnemonics.setLocalizedText(jarFile,
230: org.openide.util.NbBundle.getMessage(
231: CustomizerPackaging.class, "LBL_JarFile")); // NOI18N
232: gridBagConstraints = new java.awt.GridBagConstraints();
233: gridBagConstraints.gridx = 0;
234: gridBagConstraints.gridy = 0;
235: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
236: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
237: add(jarFile, gridBagConstraints);
238:
239: jarFileValue.setEditable(false);
240: gridBagConstraints = new java.awt.GridBagConstraints();
241: gridBagConstraints.gridx = 1;
242: gridBagConstraints.gridy = 0;
243: gridBagConstraints.gridwidth = 2;
244: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
245: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
246: add(jarFileValue, gridBagConstraints);
247: gridBagConstraints = new java.awt.GridBagConstraints();
248: gridBagConstraints.gridx = 0;
249: gridBagConstraints.gridy = 2;
250: gridBagConstraints.gridwidth = 3;
251: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252: gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
253: add(sep1, gridBagConstraints);
254:
255: org.openide.awt.Mnemonics.setLocalizedText(needsRestart,
256: org.openide.util.NbBundle.getMessage(
257: CustomizerPackaging.class,
258: "CTL_NeedsRestartOnInstall")); // NOI18N
259: gridBagConstraints = new java.awt.GridBagConstraints();
260: gridBagConstraints.gridx = 0;
261: gridBagConstraints.gridy = 3;
262: gridBagConstraints.gridwidth = 3;
263: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
264: add(needsRestart, gridBagConstraints);
265: gridBagConstraints = new java.awt.GridBagConstraints();
266: gridBagConstraints.gridx = 0;
267: gridBagConstraints.gridy = 8;
268: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
269: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
270: gridBagConstraints.weighty = 1.0;
271: add(filler, gridBagConstraints);
272:
273: org.openide.awt.Mnemonics.setLocalizedText(browseLicense,
274: org.openide.util.NbBundle.getMessage(
275: CustomizerPackaging.class, "CTL_BrowseButton")); // NOI18N
276: browseLicense
277: .addActionListener(new java.awt.event.ActionListener() {
278: public void actionPerformed(
279: java.awt.event.ActionEvent evt) {
280: browseLicense(evt);
281: }
282: });
283: gridBagConstraints = new java.awt.GridBagConstraints();
284: gridBagConstraints.gridx = 2;
285: gridBagConstraints.gridy = 5;
286: gridBagConstraints.insets = new java.awt.Insets(6, 12, 6, 0);
287: add(browseLicense, gridBagConstraints);
288: }// </editor-fold>//GEN-END:initComponents
289:
290: private void browseLicense(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLicense
291: String startDir;
292: File currentLicenceF = getCurrentLicenceFile();
293: if (currentLicenceF != null && currentLicenceF.exists()
294: && currentLicenceF.getParent() != null) {
295: startDir = currentLicenceF.getParent();
296: } else {
297: startDir = getProperties().getProjectDirectory();
298: }
299: JFileChooser chooser = new JFileChooser(startDir);
300: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
301: int ret = chooser.showOpenDialog(this );
302: if (ret == JFileChooser.APPROVE_OPTION) {
303: String relPath = PropertyUtils.relativizeFile(
304: getProperties().getProjectDirectoryFile(), chooser
305: .getSelectedFile());
306: licenseValue.setText(relPath);
307: }
308: }//GEN-LAST:event_browseLicense
309:
310: // Variables declaration - do not modify//GEN-BEGIN:variables
311: private javax.swing.JLabel author;
312: private javax.swing.JTextField authorValue;
313: private javax.swing.JButton browseLicense;
314: private javax.swing.JLabel filler;
315: private javax.swing.JLabel homePage;
316: private javax.swing.JTextField homePageValue;
317: private javax.swing.JLabel jarFile;
318: private javax.swing.JTextField jarFileValue;
319: private javax.swing.JLabel license;
320: private javax.swing.JTextField licenseValue;
321: private javax.swing.JLabel nbmPkgMetadata;
322: private javax.swing.JCheckBox needsRestart;
323: private javax.swing.JSeparator sep1;
324:
325: // End of variables declaration//GEN-END:variables
326:
327: private static String getMessage(String key) {
328: return NbBundle.getMessage(CustomizerPackaging.class, key);
329: }
330:
331: private void initAccesibility() {
332: browseLicense.getAccessibleContext().setAccessibleDescription(
333: getMessage("ACSD_BrowseLicense"));
334: needsRestart.getAccessibleContext().setAccessibleDescription(
335: getMessage("ACSD_NeedsRestart"));
336: authorValue.getAccessibleContext().setAccessibleDescription(
337: getMessage("ACSD_AuthorValue"));
338: homePageValue.getAccessibleContext().setAccessibleDescription(
339: getMessage("ACSD_HomePageValue"));
340: jarFileValue.getAccessibleContext().setAccessibleDescription(
341: getMessage("ACSD_JarFileValue"));
342: licenseValue.getAccessibleContext().setAccessibleDescription(
343: getMessage("ACSD_LicenseValue"));
344: }
345:
346: }
|