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.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046: import java.net.URL;
047: import java.util.SortedSet;
048: import java.util.TreeSet;
049: import javax.swing.DefaultListModel;
050: import javax.swing.JPanel;
051: import org.netbeans.modules.apisupport.project.ManifestManager;
052: import org.netbeans.modules.apisupport.project.Util;
053: import org.netbeans.modules.apisupport.project.ui.UIUtil;
054: import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
055: import org.netbeans.modules.apisupport.project.universe.NbPlatform;
056: import org.openide.awt.HtmlBrowser;
057: import org.openide.util.NbBundle;
058:
059: /**
060: * Represents panel for editing dependency details. Shown e.g. after <em>Edit</em>
061: * button on the <code>CustomizerLibraries</code> panel has been pushed.
062: *
063: * @author Martin Krauskopf
064: */
065: public final class EditDependencyPanel extends JPanel {
066:
067: private final ModuleDependency origDep;
068: private final URL javadoc;
069:
070: private final ManifestManager.PackageExport[] pp;
071: private final DefaultListModel packagesModel = new DefaultListModel();
072:
073: /** Creates new form EditDependencyPanel */
074: public EditDependencyPanel(final ModuleDependency dep,
075: final NbPlatform platform) {
076: this .origDep = dep;
077: this .pp = origDep.getModuleEntry().getPublicPackages();
078: initComponents();
079: initDependency();
080: if (platform == null) { // NetBeans.org module
081: javadoc = Util.findJavadocForNetBeansOrgModules(origDep);
082: } else {
083: javadoc = Util.findJavadoc(origDep, platform);
084: }
085: showJavadocButton.setEnabled(javadoc != null);
086: getAccessibleContext()
087: .setAccessibleDescription(
088: NbBundle
089: .getMessage(EditDependencyPanel.class,
090: "EditDependencyPanel.title.AccessibleContext.accessibleName"));
091: }
092:
093: private void refresh() {
094: specVerValue.setEnabled(specVer.isSelected());
095: includeInCP.setEnabled(hasAvailablePackages());
096: if (!includeInCP.isEnabled()) {
097: includeInCP.setSelected(false);
098: } // else leave the user's selection
099: }
100:
101: private boolean hasAvailablePackages() {
102: return implVer.isSelected() || pp.length > 0;
103: }
104:
105: /** Called first time dialog is opened. */
106: private void initDependency() {
107: ModuleEntry me = origDep.getModuleEntry();
108: UIUtil.setText(codeNameBaseValue, me.getCodeNameBase());
109: UIUtil.setText(jarLocationValue, me.getJarLocation()
110: .getAbsolutePath());
111: UIUtil
112: .setText(releaseVersionValue, origDep
113: .getReleaseVersion());
114: UIUtil.setText(specVerValue, origDep
115: .hasImplementationDepedendency() ? me
116: .getSpecificationVersion() : origDep
117: .getSpecificationVersion());
118: implVer.setSelected(origDep.hasImplementationDepedendency());
119: availablePkg.setEnabled(hasAvailablePackages());
120: includeInCP.setSelected(origDep.hasCompileDependency());
121: refreshAvailablePackages();
122: refresh();
123: ActionListener versionListener = new ActionListener() {
124: public void actionPerformed(ActionEvent arg0) {
125: refreshAvailablePackages();
126: }
127: };
128: implVer.addActionListener(versionListener);
129: specVer.addActionListener(versionListener);
130: }
131:
132: public void refreshAvailablePackages() {
133: packagesModel.clear();
134: if (hasAvailablePackages()) {
135: // XXX should show all subpackages in the case of recursion is set
136: // to true instead of e.g. org/**
137: SortedSet<String> packages = new TreeSet<String>();
138: for (int i = 0; i < pp.length; i++) { // add public packages
139: packages.add(pp[i].getPackage()
140: + (pp[i].isRecursive() ? ".**" : "")); // NOI18N
141: }
142: if (implVer.isSelected()) { // add all packages
143: packages.addAll(origDep.getModuleEntry()
144: .getAllPackageNames());
145: }
146: for (String pkg : packages) {
147: packagesModel.addElement(pkg);
148: }
149: } else {
150: packagesModel.addElement(NbBundle.getMessage(
151: EditDependencyPanel.class,
152: "EditDependencyPanel_empty"));
153: }
154: availablePkg.setModel(packagesModel);
155: }
156:
157: public ModuleDependency getEditedDependency() {
158: ModuleDependency dep = new ModuleDependency(origDep
159: .getModuleEntry(),
160: releaseVersionValue.getText().trim(), specVerValue
161: .getText().trim(), includeInCP.isSelected(),
162: implVer.isSelected());
163: return dep;
164: }
165:
166: /** This method is called from within the constructor to
167: * initialize the form.
168: * WARNING: Do NOT modify this code. The content of this method is
169: * always regenerated by the Form Editor.
170: */
171: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
172: private void initComponents() {
173: java.awt.GridBagConstraints gridBagConstraints;
174:
175: versionGroup = new javax.swing.ButtonGroup();
176: codeNameBase = new javax.swing.JLabel();
177: jarLocation = new javax.swing.JLabel();
178: releaseVersion = new javax.swing.JLabel();
179: releaseVersionValue = new javax.swing.JTextField();
180: specVer = new javax.swing.JRadioButton();
181: specVerValue = new javax.swing.JTextField();
182: implVer = new javax.swing.JRadioButton();
183: includeInCP = new javax.swing.JCheckBox();
184: availablePkgSP = new javax.swing.JScrollPane();
185: availablePkg = new javax.swing.JList();
186: codeNameBaseValue = new javax.swing.JTextField();
187: jarLocationValue = new javax.swing.JTextField();
188: showJavadocButton = new javax.swing.JButton();
189:
190: setBorder(javax.swing.BorderFactory.createEmptyBorder(6, 6, 6,
191: 6));
192: setPreferredSize(new java.awt.Dimension(400, 300));
193: setLayout(new java.awt.GridBagLayout());
194:
195: codeNameBase.setLabelFor(codeNameBaseValue);
196: org.openide.awt.Mnemonics.setLocalizedText(codeNameBase,
197: org.openide.util.NbBundle.getMessage(
198: EditDependencyPanel.class, "LBL_CNB")); // NOI18N
199: gridBagConstraints = new java.awt.GridBagConstraints();
200: gridBagConstraints.gridx = 0;
201: gridBagConstraints.gridy = 0;
202: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
203: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
204: add(codeNameBase, gridBagConstraints);
205: codeNameBase
206: .getAccessibleContext()
207: .setAccessibleDescription(
208: org.openide.util.NbBundle
209: .getMessage(EditDependencyPanel.class,
210: "EditDependencyPanel.codeNameBase.AccessibleContext.accessibleDescription")); // NOI18N
211:
212: jarLocation.setLabelFor(jarLocationValue);
213: org.openide.awt.Mnemonics.setLocalizedText(jarLocation,
214: org.openide.util.NbBundle.getMessage(
215: EditDependencyPanel.class, "LBL_JAR")); // NOI18N
216: gridBagConstraints = new java.awt.GridBagConstraints();
217: gridBagConstraints.gridx = 0;
218: gridBagConstraints.gridy = 1;
219: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220: gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 12);
221: add(jarLocation, gridBagConstraints);
222: jarLocation
223: .getAccessibleContext()
224: .setAccessibleDescription(
225: org.openide.util.NbBundle
226: .getMessage(EditDependencyPanel.class,
227: "EditDependencyPanel.jarLocation.AccessibleContext.accessibleDescription")); // NOI18N
228:
229: releaseVersion.setLabelFor(releaseVersionValue);
230: org.openide.awt.Mnemonics.setLocalizedText(releaseVersion,
231: org.openide.util.NbBundle.getMessage(
232: EditDependencyPanel.class,
233: "LBL_MajorReleaseVersion")); // NOI18N
234: gridBagConstraints = new java.awt.GridBagConstraints();
235: gridBagConstraints.gridx = 0;
236: gridBagConstraints.gridy = 2;
237: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
238: gridBagConstraints.insets = new java.awt.Insets(24, 0, 0, 12);
239: add(releaseVersion, gridBagConstraints);
240: gridBagConstraints = new java.awt.GridBagConstraints();
241: gridBagConstraints.gridx = 1;
242: gridBagConstraints.gridy = 2;
243: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
244: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
245: gridBagConstraints.weightx = 1.0;
246: gridBagConstraints.insets = new java.awt.Insets(24, 0, 0, 0);
247: add(releaseVersionValue, gridBagConstraints);
248: releaseVersionValue
249: .getAccessibleContext()
250: .setAccessibleName(
251: org.openide.util.NbBundle
252: .getMessage(EditDependencyPanel.class,
253: "EditDependencyPanel.releaseVersionValue.AccessibleContext.accessibleName")); // NOI18N
254: releaseVersionValue
255: .getAccessibleContext()
256: .setAccessibleDescription(
257: org.openide.util.NbBundle
258: .getMessage(
259: EditDependencyPanel.class,
260: "EditDependencyPanel.releaseVersionValue.AccessibleContext.accessibleDescription")); // NOI18N
261:
262: versionGroup.add(specVer);
263: specVer.setSelected(true);
264: org.openide.awt.Mnemonics.setLocalizedText(specVer,
265: org.openide.util.NbBundle.getMessage(
266: EditDependencyPanel.class,
267: "LBL_SpecificationVersion")); // NOI18N
268: specVer.addActionListener(new java.awt.event.ActionListener() {
269: public void actionPerformed(java.awt.event.ActionEvent evt) {
270: versionChanged(evt);
271: }
272: });
273: gridBagConstraints = new java.awt.GridBagConstraints();
274: gridBagConstraints.gridx = 0;
275: gridBagConstraints.gridy = 3;
276: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
277: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
278: add(specVer, gridBagConstraints);
279: specVer
280: .getAccessibleContext()
281: .setAccessibleDescription(
282: org.openide.util.NbBundle
283: .getMessage(EditDependencyPanel.class,
284: "EditDependencyPanel.specVer.AccessibleContext.accessibleDescription")); // NOI18N
285:
286: gridBagConstraints = new java.awt.GridBagConstraints();
287: gridBagConstraints.gridx = 1;
288: gridBagConstraints.gridy = 3;
289: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
290: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
291: add(specVerValue, gridBagConstraints);
292: specVerValue
293: .getAccessibleContext()
294: .setAccessibleName(
295: org.openide.util.NbBundle
296: .getMessage(EditDependencyPanel.class,
297: "EditDependencyPanel.specVerValue.AccessibleContext.accessibleName")); // NOI18N
298: specVerValue
299: .getAccessibleContext()
300: .setAccessibleDescription(
301: org.openide.util.NbBundle
302: .getMessage(EditDependencyPanel.class,
303: "EditDependencyPanel.specVerValue.AccessibleContext.accessibleDescription")); // NOI18N
304:
305: versionGroup.add(implVer);
306: org.openide.awt.Mnemonics.setLocalizedText(implVer,
307: org.openide.util.NbBundle.getMessage(
308: EditDependencyPanel.class,
309: "LBL_ImplementationVersion")); // NOI18N
310: implVer.addActionListener(new java.awt.event.ActionListener() {
311: public void actionPerformed(java.awt.event.ActionEvent evt) {
312: versionChanged(evt);
313: }
314: });
315: gridBagConstraints = new java.awt.GridBagConstraints();
316: gridBagConstraints.gridx = 0;
317: gridBagConstraints.gridy = 4;
318: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
319: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
320: add(implVer, gridBagConstraints);
321: implVer
322: .getAccessibleContext()
323: .setAccessibleDescription(
324: org.openide.util.NbBundle
325: .getMessage(EditDependencyPanel.class,
326: "EditDependencyPanel.implVer.AccessibleContext.accessibleDescription")); // NOI18N
327:
328: org.openide.awt.Mnemonics.setLocalizedText(includeInCP,
329: org.openide.util.NbBundle.getMessage(
330: EditDependencyPanel.class,
331: "LBL_IncludeAPIPackages")); // NOI18N
332: gridBagConstraints = new java.awt.GridBagConstraints();
333: gridBagConstraints.gridx = 0;
334: gridBagConstraints.gridy = 5;
335: gridBagConstraints.gridwidth = 2;
336: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
337: gridBagConstraints.insets = new java.awt.Insets(24, 0, 0, 0);
338: add(includeInCP, gridBagConstraints);
339: includeInCP
340: .getAccessibleContext()
341: .setAccessibleDescription(
342: org.openide.util.NbBundle
343: .getMessage(EditDependencyPanel.class,
344: "EditDependencyPanel.includeInCP.AccessibleContext.accessibleDescription")); // NOI18N
345:
346: availablePkgSP.setViewportView(availablePkg);
347: availablePkg
348: .getAccessibleContext()
349: .setAccessibleName(
350: org.openide.util.NbBundle
351: .getMessage(EditDependencyPanel.class,
352: "EditDependencyPanel.availablePkg.AccessibleContext.accessibleName")); // NOI18N
353: availablePkg
354: .getAccessibleContext()
355: .setAccessibleDescription(
356: org.openide.util.NbBundle
357: .getMessage(EditDependencyPanel.class,
358: "EditDependencyPanel.availablePkg.AccessibleContext.accessibleDescription")); // NOI18N
359:
360: gridBagConstraints = new java.awt.GridBagConstraints();
361: gridBagConstraints.gridx = 0;
362: gridBagConstraints.gridy = 6;
363: gridBagConstraints.gridwidth = 2;
364: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
365: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
366: gridBagConstraints.weighty = 1.0;
367: add(availablePkgSP, gridBagConstraints);
368:
369: codeNameBaseValue.setEditable(false);
370: gridBagConstraints = new java.awt.GridBagConstraints();
371: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
372: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
373: add(codeNameBaseValue, gridBagConstraints);
374: codeNameBaseValue
375: .getAccessibleContext()
376: .setAccessibleName(
377: org.openide.util.NbBundle
378: .getMessage(EditDependencyPanel.class,
379: "EditDependencyPanel.codeNameBaseValue.AccessibleContext.accessibleName")); // NOI18N
380: codeNameBaseValue
381: .getAccessibleContext()
382: .setAccessibleDescription(
383: org.openide.util.NbBundle
384: .getMessage(EditDependencyPanel.class,
385: "EditDependencyPanel.codeNameBaseValue.AccessibleContext.accessibleDescription")); // NOI18N
386:
387: jarLocationValue.setEditable(false);
388: gridBagConstraints = new java.awt.GridBagConstraints();
389: gridBagConstraints.gridx = 1;
390: gridBagConstraints.gridy = 1;
391: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
392: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
393: gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
394: add(jarLocationValue, gridBagConstraints);
395: jarLocationValue
396: .getAccessibleContext()
397: .setAccessibleName(
398: org.openide.util.NbBundle
399: .getMessage(EditDependencyPanel.class,
400: "EditDependencyPanel.jarLocationValue.AccessibleContext.accessibleName")); // NOI18N
401: jarLocationValue
402: .getAccessibleContext()
403: .setAccessibleDescription(
404: org.openide.util.NbBundle
405: .getMessage(EditDependencyPanel.class,
406: "EditDependencyPanel.jarLocationValue.AccessibleContext.accessibleDescription")); // NOI18N
407:
408: org.openide.awt.Mnemonics.setLocalizedText(showJavadocButton,
409: org.openide.util.NbBundle.getMessage(
410: EditDependencyPanel.class, "CTL_ShowJavadoc")); // NOI18N
411: showJavadocButton
412: .addActionListener(new java.awt.event.ActionListener() {
413: public void actionPerformed(
414: java.awt.event.ActionEvent evt) {
415: showJavadoc(evt);
416: }
417: });
418: gridBagConstraints = new java.awt.GridBagConstraints();
419: gridBagConstraints.gridx = 0;
420: gridBagConstraints.gridy = 7;
421: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
422: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
423: gridBagConstraints.insets = new java.awt.Insets(24, 0, 0, 0);
424: add(showJavadocButton, gridBagConstraints);
425: showJavadocButton
426: .getAccessibleContext()
427: .setAccessibleDescription(
428: org.openide.util.NbBundle
429: .getMessage(EditDependencyPanel.class,
430: "EditDependencyPanel.showJavadocButton.AccessibleContext.accessibleDescription")); // NOI18N
431: }// </editor-fold>//GEN-END:initComponents
432:
433: private void showJavadoc(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showJavadoc
434: HtmlBrowser.URLDisplayer.getDefault().showURL(javadoc);
435: }//GEN-LAST:event_showJavadoc
436:
437: private void versionChanged(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_versionChanged
438: refresh();
439: if (implVer.isSelected()) { // automatic compile-time dependency
440: includeInCP.setSelected(true);
441: }
442: }//GEN-LAST:event_versionChanged
443:
444: // Variables declaration - do not modify//GEN-BEGIN:variables
445: private javax.swing.JList availablePkg;
446: private javax.swing.JScrollPane availablePkgSP;
447: private javax.swing.JLabel codeNameBase;
448: private javax.swing.JTextField codeNameBaseValue;
449: private javax.swing.JRadioButton implVer;
450: private javax.swing.JCheckBox includeInCP;
451: private javax.swing.JLabel jarLocation;
452: private javax.swing.JTextField jarLocationValue;
453: private javax.swing.JLabel releaseVersion;
454: private javax.swing.JTextField releaseVersionValue;
455: private javax.swing.JButton showJavadocButton;
456: private javax.swing.JRadioButton specVer;
457: private javax.swing.JTextField specVerValue;
458: private javax.swing.ButtonGroup versionGroup;
459: // End of variables declaration//GEN-END:variables
460:
461: }
|