1 19 20 package org.netbeans.modules.java.project; 21 22 import java.awt.Component ; 23 import java.io.File ; 24 import javax.swing.AbstractListModel ; 25 import javax.swing.DefaultListCellRenderer ; 26 import javax.swing.Icon ; 27 import javax.swing.ImageIcon ; 28 import javax.swing.JFileChooser ; 29 import javax.swing.JList ; 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 43 public class BrokenReferencesCustomizer extends javax.swing.JPanel { 44 45 private BrokenReferencesModel model; 46 private File lastSelectedFile; 47 48 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 62 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 64 65 errorListLabel = new javax.swing.JLabel (); 66 jScrollPane1 = new javax.swing.JScrollPane (); 67 errorList = new javax.swing.JList (); 68 fix = new javax.swing.JButton (); 69 descriptionLabel = new javax.swing.JLabel (); 70 jScrollPane2 = new javax.swing.JScrollPane (); 71 description = new javax.swing.JTextArea (); 72 73 setLayout(new java.awt.GridBagLayout ()); 74 75 setPreferredSize(new java.awt.Dimension (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 (); 81 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 82 gridBagConstraints.insets = new java.awt.Insets (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 () { 88 public void valueChanged(javax.swing.event.ListSelectionEvent evt) { 89 errorListValueChanged(evt); 90 } 91 }); 92 93 jScrollPane1.setViewportView(errorList); 94 95 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 () { 107 public void actionPerformed(java.awt.event.ActionEvent evt) { 108 fixActionPerformed(evt); 109 } 110 }); 111 112 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 124 gridBagConstraints.gridx = 0; 125 gridBagConstraints.gridy = 2; 126 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 127 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (0, 12, 5, 0); 142 add(jScrollPane2, gridBagConstraints); 143 144 } 146 private void errorListValueChanged(javax.swing.event.ListSelectionEvent evt) { updateSelection(); 148 } 150 private void fixActionPerformed(java.awt.event.ActionEvent evt) { 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 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 (); 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 } 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 fix.setEnabled(true); 199 } 200 } else { 201 description.setText(""); 202 fix.setEnabled(false); 203 } 204 } 205 206 207 private javax.swing.JTextArea description; 209 private javax.swing.JLabel descriptionLabel; 210 private javax.swing.JList errorList; 211 private javax.swing.JLabel errorListLabel; 212 private javax.swing.JButton fix; 213 private javax.swing.JScrollPane jScrollPane1; 214 private javax.swing.JScrollPane jScrollPane2; 215 217 private static Icon brokenRef = new ImageIcon (Utilities.loadImage("org/netbeans/modules/java/project/resources/broken-reference.gif")); private static Icon resolvedRef = new ImageIcon (Utilities.loadImage("org/netbeans/modules/java/project/resources/resolved-reference.gif")); 220 private static class ListCellRendererImpl extends DefaultListCellRenderer { 221 222 private BrokenReferencesModel model; 223 224 public ListCellRendererImpl(BrokenReferencesModel model) { 225 this.model = model; 226 } 227 228 public Component getListCellRendererComponent( JList list, Object 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 |