KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > project > BrokenReferencesCustomizer


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.java.project;
21
22 import java.awt.Component JavaDoc;
23 import java.io.File JavaDoc;
24 import javax.swing.AbstractListModel JavaDoc;
25 import javax.swing.DefaultListCellRenderer JavaDoc;
26 import javax.swing.Icon JavaDoc;
27 import javax.swing.ImageIcon JavaDoc;
28 import javax.swing.JFileChooser JavaDoc;
29 import javax.swing.JList JavaDoc;
30
31 import org.netbeans.api.java.platform.PlatformsCustomizer;
32 import org.netbeans.api.project.libraries.LibrariesCustomizer;
33 import org.netbeans.spi.project.ui.support.ProjectChooser;
34 import org.openide.awt.Mnemonics;
35 import org.openide.filesystems.FileUtil;
36 import org.openide.util.NbBundle;
37 import org.openide.util.Utilities;
38
39 /**
40  *
41  * @author David Konecny
42  */

43 public class BrokenReferencesCustomizer extends javax.swing.JPanel JavaDoc {
44
45     private BrokenReferencesModel model;
46     private File JavaDoc lastSelectedFile;
47     
48     /** Creates new form BrokenReferencesCustomizer */
49     public BrokenReferencesCustomizer(BrokenReferencesModel model) {
50         initComponents();
51         this.model = model;
52         errorList.setModel(model);
53         errorList.setSelectedIndex(0);
54         errorList.setCellRenderer(new ListCellRendererImpl(model));
55     }
56     
57     /** This method is called from within the constructor to
58      * initialize the form.
59      * WARNING: Do NOT modify this code. The content of this method is
60      * always regenerated by the Form Editor.
61      */

62     private void initComponents() {//GEN-BEGIN:initComponents
63
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
64
65         errorListLabel = new javax.swing.JLabel JavaDoc();
66         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
67         errorList = new javax.swing.JList JavaDoc();
68         fix = new javax.swing.JButton JavaDoc();
69         descriptionLabel = new javax.swing.JLabel JavaDoc();
70         jScrollPane2 = new javax.swing.JScrollPane JavaDoc();
71         description = new javax.swing.JTextArea JavaDoc();
72
73         setLayout(new java.awt.GridBagLayout JavaDoc());
74
75         setPreferredSize(new java.awt.Dimension JavaDoc(450, 300));
76         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "ACSN_BrokenReferencesCustomizer"));
77         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "ACSD_BrokenReferencesCustomizer"));
78         errorListLabel.setLabelFor(errorList);
79         org.openide.awt.Mnemonics.setLocalizedText(errorListLabel, org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "LBL_BrokenLinksCustomizer_List"));
80         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
81         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
82         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 3, 0);
83         add(errorListLabel, gridBagConstraints);
84         errorListLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "ACSD_BrokenLinksCustomizer_List"));
85
86         errorList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
87         errorList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
88             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
89                 errorListValueChanged(evt);
90             }
91         });
92
93         jScrollPane1.setViewportView(errorList);
94
95         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
96         gridBagConstraints.gridx = 0;
97         gridBagConstraints.gridy = 1;
98         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
99         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
100         gridBagConstraints.weightx = 1.0;
101         gridBagConstraints.weighty = 1.0;
102         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
103         add(jScrollPane1, gridBagConstraints);
104
105         org.openide.awt.Mnemonics.setLocalizedText(fix, org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "LBL_BrokenLinksCustomizer_Fix"));
106         fix.addActionListener(new java.awt.event.ActionListener JavaDoc() {
107             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
108                 fixActionPerformed(evt);
109             }
110         });
111
112         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
113         gridBagConstraints.gridx = 1;
114         gridBagConstraints.gridy = 1;
115         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
116         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
117         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 12);
118         add(fix, gridBagConstraints);
119         fix.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "ACSD_BrokenLinksCustomizer_Fix"));
120
121         descriptionLabel.setLabelFor(description);
122         org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "LBL_BrokenLinksCustomizer_Description"));
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridx = 0;
125         gridBagConstraints.gridy = 2;
126         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
127         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 3, 0);
128         add(descriptionLabel, gridBagConstraints);
129         descriptionLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(BrokenReferencesCustomizer.class, "ACSD_BrokenLinksCustomizer_Description"));
130
131         description.setEditable(false);
132         description.setLineWrap(true);
133         description.setWrapStyleWord(true);
134         jScrollPane2.setViewportView(description);
135
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridx = 0;
138         gridBagConstraints.gridy = 3;
139         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
140         gridBagConstraints.ipady = 60;
141         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
142         add(jScrollPane2, gridBagConstraints);
143
144     }//GEN-END:initComponents
145

146     private void errorListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_errorListValueChanged
147
updateSelection();
148     }//GEN-LAST:event_errorListValueChanged
149

150     private void fixActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_fixActionPerformed
151
int index = errorList.getSelectedIndex();
152         if (index==-1) {
153             return;
154         }
155         BrokenReferencesModel.OneReference or = model.getOneReference(index);
156         if (or.getType() == BrokenReferencesModel.REF_TYPE_LIBRARY ||
157             or.getType() == BrokenReferencesModel.REF_TYPE_LIBRARY_CONTENT) {
158             LibrariesCustomizer.showCustomizer(null);
159         } else if (or.getType() == BrokenReferencesModel.REF_TYPE_PLATFORM) {
160             PlatformsCustomizer.showCustomizer(null);
161         } else {
162             JFileChooser JavaDoc chooser;
163             if (or.getType() == BrokenReferencesModel.REF_TYPE_PROJECT) {
164                 chooser = ProjectChooser.projectChooser();
165                 chooser.setDialogTitle(NbBundle.getMessage(BrokenReferencesCustomizer.class,
166                     "LBL_BrokenLinksCustomizer_Resolve_Project", or.getDisplayID()));
167             } else {
168                 chooser = new JFileChooser JavaDoc();
169                 FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
170                 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
171                 chooser.setDialogTitle(NbBundle.getMessage(BrokenReferencesCustomizer.class,
172                     "LBL_BrokenLinksCustomizer_Resolve_File", or.getDisplayID()));
173             }
174             if (lastSelectedFile != null) {
175                 chooser.setSelectedFile(lastSelectedFile);
176             }
177             int option = chooser.showOpenDialog(null);
178             if (option == JFileChooser.APPROVE_OPTION) {
179                 model.updateReference(errorList.getSelectedIndex(), chooser.getSelectedFile());
180                 lastSelectedFile = chooser.getSelectedFile();
181             }
182         }
183         model.refresh();
184         updateSelection();
185     }//GEN-LAST:event_fixActionPerformed
186

187     private void updateSelection() {
188         if (errorList.getSelectedIndex() != -1 && errorList.getSelectedIndex() < model.getSize()) {
189             if (model.isBroken(errorList.getSelectedIndex())) {
190                 description.setText(model.getDesciption(errorList.getSelectedIndex()));
191                 fix.setEnabled(true);
192             } else {
193                 description.setText(NbBundle.getMessage(BrokenReferencesCustomizer.class,
194                     "LBL_BrokenLinksCustomizer_Problem_Was_Resolved"));
195                 // Leave the button always enabled so that user can alter
196
// resolved reference. Especially needed for automatically
197
// resolved JAR references.
198
fix.setEnabled(true);
199             }
200         } else {
201             description.setText("");
202             fix.setEnabled(false);
203         }
204     }
205     
206     
207     // Variables declaration - do not modify//GEN-BEGIN:variables
208
private javax.swing.JTextArea JavaDoc description;
209     private javax.swing.JLabel JavaDoc descriptionLabel;
210     private javax.swing.JList JavaDoc errorList;
211     private javax.swing.JLabel JavaDoc errorListLabel;
212     private javax.swing.JButton JavaDoc fix;
213     private javax.swing.JScrollPane JavaDoc jScrollPane1;
214     private javax.swing.JScrollPane JavaDoc jScrollPane2;
215     // End of variables declaration//GEN-END:variables
216

217     private static Icon JavaDoc brokenRef = new ImageIcon JavaDoc(Utilities.loadImage("org/netbeans/modules/java/project/resources/broken-reference.gif")); // NOI18N
218
private static Icon JavaDoc resolvedRef = new ImageIcon JavaDoc(Utilities.loadImage("org/netbeans/modules/java/project/resources/resolved-reference.gif")); // NOI18N
219

220     private static class ListCellRendererImpl extends DefaultListCellRenderer JavaDoc {
221
222         private BrokenReferencesModel model;
223         
224         public ListCellRendererImpl(BrokenReferencesModel model) {
225             this.model = model;
226         }
227         
228         public Component JavaDoc getListCellRendererComponent( JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
229             super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus );
230             if (model.isBroken(index)) {
231                 setIcon(brokenRef);
232             } else {
233                 setIcon(resolvedRef);
234             }
235             
236             return this;
237         }
238     }
239     
240 }
241
Popular Tags