KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > EditDependencyPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.customizer;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.SortedSet JavaDoc;
26 import java.util.TreeSet JavaDoc;
27 import javax.swing.DefaultListModel JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import org.netbeans.modules.apisupport.project.ManifestManager;
30 import org.netbeans.modules.apisupport.project.Util;
31 import org.netbeans.modules.apisupport.project.ui.UIUtil;
32 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
33 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
34 import org.openide.awt.HtmlBrowser;
35 import org.openide.util.NbBundle;
36
37 /**
38  * Represents panel for editing dependency details. Shown e.g. after <em>Edit</em>
39  * button on the <code>CustomizerLibraries</code> panel has been pushed.
40  *
41  * @author Martin Krauskopf
42  */

43 public final class EditDependencyPanel extends JPanel JavaDoc {
44     
45     private final ModuleDependency origDep;
46     private final URL JavaDoc javadoc;
47     
48     private final ManifestManager.PackageExport[] pp;
49     private final DefaultListModel JavaDoc packagesModel = new DefaultListModel JavaDoc();
50     
51     /** Creates new form EditDependencyPanel */
52     public EditDependencyPanel(final ModuleDependency dep, final NbPlatform platform) {
53         this.origDep = dep;
54         this.pp = origDep.getModuleEntry().getPublicPackages();
55         initComponents();
56         initDependency();
57         if (platform == null) { // NetBeans.org module
58
javadoc = Util.findJavadocForNetBeansOrgModules(origDep);
59         } else {
60             javadoc = Util.findJavadoc(origDep, platform);
61         }
62         showJavadocButton.setEnabled(javadoc != null);
63         getAccessibleContext().setAccessibleDescription(
64                 NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.title.AccessibleContext.accessibleName"));
65     }
66     
67     private void refresh() {
68         specVerValue.setEnabled(specVer.isSelected());
69         includeInCP.setEnabled(hasAvailablePackages());
70         if (!includeInCP.isEnabled()) {
71             includeInCP.setSelected(false);
72         } // else leave the user's selection
73
}
74     
75     private boolean hasAvailablePackages() {
76         return implVer.isSelected() || pp.length > 0;
77     }
78     
79     /** Called first time dialog is opened. */
80     private void initDependency() {
81         ModuleEntry me = origDep.getModuleEntry();
82         UIUtil.setText(codeNameBaseValue, me.getCodeNameBase());
83         UIUtil.setText(jarLocationValue, me.getJarLocation().getAbsolutePath());
84         UIUtil.setText(releaseVersionValue, origDep.getReleaseVersion());
85         UIUtil.setText(specVerValue, origDep.hasImplementationDepedendency() ?
86             me.getSpecificationVersion() :
87             origDep.getSpecificationVersion());
88         implVer.setSelected(origDep.hasImplementationDepedendency());
89         availablePkg.setEnabled(hasAvailablePackages());
90         includeInCP.setSelected(origDep.hasCompileDependency());
91         refreshAvailablePackages();
92         refresh();
93         ActionListener JavaDoc versionListener = new ActionListener JavaDoc() {
94             public void actionPerformed(ActionEvent JavaDoc arg0) {
95                 refreshAvailablePackages();
96             }
97         };
98         implVer.addActionListener(versionListener);
99         specVer.addActionListener(versionListener);
100     }
101     
102     public void refreshAvailablePackages() {
103         packagesModel.clear();
104         if (hasAvailablePackages()) {
105             // XXX should show all subpackages in the case of recursion is set
106
// to true instead of e.g. org/**
107
SortedSet JavaDoc<String JavaDoc> packages = new TreeSet JavaDoc<String JavaDoc>();
108             for (int i = 0; i < pp.length; i++) { // add public packages
109
packages.add(pp[i].getPackage() + (pp[i].isRecursive() ? ".**" : "")); // NOI18N
110
}
111             if (implVer.isSelected()) { // add all packages
112
packages.addAll(origDep.getModuleEntry().getAllPackageNames());
113             }
114             for (String JavaDoc pkg : packages) {
115                 packagesModel.addElement(pkg);
116             }
117         } else {
118             packagesModel.addElement(NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel_empty"));
119         }
120         availablePkg.setModel(packagesModel);
121     }
122     
123     public ModuleDependency getEditedDependency() {
124         ModuleDependency dep = new ModuleDependency(origDep.getModuleEntry(),
125                 releaseVersionValue.getText().trim(),
126                 specVerValue.getText().trim(),
127                 includeInCP.isSelected(),
128                 implVer.isSelected());
129         return dep;
130     }
131     
132     /** This method is called from within the constructor to
133      * initialize the form.
134      * WARNING: Do NOT modify this code. The content of this method is
135      * always regenerated by the Form Editor.
136      */

137     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
138
private void initComponents() {
139         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
140
141         versionGroup = new javax.swing.ButtonGroup JavaDoc();
142         codeNameBase = new javax.swing.JLabel JavaDoc();
143         jarLocation = new javax.swing.JLabel JavaDoc();
144         releaseVersion = new javax.swing.JLabel JavaDoc();
145         releaseVersionValue = new javax.swing.JTextField JavaDoc();
146         specVer = new javax.swing.JRadioButton JavaDoc();
147         specVerValue = new javax.swing.JTextField JavaDoc();
148         implVer = new javax.swing.JRadioButton JavaDoc();
149         includeInCP = new javax.swing.JCheckBox JavaDoc();
150         availablePkgSP = new javax.swing.JScrollPane JavaDoc();
151         availablePkg = new javax.swing.JList JavaDoc();
152         codeNameBaseValue = new javax.swing.JTextField JavaDoc();
153         jarLocationValue = new javax.swing.JTextField JavaDoc();
154         showJavadocButton = new javax.swing.JButton JavaDoc();
155
156         setBorder(javax.swing.BorderFactory.createEmptyBorder(6, 6, 6, 6));
157         setPreferredSize(new java.awt.Dimension JavaDoc(400, 300));
158         setLayout(new java.awt.GridBagLayout JavaDoc());
159
160         codeNameBase.setLabelFor(codeNameBaseValue);
161         org.openide.awt.Mnemonics.setLocalizedText(codeNameBase, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_CNB")); // NOI18N
162
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 0;
165         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
166         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
167         add(codeNameBase, gridBagConstraints);
168         codeNameBase.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.codeNameBase.AccessibleContext.accessibleDescription")); // NOI18N
169

170         jarLocation.setLabelFor(jarLocationValue);
171         org.openide.awt.Mnemonics.setLocalizedText(jarLocation, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_JAR")); // NOI18N
172
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 0;
174         gridBagConstraints.gridy = 1;
175         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
176         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 12);
177         add(jarLocation, gridBagConstraints);
178         jarLocation.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.jarLocation.AccessibleContext.accessibleDescription")); // NOI18N
179

180         releaseVersion.setLabelFor(releaseVersionValue);
181         org.openide.awt.Mnemonics.setLocalizedText(releaseVersion, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_MajorReleaseVersion")); // NOI18N
182
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
183         gridBagConstraints.gridx = 0;
184         gridBagConstraints.gridy = 2;
185         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
186         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 0, 0, 12);
187         add(releaseVersion, gridBagConstraints);
188         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
189         gridBagConstraints.gridx = 1;
190         gridBagConstraints.gridy = 2;
191         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
193         gridBagConstraints.weightx = 1.0;
194         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 0, 0, 0);
195         add(releaseVersionValue, gridBagConstraints);
196         releaseVersionValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.releaseVersionValue.AccessibleContext.accessibleName")); // NOI18N
197
releaseVersionValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.releaseVersionValue.AccessibleContext.accessibleDescription")); // NOI18N
198

199         versionGroup.add(specVer);
200         specVer.setSelected(true);
201         org.openide.awt.Mnemonics.setLocalizedText(specVer, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_SpecificationVersion")); // NOI18N
202
specVer.addActionListener(new java.awt.event.ActionListener JavaDoc() {
203             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
204                 versionChanged(evt);
205             }
206         });
207         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
208         gridBagConstraints.gridx = 0;
209         gridBagConstraints.gridy = 3;
210         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
211         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
212         add(specVer, gridBagConstraints);
213         specVer.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.specVer.AccessibleContext.accessibleDescription")); // NOI18N
214

215         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
216         gridBagConstraints.gridx = 1;
217         gridBagConstraints.gridy = 3;
218         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
219         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
220         add(specVerValue, gridBagConstraints);
221         specVerValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.specVerValue.AccessibleContext.accessibleName")); // NOI18N
222
specVerValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.specVerValue.AccessibleContext.accessibleDescription")); // NOI18N
223

224         versionGroup.add(implVer);
225         org.openide.awt.Mnemonics.setLocalizedText(implVer, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_ImplementationVersion")); // NOI18N
226
implVer.addActionListener(new java.awt.event.ActionListener JavaDoc() {
227             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
228                 versionChanged(evt);
229             }
230         });
231         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
232         gridBagConstraints.gridx = 0;
233         gridBagConstraints.gridy = 4;
234         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
235         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
236         add(implVer, gridBagConstraints);
237         implVer.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.implVer.AccessibleContext.accessibleDescription")); // NOI18N
238

239         org.openide.awt.Mnemonics.setLocalizedText(includeInCP, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "LBL_IncludeAPIPackages")); // NOI18N
240
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
241         gridBagConstraints.gridx = 0;
242         gridBagConstraints.gridy = 5;
243         gridBagConstraints.gridwidth = 2;
244         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
245         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 0, 0, 0);
246         add(includeInCP, gridBagConstraints);
247         includeInCP.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.includeInCP.AccessibleContext.accessibleDescription")); // NOI18N
248

249         availablePkgSP.setViewportView(availablePkg);
250         availablePkg.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.availablePkg.AccessibleContext.accessibleName")); // NOI18N
251
availablePkg.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.availablePkg.AccessibleContext.accessibleDescription")); // NOI18N
252

253         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.gridx = 0;
255         gridBagConstraints.gridy = 6;
256         gridBagConstraints.gridwidth = 2;
257         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
258         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
259         gridBagConstraints.weighty = 1.0;
260         add(availablePkgSP, gridBagConstraints);
261
262         codeNameBaseValue.setEditable(false);
263         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
264         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
265         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
266         add(codeNameBaseValue, gridBagConstraints);
267         codeNameBaseValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.codeNameBaseValue.AccessibleContext.accessibleName")); // NOI18N
268
codeNameBaseValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.codeNameBaseValue.AccessibleContext.accessibleDescription")); // NOI18N
269

270         jarLocationValue.setEditable(false);
271         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
272         gridBagConstraints.gridx = 1;
273         gridBagConstraints.gridy = 1;
274         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
275         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
276         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 0, 0);
277         add(jarLocationValue, gridBagConstraints);
278         jarLocationValue.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.jarLocationValue.AccessibleContext.accessibleName")); // NOI18N
279
jarLocationValue.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.jarLocationValue.AccessibleContext.accessibleDescription")); // NOI18N
280

281         org.openide.awt.Mnemonics.setLocalizedText(showJavadocButton, org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "CTL_ShowJavadoc")); // NOI18N
282
showJavadocButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
283             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
284                 showJavadoc(evt);
285             }
286         });
287         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
288         gridBagConstraints.gridx = 0;
289         gridBagConstraints.gridy = 7;
290         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
291         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
292         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 0, 0, 0);
293         add(showJavadocButton, gridBagConstraints);
294         showJavadocButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(EditDependencyPanel.class, "EditDependencyPanel.showJavadocButton.AccessibleContext.accessibleDescription")); // NOI18N
295
}// </editor-fold>//GEN-END:initComponents
296

297     private void showJavadoc(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_showJavadoc
298
HtmlBrowser.URLDisplayer.getDefault().showURL(javadoc);
299     }//GEN-LAST:event_showJavadoc
300

301     private void versionChanged(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_versionChanged
302
refresh();
303         if (implVer.isSelected()) { // automatic compile-time dependency
304
includeInCP.setSelected(true);
305         }
306     }//GEN-LAST:event_versionChanged
307

308     // Variables declaration - do not modify//GEN-BEGIN:variables
309
private javax.swing.JList JavaDoc availablePkg;
310     private javax.swing.JScrollPane JavaDoc availablePkgSP;
311     private javax.swing.JLabel JavaDoc codeNameBase;
312     private javax.swing.JTextField JavaDoc codeNameBaseValue;
313     private javax.swing.JRadioButton JavaDoc implVer;
314     private javax.swing.JCheckBox JavaDoc includeInCP;
315     private javax.swing.JLabel JavaDoc jarLocation;
316     private javax.swing.JTextField JavaDoc jarLocationValue;
317     private javax.swing.JLabel JavaDoc releaseVersion;
318     private javax.swing.JTextField JavaDoc releaseVersionValue;
319     private javax.swing.JButton JavaDoc showJavadocButton;
320     private javax.swing.JRadioButton JavaDoc specVer;
321     private javax.swing.JTextField JavaDoc specVerValue;
322     private javax.swing.ButtonGroup JavaDoc versionGroup;
323     // End of variables declaration//GEN-END:variables
324

325 }
326
Popular Tags