Changeset 12167


Ignore:
Timestamp:
2006-07-12T14:05:55+12:00 (18 years ago)
Author:
kjdon
Message:

add and replace buttons now one button called add_or_replace_button; replace all and select all buttons now one button called add_or_replace_all_button; added in allfields selector

File:
1 edited

Legend:

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

    r12127 r12167  
    641641        // mg uses a level box
    642642        private JComboBox level_combobox;
    643 
    644         private JButton add_button;
    645         private JButton add_all_button;
    646         private JButton select_all_button;
    647         private JButton replace_button;
     643        // mgpp has a allfields selector
     644        private JCheckBox allfields_box;
     645
     646        private JButton add_or_replace_button;
     647        private JButton add_or_select_all_button;
     648        //private JButton select_all_button;
     649        //private JButton replace_button;
    648650        private JButton cancel_button;
    649 
    650         // some panels that we need to manipulate later on
    651         private JPanel boxes_pane;
    652         private JPanel labels_pane;
    653         private JLabel level_label;
    654651
    655652        private boolean mgpp_enabled = false;
     
    688685
    689686        JPanel button_pane = new JPanel();
     687        button_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    690688        // three buttons for new index, or replace mg index, two buttons otherwise
    691689        if (existing_index == null || !mgpp_enabled) {
     
    696694
    697695        if (existing_index != null) {
    698             replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Replace_Index"), Dictionary.get("CDM.IndexManager.Replace_Index_Tooltip"));
    699             replace_button.setEnabled(false);
    700             replace_button.addActionListener(new ReplaceIndexListener());
    701             button_pane.add(replace_button);
     696            add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Replace_Index"), Dictionary.get("CDM.IndexManager.Replace_Index_Tooltip"));
     697            add_or_replace_button.addActionListener(new ReplaceIndexListener());
    702698        } else {
    703             add_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_Index"), Dictionary.get("CDM.IndexManager.Add_Index_Tooltip"));
    704             add_button.setEnabled(false);
    705             add_button.addActionListener(new AddIndexListener());
    706             button_pane.add(add_button);
    707         }
     699            add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_Index"), Dictionary.get("CDM.IndexManager.Add_Index_Tooltip"));
     700            add_or_replace_button.addActionListener(new AddIndexListener());
     701        }
     702       
     703        add_or_replace_button.setEnabled(false);
     704        button_pane.add(add_or_replace_button);
    708705       
    709706        if (!mgpp_enabled) {
    710             select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_All"), Dictionary.get("CDM.IndexManager.Select_All_Tooltip"));
    711             select_all_button.setEnabled(true);
    712             select_all_button.addActionListener(new SelectAllActionListener());
    713             button_pane.add(select_all_button);
     707            // its select all
     708            add_or_select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_All"), Dictionary.get("CDM.IndexManager.Select_All_Tooltip"));
     709            add_or_select_all_button.setEnabled(true);
     710            add_or_select_all_button.addActionListener(new SelectAllActionListener());
     711            button_pane.add(add_or_select_all_button);
    714712        } else if (existing_index == null) {
    715713            // mgpp, and new index
    716             add_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_All"), Dictionary.get("CDM.IndexManager.Add_All_Tooltip"));
    717             add_all_button.setEnabled(true);
    718             add_all_button.addActionListener(new AddAllIndexActionListener());     
    719             button_pane.add(add_all_button);
     714            add_or_select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_All"), Dictionary.get("CDM.IndexManager.Add_All_Tooltip"));
     715            add_or_select_all_button.setEnabled(true);
     716            add_or_select_all_button.addActionListener(new AddAllIndexActionListener());       
     717            button_pane.add(add_or_select_all_button);
    720718           
    721719        }
     720       
    722721        // always have a cancel button
    723722        cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel"));
     
    738737
    739738        // do type specific stuff
    740         if (!mgpp_enabled) {
    741 
    742             level_label = new JLabel(Dictionary.get("CDM.IndexManager.Level"));
     739        if (mgpp_enabled) {
     740            // allfields
     741            allfields_box = new JCheckBox(Dictionary.get("CDM.IndexManager.Allfields_Index"));
     742            allfields_box.addItemListener(new AllFieldsBoxListener());
     743            //JLabel allfields_label = new JLabel(Dictionary.get("CDM.IndexManager.Allfields_Index"));
     744            details_pane.add(allfields_box, BorderLayout.SOUTH);
     745           
     746           
     747        } else {
     748            // index level
     749            JLabel level_label = new JLabel(Dictionary.get("CDM.IndexManager.Level"));
    743750            level_combobox = new JComboBox();
    744751            level_combobox.setPreferredSize(FIELD_SIZE);
     
    758765        if (existing_index !=null) {
    759766            ArrayList sources = existing_index.getSources();
    760             source_list.setTickedObjects(sources.toArray());
    761             source_list.setEnabled(true);
     767            if (mgpp_enabled && sources.get(0).equals(ALLFIELDS)) {
     768            allfields_box.setSelected(true);
     769            source_list.setEnabled(false);
     770            } else {
     771            source_list.setTickedObjects(sources.toArray());
     772            source_list.setEnabled(true);
     773            }
    762774            if (!mgpp_enabled) {
    763775            level_combobox.setSelectedIndex(existing_index.getLevel());
     
    789801        }
    790802
     803        // Checks that specified index not already in the collection
     804        private void validateAddOrReplaceButton() {
     805        Index index;
     806        ArrayList sources;
     807        if (mgpp_enabled && allfields_box.isSelected()) {
     808            sources = new ArrayList();
     809            sources.add(ALLFIELDS);
     810            index = new Index(sources);
     811           
     812        } else if (!source_list.isNothingTicked()) {
     813            Object object[] = source_list.getTicked().toArray();
     814            sources = new ArrayList();
     815            for(int i = 0; i < object.length; i++) {
     816            sources.add(object[i]);
     817            }
     818            object = null;
     819           
     820            if (mgpp_enabled) {
     821            index = new Index(sources);
     822            } else {
     823            index = new Index(level_combobox.getSelectedIndex(), sources);
     824            }
     825        } else {
     826            // nothing selected
     827            add_or_replace_button.setEnabled(false);
     828            return;
     829        }
     830       
     831        sources = null;
     832        if (index_model.contains(index)) {
     833            add_or_replace_button.setEnabled(false);
     834        }
     835        else {
     836            add_or_replace_button.setEnabled(true);
     837        }
     838       
     839        }
    791840        private class AddIndexListener
    792841        implements ActionListener
     
    795844        {
    796845            Index index;
    797             if (!source_list.isNothingTicked()) {
     846            if (mgpp_enabled && allfields_box.isSelected()) {
     847            ArrayList sources = new ArrayList();
     848            sources.add(ALLFIELDS);
     849            index = new Index(sources);
     850            }
     851            else if (!source_list.isNothingTicked()) {
    798852            ArrayList sources = source_list.getTicked();
    799853            if(mgpp_enabled) {
     
    853907        }
    854908   
     909        private class AllFieldsBoxListener
     910        implements ItemListener {
     911       
     912        public void itemStateChanged(ItemEvent event) {
     913            if (event.getStateChange() == ItemEvent.SELECTED) {
     914            source_list.setEnabled(false);
     915            } else if (event.getStateChange() == ItemEvent.DESELECTED) {
     916            source_list.setEnabled(true);
     917            }
     918            validateAddOrReplaceButton();
     919        }
     920       
     921        }
     922
    855923        private class SelectAllActionListener
    856924        implements ActionListener {
     
    858926        public void actionPerformed(ActionEvent event) {
    859927            source_list.setAllTicked();
    860             if (editing) {
    861             replace_button.setEnabled(true);
    862             } else {
    863             add_button.setEnabled(true);
    864             }
     928            validateAddOrReplaceButton();
    865929        }
    866930        }
     
    873937            return;
    874938            }
    875             boolean enabled = !source_list.isNothingTicked();
    876             if (editing) {
    877             replace_button.setEnabled(enabled);
    878             } else {
    879             add_button.setEnabled(enabled);
    880             }
    881        
     939            validateAddOrReplaceButton();
    882940        }
    883941        }
Note: See TracChangeset for help on using the changeset viewer.