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 | */
|
---|
27 | package org.greenstone.gatherer.cdm;
|
---|
28 |
|
---|
29 | import java.awt.*;
|
---|
30 | import java.awt.event.*;
|
---|
31 | import java.util.*;
|
---|
32 | import javax.swing.*;
|
---|
33 | import javax.swing.event.*;
|
---|
34 | import org.greenstone.gatherer.Configuration;
|
---|
35 | import org.greenstone.gatherer.DebugStream;
|
---|
36 | import org.greenstone.gatherer.Dictionary;
|
---|
37 | import org.greenstone.gatherer.Gatherer;
|
---|
38 | import org.greenstone.gatherer.gui.DesignPaneHeader;
|
---|
39 | import org.greenstone.gatherer.gui.GComboBox;
|
---|
40 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
41 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
42 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
43 | import org.greenstone.gatherer.metadata.MetadataElement;
|
---|
44 | import org.greenstone.gatherer.metadata.MetadataSetManager;
|
---|
45 | import org.greenstone.gatherer.util.CheckList;
|
---|
46 | import org.greenstone.gatherer.util.JarTools;
|
---|
47 | import org.greenstone.gatherer.util.XMLTools;
|
---|
48 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
49 | import org.w3c.dom.*;
|
---|
50 | /** This class is resposible for storing the indexes which have been assigned to this collection and the default index, and providing methods for interacting with both these data pools. It also knows how to turn itself into a String as it would be displayed in the collection configuration file.
|
---|
51 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
52 | * @version 2.3
|
---|
53 | */
|
---|
54 | public class IndexManager
|
---|
55 | extends DOMProxyListModel
|
---|
56 | implements BuildTypeManager.BuildTypeListener {
|
---|
57 |
|
---|
58 | /** A reference to ourselves so our inner methods have access. */
|
---|
59 | private DOMProxyListModel index_model = null;
|
---|
60 | /** The default index. */
|
---|
61 | private Index default_index = null;
|
---|
62 |
|
---|
63 | private Control controls = null;
|
---|
64 | private String build_type = null;
|
---|
65 |
|
---|
66 | static final private Dimension FIELD_SIZE = new Dimension(200,30);
|
---|
67 | static final private String ALLFIELDS = "allfields";
|
---|
68 |
|
---|
69 | static final private Dimension PROMPT_SIZE = new Dimension(400,400);
|
---|
70 | public IndexManager(Element indexes, String current_build_type) {
|
---|
71 |
|
---|
72 | super(indexes, StaticStrings.INDEX_ELEMENT, new Index());
|
---|
73 | DebugStream.println("IndexManager: " + getSize() + " indexes parsed.");
|
---|
74 | index_model = this;
|
---|
75 |
|
---|
76 |
|
---|
77 | // Parse and retrieve the default index
|
---|
78 | NodeList default_index_elements = CollectionConfiguration.getElementsByTagName(StaticStrings.INDEX_DEFAULT_ELEMENT);
|
---|
79 | if(default_index_elements.getLength() > 0) {
|
---|
80 |
|
---|
81 | default_index = new Index((Element)default_index_elements.item(0));
|
---|
82 | }
|
---|
83 | build_type = current_build_type;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /** Method to add a new index.
|
---|
87 | * @param index The <strong>Index</strong> to add.
|
---|
88 | * @see org.greenstone.gatherer.Gatherer
|
---|
89 | * @see org.greenstone.gatherer.collection.CollectionManager
|
---|
90 | */
|
---|
91 | private void addIndex(Index index, CollectionMeta metadatum) {
|
---|
92 | ///ystem.err.println("Adding an index: " + index.toString());
|
---|
93 | if(!contains(index)) {
|
---|
94 | CollectionDesignManager.collectionmeta_manager.addMetadatum(metadatum);
|
---|
95 | // Retrieve the currently last index
|
---|
96 | if(getSize() > 0) {
|
---|
97 | Index last_index = (Index)getElementAt(getSize() - 1);
|
---|
98 | addAfter(index, last_index);
|
---|
99 |
|
---|
100 | }
|
---|
101 | else {
|
---|
102 | add(index);
|
---|
103 | // Also set this index as the default one,
|
---|
104 | setDefault(index);
|
---|
105 | }
|
---|
106 | }
|
---|
107 | else {
|
---|
108 | JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.IndexManager.Index_Exists"), Dictionary.get("General.Warning"), JOptionPane.WARNING_MESSAGE);
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | public void buildTypeChanged(String new_build_type) {
|
---|
113 | if (build_type.equals(new_build_type)) {
|
---|
114 | return;
|
---|
115 | }
|
---|
116 | // we don;t care about this if old or new is not MG as MGPP and
|
---|
117 | // Lucene have the same index specification
|
---|
118 | if (!build_type.equals(BuildTypeManager.BUILD_TYPE_MG) && !new_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
119 | return;
|
---|
120 | }
|
---|
121 | boolean mg_to_mgpp = true;
|
---|
122 | if (new_build_type.equals(BuildTypeManager.BUILD_TYPE_MG)) {
|
---|
123 | mg_to_mgpp = false;
|
---|
124 | }
|
---|
125 | build_type = new_build_type;
|
---|
126 | if (mg_to_mgpp) {
|
---|
127 | changeToMGPPIndexes();
|
---|
128 | } else {
|
---|
129 | changeToMGIndexes();
|
---|
130 | }
|
---|
131 | // its really hard to transfer defaults between mgpp/lucene and mg indexes, so we'll just set the first one to be the default
|
---|
132 | Index first_index = (Index) getElementAt(0);
|
---|
133 | setDefault(first_index);
|
---|
134 | first_index = null;
|
---|
135 | }
|
---|
136 |
|
---|
137 | private void changeToMGIndexes() {
|
---|
138 | Element mgpp_element = root;
|
---|
139 | // Retrieve and assign MG element and default index element
|
---|
140 | Element mg_element = CollectionDesignManager.collect_config.getMGIndexes();
|
---|
141 | mg_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
142 | NodeList indexes = mg_element.getElementsByTagName(StaticStrings.INDEX_ELEMENT);
|
---|
143 | if(indexes.getLength() != 0) {
|
---|
144 | //just reinstate what we had previously
|
---|
145 | setRoot(mg_element);
|
---|
146 | } else {
|
---|
147 | // If mg element has no indexes, and the current mgpp index includes a text one, then generate text indexes for each of the registered levels.
|
---|
148 | Index index = getIndex(StaticStrings.TEXT_STR);
|
---|
149 | if(index != null) {
|
---|
150 | // Replace mgpp element with mg element
|
---|
151 | setRoot(mg_element);
|
---|
152 | ArrayList levels = CollectionDesignManager.index_manager.getLevels();
|
---|
153 | int level_size = levels.size();
|
---|
154 | for(int i = 0; i < level_size; i++) {
|
---|
155 | IndexOption level = (IndexOption) levels.get(i);
|
---|
156 | Index new_index = new Index(level.getName(), index.getSources());
|
---|
157 | // Try to retrieve existing metadatum
|
---|
158 | String source_str = new_index.getID();
|
---|
159 | CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(StaticStrings.STOP_CHARACTER + source_str, false);
|
---|
160 | // If no metadata was found, add new pseudo metadata using the id
|
---|
161 | if(metadatum == null) {
|
---|
162 | metadatum = new CollectionMeta(StaticStrings.STOP_CHARACTER + source_str);
|
---|
163 | metadatum.setAssigned(true);
|
---|
164 | metadatum.setValue(source_str);
|
---|
165 | }
|
---|
166 | // If it was found, ensure it is assigned
|
---|
167 | else {
|
---|
168 | metadatum.setAssigned(true);
|
---|
169 | }
|
---|
170 | source_str = null;
|
---|
171 | addIndex(new_index, metadatum);
|
---|
172 | new_index = null;
|
---|
173 | level = null;
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | // Unassign mgpp element
|
---|
179 | mgpp_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
180 | mgpp_element = null;
|
---|
181 |
|
---|
182 | }
|
---|
183 |
|
---|
184 | private void changeToMGPPIndexes() {
|
---|
185 | Element mg_element = root;
|
---|
186 | // Retrieve and assign the MGPP indexes element.
|
---|
187 | Element mgpp_element = CollectionDesignManager.collect_config.getMGPPIndexes();
|
---|
188 | mgpp_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.TRUE_STR);
|
---|
189 | NodeList indexes = mgpp_element.getElementsByTagName(StaticStrings.INDEX_ELEMENT);
|
---|
190 | if(indexes.getLength() != 0) {
|
---|
191 | // we just reinstate the indexes we had before the change
|
---|
192 | setRoot(mgpp_element);
|
---|
193 | } else {
|
---|
194 | // If the MGPP indexes element is empty (ie was created by CollectionConfiguration), generate new MGPP index from the existing index
|
---|
195 |
|
---|
196 | ArrayList sources_list = new ArrayList();
|
---|
197 | // We first use details from the default index if any
|
---|
198 | if(default_index != null) {
|
---|
199 | ArrayList sources = default_index.getSources();
|
---|
200 | sources_list.addAll(sources);
|
---|
201 | }
|
---|
202 | int size = getSize();
|
---|
203 | for(int i = 0; i < size; i++) {
|
---|
204 | Index index = (Index) getElementAt(i);
|
---|
205 | ArrayList sources = index.getSources();
|
---|
206 | sources.removeAll(sources_list);
|
---|
207 | sources_list.addAll(sources);
|
---|
208 | index = null;
|
---|
209 | }
|
---|
210 | // Replace mg element with mgpp element
|
---|
211 | setRoot(mgpp_element);
|
---|
212 |
|
---|
213 | // We now have a list of sources, so create new indexes based on these
|
---|
214 | int sources_list_size = sources_list.size();
|
---|
215 | for(int j = 0; j < sources_list_size; j++) {
|
---|
216 | Object source_object = sources_list.get(j);
|
---|
217 | String source_str = null;
|
---|
218 | if(source_object instanceof MetadataElement) {
|
---|
219 | source_str = ((MetadataElement) source_object).getFullName();
|
---|
220 | }
|
---|
221 | else {
|
---|
222 | source_str = source_object.toString();
|
---|
223 | }
|
---|
224 | ArrayList new_sources = new ArrayList();
|
---|
225 | new_sources.add(source_object);
|
---|
226 | source_object = null;
|
---|
227 | Index new_index = new Index(new_sources);
|
---|
228 | // Try to retrieve existing metadatum
|
---|
229 | source_str = new_index.getID();
|
---|
230 | CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(StaticStrings.STOP_CHARACTER + source_str, false);
|
---|
231 | // If no metadata was found, add new pseudo metadata using the id
|
---|
232 | if(metadatum == null) {
|
---|
233 | metadatum = new CollectionMeta(StaticStrings.STOP_CHARACTER + source_str);
|
---|
234 | metadatum.setAssigned(true);
|
---|
235 | metadatum.setValue(source_str);
|
---|
236 | }
|
---|
237 | // If it was found, ensure it is assigned
|
---|
238 | else {
|
---|
239 | metadatum.setAssigned(true);
|
---|
240 | }
|
---|
241 | source_str = null;
|
---|
242 | addIndex(new_index, metadatum);
|
---|
243 | metadatum = null;
|
---|
244 | new_index = null;
|
---|
245 | new_sources = null;
|
---|
246 | source_str = null;
|
---|
247 | }
|
---|
248 |
|
---|
249 | }
|
---|
250 |
|
---|
251 | // Unassign MG element
|
---|
252 | mg_element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
253 | mg_element = null;
|
---|
254 |
|
---|
255 | }
|
---|
256 |
|
---|
257 | public Control getControls() {
|
---|
258 | if (controls == null) {
|
---|
259 | controls = new IndexControl();
|
---|
260 | }
|
---|
261 | return controls;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /** Method to retrieve a certain index, as referenced by an index number.
|
---|
265 | * @param index An <i>int</i> which indicates the position of the desired index.
|
---|
266 | * @return The <strong>Index</strong> at the given index, or <i>null</i> if no such index exists.
|
---|
267 | */
|
---|
268 | public Index getIndex(int index) {
|
---|
269 | if(0 <= index && index < getSize()) {
|
---|
270 | return (Index)getElementAt(index);
|
---|
271 | }
|
---|
272 | return null;
|
---|
273 | }
|
---|
274 |
|
---|
275 | /** Method to retrieve a certain index, given its id.
|
---|
276 | * @param id the id of the index as a String
|
---|
277 | * @return the Index that matches id, or null if no such index exists
|
---|
278 | */
|
---|
279 | public Index getIndex(String id) {
|
---|
280 | int size = getSize();
|
---|
281 | for(int i = 0; i < size; i++) {
|
---|
282 | Index index = (Index) getElementAt(i);
|
---|
283 | if(index.getID().equals(id)) {
|
---|
284 | return index;
|
---|
285 | }
|
---|
286 | }
|
---|
287 | return null;
|
---|
288 | }
|
---|
289 |
|
---|
290 | public ArrayList getIndexes() {
|
---|
291 | return children();
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 |
|
---|
296 | /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
|
---|
297 | * @param mode the new mode as an int
|
---|
298 | */
|
---|
299 | public void modeChanged(int mode) {
|
---|
300 |
|
---|
301 | }
|
---|
302 |
|
---|
303 | private void moveIndex(Index index, boolean move_up)
|
---|
304 | {
|
---|
305 | // Determine the current position of the index
|
---|
306 | int position = indexOf(index);
|
---|
307 | // Determine if it can be moved, ie if its not already at the top trying to move up, or at the bottom trying to move down.
|
---|
308 | if(position == -1) {
|
---|
309 | return;
|
---|
310 | }
|
---|
311 | if(position == 0 && move_up) {
|
---|
312 | return;
|
---|
313 | }
|
---|
314 | if(position == (getSize()) - 1 && !move_up) {
|
---|
315 | return;
|
---|
316 | }
|
---|
317 |
|
---|
318 | // Ok, move up
|
---|
319 | if (move_up) {
|
---|
320 | position--;
|
---|
321 | remove(index);
|
---|
322 | add(position, index);
|
---|
323 | }
|
---|
324 |
|
---|
325 | // Or move down
|
---|
326 | else {
|
---|
327 | position++;
|
---|
328 | remove(index);
|
---|
329 | add(position, index);
|
---|
330 | }
|
---|
331 | }
|
---|
332 |
|
---|
333 |
|
---|
334 |
|
---|
335 | /** Method to remove a certain index.
|
---|
336 | * @param index the Index to remove.
|
---|
337 | * @see org.greenstone.gatherer.Gatherer
|
---|
338 | * @see org.greenstone.gatherer.cdm.CollectionDesignManager
|
---|
339 | * @see org.greenstone.gatherer.cdm.CollectionMetaManager
|
---|
340 | * @see org.greenstone.gatherer.collection.CollectionManager
|
---|
341 | */
|
---|
342 | private void removeIndex(Index index) {
|
---|
343 | if(index != null) {
|
---|
344 | // Remove any current metadata from this index
|
---|
345 | CollectionDesignManager.collectionmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + index.getID());
|
---|
346 | // Remove the index
|
---|
347 | remove(index);
|
---|
348 | // Check if the index removed happens to be the default index
|
---|
349 | if(default_index != null && default_index.equals(index)) {
|
---|
350 | // If so our first solution is to set the first index to be default
|
---|
351 | if(getSize() > 0) {
|
---|
352 | Index another_index = (Index) getElementAt(0);
|
---|
353 | setDefault(another_index);
|
---|
354 | another_index = null;
|
---|
355 | }
|
---|
356 | else {
|
---|
357 | default_index.setAssigned(false);
|
---|
358 | }
|
---|
359 | }
|
---|
360 | }
|
---|
361 | }
|
---|
362 |
|
---|
363 |
|
---|
364 | /* replace an index in the list. new index may have the same sources but a
|
---|
365 | different name, or may be a new index altogether */
|
---|
366 | private void replaceIndex(Index old_index, Index new_index,
|
---|
367 | CollectionMeta coll_meta) {
|
---|
368 | if (old_index == null || new_index == null || coll_meta == null) {
|
---|
369 | return;
|
---|
370 | }
|
---|
371 | if (!old_index.getID().equals(new_index.getID()) && contains(new_index)) {
|
---|
372 | // shoudl we output an error??
|
---|
373 | return;
|
---|
374 | }
|
---|
375 | // Remove the old index coll meta
|
---|
376 | CollectionDesignManager.collectionmeta_manager.removeMetadata(StaticStrings.STOP_CHARACTER + old_index.getID());
|
---|
377 | // Add the new coll meta
|
---|
378 | CollectionDesignManager.collectionmeta_manager.addMetadatum(coll_meta);
|
---|
379 |
|
---|
380 | // get the position of the old one
|
---|
381 | int position = indexOf(old_index);
|
---|
382 | // remove it
|
---|
383 | remove(old_index);
|
---|
384 | // add the new one at that position
|
---|
385 | add(position, new_index);
|
---|
386 | }
|
---|
387 |
|
---|
388 |
|
---|
389 | /** Method to set the default index.
|
---|
390 | * @param index the new default Index
|
---|
391 | * @see org.greenstone.gatherer.Gatherer
|
---|
392 | * @see org.greenstone.gatherer.collection.CollectionManager
|
---|
393 | */
|
---|
394 | public void setDefault(Index index) {
|
---|
395 | if(index != null) {
|
---|
396 | if(default_index == null) {
|
---|
397 | // Create the default index element, and place immediately after indexes element.
|
---|
398 | Element default_index_element = root.getOwnerDocument().createElement(StaticStrings.INDEX_DEFAULT_ELEMENT);
|
---|
399 | default_index = new Index(default_index_element);
|
---|
400 | Node target_node = CollectionConfiguration.findInsertionPoint(default_index_element);
|
---|
401 | if(target_node != null) {
|
---|
402 | root.getOwnerDocument().getDocumentElement().insertBefore(default_index_element, target_node);
|
---|
403 | }
|
---|
404 | else {
|
---|
405 | root.getOwnerDocument().getDocumentElement().appendChild(default_index_element);
|
---|
406 | }
|
---|
407 | }
|
---|
408 | default_index.setAssigned(true);
|
---|
409 | default_index.setLevel(index.getLevel());
|
---|
410 | default_index.setSources(index.getSources());
|
---|
411 |
|
---|
412 | }
|
---|
413 | else {
|
---|
414 | if(default_index != null) {
|
---|
415 | default_index.setAssigned(false);
|
---|
416 | }
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 |
|
---|
421 | private class IndexControl
|
---|
422 | extends JPanel
|
---|
423 | implements Control {
|
---|
424 |
|
---|
425 | private JList index_list;
|
---|
426 | private JButton move_down_button;
|
---|
427 | private JButton move_up_button;
|
---|
428 | private JButton set_default_button;
|
---|
429 |
|
---|
430 | private JButton new_button;
|
---|
431 | private JButton edit_button;
|
---|
432 | private JButton remove_button;
|
---|
433 |
|
---|
434 | public IndexControl() {
|
---|
435 | super();
|
---|
436 |
|
---|
437 | // Creation
|
---|
438 | JPanel assigned_indexes_pane = new JPanel();
|
---|
439 |
|
---|
440 | JLabel index_label = new JLabel(Dictionary.get("CDM.IndexManager.Indexes"));
|
---|
441 | index_list = new JList(index_model);
|
---|
442 | index_list.setCellRenderer(new IndexListRenderer());
|
---|
443 | index_list.setVisibleRowCount(6);
|
---|
444 | index_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
445 |
|
---|
446 | JPanel movement_pane = new JPanel();
|
---|
447 | move_up_button = new GLIButton(Dictionary.get("CDM.Move.Move_Up"), JarTools.getImage("arrow-up.gif"), Dictionary.get("CDM.Move.Move_Up_Tooltip"));
|
---|
448 | move_up_button.setEnabled(false);
|
---|
449 |
|
---|
450 | move_down_button = new GLIButton(Dictionary.get("CDM.Move.Move_Down"), JarTools.getImage("arrow-down.gif"), Dictionary.get("CDM.Move.Move_Down_Tooltip"));
|
---|
451 | move_down_button.setEnabled(false);
|
---|
452 |
|
---|
453 | set_default_button = new GLIButton(Dictionary.get("CDM.IndexManager.Set_Default"), Dictionary.get("CDM.IndexManager.Set_Default_Tooltip"));
|
---|
454 | set_default_button.setEnabled(false);
|
---|
455 |
|
---|
456 | JPanel button_pane = new JPanel();
|
---|
457 | new_button = new GLIButton(Dictionary.get("CDM.IndexManager.New_Index")+StaticStrings.FURTHER_DIALOG_INDICATOR, Dictionary.get("CDM.IndexManager.New_Index_Tooltip"));
|
---|
458 | new_button.setEnabled(true);
|
---|
459 |
|
---|
460 | edit_button = new GLIButton(Dictionary.get("CDM.IndexManager.Edit_Index")+StaticStrings.FURTHER_DIALOG_INDICATOR, Dictionary.get("CDM.IndexManager.Edit_Index_Tooltip"));
|
---|
461 | edit_button.setEnabled(false);
|
---|
462 |
|
---|
463 | remove_button = new GLIButton(Dictionary.get("CDM.IndexManager.Remove_Index"), Dictionary.get("CDM.IndexManager.Remove_Index_Tooltip"));
|
---|
464 | remove_button.setEnabled(false);
|
---|
465 |
|
---|
466 | // Listeners
|
---|
467 | new_button.addActionListener(new NewIndexListener());
|
---|
468 | edit_button.addActionListener(new EditIndexListener());
|
---|
469 | remove_button.addActionListener(new RemoveIndexListener());
|
---|
470 | remove_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
471 |
|
---|
472 | index_list.addListSelectionListener(new IndexListListener());
|
---|
473 |
|
---|
474 | move_down_button.addActionListener(new MoveListener(false));
|
---|
475 | move_down_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
476 | move_up_button.addActionListener(new MoveListener(true));
|
---|
477 | move_up_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
478 |
|
---|
479 | set_default_button.addActionListener(new SetDefaultListener());
|
---|
480 | // Layout
|
---|
481 | movement_pane.setBorder(BorderFactory.createEmptyBorder(0,2,0,0));
|
---|
482 | movement_pane.setLayout(new GridLayout(3,1));
|
---|
483 | movement_pane.add(move_up_button);
|
---|
484 | movement_pane.add(move_down_button);
|
---|
485 | movement_pane.add(set_default_button);
|
---|
486 |
|
---|
487 | assigned_indexes_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
|
---|
488 | assigned_indexes_pane.setLayout(new BorderLayout());
|
---|
489 | assigned_indexes_pane.add(index_label, BorderLayout.NORTH);
|
---|
490 | assigned_indexes_pane.add(new JScrollPane(index_list), BorderLayout.CENTER);
|
---|
491 | assigned_indexes_pane.add(movement_pane, BorderLayout.EAST);
|
---|
492 |
|
---|
493 | button_pane.setLayout(new GridLayout(1,3,5,0));
|
---|
494 | button_pane.add(new_button);
|
---|
495 | button_pane.add(edit_button);
|
---|
496 | button_pane.add(remove_button);
|
---|
497 |
|
---|
498 | setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
|
---|
499 | setLayout(new BorderLayout());
|
---|
500 | add(assigned_indexes_pane, BorderLayout.CENTER);
|
---|
501 | add(button_pane, BorderLayout.SOUTH);
|
---|
502 |
|
---|
503 | }
|
---|
504 | public void loseFocus() {}
|
---|
505 | public void gainFocus() {}
|
---|
506 | public void destroy() {}
|
---|
507 |
|
---|
508 | private class IndexListListener
|
---|
509 | implements ListSelectionListener {
|
---|
510 |
|
---|
511 | /** This method is called whenever the source list selection changes. When it does we need to fill in the various parts of the list description panel
|
---|
512 | * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
|
---|
513 | */
|
---|
514 | public void valueChanged(ListSelectionEvent event)
|
---|
515 | {
|
---|
516 | if (event.getValueIsAdjusting()) {
|
---|
517 | return;
|
---|
518 | }
|
---|
519 |
|
---|
520 | set_default_button.setEnabled(true);
|
---|
521 | Object value = index_list.getSelectedValue();
|
---|
522 | if (value == null) {
|
---|
523 | move_down_button.setEnabled(false);
|
---|
524 | move_up_button.setEnabled(false);
|
---|
525 | remove_button.setEnabled(false);
|
---|
526 | edit_button.setEnabled(false);
|
---|
527 | set_default_button.setEnabled(false);
|
---|
528 | return;
|
---|
529 | }
|
---|
530 |
|
---|
531 | // Enable the buttons appropriately
|
---|
532 | remove_button.setEnabled(true);
|
---|
533 | edit_button.setEnabled(true);
|
---|
534 | set_default_button.setEnabled(default_index == null || !default_index.equals(value));
|
---|
535 | int i = index_list.getSelectedIndex();
|
---|
536 | int size = index_list.getModel().getSize();
|
---|
537 | move_up_button.setEnabled((i>0));
|
---|
538 | move_down_button.setEnabled((i<size-1));
|
---|
539 | }
|
---|
540 | }
|
---|
541 |
|
---|
542 | private class IndexListRenderer
|
---|
543 | extends DefaultListCellRenderer {
|
---|
544 |
|
---|
545 | /** Return a component that has been configured to display the specified value. */
|
---|
546 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
---|
547 | JLabel component = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
---|
548 | if(default_index != null && default_index.equals(value)) {
|
---|
549 | component.setText(component.getText() + " " + Dictionary.get("CDM.IndexManager.Default_Index_Indicator"));
|
---|
550 | }
|
---|
551 | return component;
|
---|
552 | }
|
---|
553 |
|
---|
554 | }
|
---|
555 |
|
---|
556 | private class NewIndexListener
|
---|
557 | implements ActionListener {
|
---|
558 |
|
---|
559 | public void actionPerformed(ActionEvent event) {
|
---|
560 | NewIndexPrompt nip = new NewIndexPrompt(build_type, null);
|
---|
561 | nip.destroy();
|
---|
562 | }
|
---|
563 | }
|
---|
564 |
|
---|
565 | private class EditIndexListener
|
---|
566 | implements ActionListener {
|
---|
567 |
|
---|
568 | public void actionPerformed(ActionEvent event) {
|
---|
569 | Index index = (Index) index_list.getSelectedValue();
|
---|
570 | NewIndexPrompt nip = new NewIndexPrompt(build_type, index);
|
---|
571 | nip.destroy();
|
---|
572 | }
|
---|
573 | }
|
---|
574 |
|
---|
575 | private class RemoveIndexListener
|
---|
576 | implements ActionListener {
|
---|
577 |
|
---|
578 | public void actionPerformed(ActionEvent event) {
|
---|
579 |
|
---|
580 | int i = index_list.getSelectedIndex();
|
---|
581 | if (i != -1) {
|
---|
582 | removeIndex((Index) index_list.getSelectedValue());
|
---|
583 | }
|
---|
584 | int size = index_list.getModel().getSize();
|
---|
585 | if (i == size) {
|
---|
586 | i--;
|
---|
587 | }
|
---|
588 | index_list.setSelectedIndex(i);
|
---|
589 | // This will produce an event on the list, updating the other buttons
|
---|
590 | }
|
---|
591 | }
|
---|
592 |
|
---|
593 | private class MoveListener
|
---|
594 | implements ActionListener {
|
---|
595 |
|
---|
596 | private boolean move_up;
|
---|
597 |
|
---|
598 | public MoveListener(boolean move_up) {
|
---|
599 | this.move_up = move_up;
|
---|
600 | }
|
---|
601 |
|
---|
602 | public void actionPerformed(ActionEvent event) {
|
---|
603 | // Retrieve the selected index
|
---|
604 | Index index = (Index) index_list.getSelectedValue();
|
---|
605 | if(index != null) {
|
---|
606 | moveIndex(index, move_up);
|
---|
607 | // Ensure the index that moved is still selected
|
---|
608 | index_list.setSelectedValue(index, true);
|
---|
609 | index = null;
|
---|
610 | }
|
---|
611 | }
|
---|
612 | }
|
---|
613 |
|
---|
614 | private class SetDefaultListener
|
---|
615 | implements ActionListener {
|
---|
616 |
|
---|
617 | public void actionPerformed(ActionEvent event) {
|
---|
618 | Index index = (Index) index_list.getSelectedValue();
|
---|
619 | if(index != null) {
|
---|
620 | setDefault(index);
|
---|
621 | // This should cause a repaint of just the desired row
|
---|
622 | index_list.setSelectedValue(index, true);
|
---|
623 | }
|
---|
624 | set_default_button.setEnabled(false);
|
---|
625 | }
|
---|
626 | }
|
---|
627 |
|
---|
628 |
|
---|
629 |
|
---|
630 | private class NewIndexPrompt
|
---|
631 | extends ModalDialog {
|
---|
632 |
|
---|
633 | NewIndexPrompt new_index_prompt = null;
|
---|
634 |
|
---|
635 | private JCheckBox text_checkbox;
|
---|
636 | private CheckList source_list;
|
---|
637 | // mg uses a level box
|
---|
638 | private JComboBox level_combobox;
|
---|
639 | // mgpp has a allfields selector
|
---|
640 | private JCheckBox allfields_box;
|
---|
641 |
|
---|
642 | private JButton add_or_replace_button;
|
---|
643 | private JButton select_all_button;
|
---|
644 | private JButton select_none_button;
|
---|
645 | private JButton add_all_button;
|
---|
646 | //private JButton select_all_button;
|
---|
647 | //private JButton replace_button;
|
---|
648 | private JButton cancel_button;
|
---|
649 |
|
---|
650 | private boolean mgpp_enabled = false;
|
---|
651 | private boolean editing = false;
|
---|
652 |
|
---|
653 | public NewIndexPrompt(String build_type, Index existing_index) {
|
---|
654 | super(Gatherer.g_man, true);
|
---|
655 | new_index_prompt = this;
|
---|
656 |
|
---|
657 | setModal(true);
|
---|
658 | setSize(PROMPT_SIZE);
|
---|
659 | if (existing_index != null) {
|
---|
660 | setTitle (Dictionary.get("CDM.IndexManager.Edit_Index"));
|
---|
661 | editing = true;
|
---|
662 | } else {
|
---|
663 | setTitle(Dictionary.get("CDM.IndexManager.New_Index"));
|
---|
664 | }
|
---|
665 |
|
---|
666 | setJMenuBar(new SimpleMenuBar("searchindexes"));
|
---|
667 | if (build_type.equals(BuildTypeManager.BUILD_TYPE_MGPP) || build_type.equals(BuildTypeManager.BUILD_TYPE_LUCENE)) {
|
---|
668 | mgpp_enabled = true;
|
---|
669 | }
|
---|
670 | JPanel content_pane = (JPanel)this.getContentPane();
|
---|
671 | ArrayList new_data = new ArrayList();
|
---|
672 | new_data.addAll(MetadataSetManager.getEveryMetadataSetElement());
|
---|
673 |
|
---|
674 | JPanel details_pane = new JPanel();
|
---|
675 |
|
---|
676 | text_checkbox = new JCheckBox(Dictionary.get("CDM.IndexManager.Text_Source"));
|
---|
677 | text_checkbox.setToolTipText(Dictionary.get("CDM.IndexManager.Text_Source_Tooltip"));
|
---|
678 | text_checkbox.addActionListener(new ActionListener() {
|
---|
679 | public void actionPerformed(ActionEvent event) {
|
---|
680 | validateAddOrReplaceButton();
|
---|
681 | }
|
---|
682 | });
|
---|
683 | JLabel source_label = new JLabel(Dictionary.get("CDM.IndexManager.Source"));
|
---|
684 | source_list = new CheckList(false);
|
---|
685 | source_list.setListData(new_data);
|
---|
686 | source_list.setToolTipText(Dictionary.get("CDM.IndexManager.Source_Tooltip"));
|
---|
687 | source_list.addListSelectionListener(new SourceListListener());
|
---|
688 |
|
---|
689 | JPanel button_pane = new JPanel();
|
---|
690 | button_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
691 |
|
---|
692 | if (existing_index == null && mgpp_enabled) {
|
---|
693 | button_pane.setLayout(new GridLayout(2,3,5,0));
|
---|
694 | button_pane.add(new JPanel());
|
---|
695 | } else {
|
---|
696 | button_pane.setLayout(new GridLayout(2,2,5,0));
|
---|
697 | }
|
---|
698 |
|
---|
699 | select_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_All"), Dictionary.get("CDM.IndexManager.Select_All_Tooltip"));
|
---|
700 | select_all_button.addActionListener(new ActionListener() {
|
---|
701 |
|
---|
702 | public void actionPerformed(ActionEvent event) {
|
---|
703 | text_checkbox.setSelected(true);
|
---|
704 | source_list.setAllTicked();
|
---|
705 | validateAddOrReplaceButton();
|
---|
706 | }
|
---|
707 | });
|
---|
708 |
|
---|
709 | select_none_button = new GLIButton(Dictionary.get("CDM.IndexManager.Select_None"), Dictionary.get("CDM.IndexManager.Select_None_Tooltip"));
|
---|
710 | select_none_button.addActionListener(new ActionListener() {
|
---|
711 |
|
---|
712 | public void actionPerformed(ActionEvent event) {
|
---|
713 | text_checkbox.setSelected(false);
|
---|
714 | source_list.clearTicked();
|
---|
715 | validateAddOrReplaceButton();
|
---|
716 | }
|
---|
717 | });
|
---|
718 |
|
---|
719 |
|
---|
720 | button_pane.add(select_all_button);
|
---|
721 | button_pane.add(select_none_button);
|
---|
722 |
|
---|
723 | if (existing_index != null) {
|
---|
724 | add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Replace_Index"), Dictionary.get("CDM.IndexManager.Replace_Index_Tooltip"));
|
---|
725 | add_or_replace_button.addActionListener(new ReplaceIndexListener());
|
---|
726 | } else {
|
---|
727 | add_or_replace_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_Index"), Dictionary.get("CDM.IndexManager.Add_Index_Tooltip"));
|
---|
728 | add_or_replace_button.addActionListener(new AddIndexListener());
|
---|
729 | }
|
---|
730 |
|
---|
731 | add_or_replace_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
|
---|
732 | add_or_replace_button.setEnabled(false);
|
---|
733 | button_pane.add(add_or_replace_button);
|
---|
734 |
|
---|
735 | if (existing_index == null && mgpp_enabled) {
|
---|
736 | add_all_button = new GLIButton(Dictionary.get("CDM.IndexManager.Add_All"), Dictionary.get("CDM.IndexManager.Add_All_Tooltip"));
|
---|
737 | add_all_button.setEnabled(true);
|
---|
738 | add_all_button.addActionListener(new AddAllIndexActionListener());
|
---|
739 | button_pane.add(add_all_button);
|
---|
740 | }
|
---|
741 |
|
---|
742 | // always have a cancel button
|
---|
743 | cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel"));
|
---|
744 | cancel_button.setEnabled(true);
|
---|
745 | cancel_button.addActionListener(new ActionListener() {
|
---|
746 | public void actionPerformed(ActionEvent event) {
|
---|
747 | new_index_prompt.dispose();
|
---|
748 | }
|
---|
749 | });
|
---|
750 | button_pane.add(cancel_button);
|
---|
751 |
|
---|
752 | //Layout
|
---|
753 | details_pane.setLayout(new BorderLayout(10,10));
|
---|
754 | details_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
755 | details_pane.add(text_checkbox, BorderLayout.NORTH);
|
---|
756 | details_pane.add(new JScrollPane(source_list), BorderLayout.CENTER);
|
---|
757 |
|
---|
758 |
|
---|
759 | // do type specific stuff
|
---|
760 | if (mgpp_enabled) {
|
---|
761 | // allfields
|
---|
762 | allfields_box = new JCheckBox(Dictionary.get("CDM.IndexManager.Allfields_Index"));
|
---|
763 | allfields_box.addItemListener(new AllFieldsBoxListener());
|
---|
764 | //JLabel allfields_label = new JLabel(Dictionary.get("CDM.IndexManager.Allfields_Index"));
|
---|
765 | details_pane.add(allfields_box, BorderLayout.SOUTH);
|
---|
766 |
|
---|
767 |
|
---|
768 | } else {
|
---|
769 | // index level
|
---|
770 | JLabel level_label = new JLabel(Dictionary.get("CDM.IndexManager.Level"));
|
---|
771 | level_combobox = new JComboBox();
|
---|
772 | level_combobox.setOpaque(false);
|
---|
773 | level_combobox.setPreferredSize(FIELD_SIZE);
|
---|
774 | // Note the order of these must be the same as the
|
---|
775 | // level order in Index
|
---|
776 | level_combobox.addItem(StaticStrings.DOCUMENT_STR);//Dictionary.get("CDM.LevelManager.Document"));
|
---|
777 | level_combobox.addItem(StaticStrings.SECTION_STR);//Dictionary.get("CDM.LevelManager.Section"));
|
---|
778 | level_combobox.addItem(StaticStrings.PARAGRAPH_STR);//Dictionary.get("CDM.LevelManager.Paragraph"));
|
---|
779 | level_combobox.setEditable(false);
|
---|
780 | level_combobox.setToolTipText(Dictionary.get("CDM.IndexManager.Level_Tooltip"));
|
---|
781 | level_combobox.addActionListener(new ActionListener() {
|
---|
782 | public void actionPerformed(ActionEvent event) {
|
---|
783 | validateAddOrReplaceButton();
|
---|
784 | }
|
---|
785 | });
|
---|
786 | JPanel level_pane = new JPanel();
|
---|
787 | level_pane.setLayout(new BorderLayout());
|
---|
788 | level_pane.add(level_label, BorderLayout.WEST);
|
---|
789 | level_pane.add(level_combobox, BorderLayout.CENTER);
|
---|
790 | details_pane.add(level_pane, BorderLayout.SOUTH);
|
---|
791 |
|
---|
792 | }
|
---|
793 | // if we are editing, fill in the controls
|
---|
794 | if (existing_index !=null) {
|
---|
795 | ArrayList sources = existing_index.getSources();
|
---|
796 | if (mgpp_enabled && sources.get(0).equals(ALLFIELDS)) {
|
---|
797 | allfields_box.setSelected(true);
|
---|
798 | source_list.setEnabled(false);
|
---|
799 | } else {
|
---|
800 | source_list.setTickedObjects(sources.toArray());
|
---|
801 | source_list.setEnabled(true);
|
---|
802 | if (sources.contains(StaticStrings.TEXT_STR)) {
|
---|
803 | text_checkbox.setSelected(true);
|
---|
804 | }
|
---|
805 | }
|
---|
806 | if (!mgpp_enabled) {
|
---|
807 | level_combobox.setSelectedIndex(existing_index.getLevel());
|
---|
808 | }
|
---|
809 |
|
---|
810 | }
|
---|
811 | content_pane.setLayout(new BorderLayout());
|
---|
812 | content_pane.add(source_label, BorderLayout.NORTH);
|
---|
813 | content_pane.add(details_pane, BorderLayout.CENTER);
|
---|
814 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
815 |
|
---|
816 | // Display on screen.
|
---|
817 | Dimension screen_size = Configuration.screen_size;
|
---|
818 | setLocation((screen_size.width - PROMPT_SIZE.width) / 2, (screen_size.height - PROMPT_SIZE.height) / 2);
|
---|
819 | screen_size = null;
|
---|
820 | setVisible(true);
|
---|
821 |
|
---|
822 | }
|
---|
823 |
|
---|
824 | /** Method which actually forces the dialog to be shown on screen.
|
---|
825 | * @return <i>true</i> if the user completed configuration and pressed ok, <i>false</i> otherwise.
|
---|
826 | */
|
---|
827 | public boolean display() {
|
---|
828 | setVisible(true);
|
---|
829 | return true;
|
---|
830 | // return success;
|
---|
831 | }
|
---|
832 |
|
---|
833 | public void destroy() {
|
---|
834 | }
|
---|
835 |
|
---|
836 | // Checks that specified index not already in the collection
|
---|
837 | private void validateAddOrReplaceButton() {
|
---|
838 | Index index;
|
---|
839 | ArrayList sources;
|
---|
840 | if (mgpp_enabled && allfields_box.isSelected()) {
|
---|
841 | sources = new ArrayList();
|
---|
842 | sources.add(ALLFIELDS);
|
---|
843 | index = new Index(sources);
|
---|
844 |
|
---|
845 | } else if (text_checkbox.isSelected() ||
|
---|
846 | !source_list.isNothingTicked()) {
|
---|
847 | sources = source_list.getTicked();
|
---|
848 | if (text_checkbox.isSelected()) {
|
---|
849 | sources.add(0, StaticStrings.TEXT_STR);
|
---|
850 | }
|
---|
851 | if (mgpp_enabled) {
|
---|
852 | index = new Index(sources);
|
---|
853 | } else {
|
---|
854 | index = new Index(level_combobox.getSelectedIndex(), sources);
|
---|
855 | }
|
---|
856 | } else {
|
---|
857 | // nothing selected
|
---|
858 | add_or_replace_button.setEnabled(false);
|
---|
859 | return;
|
---|
860 | }
|
---|
861 |
|
---|
862 | sources = null;
|
---|
863 | if (index_model.contains(index)) {
|
---|
864 | add_or_replace_button.setEnabled(false);
|
---|
865 | }
|
---|
866 | else {
|
---|
867 | add_or_replace_button.setEnabled(true);
|
---|
868 | }
|
---|
869 |
|
---|
870 | }
|
---|
871 | private class AddIndexListener
|
---|
872 | implements ActionListener
|
---|
873 | {
|
---|
874 | public void actionPerformed(ActionEvent event)
|
---|
875 | {
|
---|
876 | Index index;
|
---|
877 | if (mgpp_enabled && allfields_box.isSelected()) {
|
---|
878 | ArrayList sources = new ArrayList();
|
---|
879 | sources.add(ALLFIELDS);
|
---|
880 | index = new Index(sources);
|
---|
881 | }
|
---|
882 | else if (text_checkbox.isSelected() ||
|
---|
883 | !source_list.isNothingTicked()) {
|
---|
884 | ArrayList sources = source_list.getTicked();
|
---|
885 | if (text_checkbox.isSelected()) {
|
---|
886 | sources.add(0, StaticStrings.TEXT_STR);
|
---|
887 | }
|
---|
888 | if(mgpp_enabled) {
|
---|
889 | index = new Index(sources);
|
---|
890 | } else {
|
---|
891 | index = new Index(level_combobox.getSelectedIndex(), sources);
|
---|
892 | }
|
---|
893 | } else {
|
---|
894 | return;
|
---|
895 | }
|
---|
896 |
|
---|
897 | // Before we add the index to the model, we have to add a default collection metadata for this
|
---|
898 | CollectionMeta metadatum = new CollectionMeta(StaticStrings.STOP_CHARACTER + index.getID());
|
---|
899 | metadatum.setValue(index.getID());
|
---|
900 |
|
---|
901 | // Finally, add the index
|
---|
902 | addIndex(index, metadatum);
|
---|
903 | index_list.setSelectedValue(index, true);
|
---|
904 | new_index_prompt.dispose();
|
---|
905 | }
|
---|
906 | }
|
---|
907 |
|
---|
908 | /** add all sources as separate indexes (fields). */
|
---|
909 | private class AddAllIndexActionListener
|
---|
910 | implements ActionListener {
|
---|
911 |
|
---|
912 | public void actionPerformed(ActionEvent event) {
|
---|
913 | ArrayList all_sources = source_list.getAll();
|
---|
914 | all_sources.add(0, StaticStrings.TEXT_STR);
|
---|
915 | ArrayList new_sources = new ArrayList();
|
---|
916 | for(int i = 0; i < all_sources.size(); i++) {
|
---|
917 | Object source = all_sources.get(i);
|
---|
918 |
|
---|
919 | // Create new index
|
---|
920 | new_sources.clear();
|
---|
921 | new_sources.add(source);
|
---|
922 | Index index = new Index(new_sources);
|
---|
923 | if(!index_model.contains(index)) {
|
---|
924 | // Determine the metadatum value
|
---|
925 | String name = source.toString();
|
---|
926 | if(name.startsWith(StaticStrings.EXTRACTED_NAMESPACE)) {
|
---|
927 | name = name.substring(StaticStrings.EXTRACTED_NAMESPACE.length());
|
---|
928 | }
|
---|
929 | // Create new metadatum
|
---|
930 | CollectionMeta metadatum = new CollectionMeta(StaticStrings.STOP_CHARACTER + index.getID());
|
---|
931 | metadatum.setValue(name);
|
---|
932 | name = null;
|
---|
933 | // Assign new index
|
---|
934 | addIndex(index, metadatum);
|
---|
935 | }
|
---|
936 | source = null;
|
---|
937 | index = null;
|
---|
938 | }
|
---|
939 | new_sources = null;
|
---|
940 | new_index_prompt.dispose();
|
---|
941 |
|
---|
942 | }
|
---|
943 | }
|
---|
944 |
|
---|
945 | private class AllFieldsBoxListener
|
---|
946 | implements ItemListener {
|
---|
947 |
|
---|
948 | public void itemStateChanged(ItemEvent event) {
|
---|
949 | if (event.getStateChange() == ItemEvent.SELECTED) {
|
---|
950 | source_list.setEnabled(false);
|
---|
951 | } else if (event.getStateChange() == ItemEvent.DESELECTED) {
|
---|
952 | source_list.setEnabled(true);
|
---|
953 | }
|
---|
954 | validateAddOrReplaceButton();
|
---|
955 | }
|
---|
956 |
|
---|
957 | }
|
---|
958 |
|
---|
959 | private class SourceListListener
|
---|
960 | implements ListSelectionListener {
|
---|
961 |
|
---|
962 | public void valueChanged(ListSelectionEvent event) {
|
---|
963 | if (event.getValueIsAdjusting()) {
|
---|
964 | return;
|
---|
965 | }
|
---|
966 | validateAddOrReplaceButton();
|
---|
967 | }
|
---|
968 | }
|
---|
969 |
|
---|
970 |
|
---|
971 | private class ReplaceIndexListener
|
---|
972 | implements ActionListener {
|
---|
973 |
|
---|
974 | public void actionPerformed(ActionEvent event) {
|
---|
975 |
|
---|
976 | ArrayList sources;
|
---|
977 | Index index = null;
|
---|
978 | if (text_checkbox.isSelected() || !source_list.isNothingTicked()) {
|
---|
979 | sources = source_list.getTicked();
|
---|
980 | if (text_checkbox.isSelected()) {
|
---|
981 | sources.add(0, StaticStrings.TEXT_STR);
|
---|
982 | }
|
---|
983 | if (mgpp_enabled) {
|
---|
984 | index = new Index(sources);
|
---|
985 | } else {
|
---|
986 | index = new Index(level_combobox.getSelectedIndex(), sources);
|
---|
987 | }
|
---|
988 | }
|
---|
989 | if (index != null) {
|
---|
990 | // Create the new collection meta
|
---|
991 | CollectionMeta metadatum = new CollectionMeta(StaticStrings.STOP_CHARACTER + index.getID());
|
---|
992 | metadatum.setValue(index.getID());
|
---|
993 |
|
---|
994 | // replace the index
|
---|
995 | replaceIndex((Index) index_list.getSelectedValue(), index, metadatum);
|
---|
996 | index_list.setSelectedValue(index, true);
|
---|
997 |
|
---|
998 | }
|
---|
999 | new_index_prompt.dispose();
|
---|
1000 |
|
---|
1001 | }
|
---|
1002 | }
|
---|
1003 | }
|
---|
1004 | }
|
---|
1005 | }
|
---|