Changeset 8496 for trunk/gli/src


Ignore:
Timestamp:
2004-11-09T13:54:52+13:00 (20 years ago)
Author:
mdewsnip
Message:

Started off fixing a bug where the loaded collection wasn't being ticked on in the cross-collection searching page. Ended up removing a ton of stuff from the CheckList class, some of which was duplicated code and buggy.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
5 edited

Legend:

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

    r8381 r8496  
    576576        JLabel source_label = new JLabel();
    577577        Dictionary.registerText(source_label, "CDM.IndexManager.Source");
    578         source_list = new CheckList(new_data, false);
     578        source_list = new CheckList(false);
     579        source_list.setListData(new_data);
    579580        Dictionary.registerTooltip(source_list, "CDM.IndexManager.Source_Tooltip");
    580581
     
    696697        new_data.addAll(MetadataSetManager.getEveryMetadataSetElement());
    697698        // reset the model in the list and combobox
    698         source_list.setListData(new_data.toArray());
     699        source_list.setListData(new_data);
    699700        new_data = null;
    700701        // refresh the indexList
     
    742743        }
    743744        // Can't add a new index if no sources are selected
    744         else if(source_list.isSelectionEmpty()) {
     745        else if (source_list.getSelected().size() == 0) {
    745746        add_enabled = false;
    746747        }
     
    795796        public void actionPerformed(ActionEvent event) {
    796797        String name = name_textfield.getText();
    797         if(!source_list.isSelectionEmpty() && name.length() != 0) {
     798        if (source_list.getSelected().size() > 0 && name.length() != 0) {
    798799            ArrayList sources = source_list.getSelected();
    799800            Index index = new Index(level_combobox.getSelectedIndex(), sources);
  • trunk/gli/src/org/greenstone/gatherer/cdm/SuperCollectionManager.java

    r8243 r8496  
    117117        super();
    118118
    119         buildModel();
    120119        // Creation
    121120        JPanel header_panel = new JPanel();
     
    135134        Dictionary.registerText(instructions, "CDM.SuperCollectionManager.Instructions");
    136135
    137         collection_checklist = new CheckList(collection_checklist_model, false);
     136        collection_checklist = new CheckList(false);
     137        buildModel();
     138        collection_checklist.setListData(collection_checklist_model);
    138139
    139140        // Layout
     
    189190    }
    190191
    191     private void buildModel() {
    192         // We start by building a model of the installed collections.
     192
     193    private void buildModel()
     194    {
    193195        collection_checklist_model = new ArrayList();
     196        current_coll_name = Gatherer.c_man.getCollection().getName();
     197
    194198        File gsdl_collection_directory;
    195199        if (Gatherer.GS3) {
    196200        gsdl_collection_directory = new File(Utility.getCollectDir(Configuration.gsdl3_path, Configuration.site_name));
    197         } else {
     201        }
     202        else {
    198203        gsdl_collection_directory = new File(Utility.getCollectDir(Configuration.gsdl_path));
    199204        }
    200         current_coll_name = Gatherer.c_man.getCollection().getName();
     205
    201206        File[] possible_collections = gsdl_collection_directory.listFiles();
    202207        for(int i = 0; possible_collections != null && i < possible_collections.length; i++) {
    203         // The simpliest case is if the directory etc/collect.cfg file and a metadata/ in it. Thus it can easily be built upon.
    204208        File collect_cfg_file = new File(possible_collections[i], Utility.CONFIG_FILE);
    205         if(collect_cfg_file.exists()) {
     209        if (collect_cfg_file.exists()) {
    206210            BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(collect_cfg_file);
    207211            StringBuffer title_buffer = new StringBuffer(collect_cfg.getName());
     
    213217            title_buffer = null;
    214218            String collection_name = possible_collections[i].getName();
    215             // We do have to block the model collection.
    216             if(!collect_cfg.getName().equals("**title**")) {
    217             Entry entry = new Entry(collection_title);
    218             entry.setProperty(collection_name);
    219             // Check if a collection with this name exists. The current collection is always selected.
    220             entry.setSelected(getSuperCollection(collection_name) != null || collection_name.equals(current_coll_name));
    221             entry.setFixed(collection_name.equals(current_coll_name));
    222             collection_checklist_model.add(entry);
    223             entry = null;
    224 
     219
     220            // We have to block the model collection.
     221            if (collect_cfg.getName().equals("**title**")) {
     222            continue;
    225223            }
    226             collection_name = null;
    227             collection_title = null;
    228             collect_cfg = null;
     224
     225            // The current collection is always selected.
     226            Entry entry = new Entry(collection_title);
     227            entry.setProperty(collection_name);
     228            entry.setSelected(getSuperCollection(collection_name) != null || collection_name.equals(current_coll_name));
     229            entry.setFixed(collection_name.equals(current_coll_name));
     230            collection_checklist_model.add(entry);
    229231        }
    230         collect_cfg_file = null;
    231         }
    232         possible_collections = null;
    233         gsdl_collection_directory = null;
    234         // Sort the result.
    235         Collections.sort(collection_checklist_model);
     232        }
    236233    }
    237234    }
  • trunk/gli/src/org/greenstone/gatherer/checklist/CheckList.java

    r8379 r8496  
    3737package org.greenstone.gatherer.checklist;
    3838
    39 /**************************************************************************************
    40  * Title:        Gatherer
    41  * Description:  The Gatherer: a tool for gathering and enriching a digital collection.
    42  * Company:      The University of Waikato
    43  * Written:      14/08/02
    44  * Revised:     
    45  **************************************************************************************/
    4639import java.awt.*;
    4740import java.awt.event.*;
     
    5043import javax.swing.border.*;
    5144
     45
    5246/** This class provides a visual component that has the form of a list, as provided by JList but uses JCheckBox for data selection. Thus several elements can be 'ticked' in the list, and this selection returned using the method getSelected().<BR>Parts of this code modified from Trevor Harmon's posting on www.dejanews.com.
    5347 * @author John Thompson
    5448 * @version 2.3
    5549 */
    56 // ####################################################################################
    57 // Optimization                          Saving
    58 // ####################################################################################
    59 // Vector -> ArrayList                   + Processor
    60 // ####################################################################################
    6150public class CheckList
    62     extends JList {
     51    extends JList
     52{
    6353    /** The border used when a list row is not in focus. */
    64     protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
    65    
     54    static private Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
     55
    6656    private boolean show_selected_row = true;
     57
     58
    6759    /** Constructor. */
    68     public CheckList(boolean show_selected_row) {
     60    public CheckList(boolean show_selected_row)
     61    {
    6962    super();
    7063    this.show_selected_row = show_selected_row;
     64
    7165    setCellRenderer(new CellRenderer());
    7266    setModel(new DefaultListModel());
     
    7468    addMouseListener(new CheckListListener());
    7569    }
    76     /** Constructor.
    77      * @param list_data An ArrayList of entries for this checklist.
    78      * @see org.greenstone.gatherer.checklist.Entry
    79      */
    80     public CheckList(ArrayList list_data, boolean show_selected_row) {
    81     super();
    82     this.show_selected_row = show_selected_row;
    83     // Create a new model.
    84     DefaultListModel model = new DefaultListModel();
    85     for(int i = 0; i < list_data.size(); i++) {
    86         Entry entry = null;
    87         Object temp = list_data.get(i);
    88         if(temp instanceof Entry) {
    89         entry = (Entry) temp;
    90         }
    91         else {
    92         entry = new Entry(list_data.get(i));
    93         }
    94         temp = null;
    95         String name = entry.toString();
    96         int index = 0;
    97         boolean found = false;
    98         while(index < model.size() && !found) {
    99         Object sibling = model.getElementAt(index);
    100         if(name.compareTo(sibling.toString()) <= 0) {
    101             model.add(index, entry);
    102             found = true;
    103         }
    104         index++;
    105         }
    106         if(!found) {
    107         model.addElement(entry);
    108         }
    109     }
    110     setModel(model);
    111     setCellRenderer(new CellRenderer());
    112     addMouseListener(new CheckListListener());
    113     setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    114     }
    115 
    116     /** Constructor. */
    117     public CheckList(ListModel data_model, boolean show_selected_row) {
    118     super(data_model);
    119     this.show_selected_row = show_selected_row;
    120     setCellRenderer(new CellRenderer());
    121     addMouseListener(new CheckListListener());
    122     setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    123     }
    124 
    125     public void addEntry(Entry entry) {
    126     DefaultListModel model = (DefaultListModel) getModel();
     70
     71
     72    public void addEntry(Entry entry)
     73    {
     74    DefaultListModel model = (DefaultListModel) getModel();
     75
     76    // Add the entry in alpabetical order
    12777    String name = entry.toString();
    128     int index = 0;
    129     boolean found = false;
    130     while(index < model.size() && !found) {
    131         Object sibling = model.getElementAt(index);
    132         if(name.compareTo(sibling.toString()) <= 0) {
    133         model.add(index, entry);
    134         found = true;
    135         }
    136         index++;
    137         sibling = null;
    138     }
    139     if(!found) {
    140         model.addElement(entry);
    141     }         
    142     name = null;
    143     model = null;
    144     }
    145 
    146     public void clearSelection() {
    147     DefaultListModel model = (DefaultListModel) getModel();
    148     int size = model.size();
    149     for(int i = 0; i < size; i++) {
    150         Entry entry = (Entry) model.get(i);
    151         entry.setSelected(false);
     78    for (int i = 0; i < model.size(); i++) {
     79        Object sibling = model.getElementAt(i);
     80        if (name.compareTo(sibling.toString()) <= 0) {
     81        model.add(i, entry);
     82        return;
     83        }
     84    }
     85
     86    model.addElement(entry);
     87    }
     88
     89
     90    public void clearSelection()
     91    {
     92    DefaultListModel model = (DefaultListModel) getModel();
     93    for (int i = 0; i < model.size(); i++) {
     94        ((Entry) model.get(i)).setSelected(false);
    15295    }
    15396    updateUI();
    15497    }
    15598
    156     public Entry get(int index) {
    157     DefaultListModel model = (DefaultListModel) getModel();
    158     return (Entry) model.get(index);
    159     }
    16099
    161100    /** Retrieve the currently ticked entries from this list.
     
    163102     * @see org.greenstone.gatherer.checklist.Entry
    164103     */
    165     public ArrayList getSelected() {
     104    public ArrayList getSelected()
     105    {
    166106    ArrayList result = new ArrayList();
    167107    DefaultListModel model = (DefaultListModel) getModel();
    168     int size = model.size();
    169     for(int i = 0; i < size; i++) {
     108    for (int i = 0; i < model.size(); i++) {
    170109        Entry entry = (Entry) model.get(i);
    171         if(entry.isSelected()) {
     110        if (entry.isSelected()) {
    172111        result.add(entry.getObject());
    173112        }
     
    176115    }
    177116
    178     public boolean isSelected(int index) {
    179     DefaultListModel model = (DefaultListModel) getModel();
    180     Entry entry = (Entry) model.get(index);
    181     return entry.isSelected();
    182     }
    183 
    184     public boolean isSelectionEmpty() {
    185     DefaultListModel model = (DefaultListModel) getModel();
    186     int size = model.size();
    187     for(int i = 0; i < size; i++) {
     117
     118//     public boolean isSelectionEmpty()
     119//     {
     120//  System.err.println("In CheckList.isSelectionEmpty()...");
     121//  DefaultListModel model = (DefaultListModel) getModel();
     122//  for (int i = 0; i < model.size(); i++) {
     123//      Entry entry = (Entry) model.get(i);
     124//      if (entry.isSelected()) {
     125//      return false;
     126//      }
     127//  }
     128
     129//  return true;
     130//     }
     131
     132
     133    public void setListData(ArrayList list_data)
     134    {
     135    // Create a new model.
     136    setModel(new DefaultListModel());
     137
     138    // Add the items from the list to the model
     139    for (int i = 0; i < list_data.size(); i++) {
     140        Object list_object = list_data.get(i);
     141        if (list_object instanceof Entry) {
     142        addEntry((Entry) list_object);
     143        }
     144        else {
     145        addEntry(new Entry(list_object));
     146        }
     147    }
     148    }
     149
     150
     151    public void setSelectedObjects(Object objects[])
     152    {
     153    if (objects == null) {
     154        return;
     155    }
     156
     157    DefaultListModel model = (DefaultListModel) getModel();
     158    for (int i = 0; i < model.size(); i++) {
    188159        Entry entry = (Entry) model.get(i);
    189         if(entry.isSelected()) {
    190         entry = null;
    191         model = null;
    192         return false;
    193         }
    194         entry = null;
    195     }
    196     model = null;
    197     return true;
    198     }
    199 
    200     public int getEntryCount() {
    201     return getModel().getSize();
    202     }
    203 
    204     public void setListData(Object[] list_data) {
    205     // Create a new model.
    206     DefaultListModel model = new DefaultListModel();
    207     for(int i = 0; i < list_data.length; i++) {
    208         Entry entry = null;
    209         Object temp = list_data[i];
    210         if(temp instanceof Entry) {
    211         entry = (Entry) temp;
    212         }
    213         else {
    214         entry = new Entry(temp);
    215         }
    216         temp = null;
    217         String name = entry.toString();
    218         int index = 0;
    219         boolean found = false;
    220         while(index < model.size() && !found) {
    221         Object sibling = model.getElementAt(index);
    222         if(name.compareTo(sibling.toString()) <= 0) {
    223             model.add(index, entry);
    224             found = true;
    225         }
    226         index++;
    227         }
    228         if(!found) {
    229         model.addElement(entry);
    230         }
    231     }
    232     setModel(model);
    233     }
    234 
    235     /** Checks the entries in the list whose name appear in the given array.
    236      * @param names The name of entries to be checked as a <strong>String[]</strong>.
    237      * @see org.greenstone.gatherer.checklist.Entry
    238      */
    239     public void setSelected(String names[]) {
    240     DefaultListModel model = (DefaultListModel) getModel();
    241     int size = model.size();
    242     for(int i = 0; i < size; i++) {
    243         Entry entry = (Entry) model.get(i);
    244         for(int j = 0; names != null && j < names.length; j++) {
    245         if(entry.toString().equals(names[j])) {
    246             entry.setSelected(true);
    247            
    248         }
    249         }
    250     }         
    251     }
    252 
    253     public void setSelectedObjects(Object objects[]) {
    254     DefaultListModel model = (DefaultListModel) getModel();
    255     int size = model.size();
    256     for(int i = 0; i < size; i++) {
    257         Entry entry = (Entry) model.get(i);
    258         for(int j = 0; objects != null && j < objects.length; j++) {
    259         if(entry.getObject().equals(objects[j])) {
     160        for (int j = 0; j < objects.length; j++) {
     161        if (entry.getObject().equals(objects[j])) {
    260162            entry.setSelected(true);
    261163        }
     
    263165    }
    264166    updateUI();
    265 
    266 
    267     }
     167    }
     168
     169
    268170    private void selectionChanged(int index) {
    269171    fireSelectionValueChanged(index, index, false);
    270172    }
     173
    271174
    272175    /** A custom list cell renderer for producing rows which contain clickable check boxes. */
    273176    protected class CellRenderer
    274177    implements ListCellRenderer {
     178
    275179    /** Return a component that has been configured to display the specified value. That component's paint method is then called to "render" the cell. If it is necessary to compute the dimensions of a list because the list cells do not have a fixed size, this method is called to generate a component on which getPreferredSize  can be invoked.
    276180     * @param list The </strong>JList</strong> we're painting.
     
    300204    }
    301205    }
     206
     207
    302208    /** Listens for clicks apon the checks within the list, and updates as necessary. */
    303209    private class CheckListListener
    304210    extends MouseAdapter {
    305211
    306     //private Entry previous_checkbox = null;
    307212    /** Called whenever the mouse is clicked over our list. We find the nearest checkbox and change its state.
    308213     * @param e A <strong>MouseEvent</strong> containing everything you ever wanted to know about the mouse event but were afraid to ask.
  • trunk/gli/src/org/greenstone/gatherer/collection/ExportCollectionPrompt.java

    r8243 r8496  
    7676    /** The currently selected collection for deletion. */
    7777    private BasicCollectionConfiguration collection = null;
    78     /** The model behind the list. */
    79     private DefaultListModel list_model = null;
    8078    /** A reference to ourself so any inner-classes can dispose of us. */
    8179    private ExportCollectionPrompt prompt = null;
     
    8886    /** The label above the list. */
    8987    private JLabel list_label = null;
    90     /** The list of available collections. */
    91     //private JList list = null;
    9288    /** The text area used to display details about the collection selected. */
    9389    private JTextArea details_textarea = null;
     
    133129    Dictionary.registerText(instructions_textarea, "ExportCollectionPrompt.Instructions");
    134130
    135     //list = new JList();
    136     //list_model = new DefaultListModel();
    137131    all_collections = new ArrayList();
    138132    list = new CheckList(true);
     
    148142    Dictionary.setText(title_label, "ExportCollectionPrompt.CD_Name");
    149143    scanForCollections();
    150     list.setListData(all_collections.toArray());
     144    list.setListData(all_collections);
    151145
    152146    prompt = this;
  • trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java

    r8243 r8496  
    734734        Gatherer.g_man.modeChanged(new_mode);
    735735        }
     736
    736737        // Warning preferences
    737         for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
    738         Entry entry = warning_preferences_check_list.get(i);
     738        ListModel warning_preferences_check_list_model = warning_preferences_check_list.getModel();
     739        for (int i = 0; i < warning_preferences_check_list_model.getSize(); i++) {
     740        Entry entry = (Entry) warning_preferences_check_list_model.getElementAt(i);
    739741        Configuration.set(entry.getProperty(), true, entry.isSelected());
    740742        }
    741743
    742         if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection()!=null) {
     744        if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection() != null) {
    743745        // shut down the collection
    744746        System.err.println("shutting down teh collection");
Note: See TracChangeset for help on using the changeset viewer.