[36150] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
| 4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
| 5 | * library suite from the New Zealand Digital Library Project at the
|
---|
| 6 | * University of Waikato, New Zealand.
|
---|
| 7 | *
|
---|
| 8 | * Copyright (C) 2022 New Zealand Digital Library Project
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *########################################################################
|
---|
| 24 | */
|
---|
| 25 | package org.greenstone.gatherer.cdm;
|
---|
| 26 |
|
---|
[36253] | 27 | import java.awt.*;
|
---|
| 28 | import java.awt.event.*;
|
---|
| 29 | import java.util.*;
|
---|
| 30 | import javax.swing.*;
|
---|
| 31 |
|
---|
| 32 | import org.greenstone.gatherer.Dictionary;
|
---|
[36150] | 33 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
| 34 | import org.w3c.dom.*;
|
---|
| 35 |
|
---|
| 36 | /** handles sortfields for lucene and solr collections */
|
---|
| 37 | public class SortFieldManager extends BaseIndexManager {
|
---|
| 38 |
|
---|
[36253] | 39 | static final private String NONE = "none";
|
---|
| 40 | static final private String RANK = "rank";
|
---|
| 41 |
|
---|
[36150] | 42 | public SortFieldManager(Element sortfields, String current_build_type) {
|
---|
[36161] | 43 | super(sortfields, current_build_type, StaticStrings.SORT_ELEMENT, StaticStrings.SORT_DEFAULT_ELEMENT, new SortField());
|
---|
[36150] | 44 | this.controls_title_key = "CDM.SortFieldManager.Title";
|
---|
| 45 | this.new_button_tooltip_key = "CDM.SortFieldManager.New_Button_Tooltip";
|
---|
| 46 | this.edit_button_tooltip_key = "CDM.SortFieldManager.Edit_Button_Tooltip";
|
---|
| 47 | this.remove_button_tooltip_key = "CDM.SortFieldManager.Remove_Button_Tooltip";
|
---|
[36161] | 48 | this.default_indicator_key = "CDM.SortFieldManager.Default_Sort_Indicator";
|
---|
[36172] | 49 | this.set_default_tooltip_key = "CDM.SortFieldManager.Set_Default_Tooltip";
|
---|
[36150] | 50 | this.nip_new_index_key = "CDM.SortFieldManager.New";
|
---|
| 51 | this.nip_edit_index_key = "CDM.SortFieldManager.Edit";
|
---|
| 52 | this.nip_source_label_key = "CDM.SortFieldManager.Source";
|
---|
[36172] | 53 | this.nip_source_tooltip_key = "CDM.SortFieldManager.Source_Tooltip";
|
---|
[36150] | 54 |
|
---|
| 55 | this.nip_add_index_button_key = "CDM.SortFieldManager.Add";
|
---|
| 56 | this.nip_add_index_tooltip_key = "CDM.SortFieldManager.Add_Tooltip";
|
---|
| 57 | this.nip_replace_index_button_key = "CDM.SortFieldManager.Replace";
|
---|
| 58 | this.nip_replace_index_tooltip_key = "CDM.SortFieldManager.Replace_Tooltip";
|
---|
[36253] | 59 | this.nip_add_all_index_button_key = "CDM.IndexManager.AddAll";
|
---|
| 60 | this.nip_add_all_index_tooltip_key = "CDM.SortFieldManager.AddAll_Tooltip";
|
---|
| 61 |
|
---|
[36150] | 62 | }
|
---|
| 63 |
|
---|
| 64 | public void buildTypeChanged(String new_build_type) {
|
---|
| 65 | if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR)|| new_build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
|
---|
| 66 | // activate
|
---|
| 67 | setAssigned(true);
|
---|
| 68 | } else {
|
---|
| 69 | // deactivate
|
---|
| 70 | setAssigned(false);
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[36253] | 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);
|
---|
[36260] | 141 | details_pane.add(extra_options_panel, BorderLayout.SOUTH);
|
---|
[36253] | 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 | }
|
---|
[36161] | 190 | }
|
---|