--- a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/Bundle.properties +++ a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/Bundle.properties @@ -68,3 +68,5 @@ LBL_PleaseWait=Please wait, searching for configuration files... LBL_NoFilesFound=No configuration files found. LBL_FileAlreadyAdded=These configuration files have already been added: +SelectConfigFilesPanel.btnSelectAll.text=Select &All +SelectConfigFilesPanel.btnSelectNone.text=Select &None --- a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/ConfigFilesUIs.java +++ a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/ConfigFilesUIs.java @@ -47,6 +47,7 @@ import java.awt.Component; import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Set; import javax.swing.DefaultListCellRenderer; @@ -57,6 +58,7 @@ import javax.swing.JTable; import javax.swing.ListModel; import javax.swing.event.ListDataListener; +import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; @@ -112,6 +114,10 @@ public static List getSelectedFiles(JTable table) { return ((ConfigFileSelectionTableModel)table.getModel()).getSelectedFiles(); } + + public static List getSelectableFiles(JTable table) { + return ((ConfigFileSelectionTableModel)table.getModel()).getSelectableFiles(); + } private static final class ConfigFileGroupListModel implements ListModel { @@ -187,11 +193,12 @@ } } - private static final class ConfigFileSelectionTableModel implements TableModel { + private static final class ConfigFileSelectionTableModel implements TableModel, SelectAllNoneModel { private final List availableFiles; private final Set alreadySelectedFiles; private boolean[] selected; + private final Collection listeners=new ArrayList(); public ConfigFileSelectionTableModel(List availableFiles, Set alreadySelectedFiles) { this.availableFiles = availableFiles; @@ -200,6 +207,7 @@ } public void addTableModelListener(TableModelListener l) { + listeners.add(l); } public Class getColumnClass(int columnIndex) { @@ -227,11 +235,13 @@ } public void removeTableModelListener(TableModelListener l) { + listeners.remove(l); } public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if (isEnabled(rowIndex)) { selected[rowIndex] = (Boolean)aValue; + informListeners(); } } @@ -248,6 +258,47 @@ } return result; } + + public List getSelectableFiles() { + List result = new ArrayList(availableFiles.size()); + for (int i = 0; i < availableFiles.size(); i++) { + if (isEnabled(i)) { + result.add(availableFiles.get(i)); + } + } + return result; + } + + /** + * Select all enabled files. + */ + @Override + public void selectAll() { + select(Boolean.TRUE); + } + + /** + * Deselect all enabled selected files. + */ + @Override + public void selectNone() { + select(Boolean.FALSE); + } + + private void select(Boolean state) { + for (int rowIndex = 0; rowIndex < selected.length; rowIndex++) { + if (isEnabled(rowIndex)) { + selected[rowIndex] = state; + } + } + informListeners(); + } + + private void informListeners() { + for (TableModelListener l : listeners) { + l.tableChanged(new TableModelEvent(this)); + } + } } private static final class ConfigFileSelectionFileRenderer extends DefaultTableCellRenderer { @@ -304,6 +355,18 @@ } } + interface SelectAllNoneModel { + /** + * Select all entries. + */ + void selectAll(); + + /** + * Deselect all entries.. + */ + void selectNone(); + } + public interface FileDisplayName { String getDisplayName(File file); --- a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/SelectConfigFilesPanel.form +++ a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/SelectConfigFilesPanel.form @@ -1,11 +1,11 @@ - +
- + @@ -16,13 +16,24 @@ - + - + - - + + + + + + + + + + + + + @@ -34,7 +45,12 @@ - + + + + + + @@ -86,5 +102,26 @@ + + + + + + + + + + + + + + + + + + + + + --- a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/SelectConfigFilesPanel.java +++ a/spring.beans/src/org/netbeans/modules/spring/beans/ui/customizer/SelectConfigFilesPanel.java @@ -55,6 +55,9 @@ import java.util.Set; import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.table.TableModel; import org.netbeans.api.java.project.JavaProjectConstants; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectUtils; @@ -155,16 +158,33 @@ return ConfigFilesUIs.getSelectedFiles(configFileTable); } + public List getSelectableFiles() { + return ConfigFilesUIs.getSelectableFiles(configFileTable); + } + private void cancelDetection() { if (detectTask != null) { detectTask.cancel(); } } + private void updateSelectAllNonButtons() { + final int maxSize = getSelectableFiles().size(); + final int size = getSelectedFiles().size(); + + btnSelectAll.setEnabled(maxSize > 0 && size < maxSize); + btnSelectNone.setEnabled(maxSize > 0 && size > 0); + } private void updateAvailableFiles(List availableFiles) { this.availableFiles = availableFiles; configFileTable.setEnabled(true); ConfigFilesUIs.connectFilesSelectionTable(availableFiles, alreadySelectedFiles, configFileTable); + configFileTable.getModel().addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(TableModelEvent e) { + updateSelectAllNonButtons(); + } + }); configFileTable.getColumnModel().getColumn(0).setMaxWidth(0); // In an attempt to hide the progress bar and label, but force // the occupy the same space. @@ -174,6 +194,8 @@ progressBar.setBorderPainted(false); progressBar.setBackground(getBackground()); descriptor.setValid(true); + + updateSelectAllNonButtons(); } /** This method is called from within the constructor to @@ -190,8 +212,10 @@ configFileTable = new javax.swing.JTable(); progressBar = new javax.swing.JProgressBar(); messageLabel = new javax.swing.JLabel(); + btnSelectAll = new javax.swing.JButton(); + btnSelectNone = new javax.swing.JButton(); - detectedFilesLabel.setText(org.openide.util.NbBundle.getMessage(SelectConfigFilesPanel.class, "LBL_ConfigFiles")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(detectedFilesLabel, org.openide.util.NbBundle.getMessage(SelectConfigFilesPanel.class, "LBL_ConfigFiles")); // NOI18N configFileTable.setIntercellSpacing(new java.awt.Dimension(0, 0)); configFileTable.setShowHorizontalLines(false); @@ -202,19 +226,42 @@ progressBar.setString(" "); // NOI18N progressBar.setStringPainted(true); - messageLabel.setText(org.openide.util.NbBundle.getMessage(SelectConfigFilesPanel.class, "LBL_PleaseWait")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(messageLabel, org.openide.util.NbBundle.getMessage(SelectConfigFilesPanel.class, "LBL_PleaseWait")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(btnSelectAll, org.openide.util.NbBundle.getMessage(SelectConfigFilesPanel.class, "SelectConfigFilesPanel.btnSelectAll.text")); // NOI18N + btnSelectAll.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnSelectAllActionPerformed(evt); + } + }); + + btnSelectNone.setMnemonic('n'); + org.openide.awt.Mnemonics.setLocalizedText(btnSelectNone, org.openide.util.NbBundle.getMessage(SelectConfigFilesPanel.class, "SelectConfigFilesPanel.btnSelectNone.text")); // NOI18N + btnSelectNone.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnSelectNoneActionPerformed(evt); + } + }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createSequentialGroup() .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(configFileScrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE) - .addComponent(progressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE) - .addComponent(detectedFilesLabel, javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(messageLabel, javax.swing.GroupLayout.Alignment.LEADING)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(configFileScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE) + .addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(detectedFilesLabel) + .addComponent(messageLabel)) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btnSelectAll) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnSelectNone))) .addContainerGap()) ); layout.setVerticalGroup( @@ -223,7 +270,11 @@ .addContainerGap() .addComponent(detectedFilesLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(configFileScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE) + .addComponent(configFileScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnSelectAll) + .addComponent(btnSelectNone)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(messageLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -232,8 +283,24 @@ ); }// //GEN-END:initComponents + private void btnSelectNoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectNoneActionPerformed + if (configFileTable.getModel() instanceof ConfigFilesUIs.SelectAllNoneModel) { + ((ConfigFilesUIs.SelectAllNoneModel) configFileTable.getModel()).selectNone(); + configFileTable.repaint(); + } + }//GEN-LAST:event_btnSelectNoneActionPerformed + + private void btnSelectAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectAllActionPerformed + if (configFileTable.getModel() instanceof ConfigFilesUIs.SelectAllNoneModel) { + ((ConfigFilesUIs.SelectAllNoneModel) configFileTable.getModel()).selectAll(); + configFileTable.repaint(); + } + }//GEN-LAST:event_btnSelectAllActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnSelectAll; + private javax.swing.JButton btnSelectNone; private javax.swing.JScrollPane configFileScrollPane; private javax.swing.JTable configFileTable; private javax.swing.JLabel detectedFilesLabel;