Changeset 8360


Ignore:
Timestamp:
2004-10-18T13:43:20+13:00 (20 years ago)
Author:
kjdon
Message:

changed the removelistener for classifier list - if remove a classifier it now selects the next one in the list (or previous one if the list one was deleted)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java

    r8249 r8360  
    957957    }
    958958
    959     /** This class listens for actions upon the remove button in the controls, and if detected calls the removeClassifier() method.
     959    /** This class listens for actions upon the remove button in the controls, and if detected calls the <i>removeClassifier()</i> method.
    960960     */
    961961    private class RemoveListener
    962962        implements ActionListener {
    963         /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls, so we can remove the selected Classifier.
     963        /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
    964964         * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
    965          * @see org.greenstone.gatherer.cdm.Classifier
    966965         */
    967966        public void actionPerformed(ActionEvent event) {
    968         if(!classifier_list.isSelectionEmpty()) {
    969             Object [] objects = classifier_list.getSelectedValues();
    970             for(int i = 0; i < objects.length; i++) {
    971             if(objects[i] instanceof Classifier) {
    972                 removeClassifier((Classifier)objects[i]);
    973             }
    974             }
    975         }
    976         }
    977     }
    978     }
     967        if(classifier_list.isSelectionEmpty()) {
     968            remove.setEnabled(false);
     969            return;
     970        }
     971        int selected_index = classifier_list.getSelectedIndex();
     972        Object selected_classifier = classifier_list.getSelectedValue();
     973        if (!(selected_classifier instanceof Classifier)) {
     974            return; // what else could we have here???
     975        }
     976        removeClassifier((Classifier)selected_classifier);
     977
     978        if (selected_index >= classifier_list.getModel().getSize()) {
     979            selected_index--;
     980        }
     981        if (selected_index >=0) {
     982            classifier_list.setSelectedIndex(selected_index);
     983        } else {
     984            // no more classifiers in the list
     985            remove.setEnabled(false);
     986        }
     987       
     988        }
     989    }
     990    }
     991   
     992
     993   
    979994}
Note: See TracChangeset for help on using the changeset viewer.