From: <rh...@us...> - 2014-08-30 12:39:12
|
Revision: 27110 http://sourceforge.net/p/jmri/code/27110 Author: rhwood Date: 2014-08-30 12:39:03 +0000 (Sat, 30 Aug 2014) Log Message: ----------- Don't enable Activate or Copy buttons if multiple profiles are selected. Delete every profile (prompting the user for each) if multiple profiles are selected when Delete button is pressed. Remove all selected search paths if multiple paths are selected when Remove button is pressed. Modified Paths: -------------- trunk/jmri/java/src/jmri/profile/ProfilePreferencesPanel.java Modified: trunk/jmri/java/src/jmri/profile/ProfilePreferencesPanel.java =================================================================== --- trunk/jmri/java/src/jmri/profile/ProfilePreferencesPanel.java 2014-08-30 10:32:45 UTC (rev 27109) +++ trunk/jmri/java/src/jmri/profile/ProfilePreferencesPanel.java 2014-08-30 12:39:03 UTC (rev 27110) @@ -10,6 +10,7 @@ import java.awt.event.MouseEvent; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.ResourceBundle; import javax.swing.GroupLayout; import javax.swing.JButton; @@ -330,15 +331,17 @@ }//GEN-LAST:event_btnAddSearchPathActionPerformed private void btnRemoveSearchPathActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnRemoveSearchPathActionPerformed - File path = (File) searchPaths.getSelectedValue(); - try { - ProfileManager.defaultManager().removeSearchPath(path); - } catch (IOException ex) { - log.warn("Unable to write profiles while removing search path {}", path.getPath(), ex); - JOptionPane.showMessageDialog(this, - Bundle.getMessage("ProfilePreferencesPanel.btnRemoveSearchPath.errorMessage", path.getPath(), ex.getLocalizedMessage()), - Bundle.getMessage("ProfilePreferencesPanel.btnRemoveSearchPath.errorTitle"), - JOptionPane.ERROR_MESSAGE); + for (Object value : this.searchPaths.getSelectedValues()) { // getSelectedValues is deprecated in Java 1.7 + File path = (File) value; + try { + ProfileManager.defaultManager().removeSearchPath(path); + } catch (IOException ex) { + log.warn("Unable to write profiles while removing search path {}", path.getPath(), ex); + JOptionPane.showMessageDialog(this, + Bundle.getMessage("ProfilePreferencesPanel.btnRemoveSearchPath.errorMessage", path.getPath(), ex.getLocalizedMessage()), + Bundle.getMessage("ProfilePreferencesPanel.btnRemoveSearchPath.errorTitle"), + JOptionPane.ERROR_MESSAGE); + } } }//GEN-LAST:event_btnRemoveSearchPathActionPerformed @@ -378,30 +381,35 @@ }//GEN-LAST:event_btnCreateNewProfileActionPerformed private void btnDeleteProfileActionPerformed(ActionEvent evt) {//GEN-FIRST:event_btnDeleteProfileActionPerformed - Profile deletedProfile = ProfileManager.defaultManager().getAllProfiles().get(profilesTbl.getSelectedRow()); - int result = JOptionPane.showOptionDialog(this, - Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.dlgMessage", deletedProfile.getName()), // NOI18N - Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.dlgTitle", deletedProfile.getName()), // NOI18N - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.QUESTION_MESSAGE, - null, // use default icon - new String[]{ - Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.text"), // NOI18N - Bundle.getMessage("AddProfileDialog.btnCancel.text") // NOI18N - }, - JOptionPane.CANCEL_OPTION - ); - if (result == JOptionPane.OK_OPTION) { - if (!FileUtil.delete(deletedProfile.getPath())) { - log.warn("Unable to delete profile directory {}", deletedProfile.getPath()); - JOptionPane.showMessageDialog(this, - Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.errorMessage", deletedProfile.getPath()), - Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.errorMessage"), - JOptionPane.ERROR_MESSAGE); + ArrayList<Profile> profiles = new ArrayList<Profile>(this.profilesTbl.getSelectedRowCount()); + for (int row : this.profilesTbl.getSelectedRows()) { + profiles.add(ProfileManager.defaultManager().getAllProfiles().get(row)); + } + for (Profile deletedProfile : profiles) { + int result = JOptionPane.showOptionDialog(this, + Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.dlgMessage", deletedProfile.getName()), // NOI18N + Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.dlgTitle", deletedProfile.getName()), // NOI18N + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, // use default icon + new String[]{ + Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.text"), // NOI18N + Bundle.getMessage("AddProfileDialog.btnCancel.text") // NOI18N + }, + JOptionPane.CANCEL_OPTION + ); + if (result == JOptionPane.OK_OPTION) { + if (!FileUtil.delete(deletedProfile.getPath())) { + log.warn("Unable to delete profile directory {}", deletedProfile.getPath()); + JOptionPane.showMessageDialog(this, + Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.errorMessage", deletedProfile.getPath()), + Bundle.getMessage("ProfilePreferencesPanel.btnDeleteProfile.errorMessage"), + JOptionPane.ERROR_MESSAGE); + } + ProfileManager.defaultManager().removeProfile(deletedProfile); + log.info("Removed profile \"{}\" from {}", deletedProfile.getName(), deletedProfile.getPath()); + profilesTbl.repaint(); } - ProfileManager.defaultManager().removeProfile(deletedProfile); - log.info("Removed profile \"{}\" from {}", deletedProfile.getName(), deletedProfile.getPath()); - profilesTbl.repaint(); } }//GEN-LAST:event_btnDeleteProfileActionPerformed @@ -513,7 +521,7 @@ @Override public void valueChanged(ListSelectionEvent e) { - if (profilesTbl.getSelectedRow() != -1 && profilesTbl.getSelectedRow() < ProfileManager.defaultManager().getAllProfiles().size()) { + if (profilesTbl.getSelectedRowCount() == 1 && profilesTbl.getSelectedRow() < ProfileManager.defaultManager().getAllProfiles().size()) { Profile p = ProfileManager.defaultManager().getAllProfiles().get(profilesTbl.getSelectedRow()); this.btnDeleteProfile.setEnabled(!p.equals(ProfileManager.defaultManager().getActiveProfile())); if (ProfileManager.defaultManager().getNextActiveProfile() != null) { @@ -523,6 +531,18 @@ } this.btnCopyProfile.setEnabled(true); this.btnExportProfile.setEnabled(true); + } else if (this.profilesTbl.getSelectedRowCount() > 1) { + this.btnDeleteProfile.setEnabled(true); + for (int row : this.profilesTbl.getSelectedRows()) { + Profile p = ProfileManager.defaultManager().getAllProfiles().get(row); + if (p.equals(ProfileManager.defaultManager().getActiveProfile())) { + this.btnDeleteProfile.setEnabled(false); + break; + } + } + this.btnCopyProfile.setEnabled(false); + this.btnExportProfile.setEnabled(false); + this.btnActivateProfile.setEnabled(false); } else { this.btnDeleteProfile.setEnabled(false); this.btnCopyProfile.setEnabled(false); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |