source: main/trunk/gli/src/org/greenstone/gatherer/cdm/IndexingManager.java@ 36160

Last change on this file since 36160 was 36160, checked in by kjdon, 2 years ago

added methods to get the sortfields and facets

  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.util.*;
32import javax.swing.*;
33import javax.swing.event.*;
34import org.greenstone.gatherer.Configuration;
35import org.greenstone.gatherer.DebugStream;
36import org.greenstone.gatherer.Dictionary;
37import org.greenstone.gatherer.Gatherer;
38import org.greenstone.gatherer.gui.DesignPaneHeader;
39import org.greenstone.gatherer.gui.GComboBox;
40import org.greenstone.gatherer.gui.GLIButton;
41import org.greenstone.gatherer.metadata.MetadataElement;
42import org.greenstone.gatherer.metadata.MetadataSetManager;
43import org.greenstone.gatherer.util.CheckList;
44import org.greenstone.gatherer.util.JarTools;
45import org.greenstone.gatherer.util.StaticStrings;
46
47
48/** This class is responsible for coordinating the IndexManager and IndexOptionManager (controls levels, stem options etc) and BuildTypeManager into one panel
49 * @author John Thompson, Greenstone Digital Library, University of Waikato
50 * @version 2.3
51 */
52public class IndexingManager {
53
54 private IndexOptionManager option_manager = null;
55 private SearchIndexManager index_manager = null;
56 private BuildTypeManager build_type_manager = null;
57 private SortFieldManager sortfield_manager = null;
58 private FacetManager facet_manager = null;
59
60 private String build_type = null;
61
62 private Control controls = null;
63
64 public IndexingManager()
65 {
66 build_type_manager = new BuildTypeManager();
67 build_type = build_type_manager.getBuildType();
68 option_manager = new IndexOptionManager(build_type);
69 if (isMG()) {
70 index_manager = new SearchIndexManager(CollectionDesignManager.collect_config.getMGIndexes(), build_type);
71 } else {
72 index_manager = new SearchIndexManager(CollectionDesignManager.collect_config.getMGPPIndexes(), build_type);
73 }
74 // we always create the managers, but only display the controls if we
75 // are Lucene/SOLR
76 sortfield_manager = new SortFieldManager(CollectionDesignManager.collect_config.getSorts(), build_type);
77 facet_manager = new FacetManager(CollectionDesignManager.collect_config.getFacets(), build_type);
78
79 }
80 public boolean isMGPP() {
81 return build_type_manager.isMGPP();
82 }
83
84 public boolean isLucene() {
85 return build_type_manager.isLucene();
86 }
87
88 public boolean isMG() {
89 return build_type_manager.isMG();
90 }
91
92 public boolean isSOLR() {
93 return build_type_manager.isSOLR();
94 }
95
96 public int getNumLevels() {
97 return option_manager.getNumLevels();
98 }
99
100 public int getNumIndexes() {
101 return index_manager.getSize();
102 }
103
104 public ArrayList getIndexes() {
105 return index_manager.getIndexes();
106 }
107
108 public ArrayList getLevels() {
109 if (!isMG()) {
110 return option_manager.getLevels();
111 }
112 return null;
113 }
114
115 public ArrayList getSortFields() {
116 if (isLucene() || isSOLR()) {
117 return sortfield_manager.getIndexes();
118 }
119 return null;
120 }
121 public ArrayList getFacets() {
122 if (isSOLR()) {
123 return facet_manager.getIndexes();
124 }
125 return null;
126 }
127
128
129 public Control getControls() {
130 if (controls == null) {
131 controls = new IndexingControl();
132 }
133 return controls;
134 }
135
136 public void destroy() {
137
138 }
139
140 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
141 * @param mode the new mode as an int
142 */
143 public void modeChanged(int mode) {
144
145 }
146
147
148 private class IndexingControl
149 extends JPanel
150 implements Control, BuildTypeManager.BuildTypeListener
151 {
152 JPanel main_index_pane = null;
153 JPanel index_options_panel = null;
154
155 JPanel index_sort_facet_panel = null;
156 // these get added/removed depending on indexer in use
157 private JPanel sortfield_panel = null;
158 private JPanel facet_panel = null;
159
160 public IndexingControl() {
161 super();
162 this.setComponentOrientation(Dictionary.getOrientation());
163 // Creation
164 JPanel header_pane = new DesignPaneHeader("CDM.GUI.Indexes", "searchindexes");
165
166 JPanel build_type_panel = (JPanel)build_type_manager.getControls();
167 index_options_panel = (JPanel)option_manager.getControls();
168
169 index_sort_facet_panel = new JPanel();
170
171 index_sort_facet_panel.setLayout(new GridLayout(0,1));
172 JPanel index_panel = (JPanel)index_manager.getControls();
173 index_sort_facet_panel.add(index_panel);
174 if (isLucene() || isSOLR() ) {
175 sortfield_panel = (JPanel)sortfield_manager.getControls();
176 index_sort_facet_panel.add(sortfield_panel);
177 }
178 if (isSOLR()) {
179 facet_panel = (JPanel)facet_manager.getControls();
180 index_sort_facet_panel.add(facet_panel);
181 }
182 main_index_pane = new JPanel();
183 main_index_pane.setLayout(new BorderLayout());
184 main_index_pane.add(build_type_panel, BorderLayout.NORTH);
185 main_index_pane.add(index_sort_facet_panel, BorderLayout.CENTER);
186 main_index_pane.add(index_options_panel, BorderLayout.SOUTH);
187 main_index_pane.setComponentOrientation(Dictionary.getOrientation());
188
189 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
190 setLayout(new BorderLayout());
191 add(header_pane, BorderLayout.NORTH);
192 add(main_index_pane, BorderLayout.CENTER);
193
194 build_type_manager.addBuildTypeListener(this);
195 build_type_manager.addBuildTypeListener(index_manager);
196 build_type_manager.addBuildTypeListener(sortfield_manager);
197 build_type_manager.addBuildTypeListener(facet_manager);
198 build_type_manager.addBuildTypeListener(option_manager);
199 }
200
201 public void loseFocus() {}
202 public void gainFocus() {}
203 public void destroy() {}
204
205 public void buildTypeChanged(String new_build_type)
206 {
207 if (build_type.equals(new_build_type)) {
208 // shouldn't happen
209 return;
210 }
211 if (hasSorts(new_build_type) && !hasSorts(build_type)) {
212 sortfield_panel = (JPanel)sortfield_manager.getControls();
213 index_sort_facet_panel.add(sortfield_panel);
214 // add sort panel
215 }
216 if (hasSorts(build_type) && ! hasSorts(new_build_type)) {
217 // remove sort panel
218 index_sort_facet_panel.remove(sortfield_panel);
219 }
220 if (hasFacets(new_build_type) && ! hasFacets(build_type)) {
221 // add facet
222 facet_panel = (JPanel)facet_manager.getControls();
223 index_sort_facet_panel.add(facet_panel);
224 }
225 if (hasFacets(build_type) && ! hasFacets(new_build_type)) {
226 // remove facet pane
227 index_sort_facet_panel.remove(facet_panel);
228 }
229 build_type = new_build_type;
230 }
231
232 private boolean hasSorts(String build_type) {
233 return build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE) || build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR);
234 }
235 private boolean hasFacets(String build_type) {
236 return build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR);
237
238 }
239
240 }
241}
Note: See TracBrowser for help on using the repository browser.