Ignore:
Timestamp:
2022-06-13T16:29:22+12:00 (23 months ago)
Author:
kjdon
Message:

added back in an 'add all' button. This is different to the previous one - it adds all *selected* items as new indexes (not all available metadata as previously implemeneted)

File:
1 edited

Legend:

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

    r36190 r36251  
    7575    protected String remove_button_key = "CDM.IndexManager.Remove";
    7676    protected String remove_button_tooltip_key = null;
    77   protected String default_indicator_key = null; //"CDM.IndexManager.Default_Index_Indicator";
    78   protected String set_default_tooltip_key = "CDM.IndexManager.Set_Default_Tooltip";
     77    protected String default_indicator_key = null;
     78    protected String set_default_tooltip_key = "CDM.IndexManager.Set_Default_Tooltip";
     79
     80
    7981    protected String nip_new_index_key = null;
    8082    protected String nip_edit_index_key = null;
    81     protected String nip_source_label_key = null; //"CDM.IndexManager.Source"
    82     protected String nip_source_tooltip_key = null; //"CDM.IndexManager.Source"
    83 
    84     protected String nip_add_index_button_key = null;//"CDM.IndexManager.Add_Index"
    85     protected String nip_add_index_tooltip_key = null; //"CDM.IndexManager.Add_Index_Tooltip"
    86     protected String nip_replace_index_button_key = null; //"CDM.IndexManager.Replace_Index"
    87     protected String nip_replace_index_tooltip_key = null; //"CDM.IndexManager.Replace_Index_Tooltip"
    88 
    89     static final protected Dimension PROMPT_SIZE = new Dimension(400,400);
     83    protected String nip_source_label_key = null;
     84    protected String nip_source_tooltip_key = null;
     85    protected String nip_add_index_button_key = null;
     86    protected String nip_add_index_tooltip_key = null;
     87    protected String nip_replace_index_button_key = null;
     88    protected String nip_replace_index_tooltip_key = null;
     89    protected String nip_add_all_index_button_key = null;
     90    protected String nip_add_all_index_tooltip_key = null;
     91
     92    static final protected Dimension PROMPT_SIZE = new Dimension(500,500);
    9093
    9194    public BaseIndexManager(Element indexes, String current_build_type, String index_element_name, String index_default_element_name, Index class_type) {
     
    234237    protected void removeIndex(Index index) {
    235238    if(index != null) {
    236         // Remove any current metadata from this index
    237         //CollectionDesignManager.searchmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + index.getID());
     239        // Remove any current metadata for this index
    238240        CollectionDesignManager.searchmeta_manager.removeMetadata(index.getID(), SearchMeta.TYPE_INDEX);
    239241        // Remove the index
     
    267269    }
    268270    // Remove the old index coll meta
    269     CollectionDesignManager.searchmeta_manager.removeMetadata(/*StaticStrings.STOP_CHARACTER +*/ old_index.getID(), old_index.getType());
     271    CollectionDesignManager.searchmeta_manager.removeMetadata( old_index.getID(), old_index.getType());
    270272    // Add the new coll meta
    271273    CollectionDesignManager.searchmeta_manager.addMetadatum(coll_meta);
     
    565567    protected class NewIndexPrompt
    566568        extends ModalDialog {
    567 
     569       
    568570        NewIndexPrompt new_index_prompt = null;
    569571
    570572        protected CheckList source_list;
    571573        protected JButton add_or_replace_button;
    572 
    573         //protected JButton select_none_button;
    574         //protected JButton add_all_button;
    575         //protected JButton select_all_button;
    576         //protected JButton replace_button;
     574        protected JButton add_all_button;
    577575        protected JButton cancel_button;
    578576
    579           protected JPanel content_pane;
    580           protected JPanel details_pane;
    581           protected JPanel button_pane;
     577        protected JPanel content_pane;
     578        protected JPanel details_pane;
     579        protected JPanel button_pane;
    582580        protected boolean editing = false;
    583581   
     
    643641        button_pane.setComponentOrientation(Dictionary.getOrientation());
    644642               
    645         button_pane.setLayout(new GridLayout(0,2,5,0));
    646 
     643        if (editing) {
     644            button_pane.setLayout(new GridLayout(0,2,5,0));
     645        } else {
     646             button_pane.setLayout(new GridLayout(0,3,5,0));
     647        }
    647648        if (existing_index != null) {
    648             add_or_replace_button = new GLIButton(Dictionary.get(nip_add_index_button_key), Dictionary.get(nip_replace_index_tooltip_key));
     649            // replace
     650            add_or_replace_button = new GLIButton(Dictionary.get(nip_replace_index_button_key), Dictionary.get(nip_replace_index_tooltip_key));
    649651            add_or_replace_button.addActionListener(new ReplaceIndexListener());
    650652        } else {
     653            //new
    651654            add_or_replace_button = new GLIButton(Dictionary.get(nip_add_index_button_key), Dictionary.get(nip_add_index_tooltip_key));
    652655            add_or_replace_button.addActionListener(new AddIndexListener());
     656            // create the add all button, which we only have for "add"
     657            add_all_button = new GLIButton(Dictionary.get(nip_add_all_index_button_key), Dictionary.get(nip_add_all_index_tooltip_key));
     658            add_all_button.addActionListener(new AddAllActionListener());
     659
    653660        }
    654661
     
    656663        add_or_replace_button.setEnabled(false);
    657664        button_pane.add(add_or_replace_button);
    658        
    659        
     665        if (!editing) {
     666            button_pane.add(add_all_button);
     667        }
    660668        // always have a cancel button
    661669        cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel"));
     
    686694           
    687695          }
    688         // Checks that specified index not already in the collection
    689         protected void validateAddOrReplaceButton() {
    690         Index index;
    691         ArrayList sources;
    692         if (!source_list.isNothingTicked()) {
    693             sources = source_list.getTicked();
    694             index = createIndex(sources);
    695         } else {
    696             // nothing selected
    697             add_or_replace_button.setEnabled(false);
    698             return;
    699         }
    700        
    701         sources = null;
    702         if (index_model.contains(index)) {
    703             add_or_replace_button.setEnabled(false);
    704         }
    705         else {
    706             add_or_replace_button.setEnabled(true);
    707         }
    708        
    709         }
    710696
    711697        protected Index generateNewIndex() {
     
    719705        return index;
    720706        }
     707
     708        // add/replace is only active if something is specified AND the specified index is not in the list already.
     709        protected void validateAddOrReplaceButton() {
     710        Index index = generateNewIndex();
     711        if (index == null || index_model.contains(index)) {
     712            add_or_replace_button.setEnabled(false);
     713        } else {
     714            add_or_replace_button.setEnabled(true);
     715        }
     716        // we enable the add_all button if we have 2 or more sources ticked
     717        // unless we are in "edit index"
     718        if (!editing) {
     719            if (source_list.isEnabled() && source_list.numTicked() > 1) {
     720            add_all_button.setEnabled(true);
     721            } else {
     722            add_all_button.setEnabled(false);
     723            }
     724        }
     725        }
     726
    721727       
    722728        protected SearchMeta generateSearchMeta(Index index) {
    723         SearchMeta metadatum = new SearchMeta(/*StaticStrings.STOP_CHARACTER +*/ index.getID(), index.getType());
     729        SearchMeta metadatum = new SearchMeta(index.getID(), index.getType());
    724730        if (use_macro_as_display_name(index.getID())) {
    725731            metadatum.setValue(get_macro_name(index.getID()));
     
    727733            metadatum.setValue(index.getID());
    728734        }
    729                 // is this right? Index vs index
    730                 //metadatum.setType(index_element_name);
    731735        return metadatum;
    732736        }
     
    749753        }
    750754
     755        /** add all selected sources as separate indexes (fields).  */
     756        private class AddAllActionListener
     757            implements ActionListener {
     758
     759            public void actionPerformed(ActionEvent event) {
     760                ArrayList sources = source_list.getTicked();
     761
     762                ArrayList new_sources = new ArrayList();
     763                for(int i = 0; i < sources.size(); i++) {
     764                Object source = sources.get(i);
     765
     766                // Create new index
     767                new_sources.clear();
     768                new_sources.add(source);
     769                Index index = createIndex(new_sources);
     770                if(!index_model.contains(index)) {
     771                SearchMeta metadatum = generateSearchMeta(index);
     772                    addIndex(index, metadatum);
     773                }
     774                source = null;
     775                index = null;
     776                }
     777                new_sources = null;
     778                new_index_prompt.dispose();
     779       
     780            }
     781        }
     782
    751783
    752784        protected class SourceListListener
     
    787819         */
    788820        protected boolean use_macro_as_display_name(String index_id) {
    789         //String metaname = index_id;   
     821
    790822        if (index_id.indexOf(":") != -1) {
    791823            index_id = index_id.substring(index_id.indexOf(":") + 1);
Note: See TracChangeset for help on using the changeset viewer.