Changeset 36253 for main/trunk


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

added in the none/rank options for sort fields

File:
1 edited

Legend:

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

    r36172 r36253  
    2525package org.greenstone.gatherer.cdm;
    2626
     27import java.awt.*;
     28import java.awt.event.*;
     29import java.util.*;
     30import javax.swing.*;
     31
     32import org.greenstone.gatherer.Dictionary;
    2733import org.greenstone.gatherer.util.StaticStrings;
    2834import org.w3c.dom.*;
     
    3036/** handles sortfields for lucene and solr collections */
    3137public class SortFieldManager extends BaseIndexManager {
     38
     39    static final private String NONE = "none";
     40    static final private String RANK = "rank";
    3241
    3342    public SortFieldManager(Element sortfields, String current_build_type) {
     
    4857    this.nip_replace_index_button_key = "CDM.SortFieldManager.Replace";
    4958    this.nip_replace_index_tooltip_key = "CDM.SortFieldManager.Replace_Tooltip";
     59    this.nip_add_all_index_button_key = "CDM.IndexManager.AddAll";
     60      this.nip_add_all_index_tooltip_key = "CDM.SortFieldManager.AddAll_Tooltip";
     61
    5062    }
    5163
     
    6072    }
    6173
     74    public Control getControls() {
     75    if (controls == null) {
     76        controls = new SortFieldControl();
     77    }
     78    return controls;
     79    }
     80
     81    private class SortFieldControl
     82    extends IndexControl {
     83
     84    public SortFieldControl() {
     85        super();       
     86    }
     87
     88    /** we want our own custom new index prompt for searhc indexes */
     89    protected NewIndexPrompt createNewIndexPrompt(String build_type, Index index) {
     90        return new NewSortFieldPrompt(build_type, index);
     91       
     92    }
     93
     94    // we extend this to add in the rank/none options
     95    protected class NewSortFieldPrompt
     96        extends NewIndexPrompt {
     97
     98        private JCheckBox none_checkbox;
     99        private JCheckBox rank_checkbox;
     100
     101          public NewSortFieldPrompt(String build_type, Index existing_index) {
     102            super(build_type, existing_index);     
     103          }
     104         
     105          /** inside here is where we customise our controls */
     106          protected void generateContents(String build_type, Index existing_index) {
     107          super.generateContents(build_type, existing_index);
     108          none_checkbox = new JCheckBox(Dictionary.get("CDM.SortFieldManager.Field_None"));
     109              none_checkbox.addItemListener(new NoneRankBoxListener());
     110              none_checkbox.setComponentOrientation(Dictionary.getOrientation());
     111          none_checkbox.setToolTipText(Dictionary.get("CDM.SortFieldManager.Field_None_Tooltip"));
     112
     113          rank_checkbox = new JCheckBox(Dictionary.get("CDM.SortFieldManager.Field_Rank"));
     114              rank_checkbox.addItemListener(new NoneRankBoxListener());
     115              rank_checkbox.setComponentOrientation(Dictionary.getOrientation());
     116          rank_checkbox.setToolTipText(Dictionary.get("CDM.SortFieldManager.Field_Rank_Tooltip"));
     117
     118          // fill in none/rank if it is selected in existing index
     119          if (existing_index !=null) {
     120          ArrayList sources = existing_index.getSources();
     121          if (sources.contains(NONE)) {
     122              none_checkbox.setSelected(true);
     123              rank_checkbox.setEnabled(false);
     124              source_list.setEnabled(false);
     125          } else if (sources.contains(RANK)) {
     126              rank_checkbox.setSelected(true);
     127              none_checkbox.setEnabled(false);
     128              source_list.setEnabled(false);
     129          }
     130         
     131          }
     132
     133
     134          JPanel extra_options_panel = new JPanel();
     135          extra_options_panel.setComponentOrientation(Dictionary.getOrientation());
     136          extra_options_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     137
     138          extra_options_panel.setLayout(new GridLayout(2,1,5,5));//**
     139          extra_options_panel.add(none_checkbox);
     140          extra_options_panel.add(rank_checkbox);
     141              details_pane.add(extra_options_panel, BorderLayout.NORTH);
     142
     143      }
     144
     145        // override this to take into account none/rank options
     146        protected Index generateNewIndex() {
     147        ArrayList sources;
     148
     149        if (none_checkbox.isSelected()) {
     150            sources = new ArrayList();
     151            sources.add(NONE);
     152        } else if (rank_checkbox.isSelected()) {
     153            sources = new ArrayList();
     154            sources.add(RANK);
     155        } else if (!source_list.isNothingTicked()) {
     156            sources = source_list.getTicked();
     157        } else {
     158            // nothing selected
     159            return null;
     160        }
     161        return new SortField(sources);
     162
     163        }
     164
     165
     166        private class NoneRankBoxListener
     167        implements ItemListener {
     168
     169        public void itemStateChanged(ItemEvent event) {
     170
     171            if (none_checkbox.isSelected() ) {
     172            source_list.setEnabled(false);
     173            rank_checkbox.setEnabled(false);
     174            } else if (rank_checkbox.isSelected()) {
     175            source_list.setEnabled(false);
     176            none_checkbox.setEnabled(false);
     177            } else {
     178            // neither button is selected
     179            none_checkbox.setEnabled(true);
     180            rank_checkbox.setEnabled(true);
     181            source_list.setEnabled(true);
     182            }
     183            validateAddOrReplaceButton();
     184        }
     185       
     186        }
     187    }
     188       
     189    }
    62190}
Note: See TracChangeset for help on using the changeset viewer.