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

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

IndexingManager updated to add in sortfield panel and facet panel if needed

  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 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 Control getControls() {
116 if (controls == null) {
117 controls = new IndexingControl();
118 }
119 return controls;
120 }
121
122 public void destroy() {
123
124 }
125
126 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
127 * @param mode the new mode as an int
128 */
129 public void modeChanged(int mode) {
130
131 }
132
133
134 private class IndexingControl
135 extends JPanel
136 implements Control, BuildTypeManager.BuildTypeListener
137 {
138 JPanel main_index_pane = null;
139 JPanel index_options_panel = null;
140
141 JPanel index_sort_facet_panel = null;
142 // these get added/removed depending on indexer in use
143 private JPanel sortfield_panel = null;
144 private JPanel facet_panel = null;
145
146 public IndexingControl() {
147 super();
148 this.setComponentOrientation(Dictionary.getOrientation());
149 // Creation
150 JPanel header_pane = new DesignPaneHeader("CDM.GUI.Indexes", "searchindexes");
151
152 JPanel build_type_panel = (JPanel)build_type_manager.getControls();
153 index_options_panel = (JPanel)option_manager.getControls();
154
155 index_sort_facet_panel = new JPanel();
156
157 index_sort_facet_panel.setLayout(new GridLayout(0,1));
158 JPanel index_panel = (JPanel)index_manager.getControls();
159 index_sort_facet_panel.add(index_panel);
160 if (isLucene() || isSOLR() ) {
161 sortfield_panel = (JPanel)sortfield_manager.getControls();
162 index_sort_facet_panel.add(sortfield_panel);
163 }
164 if (isSOLR()) {
165 facet_panel = (JPanel)facet_manager.getControls();
166 index_sort_facet_panel.add(facet_panel);
167 }
168 main_index_pane = new JPanel();
169 main_index_pane.setLayout(new BorderLayout());
170 main_index_pane.add(build_type_panel, BorderLayout.NORTH);
171 main_index_pane.add(index_sort_facet_panel, BorderLayout.CENTER);
172 main_index_pane.add(index_options_panel, BorderLayout.SOUTH);
173 main_index_pane.setComponentOrientation(Dictionary.getOrientation());
174
175 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
176 setLayout(new BorderLayout());
177 add(header_pane, BorderLayout.NORTH);
178 add(main_index_pane, BorderLayout.CENTER);
179
180 build_type_manager.addBuildTypeListener(this);
181 build_type_manager.addBuildTypeListener(index_manager);
182 build_type_manager.addBuildTypeListener(sortfield_manager);
183 build_type_manager.addBuildTypeListener(facet_manager);
184 build_type_manager.addBuildTypeListener(option_manager);
185 }
186
187 public void loseFocus() {}
188 public void gainFocus() {}
189 public void destroy() {}
190
191 public void buildTypeChanged(String new_build_type)
192 {
193 if (build_type.equals(new_build_type)) {
194 // shouldn't happen
195 return;
196 }
197 if (hasSorts(new_build_type) && !hasSorts(build_type)) {
198 sortfield_panel = (JPanel)sortfield_manager.getControls();
199 index_sort_facet_panel.add(sortfield_panel);
200 // add sort panel
201 }
202 if (hasSorts(build_type) && ! hasSorts(new_build_type)) {
203 // remove sort panel
204 index_sort_facet_panel.remove(sortfield_panel);
205 }
206 if (hasFacets(new_build_type) && ! hasFacets(build_type)) {
207 // add facet
208 facet_panel = (JPanel)facet_manager.getControls();
209 index_sort_facet_panel.add(facet_panel);
210 }
211 if (hasFacets(build_type) && ! hasFacets(new_build_type)) {
212 // remove facet pane
213 index_sort_facet_panel.remove(facet_panel);
214 }
215 build_type = new_build_type;
216 }
217
218 private boolean hasSorts(String build_type) {
219 return build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE) || build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR);
220 }
221 private boolean hasFacets(String build_type) {
222 return build_type.equals(BuildTypeManager.BUILD_TYPE_SOLR);
223
224 }
225
226 }
227}
Note: See TracBrowser for help on using the repository browser.