Changeset 12283


Ignore:
Timestamp:
2006-07-24T13:46:29+12:00 (18 years ago)
Author:
kjdon
Message:

made this more like LanguageManager. A bit more simple.

File:
1 edited

Legend:

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

    r12123 r12283  
    6060    super(subindexes, CollectionConfiguration.INDEX_ELEMENT, new SubcollectionIndex());
    6161    DebugStream.println("SubcollectionIndexManager: " + getSize() + " subcollection indexes parsed.");
    62     model = this;
     62    this.model = this;
    6363
    6464    // Parse and retrieve the default index
     
    7878    {
    7979    if (!contains(subcollection_index)) {
     80        // add a pseudo metadata
     81        CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + subcollection_index.getID());
     82        metadatum.setValue(subcollection_index.getID());
     83        CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
    8084        add(getSize(), subcollection_index);
    8185        Gatherer.c_man.configurationChanged();
     
    112116    }
    113117
     118    /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
     119     * @param mode the new mode as an int
     120     */
     121    public void modeChanged(int mode) {
     122   
     123    }
    114124
    115125    private int moveSubcollectionIndex(SubcollectionIndex subcollection_index, boolean move_up)
     
    154164    if (subcollection_index != null) {
    155165        // Remove any current metadata from this index
    156         CollectionDesignManager.collectionmeta_manager.removeMetadata("." + subcollection_index.getID());
     166        CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + subcollection_index.getID());
    157167
    158168        // Check if the index removed happens to be the default index
    159169        if (default_index != null && default_index.equals(subcollection_index)) {
    160         // If so our first solution is to set the first subcollection index to be the default
    161         if (getSize() > 0) {
    162             setDefaultSubcollectionIndex((SubcollectionIndex) getElementAt(0));
    163         }
    164         else {
    165             default_index.setAssigned(false);
    166         }
    167         }
    168 
     170        setDefault(null);
     171        }
     172       
    169173        // Remove the index
    170174        remove(subcollection_index);
     
    191195    }
    192196
     197    private void replaceSubcollectionIndex(SubcollectionIndex old_subcollection, SubcollectionIndex new_subcollection) {
     198    // Remove old collection meta
     199    CollectionDesignManager.collectionmeta_manager.removeMetadata(CollectionConfiguration.STOP_CHARACTER + old_subcollection.getID());
     200    // Add new one
     201    CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + new_subcollection.getID());
     202    metadatum.setValue(new_subcollection.getID());
     203    CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
     204    if(default_index != null && default_index.equals(old_subcollection)) {
     205        setDefault(new_subcollection);
     206    }
     207
     208    // get the position of the old one
     209    int position = indexOf(old_subcollection);
     210    remove(old_subcollection);
     211    add(position, new_subcollection);
     212   
     213    // Schedule the collection for saving
     214    Gatherer.c_man.configurationChanged();
     215
     216    }
    193217
    194218    /** Method to set the default subcollection index.
     
    198222     * @see org.greenstone.gatherer.cdm.SubcollectionIndex
    199223     */
    200     private void setDefaultSubcollectionIndex(SubcollectionIndex subcollection_index)
     224    private void setDefault(SubcollectionIndex subcollection_index)
    201225    {
    202226    if (subcollection_index != null) {
     
    306330        set_default_button.addActionListener(new SetDefaultListener());
    307331        set_default_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
    308         subcollection_index_list.addListSelectionListener(new SubcollectionIndexListListener());
     332        subcollection_index_list.addListSelectionListener(new AssignedListListener());
    309333        source_list.addListSelectionListener(new SourceListListener());
    310334
     
    370394        subcollection_index_list.updateUI();
    371395
    372         // If there is one selected, fill in the controls
    373         updateControlsWithSelectedIndex();
    374     }
    375 
    376 
    377     public void loseFocus()
    378     {
    379     }
    380 
     396        clearControls();
     397       
     398    }
     399
     400
     401    public void loseFocus() {
     402    }
     403
     404    private void clearControls() {
     405        subcollection_index_list.clearSelection();
     406        source_list.clearTicked();
     407        add_button.setEnabled(false);
     408        remove_button.setEnabled(false);
     409        replace_button.setEnabled(false);
     410        set_default_button.setEnabled(false);
     411        move_down_button.setEnabled(false);
     412        move_up_button.setEnabled(false);
     413
     414    }
    381415
    382416    private void updateControlsWithSelectedIndex()
     
    384418        SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
    385419        if (selected_index == null) {
     420        source_list.clearTicked();
    386421        return;
    387422        }
     
    393428
    394429
    395     private void validateControls()
    396     {
     430    private void validateButtons() {
     431       
    397432        boolean add_enabled = false;
    398433        boolean replace_enabled = false;
    399434
    400435        // Can't add a new index if no sources are selected
    401         if (source_list.isNothingTicked()) {
    402         add_enabled = false;
    403         }
    404         // If we get this far, create a dummy index and see if it's already assigned in the collection
    405         else {
    406         ArrayList sources = source_list.getTicked();
     436        if (!source_list.isNothingTicked()) {
     437        ArrayList sources = source_list.getTicked();
    407438        SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray());
    408439
    409440        // Subcollection index already exists: can't add, but can replace if the name has changed
    410         if (model.contains(subcollection_index)) {
    411             add_enabled = false;
    412 
    413             // Here we need to check if we have changed the name - if so, we can enable the replace button
    414             if (subcollection_index_list.getSelectedIndex() != -1) {
    415             SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
    416             }
    417         }
    418 
    419         // Subcollection index doesn't already exist: can add, or replace if there is something selected
    420         else {
     441        if (!model.contains(subcollection_index)) {
    421442            add_enabled = true;
    422             if (subcollection_index_list.getSelectedIndex() != -1) {
     443            if (!subcollection_index_list.isSelectionEmpty()) {
    423444            replace_enabled = true;
    424445            }
     
    433454
    434455    private class AddListener
    435         implements ActionListener
    436     {
     456        implements ActionListener {
     457       
    437458        public void actionPerformed(ActionEvent event)
    438459        {
    439         if (!source_list.isNothingTicked()) {// && name.length() != 0) {
     460        if (!source_list.isNothingTicked()) {
    440461            ArrayList sources = source_list.getTicked();
    441462            SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray());
    442 
    443             // Before we add the index to the model, we have to add a default collection metadata for this
    444             CollectionMeta metadatum = new CollectionMeta("." + subcollection_index.getID());
    445             metadatum.setValue(subcollection_index.getID());
    446             CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
    447 
    448             // Finally, add the subcollection index
    449463            addSubcollectionIndex(subcollection_index);
    450             subcollection_index_list.setSelectedIndex(model.getSize() - 1);
     464            clearControls();
    451465        }
    452466        }
     
    476490    }
    477491
    478 
    479     /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
    480     private class NameListener
    481         implements DocumentListener
    482     {
    483         public void changedUpdate(DocumentEvent e)
    484         {
    485         validateControls();
    486         }
    487 
    488         public void insertUpdate(DocumentEvent e)
    489         {
    490         validateControls();
    491         }
    492 
    493         public void removeUpdate(DocumentEvent e)
    494         {
    495         validateControls();
    496         }
    497     }
    498 
    499 
    500492    private class RemoveListener
    501493        implements ActionListener
    502494    {
    503         public void actionPerformed(ActionEvent event)
    504         {
    505         int i = subcollection_index_list.getSelectedIndex();
    506         if (i != -1) {
    507             removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue());
    508         }
    509 
    510         int size = subcollection_index_list.getModel().getSize();
    511         if (i == size) {
    512             i--;
    513         }
    514         subcollection_index_list.setSelectedIndex(i);
    515         validateControls();
     495        public void actionPerformed(ActionEvent event) {
     496       
     497        SubcollectionIndex delete_me = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
     498        if (delete_me != null) {
     499            removeSubcollectionIndex(delete_me);
     500        }
    516501        }
    517502    }
     
    519504
    520505    private class ReplaceListener
    521         implements ActionListener
    522     {
    523         public void actionPerformed(ActionEvent event)
    524         {
    525         if (subcollection_index_list.isSelectionEmpty()) {
     506        implements ActionListener {
     507       
     508        public void actionPerformed(ActionEvent event) {
     509       
     510        if (subcollection_index_list.isSelectionEmpty()|| source_list.isNothingTicked()) {
    526511            // This should never happen, but just in case...
    527512            replace_button.setEnabled(false);
    528513            return;
    529514        }
    530 
    531         // We'll just remove the old one and add the new one
    532         removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue());
    533         replace_button.setEnabled(false);
    534         add_button.setEnabled(true);
    535         add_button.doClick();
    536         add_button.setEnabled(false);
     515        SubcollectionIndex old_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
     516        ArrayList sources = source_list.getTicked();
     517        SubcollectionIndex new_index = new SubcollectionIndex(sources.toArray());
     518        replaceSubcollectionIndex(old_index, new_index);
    537519        }
    538520    }
     
    540522
    541523    private class SetDefaultListener
    542         implements ActionListener
    543     {
     524        implements ActionListener {
     525       
    544526        public void actionPerformed(ActionEvent event)
    545527        {
    546528        SubcollectionIndex subcollection_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
    547529        if (subcollection_index != null) {
    548             setDefaultSubcollectionIndex(subcollection_index);
     530            setDefault(subcollection_index);
    549531            // This should cause a repaint of just the desired row
    550532            subcollection_index_list.setSelectedValue(subcollection_index, true);
     
    556538
    557539    private class SourceListListener
    558         implements ListSelectionListener
    559     {
    560         public void valueChanged(ListSelectionEvent event)
    561         {
    562         validateControls();
    563         }
    564     }
    565 
    566 
    567     /** Listens for selections within the list on the SubcollectionIndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
    568     private class SubcollectionIndexListListener
    569         implements ListSelectionListener
    570     {
    571         /** This method is called whenever the source list selection changes. When it does we need to fill in the various parts of the list description panel
    572          * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
    573          */
    574         public void valueChanged(ListSelectionEvent event)
    575         {
     540        implements ListSelectionListener {
     541   
     542        public void valueChanged(ListSelectionEvent event) {
    576543        if (event.getValueIsAdjusting()) {
    577544            return;
    578545        }
    579 
     546        validateButtons();
     547        }
     548    }
     549
     550
     551    /** Listens for selections within the assigned subcollection indexes list  */
     552    private class AssignedListListener
     553        implements ListSelectionListener {
     554       
     555        public void valueChanged(ListSelectionEvent event) {
     556       
     557        if (event.getValueIsAdjusting()) {
     558            return;
     559        }
     560
     561        if (subcollection_index_list.isSelectionEmpty()) {
     562            clearControls();
     563            return;
     564        }
     565       
    580566        int i = subcollection_index_list.getSelectedIndex();
    581567        int size = subcollection_index_list.getModel().getSize();
    582         if (i < 0 || i >= size) {
    583             move_down_button.setEnabled(false);
    584             move_up_button.setEnabled(false);
    585             remove_button.setEnabled(false);
    586             replace_button.setEnabled(false);
    587             set_default_button.setEnabled(false);
    588             return;
    589         }
    590 
     568       
    591569        // Enable the buttons appropriately
    592570        remove_button.setEnabled(true);
     571        replace_button.setEnabled(false);
     572        add_button.setEnabled(false);
    593573        SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
    594574        set_default_button.setEnabled(default_index == null || !default_index.equals(selected_index));
Note: See TracChangeset for help on using the changeset viewer.