Changeset 9161


Ignore:
Timestamp:
2005-02-23T17:02:05+13:00 (19 years ago)
Author:
mdewsnip
Message:

Made the "assign partitions" tab in the "Partition Indexes" section look a lot like the "Search Indexes" pane.

Location:
trunk/gli
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/classes/dictionary.properties

    r9154 r9161  
    329329CDM.SubcollectionIndexManager.Add_Subindex:Add Partition
    330330CDM.SubcollectionIndexManager.Add_Subindex_Tooltip:Add the specified partition to this collection
    331 CDM.SubcollectionIndexManager.Clear_Default_Subindex:Clear Default
    332 CDM.SubcollectionIndexManager.Clear_Default_Subindex_Tooltip:Clear the default partition
    333 CDM.SubcollectionIndexManager.Default_Subindex:Default:
     331CDM.SubcollectionIndexManager.Default_Partition_Indicator:[Default Partition]
    334332CDM.SubcollectionIndexManager.PartitionName:Partition Name:
    335333CDM.SubcollectionIndexManager.PartitionName_Tooltip:The name of the new partition
    336334CDM.SubcollectionIndexManager.Remove_Subindex:Remove Partition
    337335CDM.SubcollectionIndexManager.Remove_Subindex_Tooltip:Remove the selected partition from this collection
     336CDM.SubcollectionIndexManager.Replace_Subindex:Replace Partition
     337CDM.SubcollectionIndexManager.Replace_Subindex_Tooltip:Update the selected partition
    338338CDM.SubcollectionIndexManager.Set_Default_Subindex:Set Default
    339339CDM.SubcollectionIndexManager.Set_Default_Subindex_Tooltip:Make the selected partition the default
    340 CDM.SubcollectionIndexManager.Subcollection:Defined Subcollection Filters
     340CDM.SubcollectionIndexManager.Source:Build partition on:
     341CDM.SubcollectionIndexManager.Source_Tooltip:The subcollection filters to build the partition on
    341342CDM.SubcollectionIndexManager.Subindexes:Assigned Subcollection Partitions
    342343CDM.SuperCollectionManager.Instructions:Cross-collection searching is where a single search is performed over several collections, as if all the collections were one. Specify the collections to include in a search by clicking on the appropriate collection's name in the list below. The current collection will automatically be included. \nWARNING: If the individual collections do not have the same indexes (including subcollection partitions and language partitions) as each other, cross-collection searching will not work properly. The user will only be able to search using indexes common to all collections.
  • trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java

    r9077 r9161  
    200200    }
    201201
    202     private void moveIndex(Index index, boolean move_up) {
    203     // Determine the indexes current position
     202
     203    private void moveIndex(Index index, boolean move_up)
     204    {
     205    // Determine the current position of the index
    204206    int position = indexOf(index);
    205     // Determine if it can be moved, ie if its not already at the top trying to move up, or at the bottom trying to move down.
    206     if(position == -1) {
     207    if (position == -1) {
    207208        return;
    208209    }
    209     if(position == 0 && move_up) {
    210         return;
    211     }
    212     if(position == (getSize()) - 1 && !move_up) {
    213         return;
    214     }
    215     // Ok, move the index
    216     if(move_up) {
     210
     211    // Attempt to move the index up
     212    if (move_up) {
     213        // Check it's not already at the top
     214        if (position == 0) {
     215        return;
     216        }
     217
    217218        // Retrieve the index at position - 1
    218         Index previous_index = (Index) getElementAt(position - 1);
    219         // And add before. This will automatically remove the index first, as an Element can only exist once in a particular document
    220         addBefore(index, previous_index);
    221     }
     219        Index preceeding_index = (Index) getElementAt(position - 1);
     220
     221        // This automatically removes the index first, as an Element can only exist once in a particular document
     222        addBefore(index, preceeding_index);
     223    }
     224
     225    // Attempt to move the index down
    222226    else {
     227        // Check it's not already at the bottom
     228        if (position == (getSize()) - 1) {
     229        return;
     230        }
     231
    223232        // Retrieve the index at position + 1
    224         Index next_index = (Index) getElementAt(position + 1);
    225         // And add after. This will automatically remove the index first, as an Element can only exist once in a particular document
    226         addAfter(index, next_index);
    227     }
     233        Index following_index = (Index) getElementAt(position + 1);
     234
     235        // This automatically removes the index first, as an Element can only exist once in a particular document
     236        addAfter(index, following_index);
     237    }
     238
    228239    // Schedule the collection for saving
    229240    Gatherer.c_man.configurationChanged();
    230241    }
     242
    231243
    232244    private void moveLevel(Level level, boolean move_up) {
     
    727739        return;
    728740        }
    729         String name = CollectionDesignManager.collectionmeta_manager.getMetadatum(CollectionConfiguration.STOP_CHARACTER+selected_index.getID()).getValue(true);
     741        String name = CollectionDesignManager.collectionmeta_manager.getMetadatum("." + id).getValue(true);
    730742        name_textfield.setText(name);
    731743        level_combobox.setSelectedIndex(selected_index.getLevel());
     
    736748    }
    737749   
    738     private void validateAddButton() {
     750    private void validateAddButton()
     751    {
    739752        boolean add_enabled = false;
    740753        boolean replace_enabled = false;
     754
    741755        // Indexes must have a name
    742         if(name_textfield.getText().length() == 0) {
     756        if (name_textfield.getText().length() == 0) {
    743757        add_enabled = false;
    744758        }
     
    747761        add_enabled = false;
    748762        }
    749         // If we get this far, create a dummy index and see if its already assigned in the collection
     763        // If we get this far, create a dummy index and see if it's already assigned in the collection
    750764        else {
    751765        Object object[] = source_list.getSelected().toArray();
     
    757771        Index index = new Index(level_combobox.getSelectedIndex(), sources);
    758772        sources = null;
    759         if(model.contains(index)) {
     773        if (model.contains(index)) {
    760774            add_enabled = false;
    761             // here we need to check if we have changed the name - if so, we can enable the replace button
     775
     776            // Here we need to check if we have changed the name - if so, we can enable the replace button
    762777            if (index_list.getSelectedIndex() != -1) {
    763778            Index selected_index = (Index)index_list.getSelectedValue();
     
    771786        else {
    772787            add_enabled = true;
    773             // we have a new index, do we have something selected in the index list? if so, enable the replace button
     788
     789            // We have a new index, do we have something selected in the index list? if so, enable the replace button
    774790            if (index_list.getSelectedIndex() != -1) {
    775791            replace_enabled = true;
    776792            }
    777            
    778         }
    779         }
     793        }
     794        }
     795
    780796        // We should now know the add_button state
    781797        add_button.setEnabled(add_enabled);
     
    783799    }
    784800
    785     /** Listens for actions apon the 'add' button in the IndexManager controls, and if detected calls the add method of the manager with a newly created index. */
     801
    786802    private class AddListener
    787         implements ActionListener {
    788         /** Method called when an action is performed on a registered component, and when it does we check if we have enough data to create a new index, and if so we create one.
    789          * @param event An <strong>ActionEvent</strong> providing extra information about the event.
    790          * @see org.greenstone.gatherer.cdm.CollectionDesignManager
    791          * @see org.greenstone.gatherer.cdm.CollectionMeta
    792          * @see org.greenstone.gatherer.cdm.CollectionMetaManager
    793          * @see org.greenstone.gatherer.cdm.Index
    794          * @see org.greenstone.gatherer.cdm.Language
    795          * @see org.greenstone.gatherer.cdm.LanguageManager
    796          */
    797         public void actionPerformed(ActionEvent event) {
     803        implements ActionListener
     804    {
     805        public void actionPerformed(ActionEvent event)
     806        {
    798807        String name = name_textfield.getText();
    799         System.err.println("Add button height: " + add_button.getHeight());
    800         System.err.println("Set default button height: " + set_default_button.getHeight());
    801808        if (source_list.getSelected().size() > 0 && name.length() != 0) {
    802809            ArrayList sources = source_list.getSelected();
    803810            Index index = new Index(level_combobox.getSelectedIndex(), sources);
    804             sources = null;
    805             // Before we add the index to the model, we have to add the collection metadata for this.
     811
     812            // Before we add the index to the model, we have to add the collection metadata for this
    806813            CollectionMeta metadatum = new CollectionMeta(CollectionConfiguration.STOP_CHARACTER + index.getID());
    807814            metadatum.setValue(name);
    808             // Finally add index.
     815
     816            // Finally, add the index
    809817            addIndex(index, metadatum);
    810818            index_list.setSelectedValue(index, true);
    811             metadatum = null;
    812             index = null;
    813         }
    814         name = null;
    815         }
    816     }
     819        }
     820        }
     821    }
     822
    817823
    818824    /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
    819825    private class IndexListListener
    820         implements ListSelectionListener {
     826        implements ListSelectionListener
     827    {
    821828        /** 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
    822829         * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
     
    837844            return;
    838845        }
    839         // enable the buttons appropriately
     846
     847        // Enable the buttons appropriately
    840848        remove_button.setEnabled(true);
    841849        set_default_button.setEnabled(default_index == null || !default_index.equals(value));
     
    844852        if (i > 0) {
    845853            move_up_button.setEnabled(true);
    846         } else {
     854        }
     855        else {
    847856            move_up_button.setEnabled(false);
    848857        }
    849         if (i<size-1){
     858        if (i < size-1){
    850859            move_down_button.setEnabled(true);
    851         } else {
     860        }
     861        else {
    852862            move_down_button.setEnabled(false);
    853863        }
    854864
    855         // need to fill in the rest of the bits
     865        // Need to fill in the rest of the bits
    856866        updateControlsWithSelectedIndex();     
    857867        }
     
    904914    }
    905915
    906     /** Listens for actions apon the 'remove' button in the IndexManager controls, and if detected calls the remove method of the manager with the index selected for removal. */
     916
     917    /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
     918    private class NameListener
     919        implements DocumentListener
     920    {
     921        public void changedUpdate(DocumentEvent e)
     922        {
     923        validateAddButton();
     924        }
     925
     926        public void insertUpdate(DocumentEvent e)
     927        {
     928        validateAddButton();
     929        }
     930
     931        public void removeUpdate(DocumentEvent e)
     932        {
     933        validateAddButton();
     934        }
     935    }
     936
     937
    907938    private class RemoveListener
    908         implements ActionListener {
    909         /** If called when an action occurs on a registered component, we remove the currently selected index, if there is one.
    910          * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
    911          * @see org.greenstone.gatherer.cdm.Index
    912          */
    913         public void actionPerformed(ActionEvent event) {
     939        implements ActionListener
     940    {
     941        public void actionPerformed(ActionEvent event)
     942        {
    914943        int i = index_list.getSelectedIndex();
    915         if(i != -1) {
    916             removeIndex((Index)index_list.getSelectedValue());
    917         }
     944        if (i != -1) {
     945            removeIndex((Index) index_list.getSelectedValue());
     946        }
     947
    918948        int size = index_list.getModel().getSize();
    919949        if (i == size) {
    920950            i--;
    921951        }
    922        
    923952        index_list.setSelectedIndex(i);
    924         // this will produce an event on the list, updating the other buttons
     953
     954        // This will produce an event on the list, updating the other buttons
    925955        if (size == 0) {
    926             // we have removed the last index, should be able to add whats filled in currently, if valid
     956            // We have removed the last index, should be able to add what's filled in currently, if valid
    927957            validateAddButton();
    928         }       
    929         }
    930     }
    931 
    932     /** Listens for actions apon the 'remove' button in the IndexManager controls, and if detected calls the remove method of the manager with the index selected for removal. */
     958        }
     959        }
     960    }
     961
     962
    933963    private class ReplaceListener
    934         implements ActionListener {
    935         /** If called when an action occurs on a registered component, we replace the currently selected index, with the new details
    936          * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
    937          * @see org.greenstone.gatherer.cdm.Index
    938          */
    939         public void actionPerformed(ActionEvent event) {
    940         if(index_list.isSelectionEmpty()) {
    941             // this should never happen, but just in case..
     964        implements ActionListener
     965    {
     966        public void actionPerformed(ActionEvent event)
     967        {
     968        if (index_list.isSelectionEmpty()) {
     969            // This should never happen, but just in case...
    942970            replace_button.setEnabled(false);
    943971            return;
    944972        }
    945         // we'll just remove the old one and add the new one
    946         removeIndex((Index)index_list.getSelectedValue());
     973
     974        // We'll just remove the old one and add the new one
     975        removeIndex((Index) index_list.getSelectedValue());
    947976        replace_button.setEnabled(false);
    948977        add_button.setEnabled(true);
     
    951980        }
    952981    }
     982
    953983
    954984    private class SetDefaultListener
     
    966996    }
    967997
    968     /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
     998
    969999    private class SourceListListener
    970         implements ListSelectionListener {
    971         /** This method is called whenever the source list selection changes. When it does we need to check if the add button should now be enabled.
    972          * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
    973          */
    974         public void valueChanged(ListSelectionEvent event) {
    975         validateAddButton();
    976         }
    977     }
    978 
    979     /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
    980     private class NameListener
    981         implements DocumentListener {
    982         /** Gives notification that an attribute or set of attributes changed. */
    983         public void changedUpdate(DocumentEvent e) {
    984         validateAddButton();
    985         }
    986 
    987         /** Gives notification that there was an insert into the document. */
    988         public void insertUpdate(DocumentEvent e) {
    989         validateAddButton();
    990         }
    991 
    992         /** Gives notification that a portion of the document has been removed. */
    993         public void removeUpdate(DocumentEvent e) {
     1000        implements ListSelectionListener
     1001    {
     1002        public void valueChanged(ListSelectionEvent event)
     1003        {
    9941004        validateAddButton();
    9951005        }
  • trunk/gli/src/org/greenstone/gatherer/cdm/Subcollection.java

    r8313 r9161  
    9797     * @return an int which is &gt;0, 0, or &lt;0 if this subcollection is before, equal to, or after the target object respectively.
    9898     */
    99     public int compareTo(Object object) {
    100     if(object == null) {
     99    public int compareTo(Object object)
     100    {
     101    if (object == null) {
    101102        return -1;
    102103    }
    103     return getName().compareTo(((Subcollection)object).getName());
    104     }
     104
     105    // Object may be a String
     106    if (object instanceof String) {
     107        return getName().compareTo(object);
     108    }
     109
     110    // Otherwise assume it is a Subcollection object
     111    return getName().compareTo(((Subcollection) object).getName());
     112    }
     113
    105114
    106115    public DOMProxyListEntry create(Element element) {
  • trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionIndex.java

    r8243 r9161  
    8181     */
    8282    public int compareTo(Object object) {
    83     return id.compareTo(((SubcollectionIndex)object).getID());
     83    return getID().compareTo(((SubcollectionIndex)object).getID());
    8484    }
    8585   
     
    168168        this.sources = sources;
    169169    }
    170     else {
    171         DebugStream.println("Error! Called setSource() of index other than the default.");
    172     }
    173170    }
    174171
  • trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionIndexManager.java

    r8243 r9161  
    3232import javax.swing.*;
    3333import javax.swing.event.*;
    34 import org.greenstone.gatherer.Configuration;
    3534import org.greenstone.gatherer.DebugStream;
    3635import org.greenstone.gatherer.Dictionary;
    3736import org.greenstone.gatherer.Gatherer;
    3837import org.greenstone.gatherer.gui.GLIButton;
    39 import org.greenstone.gatherer.util.ExclusiveListSelectionListener;
    40 import org.greenstone.gatherer.util.StaticStrings;
     38import org.greenstone.gatherer.util.CheckList;
    4139import org.greenstone.gatherer.util.Utility;
    4240import org.w3c.dom.*;
     41
     42
    4343/** This class maintains a list of indexes partitions for the purpose of defining subcollections.
    4444 * @author John Thompson, Greenstone Digital Library, University of Waikato
     
    4646 */
    4747public class SubcollectionIndexManager
    48     extends DOMProxyListModel {
     48    extends DOMProxyListModel
     49{
     50    static final private Dimension FIELD_SIZE = new Dimension(200, 30);
    4951
    5052    private Control controls;
     
    5254    private SubcollectionIndex default_index;
    5355
     56
    5457    /** Constructor. */
    55     public SubcollectionIndexManager(Element subindexes) {
     58    public SubcollectionIndexManager(Element subindexes)
     59    {
    5660    super(subindexes, CollectionConfiguration.INDEX_ELEMENT, new SubcollectionIndex());
    5761    DebugStream.println("SubcollectionIndexManager: " + getSize() + " subcollection indexes parsed.");
    5862    model = this;
     63
    5964    // Parse and retrieve the default index
    6065    NodeList default_index_elements = CollectionDesignManager.collect_config.getDocumentElement().getElementsByTagName(CollectionConfiguration.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT);
    61     if(default_index_elements.getLength() > 0) {
    62         default_index = new SubcollectionIndex((Element)default_index_elements.item(0));
    63     }
    64     }
     66    if (default_index_elements.getLength() > 0) {
     67        default_index = new SubcollectionIndex((Element) default_index_elements.item(0));
     68    }
     69    }
     70
    6571
    6672    /** Method to add a subindex.
     
    6975     * @see org.greenstone.gatherer.collection.CollectionManager
    7076     */
    71     private void addSubcollectionIndex(SubcollectionIndex subindex) {
    72     if(!contains(subindex)) {
    73         add(getSize(), subindex);
     77    private void addSubcollectionIndex(SubcollectionIndex subcollection_index)
     78    {
     79    if (!contains(subcollection_index)) {
     80        add(getSize(), subcollection_index);
    7481        Gatherer.c_man.configurationChanged();
    7582    }
    7683    }
    7784
    78     public void destroy() {
    79     if(controls != null) {
     85
     86    public void destroy()
     87    {
     88    if (controls != null) {
    8089        controls.destroy();
    8190        controls = null;
     
    8594    }
    8695
    87     public Control getControls() {
    88     if(controls == null) {
    89         controls = new SubcollectionIndexControl();
     96
     97    public Control getControls()
     98    {
     99    if (controls == null) {
     100        controls = new SubcollectionIndexControls();
    90101    }
    91102    return controls;
    92103    }
    93104
    94     /** Method to retrieve the default index.
    95      * @return the default Index, or null if no such index assigned
    96      */
    97     /* private SubcollectionIndex getDefaultSubcollectionIndex() {
    98     if(default_index != null && default_index.isAssigned()) {
    99         return default_index;
    100     }
    101     else {
    102         return null;
    103     }
    104     } */
    105 
    106     /** Retrieve a certain subindex given its name.
    107      * @param id the String identifier of a subcollectionindex
    108      * @return the SubcollectionIndex requested or null if no such subindex
    109      */
    110     private SubcollectionIndex getSubcollectionIndex(String id) {
    111     int size = getSize();
    112     for(int i = 0; i < size; i++) {
    113         SubcollectionIndex subindex = (SubcollectionIndex) getElementAt(i);
    114         if(subindex.getID().equals(id)) {
    115         return subindex;
    116         }
    117     }
    118     return null;
    119     }
    120105
    121106    /** Method to get all of the subindexes set.
    122107     * @return an ArrayList containing all the defined indexes
    123108     */
    124     public ArrayList getSubcollectionIndexes() {
     109    public ArrayList getSubcollectionIndexes()
     110    {
    125111    return children();
    126112    }
    127113
    128     /** Method to remove a certain subindex.
    129      * @param subindex the Index you wish to remove
    130      * @see org.greenstone.gatherer.Gatherer
    131      * @see org.greenstone.gatherer.collection.CollectionManager
    132      */
    133     private void removeSubcollectionIndex(SubcollectionIndex subindex) {
    134     if(subindex != null) {
     114
     115    private int moveSubcollectionIndex(SubcollectionIndex subcollection_index, boolean move_up)
     116    {
     117    // Determine the current position of the subcollection index
     118    int position = indexOf(subcollection_index);
     119    int new_position;
     120
     121    // Attempt to move the subcollection index up
     122    if (move_up) {
     123        // Check it's not already at the top
     124        if (position == 0) {
     125        return position;
     126        }
     127
     128        // This automatically removes the index first, as an Element can only exist once in a particular document
     129        new_position = position - 1;
     130        addBefore(subcollection_index, (SubcollectionIndex) getElementAt(new_position));
     131    }
     132
     133    // Attempt to move the subcollection index down
     134    else {
     135        // Check it's not already at the bottom
     136        if (position == (getSize()) - 1) {
     137        return position;
     138        }
     139
     140        // This automatically removes the index first, as an Element can only exist once in a particular document
     141        new_position = position + 1;
     142        addAfter(subcollection_index, (SubcollectionIndex) getElementAt(new_position));
     143    }
     144
     145    // Schedule the collection for saving
     146    Gatherer.c_man.configurationChanged();
     147    return new_position;
     148    }
     149
     150
     151    /** Method to remove a certain subcollection index. */
     152    private void removeSubcollectionIndex(SubcollectionIndex subcollection_index)
     153    {
     154    if (subcollection_index != null) {
    135155        // Remove any current metadata from this index
    136         CollectionDesignManager.collectionmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + subindex.getID());
     156        CollectionDesignManager.collectionmeta_manager.removeMetadata("." + subcollection_index.getID());
     157
    137158        // Check if the index removed happens to be the default index
    138         if(default_index != null && default_index.equals(subindex)) {
    139         default_index.setAssigned(false);
    140         ((SubcollectionIndexControl)controls).clearDefaultIndex();
    141         }
     159        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
    142169        // Remove the index
    143         remove(subindex);
     170        remove(subcollection_index);
    144171        Gatherer.c_man.configurationChanged();
    145172    }
    146173    }
     174
    147175
    148176    /** Method to remove all of the subindexes that contain a certain subcollection.
     
    151179     * @see org.greenstone.gatherer.cdm.SubcollectionIndex
    152180     */
    153     public void removeSubcollectionIndexes(Subcollection subcollection) {
     181    public void removeSubcollectionIndexes(Subcollection subcollection)
     182    {
    154183    String subcollection_name = subcollection.getName();
    155184    int size = getSize();
    156185    for(int i = size - 1; i >= 0; i--) {
    157         SubcollectionIndex subindex = (SubcollectionIndex)getElementAt(i);
    158         if(subindex.getSources().contains(subcollection_name)) {
    159         removeSubcollectionIndex(subindex);
    160         }
    161         subindex = null;
    162     }
    163     subcollection_name = null;
    164     }
     186        SubcollectionIndex subcollection_index = (SubcollectionIndex) getElementAt(i);
     187        if (subcollection_index.getSources().contains(subcollection_name)) {
     188        removeSubcollectionIndex(subcollection_index);
     189        }
     190    }
     191    }
     192
    165193
    166194    /** Method to set the default subcollection index.
     
    170198     * @see org.greenstone.gatherer.cdm.SubcollectionIndex
    171199     */
    172     private void setDefaultSubcollectionIndex(SubcollectionIndex index) {
    173     if(index != null) {
    174         if(default_index == null) {
     200    private void setDefaultSubcollectionIndex(SubcollectionIndex subcollection_index)
     201    {
     202    if (subcollection_index != null) {
     203        if (default_index == null) {
    175204        // Create the default index element, and place immediately after indexes element.
    176205        Element default_index_element = root.getOwnerDocument().createElement(CollectionConfiguration.SUBCOLLECTION_DEFAULT_INDEX_ELEMENT);
    177206        default_index = new SubcollectionIndex(default_index_element);
    178207        Node target_node = CollectionConfiguration.findInsertionPoint(default_index_element);
    179         if(target_node != null) {
     208        if (target_node != null) {
    180209            root.getOwnerDocument().getDocumentElement().insertBefore(default_index_element, target_node);
    181210        }
     
    183212            root.getOwnerDocument().getDocumentElement().appendChild(default_index_element);
    184213        }
    185         }
    186         default_index.setAssigned(true);
    187         default_index.setSources(index.getSources());
    188     }
    189     else {
    190         if(default_index != null) {
    191         default_index.setAssigned(false);
    192         }
    193     }
    194     Gatherer.c_man.configurationChanged();
    195     }
    196 
    197     private class SubcollectionIndexControl
     214        }
     215        default_index.setAssigned(true);
     216        default_index.setSources(subcollection_index.getSources());
     217    }
     218    else {
     219        if (default_index != null) {
     220        default_index.setAssigned(false);
     221        }
     222    }
     223    Gatherer.c_man.configurationChanged();
     224    }
     225
     226
     227    /** This class creates a set of controls for editing the indexes. */
     228    private class SubcollectionIndexControls
    198229    extends JPanel
    199     implements Control {
    200 
    201     private JButton add_index_button;
    202     private JButton clear_default_button;
    203     private JButton remove_index_button;
     230    implements Control
     231    {
     232    private CheckList source_list;
     233    private JButton add_button;
     234    private JButton move_down_button;
     235    private JButton move_up_button;
     236    private JButton remove_button;
     237    private JButton replace_button;
    204238    private JButton set_default_button;
    205     private JList subcollection_list;
    206     private JList subcollectionindexes_list;
    207     private JTextField default_value_field;
    208     private JTextField subcollectionindex_name_field;
    209 
    210     public SubcollectionIndexControl() {
     239    private JList subcollection_index_list;
     240    private JTextField subcollection_index_name_textfield;
     241
     242
     243    /** Constructor.
     244     */
     245    public SubcollectionIndexControls()
     246    {
    211247        super();
     248
     249        ArrayList sources = new ArrayList();
     250        ListModel source_model = CollectionDesignManager.subcollection_manager;
     251        for (int i = 0; i < source_model.getSize(); i++) {
     252        sources.add(source_model.getElementAt(i));
     253        }
     254
    212255        // Creation
    213         JPanel subcollection_panel = new JPanel();
    214         JPanel subindex_name_panel = new JPanel();
    215         JLabel subindex_name_label = new JLabel();
    216         Dictionary.registerText(subindex_name_label, "CDM.SubcollectionIndexManager.PartitionName");
    217         subcollectionindex_name_field = new JTextField();
    218         subcollectionindex_name_field.setPreferredSize(Utility.LABEL_SIZE);
    219         Dictionary.registerTooltip(subcollectionindex_name_field, "CDM.SubcollectionIndexManager.PartitionName_Tooltip");
     256        JPanel assigned_indexes_pane = new JPanel();
     257        JLabel index_label = new JLabel();
     258        Dictionary.registerText(index_label, "CDM.SubcollectionIndexManager.Subindexes");
     259        subcollection_index_list = new JList(model);
     260        subcollection_index_list.setCellRenderer(new SubcollectionIndexListCellRenderer());
     261        subcollection_index_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     262        subcollection_index_list.setVisibleRowCount(2);
     263
     264        JPanel movement_pane = new JPanel();
     265        move_up_button = new JButton("", Utility.getImage("arrow-up.gif"));
     266        move_up_button.setEnabled(true);
     267        move_up_button.setMnemonic(KeyEvent.VK_U);
     268        Dictionary.registerBoth(move_up_button, "CDM.Move.Move_Up", "CDM.Move.Move_Up_Tooltip");
     269
     270        move_down_button = new JButton("", Utility.getImage("arrow-down.gif"));
     271        move_down_button.setEnabled(true);
     272        move_down_button.setMnemonic(KeyEvent.VK_D);
     273        Dictionary.registerBoth(move_down_button, "CDM.Move.Move_Down", "CDM.Move.Move_Down_Tooltip");
     274
     275        set_default_button = new GLIButton();
     276        set_default_button.setEnabled(false);
     277        set_default_button.setMnemonic(KeyEvent.VK_S);
     278        Dictionary.registerBoth(set_default_button, "CDM.SubcollectionIndexManager.Set_Default_Subindex", "CDM.SubcollectionIndexManager.Set_Default_Subindex_Tooltip");
     279
     280        JPanel index_pane = new JPanel();
     281        JPanel details_pane = new JPanel();
     282        JPanel labels_pane = new JPanel();
     283        JPanel boxes_pane = new JPanel();
     284        JPanel content_pane = new JPanel();
     285
     286        JLabel name_label = new JLabel();
     287        Dictionary.registerText(name_label, "CDM.SubcollectionIndexManager.PartitionName");
     288        subcollection_index_name_textfield = new JTextField();
     289        subcollection_index_name_textfield.setPreferredSize(FIELD_SIZE);
     290        Dictionary.registerTooltip(subcollection_index_name_textfield, "CDM.SubcollectionIndexManager.PartitionName_Tooltip");
     291
     292        JLabel source_label = new JLabel();
     293        Dictionary.registerText(source_label, "CDM.SubcollectionIndexManager.Source");
     294        source_list = new CheckList(false);
     295        source_list.setListData(sources);
     296        Dictionary.registerTooltip(source_list, "CDM.SubcollectionIndexManager.Source_Tooltip");
    220297
    221298        JPanel button_pane = new JPanel();
    222 
    223         add_index_button = new GLIButton();
    224         add_index_button.setMnemonic(KeyEvent.VK_A);
    225         add_index_button.setEnabled(false);
    226         Dictionary.registerBoth(add_index_button, "CDM.SubcollectionIndexManager.Add_Subindex", "CDM.SubcollectionIndexManager.Add_Subindex_Tooltip");
    227 
    228         clear_default_button = new GLIButton();
    229         clear_default_button.setMnemonic(KeyEvent.VK_C);
    230         clear_default_button.setEnabled(default_index != null);
    231         Dictionary.registerBoth(clear_default_button, "CDM.SubcollectionIndexManager.Clear_Default_Subindex", "CDM.SubcollectionIndexManager.Clear_Default_Subindex_Tooltip");
    232 
    233         JLabel default_label = new JLabel();
    234         Dictionary.registerText(default_label, "CDM.SubcollectionIndexManager.Default_Subindex");
    235 
    236         JPanel default_pane = new JPanel();
    237         if(default_index == null) {
    238         default_value_field = new JTextField();
    239         }
    240         else {
    241         default_value_field = new JTextField(default_index.toString());
    242         }
    243         default_value_field.setPreferredSize(Utility.LABEL_SIZE);
    244         default_value_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
    245         default_value_field.setEditable(false);
    246 
    247         remove_index_button = new GLIButton();
    248         remove_index_button.setMnemonic(KeyEvent.VK_R);
    249         remove_index_button.setEnabled(false);
    250         Dictionary.registerBoth(remove_index_button, "CDM.SubcollectionIndexManager.Remove_Subindex", "CDM.SubcollectionIndexManager.Remove_Subindex_Tooltip");
    251 
    252         set_default_button = new GLIButton();
    253         set_default_button.setMnemonic(KeyEvent.VK_S);
    254         set_default_button.setEnabled(false);
    255         Dictionary.registerBoth(set_default_button, "CDM.SubcollectionIndexManager.Set_Default_Subindex", "CDM.SubcollectionIndexManager.Set_Default_Subindex_Tooltip");
    256 
    257         JLabel subcollection_label = new JLabel();
    258         Dictionary.registerText(subcollection_label, "CDM.SubcollectionIndexManager.Subcollection");
    259         subcollection_list = new JList(CollectionDesignManager.subcollection_manager);
    260         JPanel list_pane = new JPanel();
    261         JLabel subindexes_label = new JLabel();
    262         Dictionary.registerText(subcollection_label, "CDM.SubcollectionIndexManager.Subindexes");
    263         subcollectionindexes_list = new JList(model);
    264         subcollectionindexes_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    265         JPanel subindexes_pane = new JPanel();
    266 
    267         // Add listeners
    268         ExclusiveListSelectionListener ell = new ExclusiveListSelectionListener();
    269         ell.add(subcollection_list);
    270         ell.add(subcollectionindexes_list);
    271         add_index_button.addActionListener(new AddSubIndexListener());
    272         clear_default_button.addActionListener(new ClearDefaultSubIndexListener());
    273         remove_index_button.addActionListener(new RemoveSubIndexListener());
    274         set_default_button.addActionListener(new SetDefaultSubIndexListener());
    275 
    276         subcollectionindexes_list.addListSelectionListener(new SubcollectionListListener());
    277 
    278         subcollectionindex_name_field.getDocument().addDocumentListener(new SubcollectionIndexListener());
    279         subcollection_list.addListSelectionListener(new SubcollectionIndexListener());
     299        add_button = new GLIButton();
     300        add_button.setEnabled(false);
     301        add_button.setMnemonic(KeyEvent.VK_A);
     302        Dictionary.registerBoth(add_button, "CDM.SubcollectionIndexManager.Add_Subindex", "CDM.SubcollectionIndexManager.Add_Subindex_Tooltip");
     303
     304        remove_button = new GLIButton();
     305        remove_button.setEnabled(false);
     306        remove_button.setMnemonic(KeyEvent.VK_R);
     307        Dictionary.registerBoth(remove_button, "CDM.SubcollectionIndexManager.Remove_Subindex", "CDM.SubcollectionIndexManager.Remove_Subindex_Tooltip");
     308
     309        replace_button = new GLIButton();
     310        replace_button.setEnabled(false);
     311        replace_button.setMnemonic(KeyEvent.VK_P);
     312        Dictionary.registerBoth(replace_button, "CDM.SubcollectionIndexManager.Replace_Subindex", "CDM.SubcollectionIndexManager.Replace_Subindex_Tooltip");
     313
     314        // Listeners
     315        add_button.addActionListener(new AddListener());
     316        move_down_button.addActionListener(new MoveListener(false));
     317        move_up_button.addActionListener(new MoveListener(true));
     318        remove_button.addActionListener(new RemoveListener());
     319        replace_button.addActionListener(new ReplaceListener());
     320        set_default_button.addActionListener(new SetDefaultListener());
     321        subcollection_index_name_textfield.getDocument().addDocumentListener(new NameListener());
     322        subcollection_index_list.addListSelectionListener(new SubcollectionIndexListListener());
     323        source_list.addListSelectionListener(new SourceListListener());
    280324
    281325        // Layout
    282         default_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
    283 
    284         default_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(2,0,0,0), BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createEmptyBorder(2,2,2,2))));
    285         default_pane.setLayout(new BorderLayout(5,0));
    286         default_pane.add(default_label, BorderLayout.WEST);
    287         default_pane.add(default_value_field, BorderLayout.CENTER);
    288 
    289         subindexes_pane.setLayout(new BorderLayout());
    290         subindexes_pane.add(subindexes_label, BorderLayout.NORTH);
    291         subindexes_pane.add(new JScrollPane(subcollectionindexes_list), BorderLayout.CENTER);
    292         subindexes_pane.add(default_pane, BorderLayout.SOUTH);
     326        movement_pane.setBorder(BorderFactory.createEmptyBorder(0,2,0,0));
     327        movement_pane.setLayout(new GridLayout(3,1));
     328        movement_pane.add(move_up_button);
     329        movement_pane.add(move_down_button);
     330        movement_pane.add(set_default_button);
     331
     332        assigned_indexes_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     333        assigned_indexes_pane.setLayout(new BorderLayout());
     334        assigned_indexes_pane.add(index_label, BorderLayout.NORTH);
     335        assigned_indexes_pane.add(new JScrollPane(subcollection_index_list), BorderLayout.CENTER);
     336        assigned_indexes_pane.add(movement_pane, BorderLayout.EAST);
     337
     338        labels_pane.setLayout(new BorderLayout());
     339        labels_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 10, 5));
     340        labels_pane.add(name_label, BorderLayout.NORTH);
     341        labels_pane.add(source_label, BorderLayout.CENTER);
    293342       
    294         subindex_name_panel.setBorder(BorderFactory.createEmptyBorder(2,0,0,0));
    295         subindex_name_panel.setLayout(new BorderLayout(5,0));
    296         subindex_name_panel.add(subindex_name_label, BorderLayout.WEST);
    297         subindex_name_panel.add(subcollectionindex_name_field, BorderLayout.CENTER);
    298 
    299         list_pane.setBorder(BorderFactory.createEmptyBorder(5,0,2,0));
    300         list_pane.setLayout(new BorderLayout());
    301         list_pane.add(subcollection_label, BorderLayout.NORTH);
    302         list_pane.add(new JScrollPane(subcollection_list), BorderLayout.CENTER);
    303         list_pane.add(subindex_name_panel, BorderLayout.SOUTH);
    304 
    305         button_pane.setLayout(new GridLayout(2,2));
    306         button_pane.add(add_index_button);
    307         button_pane.add(remove_index_button);
    308         button_pane.add(set_default_button);
    309         button_pane.add(clear_default_button);
    310 
    311         subcollection_panel.setLayout(new BorderLayout());
    312         //subcollection_panel.add(subindex_name_panel, BorderLayout.NORTH);
    313         subcollection_panel.add(list_pane, BorderLayout.CENTER);
    314         subcollection_panel.add(button_pane, BorderLayout.SOUTH);
     343        boxes_pane.setLayout(new BorderLayout());
     344        boxes_pane.add(subcollection_index_name_textfield, BorderLayout.NORTH);
     345        boxes_pane.add(new JScrollPane(source_list), BorderLayout.CENTER);
    315346       
     347        details_pane.setLayout(new BorderLayout());
     348        details_pane.add(labels_pane, BorderLayout.WEST);
     349        details_pane.add(boxes_pane, BorderLayout.CENTER);
     350
     351        button_pane.setLayout(new GridLayout(1,3));
     352        button_pane.add(add_button);
     353        button_pane.add(replace_button);
     354        button_pane.add(remove_button);
     355
     356        index_pane.setLayout(new BorderLayout());
     357        index_pane.add(details_pane, BorderLayout.CENTER);
     358        index_pane.add(button_pane, BorderLayout.SOUTH);
     359
     360        content_pane.setLayout(new BorderLayout());
     361        content_pane.add(assigned_indexes_pane, BorderLayout.NORTH);
     362        content_pane.add(index_pane, BorderLayout.CENTER);
     363
    316364        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    317365        setLayout(new BorderLayout());
    318         add(subindexes_pane, BorderLayout.CENTER);
    319         add(subcollection_panel, BorderLayout.SOUTH);
    320     }
    321 
    322     public void clearDefaultIndex() {
    323         clear_default_button.doClick();
    324     }
    325 
    326     public void destroy() {
    327     }
    328 
    329     public void gainFocus() {
    330     }
    331 
    332     public void loseFocus() {
    333     }
    334 
    335     /** Listens for actions apon the 'add subindex' button in the SubcollectionManager controls, and if detected calls the addSubindex method of the manager with a newly created subindex. */
    336     private class AddSubIndexListener
    337         implements ActionListener {
    338         /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a series of subcollections selected, and if so build an new subindex based apon them.
    339          * @param event An <strong>ActionEvent</strong> containing information about the event.
    340          * @see org.greenstone.gatherer.cdm.SubcollectionIndex
     366        add(content_pane, BorderLayout.CENTER);
     367    }
     368
     369
     370    public void destroy()
     371    {
     372    }
     373
     374
     375    public void gainFocus()
     376    {
     377        // Reload the source list
     378        ArrayList sources = new ArrayList();
     379        ListModel source_model = CollectionDesignManager.subcollection_manager;
     380        for (int i = 0; i < source_model.getSize(); i++) {
     381        sources.add(source_model.getElementAt(i));
     382        }
     383        source_list.setListData(sources);
     384
     385        // Refresh the subcollection index list
     386        subcollection_index_list.updateUI();
     387
     388        // If there is one selected, fill in the controls
     389        updateControlsWithSelectedIndex();
     390    }
     391
     392
     393    public void loseFocus()
     394    {
     395    }
     396
     397
     398    private void updateControlsWithSelectedIndex()
     399    {
     400        SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
     401        if (selected_index == null) {
     402        return;
     403        }
     404
     405        // Display the selected subcollection index's name
     406        String id = selected_index.getID();
     407        String name = CollectionDesignManager.collectionmeta_manager.getMetadatum("." + id).getValue(true);
     408        subcollection_index_name_textfield.setText(name);
     409
     410        // Display the selected subcollection index's sources
     411        source_list.clearSelection();
     412        source_list.setSelectedObjects(selected_index.getSources().toArray());
     413    }
     414
     415
     416    private void validateControls()
     417    {
     418        boolean add_enabled = false;
     419        boolean replace_enabled = false;
     420
     421        // Indexes must have a name
     422        if (subcollection_index_name_textfield.getText().length() == 0) {
     423        add_enabled = false;
     424        }
     425        // Can't add a new index if no sources are selected
     426        else if (source_list.getSelected().size() == 0) {
     427        add_enabled = false;
     428        }
     429        // If we get this far, create a dummy index and see if it's already assigned in the collection
     430        else {
     431        ArrayList sources = source_list.getSelected();
     432        SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray());
     433
     434        // Subcollection index already exists: can't add, but can replace if the name has changed
     435        if (model.contains(subcollection_index)) {
     436            add_enabled = false;
     437
     438            // Here we need to check if we have changed the name - if so, we can enable the replace button
     439            if (subcollection_index_list.getSelectedIndex() != -1) {
     440            String name = subcollection_index_name_textfield.getText();
     441            SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
     442            String selected_name = CollectionDesignManager.collectionmeta_manager.getMetadatum("." + selected_index.getID()).getValue(true);
     443            if (!name.equals(selected_name)) {
     444                replace_enabled = true;
     445            }
     446            }
     447        }
     448
     449        // Subcollection index doesn't already exist: can add, or replace if there is something selected
     450        else {
     451            add_enabled = true;
     452            if (subcollection_index_list.getSelectedIndex() != -1) {
     453            replace_enabled = true;
     454            }
     455        }
     456        }
     457
     458        // We should now know the add_button state
     459        add_button.setEnabled(add_enabled);
     460        replace_button.setEnabled(replace_enabled);
     461    }
     462
     463
     464    private class AddListener
     465        implements ActionListener
     466    {
     467        public void actionPerformed(ActionEvent event)
     468        {
     469        String name = subcollection_index_name_textfield.getText();
     470        if (source_list.getSelected().size() > 0 && name.length() != 0) {
     471            ArrayList sources = source_list.getSelected();
     472            SubcollectionIndex subcollection_index = new SubcollectionIndex(sources.toArray());
     473
     474            // Before we add the index to the model, we have to add the collection metadata for this
     475            CollectionMeta metadatum = new CollectionMeta("." + subcollection_index.getID());
     476            metadatum.setValue(name);
     477            CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
     478
     479            // Finally, add the subcollection index
     480            addSubcollectionIndex(subcollection_index);
     481            subcollection_index_list.setSelectedIndex(model.getSize() - 1);
     482        }
     483        }
     484    }
     485
     486
     487    private class MoveListener
     488        implements ActionListener
     489    {
     490        private boolean move_up;
     491
     492        public MoveListener(boolean move_up)
     493        {
     494        this.move_up = move_up;
     495        }
     496
     497        public void actionPerformed(ActionEvent event)
     498        {
     499        // Retrieve the selected subcollection index
     500        SubcollectionIndex subcollection_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
     501        if (subcollection_index != null) {
     502            int new_position = moveSubcollectionIndex(subcollection_index, move_up);
     503            // Ensure the subcollection index that moved is still selected
     504            subcollection_index_list.setSelectedIndex(new_position);
     505        }
     506        }
     507    }
     508
     509
     510    /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
     511    private class NameListener
     512        implements DocumentListener
     513    {
     514        public void changedUpdate(DocumentEvent e)
     515        {
     516        validateControls();
     517        }
     518
     519        public void insertUpdate(DocumentEvent e)
     520        {
     521        validateControls();
     522        }
     523
     524        public void removeUpdate(DocumentEvent e)
     525        {
     526        validateControls();
     527        }
     528    }
     529
     530
     531    private class RemoveListener
     532        implements ActionListener
     533    {
     534        public void actionPerformed(ActionEvent event)
     535        {
     536        int i = subcollection_index_list.getSelectedIndex();
     537        if (i != -1) {
     538            removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue());
     539        }
     540
     541        int size = subcollection_index_list.getModel().getSize();
     542        if (i == size) {
     543            i--;
     544        }
     545        subcollection_index_list.setSelectedIndex(i);
     546        validateControls();
     547        }
     548    }
     549
     550
     551    private class ReplaceListener
     552        implements ActionListener
     553    {
     554        public void actionPerformed(ActionEvent event)
     555        {
     556        if (subcollection_index_list.isSelectionEmpty()) {
     557            // This should never happen, but just in case...
     558            replace_button.setEnabled(false);
     559            return;
     560        }
     561
     562        // We'll just remove the old one and add the new one
     563        removeSubcollectionIndex((SubcollectionIndex) subcollection_index_list.getSelectedValue());
     564        replace_button.setEnabled(false);
     565        add_button.setEnabled(true);
     566        add_button.doClick();
     567        add_button.setEnabled(false);
     568        }
     569    }
     570
     571
     572    private class SetDefaultListener
     573        implements ActionListener
     574    {
     575        public void actionPerformed(ActionEvent event)
     576        {
     577        SubcollectionIndex subcollection_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
     578        if (subcollection_index != null) {
     579            setDefaultSubcollectionIndex(subcollection_index);
     580            // This should cause a repaint of just the desired row
     581            subcollection_index_list.setSelectedValue(subcollection_index, true);
     582        }
     583        set_default_button.setEnabled(false);
     584        }
     585    }
     586
     587
     588    private class SourceListListener
     589        implements ListSelectionListener
     590    {
     591        public void valueChanged(ListSelectionEvent event)
     592        {
     593        validateControls();
     594        }
     595    }
     596
     597
     598    /** Listens for selections within the list on the SubcollectionIndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
     599    private class SubcollectionIndexListListener
     600        implements ListSelectionListener
     601    {
     602        /** 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
     603         * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
    341604         */
    342         public void actionPerformed(ActionEvent event) {
    343         if(!subcollection_list.isSelectionEmpty() && subcollectionindex_name_field.getText().length() > 0) {
    344             SubcollectionIndex subindex = new SubcollectionIndex(subcollection_list.getSelectedValues());
    345             addSubcollectionIndex(subindex);
    346             // Add the subindexes name.
    347             CollectionMeta metadatum = new CollectionMeta("." + subindex.getID());
    348             metadatum.setValue(subcollectionindex_name_field.getText());
    349             CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
    350         }
    351         }
    352     }
    353 
    354     /** Listens for actions apon the 'clear default subindex' button in the SubcollectionManager controls, and if detected calls the setDefaultSubcollectionIndex() method of the manager with <i>null</i>. */
    355     private class ClearDefaultSubIndexListener
    356         implements ActionListener {
    357         /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to clear the default subindex.
    358          * @param event An <strong>ActionEvent</strong> containing information about the event.
    359          */
    360         public void actionPerformed(ActionEvent event) {
    361         setDefaultSubcollectionIndex(null);
    362         default_value_field.setText("");
    363         clear_default_button.setEnabled(false);
    364         set_default_button.setEnabled(!subcollectionindexes_list.isSelectionEmpty());
    365         }
    366     }
    367 
    368     /** Listens for actions apon the 'remove subindex' button in the SubcollectionManager controls, and if detected calls the removeSubcollectionIndex method of the manager with the SubcollectionIndex selected for removal. */
    369     private class RemoveSubIndexListener
    370         implements ActionListener {
    371         /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subindex selected, and if so remove it.
    372          * @param event An <strong>ActionEvent</strong> containing information about the event.
    373          * @see org.greenstone.gatherer.cdm.SubcollectionIndex
    374          */
    375         public void actionPerformed(ActionEvent event) {
    376         if(!subcollectionindexes_list.isSelectionEmpty()) {
    377             removeSubcollectionIndex((SubcollectionIndex)subcollectionindexes_list.getSelectedValue());
    378         }
    379         }
    380     }
    381     /** Listens for actions apon the 'set default subindex' button in the SubcollectionManager controls, and if detected calls the setDefaultSubcollectionIndex method of the manager with the SubIndex selected for default. */
    382     private class SetDefaultSubIndexListener
    383         implements ActionListener {
    384         /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we want to check if they have a subindex selected, and if so set it as default.
    385          * @param event An <strong>ActionEvent</strong> containing information about the event.
    386          * @see org.greenstone.gatherer.cdm.SubcollectionIndex
    387          */
    388         public void actionPerformed(ActionEvent event) {
    389         if(!subcollectionindexes_list.isSelectionEmpty()) {
    390             setDefaultSubcollectionIndex((SubcollectionIndex)subcollectionindexes_list.getSelectedValue());
    391             default_value_field.setText(default_index.toString());
    392             clear_default_button.setEnabled(true);
    393             set_default_button.setEnabled(false);
    394         }
    395         }
    396     }
    397    
    398     private class SubcollectionIndexListener
    399         implements DocumentListener, ListSelectionListener {
    400 
    401         /** Gives notification that an attribute or set of attributes changed. */
    402         public void changedUpdate(DocumentEvent e) {
    403         update();
    404         }
    405         /** Gives notification that there was an insert into the document. */
    406         public void insertUpdate(DocumentEvent e) {
    407         update();
    408         }
    409         /** Gives notification that a portion of the document has been removed. */
    410         public void removeUpdate(DocumentEvent e) {
    411         update();
    412         }
    413 
    414         public void valueChanged(ListSelectionEvent event) {
    415         if(!event.getValueIsAdjusting()) {
    416             update();
    417         }
    418         }
    419 
    420         /** The text area has changed in some way. Given that this can only happed when we are editing or adding a text fragment we better respond appropriately. */
    421         private void update() {
    422         if(!subcollection_list.isSelectionEmpty() && subcollectionindex_name_field.getText().length() > 0) {
    423             if (getSubcollectionIndex(subcollectionindex_name_field.getText()) == null) {
    424             SubcollectionIndex subindex = new SubcollectionIndex(subcollection_list.getSelectedValues());
    425             add_index_button.setEnabled(!model.contains(subindex));
    426             } else {
    427             add_index_button.setEnabled(false);
    428             }
    429         }
    430         else {
    431             add_index_button.setEnabled(false);
    432         }
    433         }
    434     }
    435 
    436     private class SubcollectionListListener
    437         implements ListSelectionListener {
    438 
    439         public void valueChanged(ListSelectionEvent event) {
    440         if(!event.getValueIsAdjusting()) {
    441             boolean enable = !subcollectionindexes_list.isSelectionEmpty();
    442             remove_index_button.setEnabled(enable);
    443             set_default_button.setEnabled(enable);
    444         }
     605        public void valueChanged(ListSelectionEvent event)
     606        {
     607        if (event.getValueIsAdjusting()) {
     608            return;
     609        }
     610
     611        int i = subcollection_index_list.getSelectedIndex();
     612        int size = subcollection_index_list.getModel().getSize();
     613        if (i < 0 || i >= size) {
     614            move_down_button.setEnabled(false);
     615            move_up_button.setEnabled(false);
     616            remove_button.setEnabled(false);
     617            replace_button.setEnabled(false);
     618            set_default_button.setEnabled(false);
     619            return;
     620        }
     621
     622        // Enable the buttons appropriately
     623        remove_button.setEnabled(true);
     624        SubcollectionIndex selected_index = (SubcollectionIndex) subcollection_index_list.getSelectedValue();
     625        set_default_button.setEnabled(default_index == null || !default_index.equals(selected_index));
     626        if (i > 0) {
     627            move_up_button.setEnabled(true);
     628        }
     629        else {
     630            move_up_button.setEnabled(false);
     631        }
     632        if (i < size-1){
     633            move_down_button.setEnabled(true);
     634        }
     635        else {
     636            move_down_button.setEnabled(false);
     637        }
     638
     639        // Need to fill in the rest of the bits
     640        updateControlsWithSelectedIndex();
     641        }
     642    }
     643
     644
     645    private class SubcollectionIndexListCellRenderer
     646        extends DefaultListCellRenderer
     647    {
     648        /** Return a component that has been configured to display the specified value. */
     649        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
     650        JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
     651        if (default_index != null && default_index.equals(value)) {
     652            component.setText(component.getText() + " " + Dictionary.get("CDM.SubcollectionIndexManager.Default_Partition_Indicator"));
     653        }
     654        return component;
    445655        }
    446656    }
  • trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionManager.java

    r8576 r9161  
    158158    private class SubcollectionControl
    159159    extends JPanel
    160     implements Control {
    161 
     160    implements Control, ChangeListener
     161    {
    162162    private CardLayout card_layout;
    163163    private JButton add_button;
     
    190190
    191191        tabbed_pane = new JTabbedPane();
     192        tabbed_pane.addChangeListener(this);
    192193        JLabel title = new JLabel();
    193194        title.setHorizontalAlignment(JLabel.CENTER);
     
    380381        else {
    381382        card_layout.show(border_pane, DISABLED_CONTROLS);
     383        }
     384    }
     385
     386    public void stateChanged(ChangeEvent event)
     387    {
     388        if (tabbed_pane.getSelectedIndex() == 1) {
     389        CollectionDesignManager.subcollectionindex_manager.getControls().gainFocus();
     390        }
     391        if (tabbed_pane.getSelectedIndex() == 2) {
     392        CollectionDesignManager.language_manager.getControls().gainFocus();
    382393        }
    383394    }
Note: See TracChangeset for help on using the changeset viewer.