source: trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java@ 4675

Last change on this file since 4675 was 4675, checked in by jmt12, 21 years ago

Sunday's work

  • Property svn:keywords set to Author Date Id Revision
File size: 29.0 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 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38
39
40
41
42
43package org.greenstone.gatherer.cdm;
44/**************************************************************************************
45 * Title: Gatherer
46 * Description: The Gatherer: a tool for gathering and enriching a digital collection.
47 * Copyright: Copyright (c) 2001
48 * Company: The University of Waikato
49 * Written: 03/05/02
50 * Revised: 17/11/02 - Commented
51 **************************************************************************************/
52import java.awt.BorderLayout;
53import java.awt.Color;
54import java.awt.Component;
55import java.awt.Dimension;
56import java.awt.GridLayout;
57import java.awt.event.ActionEvent;
58import java.awt.event.ActionListener;
59import java.awt.event.KeyAdapter;
60import java.awt.event.KeyEvent;
61import java.util.Collections;
62import java.util.StringTokenizer;
63import java.util.Vector;
64import javax.swing.BorderFactory;
65import javax.swing.DefaultListCellRenderer;
66import javax.swing.DefaultListModel;
67import javax.swing.JButton;
68import javax.swing.JComboBox;
69import javax.swing.JLabel;
70import javax.swing.JList;
71import javax.swing.JOptionPane;
72import javax.swing.JPanel;
73import javax.swing.JScrollPane;
74import javax.swing.JTextArea;
75import javax.swing.JTextField;
76import javax.swing.event.ListDataEvent;
77import javax.swing.event.ListDataListener;
78import javax.swing.event.ListSelectionEvent;
79import javax.swing.event.ListSelectionListener;
80import org.greenstone.gatherer.Gatherer;
81import org.greenstone.gatherer.cdm.CommandTokenizer;
82import org.greenstone.gatherer.cdm.Index;
83import org.greenstone.gatherer.msm.ElementWrapper;
84import org.greenstone.gatherer.msm.MSMUtils;
85import org.greenstone.gatherer.util.ExclusiveListSelectionListener;
86import org.w3c.dom.Element;
87/** 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.
88 * @author John Thompson, Greenstone Digital Library, University of Waikato
89 * @version 2.3
90 */
91public class IndexManager
92 extends DefaultListModel {
93 /** A reference to our creator, the collection design manager. */
94 private CollectionDesignManager manager = null;
95 /** The controls for editing the indexes. */
96 private Control controls = null;
97 /** A reference to ourselves so our inner methods have access. */
98 private DefaultListModel model = null;
99 /** A reference to the Gatherer, for access to the Dictionary and messaging purposes. */
100 private Gatherer gatherer = null;
101 /** The default index. */
102 private Index default_index = null;
103 /** Constructor.
104 * @param gatherer A reference to the <strong>Gatherer</strong>.
105 * @param manager A reference to the <strong>CollectionDesignManager</strong>.
106 */
107 public IndexManager(Gatherer gatherer, CollectionDesignManager manager) {
108 super();
109 this.gatherer = gatherer;
110 this.manager = manager;
111 this.model = this;
112 }
113 /** Method to add a new index.
114 * @param index The <strong>Index</strong> to add.
115 * @see org.greenstone.gatherer.Gatherer
116 * @see org.greenstone.gatherer.collection.CollectionManager
117 */
118 public void addIndex(Index index) {
119 if(!contains(index)) {
120 String index_str = index.toString(false).toLowerCase();
121 // Add alphabetically.
122 for(int i = 0; i < size(); i++) {
123 Index sibling = (Index) get(i);
124 String sibling_str = sibling.toString(false).toLowerCase();
125 int position = index_str.compareTo(sibling_str);
126 // Sibling is before index.
127 if(position > 0) {
128 // Carry on.
129 }
130 // Index is equal to, or before sibling. Insert it.
131 else if(position == 0 || position < 0) {
132 add(i, index);
133 gatherer.c_man.configurationChanged();
134 return;
135 }
136 }
137 // If we got this far, we haven't inserted index, and we are out of model so.
138 addElement(index);
139 gatherer.c_man.configurationChanged();
140 }
141 else {
142 JOptionPane.showMessageDialog(manager.gui, get("CDM.IndexManager.Index_Exists"), get("General.Warning"), JOptionPane.WARNING_MESSAGE);
143 }
144 }
145 /** Method to acquire the controls for editing the indexes.
146 * @return A <strong>JPanel</strong> containing the controls.
147 * @see org.greenstone.gatherer.cdm.IndexManager.Control
148 */
149 public JPanel getControls() {
150 if(controls == null) {
151 controls = new Control();
152 }
153 return controls;
154 }
155 /** Method to get the default index.
156 * @return The default <strong>Index</strong>.
157 */
158 public Index getDefault() {
159 return default_index;
160 }
161 /** Method to retrieve a certain index, as referenced by an index number.
162 * @param index An <i>int</i> which indicates the position of the desired index.
163 * @return The <strong>Index</strong> at the given index, or <i>null</i> if no such index exists.
164 */
165 public Index getIndex(int index) {
166 if(0 <= index && index < size()) {
167 return (Index)get(index);
168 }
169 return null;
170 }
171 /** Method to retrieve a certain index, given its name.
172 * @param name The name of the index as a <Strong>String</strong>.
173 * @return The <strong>Index</strong> that matches name, or <i>null</i> if no such index exists.
174 */
175 public Index getIndex(String name) {
176 ///ystem.err.println("Searching for index " + name);
177 for(int i = 0; i < size(); i++) {
178 Index index = (Index) get(i);
179 if(index.toString(false).equals(name)) {
180 ///ystem.err.println("Found.");
181 return (Index)get(i);
182 }
183 }
184 ///ystem.err.println("No such index.");
185 return null;
186 }
187 /** A method to retrieve all of the indexes associated with this manager.
188 * @return A <strong>Vector</strong> of <strong>Index</strong>es.
189 */
190 public Vector getIndexes() {
191 Vector indexes = new Vector();
192 for(int i = 0; i < size(); i++) {
193 indexes.add(get(i));
194 }
195 Collections.sort(indexes);
196 return indexes;
197 }
198 /** Mark the current set of controls, if any, as obsolete and deallocate them. If further need of the controls will cause new controls to be created.
199 * @see org.greenstone.gatherer.cdm.IndexManager.Control
200 */
201 public void invalidateControls() {
202 if(controls != null) {
203 controls.destroy();
204 }
205 controls = null;
206 }
207 /** Method that attempts to parse an index related command from the given command. If such a command is parsed, it is immediately registered with this manager.
208 * @param command The <strong>String</strong> to parse.
209 * @return A <i>boolean</i> which is <i>true</i> if a command was parsed, <i>false</i> otherwise.
210 * @see org.greenstone.gatherer.cdm.CommandTokenizer
211 * @see org.greenstone.gatherer.cdm.Index
212 */
213 public boolean parse(String command) {
214 String temp = command.toLowerCase();
215 if(temp.startsWith("indexes")) {
216 CommandTokenizer ct = new CommandTokenizer(command);
217 ct.nextToken(); // Throw away indexes.
218 while(ct.hasMoreTokens()) {
219 String entry = ct.nextToken();
220 Index index = Index.parseIndexConfig(entry, manager);
221 if (index != null) {
222 addIndex(index);
223
224 } else { // return false if there is one error??
225 return false;
226 }
227 }
228
229 return true;
230 }
231 else if(temp.startsWith("defaultindex")) {
232 CommandTokenizer ct = new CommandTokenizer(command);
233 ct.nextToken();
234 String entry = ct.nextToken();
235 Index index = Index.parseIndexConfig(entry, manager);
236 if (index != null) {
237 setDefault(index);
238 return true;
239 }
240 return false;
241 }
242
243 return false;
244 }
245
246 public void removeAll() {
247 removeAllElements();
248 default_index = null;
249 gatherer.c_man.configurationChanged();
250 }
251
252 /** Method to remove a certain index.
253 * @param index The <Strong>Index</strong> to remove.
254 * @see org.greenstone.gatherer.Gatherer
255 * @see org.greenstone.gatherer.cdm.CollectionDesignManager
256 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
257 * @see org.greenstone.gatherer.collection.CollectionManager
258 */
259 public void removeIndex(Index index) {
260 if(index != null) {
261 String name = index.getName();
262 if(name != null) {
263 Language default_language = manager.languages.getDefaultLanguage();
264 CollectionMeta metadata = new CollectionMeta(manager, index, default_language, name);
265 manager.collectionmetadatum.removeMetadata(metadata);
266 }
267 removeElement(index);
268 if(default_index != null && default_index.equals(index)) {
269 default_index = null;
270 }
271 gatherer.c_man.configurationChanged();
272 }
273 }
274 /** Method to set the default index.
275 * @param index The new default <strong>Index</strong>.
276 * @see org.greenstone.gatherer.Gatherer
277 * @see org.greenstone.gatherer.collection.CollectionManager
278 */
279 public void setDefault(Index index) {
280 default_index = index;
281 if(index != null && !contains(index)) {
282 addElement(index);
283 }
284 gatherer.c_man.configurationChanged();
285 }
286 /** Method to print out the contents of this class as a string.
287 * @return A <strong>String</strong> just as it would appear in the colleciton configuration file.
288 */
289 public String toString() {
290 String text = "";
291 // First the indexes.
292 if(size() > 0) {
293 text = "indexes ";
294 for(int i = 0; i < size(); i++) {
295 Index index = (Index) get(i);
296 text = text + index.toStringConfig();
297 if(i < size() - 1) {
298 text = text + " ";
299 }
300 }
301 // Now the default index if there is one, or just the first index
302 // if there isn't
303 if(default_index != null) {
304 text = text + "\ndefaultindex " + default_index.toStringConfig() + "\n";
305 }
306 text = text + "\n";
307 }
308 return text;
309 }
310
311
312
313
314
315 /** Overloaded to call get with both a key and an empty argument array.
316 * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
317 * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
318 */
319 private String get(String key) {
320 return get(key, null);
321 }
322 /** Used to retrieve a property value from the Locale specific ResourceBundle, based upon the key and arguments supplied. If the key cannot be found or if some other part of the call fails a default (English) error message is returned. <BR>
323 * Here the get recieves a second argument which is an array of Strings used to populate argument fields, denoted {<I>n</I>}, within the value String returned. Note that argument numbers greater than or equal to 32 are automatically mapped to the formatting String named Farg<I>n</I>.
324 * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
325 * @param args A <strong>String[]</strong> used to populate argument fields within the complete String.
326 * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
327 * @see org.greenstone.gatherer.Gatherer
328 * @see org.greenstone.gatherer.Dictionary
329 */
330 private String get(String key, String args[]) {
331 if(key.indexOf('.') == -1) {
332 key = "CDM.IndexManager." + key;
333 }
334 return gatherer.dictionary.get(key, args);
335 }
336 /** This class creates a set of controls for editing the indexes. */
337 private class Control
338 extends JPanel {
339 /** The default size of a label on this control. */
340 private Dimension LABEL_SIZE = new Dimension(120,25);
341 /** The button used to add a new index. */
342 private JButton add = null;
343 /** The button used to clear the default index. */
344 private JButton clear_default = null;
345 /** The button used to remove an index. */
346 private JButton remove = null;
347 /** The button used to set the default index. */
348 private JButton set_default = null;
349 /** The combobox used to adjust what level the new index will built on. */
350 private JComboBox level = null;
351 /** The label denoting the default index to be built for this collection. */
352 private JLabel default_label = null;
353 /** The label denoting the list of assigned indexes. */
354 private JLabel index_label = null;
355 /** The label denoting the control for choosing index level. */
356 private JLabel level_label = null;
357 /** The label denoting the name of the index. */
358 private JLabel name_label = null;
359 /** The label denoting the list of possible sources for the index. */
360 private JLabel source_label = null;
361 /** The title shown at the top of the index controls. */
362 private JLabel title = null;
363 /** The list of assigned indexes. */
364 private JList index_list = null;
365 /** The list of possible sources on which the index could be built. */
366 private JList source_list = null;
367 /** The panel used to display the list of assigned indexes. */
368 private JPanel assigned_pane = null;
369 /** The panel which contains the buttons used to edit indexes. */
370 private JPanel button_pane = null;
371 /** The panel on which all other panels are displayed. */
372 private JPanel central_pane = null;
373 /** The control pane showing the editable controls. */
374 private JPanel control_pane = null;
375 /** The edit pane contains the list of possible sources. */
376 private JPanel edit_pane = null;
377 /** A panel used to correctly lay out the default index label. */
378 private JPanel default_pane = null;
379 /** The panel containing the title label and instructions. */
380 private JPanel header_pane = null;
381 /** The lvel panel contains the control for adjusting index level. */
382 private JPanel level_pane = null;
383 /** The pane in which the name control is set. */
384 private JPanel name_pane = null;
385 /** The scrollpane containing the instructions text area. */
386 private JScrollPane instructions_scroll = null;
387 /** A text area containing inline instructions. */
388 private JTextArea instructions = null;
389 /** A text field naming the default index. Non-editable. */
390 private JTextField default_value = null;
391 /** A text field for controlling the name of the new index. */
392 private JTextField name = null;
393 /** A model containing all of the available index sources. */
394 private Vector source_model = null;
395 /** Constructor.
396 * @see org.greenstone.gatherer.Configuration
397 * @see org.greenstone.gatherer.Gatherer
398 * @see org.greenstone.gatherer.cdm.IndexManager.Control.AddListener
399 * @see org.greenstone.gatherer.cdm.IndexManager.Control.ClearDefaultListener
400 * @see org.greenstone.gatherer.cdm.IndexManager.Control.NameListener
401 * @see org.greenstone.gatherer.cdm.IndexManager.Control.RemoveListener
402 * @see org.greenstone.gatherer.cdm.IndexManager.Control.SetDefaultListener
403 * @see org.greenstone.gatherer.collection.CollectionManager
404 * @see org.greenstone.gatherer.gui.Coloring
405 * @see org.greenstone.gatherer.msm.MetadataSetManager
406 * @see org.greenstone.gatherer.util.ExclusiveListSelectionListener
407 */
408 public Control() {
409 super();
410 source_model = new Vector();
411 source_model.add("text");
412 source_model.addAll(gatherer.c_man.msm.getAssignedElements());
413 //source_model.addAll(gatherer.c_man.msm.getElements());
414 // Creation
415 add = new JButton(get("Add"));
416 add.setEnabled(false);
417 add.setMnemonic(KeyEvent.VK_A);
418 assigned_pane = new JPanel();
419 button_pane = new JPanel();
420 central_pane = new JPanel();
421 control_pane = new JPanel();
422 clear_default = new JButton(get("Clear_Default"));
423 clear_default.setMnemonic(KeyEvent.VK_C);
424 if(default_index == null) {
425 clear_default.setEnabled(false);
426 }
427 default_label = new JLabel(get("Default_Index"));
428 default_pane = new JPanel();
429 if(default_index != null) {
430 default_value = new JTextField(default_index.toString(true));
431 default_value.setCaretPosition(0);
432 }
433 else {
434 default_value = new JTextField();
435 }
436 default_value.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
437 default_value.setEditable(false);
438 edit_pane = new JPanel();
439 header_pane = new JPanel();
440 index_label = new JLabel(get("Indexes"));
441 index_list = new JList(model);
442 index_list.setCellRenderer(new IndexListCellRenderer());
443 instructions = new JTextArea(get("Instructions"));
444 instructions.setEditable(false);
445 instructions.setLineWrap(true);
446 instructions.setRows(5);
447 instructions.setWrapStyleWord(true);
448 level = new JComboBox();
449 level.addItem(get("Document"));
450 level.addItem(get("Paragraph"));
451 level.addItem(get("Section"));
452 level.setEditable(false);
453 level_label = new JLabel(get("Level"));
454 level_label.setPreferredSize(LABEL_SIZE);
455 level_pane = new JPanel();
456 name = new JTextField();
457 name_label = new JLabel(get("Name"));
458 name_label.setPreferredSize(LABEL_SIZE);
459 name_pane = new JPanel();
460 remove = new JButton(get("Remove"));
461 remove.setEnabled(false);
462 remove.setMnemonic(KeyEvent.VK_R);
463 set_default = new JButton(get("Set_Default"));
464 set_default.setEnabled(false);
465 set_default.setMnemonic(KeyEvent.VK_S);
466 source_label = new JLabel(get("Source"));
467 source_list = new JList(source_model);
468 title = new JLabel(get("Title"));
469 title.setHorizontalAlignment(JLabel.CENTER);
470
471 // Listeners
472 add.addActionListener(new AddListener());
473 clear_default.addActionListener(new ClearDefaultListener());
474 remove.addActionListener(new RemoveListener());
475 set_default.addActionListener(new SetDefaultListener());
476 name.addKeyListener(new NameListener());
477 ListListener ll = new ListListener();
478 index_list.addListSelectionListener(ll);
479 source_list.addListSelectionListener(ll);
480 ExclusiveListSelectionListener elsl = new ExclusiveListSelectionListener();
481 elsl.add(index_list);
482 elsl.add(source_list);
483
484 // Layout
485 title.setBorder(BorderFactory.createEmptyBorder(0,0,2,0));
486
487 instructions.setBorder(BorderFactory.createEmptyBorder(2,5,2,5));
488
489 header_pane.setLayout(new BorderLayout());
490 header_pane.add(title, BorderLayout.NORTH);
491 header_pane.add(new JScrollPane(instructions), BorderLayout.CENTER);
492
493 name_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
494
495 name_pane.setBorder(BorderFactory.createEmptyBorder(4,2,4,2));
496 name_pane.setLayout(new BorderLayout());
497 name_pane.add(name_label, BorderLayout.WEST);
498 name_pane.add(name, BorderLayout.CENTER);
499
500 control_pane.setLayout(new BorderLayout());
501 control_pane.add(source_label, BorderLayout.NORTH);
502 control_pane.add(new JScrollPane(source_list), BorderLayout.CENTER);
503
504 level_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
505
506 level_pane.setBorder(BorderFactory.createEmptyBorder(4,2,4,2));
507 level_pane.setLayout(new BorderLayout());
508 level_pane.add(level_label, BorderLayout.WEST);
509 level_pane.add(level, BorderLayout.CENTER);
510
511 edit_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
512 edit_pane.setLayout(new BorderLayout());
513 edit_pane.add(name_pane, BorderLayout.NORTH);
514 edit_pane.add(control_pane, BorderLayout.CENTER);
515 edit_pane.add(level_pane, BorderLayout.SOUTH);
516
517 default_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,5));
518
519 default_pane.setBorder
520 (BorderFactory.createCompoundBorder
521 (BorderFactory.createCompoundBorder
522 (BorderFactory.createEmptyBorder(2,2,2,2),
523 BorderFactory.createRaisedBevelBorder()),
524 BorderFactory.createEmptyBorder(2,2,2,2)));
525 default_pane.setLayout(new BorderLayout());
526 default_pane.add(default_label, BorderLayout.WEST);
527 default_pane.add(default_value, BorderLayout.CENTER);
528
529 assigned_pane.setLayout(new BorderLayout());
530 assigned_pane.add(index_label, BorderLayout.NORTH);
531 assigned_pane.add(new JScrollPane(index_list), BorderLayout.CENTER);
532 assigned_pane.add(default_pane, BorderLayout.SOUTH);
533
534 central_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
535 central_pane.setLayout(new GridLayout(1,2));
536 central_pane.add(edit_pane);
537 central_pane.add(assigned_pane);
538
539 button_pane.setLayout(new GridLayout(2,2));
540 button_pane.add(add);
541 button_pane.add(remove);
542 button_pane.add(clear_default);
543 button_pane.add(set_default);
544
545 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
546 setLayout(new BorderLayout());
547 add(header_pane, BorderLayout.NORTH);
548 add(central_pane, BorderLayout.CENTER);
549 add(button_pane, BorderLayout.SOUTH);
550 }
551 /* Destructor, removes persistant listeners from the Dictionary.
552 */
553 public void destroy() {
554 }
555 /** We override the updateUI method so that we can ensure we are scrolled to the top of the instructions box first.
556 * @see org.greenstone.gatherer.Gatherer
557 * @see org.greenstone.gatherer.collection.CollectionManager
558 * @see org.greenstone.gatherer.msm.MetadataSetManager
559 */
560 public void updateUI() {
561 if(instructions != null) {
562 instructions.setCaretPosition(0);
563 }
564 // Reload the assigned indexes list.
565 if(source_model != null) {
566 source_model.clear();
567 source_model.add("text");
568 source_model.addAll(gatherer.c_man.msm.getAssignedElements());
569 // reset the model in the list - needed if the model is larger than when it was first created, the list doesn't display
570 source_list.setListData(source_model);
571
572 }
573 // Faster than a NPE its the - 'Super class'.
574 super.updateUI();
575 }
576 /** Listens for actions apon the 'add' button in the IndexManager controls, and if detected calls the add method of the manager with a newly created index. */
577 private class AddListener
578 implements ActionListener {
579 /** Method called when an action is performed on a registered component, and when it does we check if we have enough data to create a new index, and if so we create one.
580 * @param event An <strong>ActionEvent</strong> providing extra information about the event.
581 * @see org.greenstone.gatherer.cdm.CollectionDesignManager
582 * @see org.greenstone.gatherer.cdm.CollectionMeta
583 * @see org.greenstone.gatherer.cdm.CollectionMetaManager
584 * @see org.greenstone.gatherer.cdm.Index
585 * @see org.greenstone.gatherer.cdm.Language
586 * @see org.greenstone.gatherer.cdm.LanguageManager
587 */
588 public void actionPerformed(ActionEvent event) {
589 if(!source_list.isSelectionEmpty() && name.getText().length() != 0) {
590 Object object[] = source_list.getSelectedValues();
591 Vector sources = new Vector();
592 for(int i = 0; i < object.length; i++) {
593 sources.add(object[i]);
594 }
595 Index index = new Index(level.getSelectedIndex(), sources, manager);
596 // Before we add the index to the model, we have to add the collection metadata for this.
597 Language language = manager.languages.getDefaultLanguage();
598 CollectionMeta metadata = new CollectionMeta(manager, index, language, name.getText());
599 manager.collectionmetadatum.addMetadata(metadata);
600 // Finally add index.
601 addIndex(index);
602 }
603 }
604 }
605 /** Listens for actions apon the 'clear default' button in the IndexManager controls, and if detected calls the setDefault method of the manager with <i>null</i>. */
606 private class ClearDefaultListener
607 implements ActionListener {
608 /** If called when an action occurs on a registered component, we clear the default index.
609 * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
610 */
611 public void actionPerformed(ActionEvent event) {
612 setDefault(null);
613 clear_default.setEnabled(false);
614 default_value.setText("");
615 }
616 }
617 /** Listens for actions apon the 'remove' button in the IndexManager controls, and if detected calls the remove method of the manager with the index selected for removal. */
618 private class RemoveListener
619 implements ActionListener {
620 /** If called when an action occurs on a registered component, we remove the currently selected index, if there is one.
621 * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
622 * @see org.greenstone.gatherer.cdm.Index
623 */
624 public void actionPerformed(ActionEvent event) {
625 if(!index_list.isSelectionEmpty()) {
626 removeIndex((Index)index_list.getSelectedValue());
627 if(default_index == null) {
628 clear_default.setEnabled(false);
629 default_value.setText("");
630 }
631 }
632 }
633 }
634 /** Listens for actions apon the 'set default' button in the IndexManager controls, and if detected calls the setDefault method of the manager with the index selected for default. */
635 private class SetDefaultListener
636 implements ActionListener {
637 /** If called when an action occurs on a registered component, we set the default index to the index currently selected.
638 * @param event An <strong>ActionEvent</strong> containing extra information about the action that occured.
639 * @see org.greenstone.gatherer.cdm.Index
640 */
641 public void actionPerformed(ActionEvent event) {
642 setDefault((Index)index_list.getSelectedValue());
643 if(default_index != null) {
644 clear_default.setEnabled(true);
645 default_value.setText(default_index.toString(true));
646 default_value.setCaretPosition(0);
647 }
648 else {
649 clear_default.setEnabled(false);
650 default_value.setText("");
651 }
652 }
653 }
654 /** Listens for key presses within the name field, and enabled or disables controls as appropriate. */
655 private class NameListener
656 extends KeyAdapter {
657 /** Called when a key is released, this is the perfect time to enable the add button if the fields are appropriately set.
658 * @param event A <strong>KeyEvent</strong> containing information about the key released.
659 */
660 public void keyReleased(KeyEvent event) {
661 if(source_list.isSelectionEmpty() || name.getText().length() == 0) {
662 add.setEnabled(false);
663 }
664 else {
665 add.setEnabled(true);
666 }
667 if(index_list.isSelectionEmpty()) {
668 remove.setEnabled(false);
669 set_default.setEnabled(false);
670 }
671 else {
672 remove.setEnabled(true);
673 set_default.setEnabled(true);
674 }
675 }
676 }
677 /** Listens for selections within the list on the IndexManager controls, and if a change is detected enables, or disables, controls appropriately. */
678 private class ListListener
679 implements ListSelectionListener {
680 /** This method is called whenever the source list selection changes. When it does we need to check if the add button should now be enabled.
681 * @param event A <strong>ListSelectionEvent</strong> containing further information about the list selection.
682 */
683 public void valueChanged(ListSelectionEvent event) {
684 if(source_list.isSelectionEmpty() || name.getText().length() == 0) {
685 add.setEnabled(false);
686 }
687 else {
688 add.setEnabled(true);
689 }
690 if(index_list.isSelectionEmpty()) {
691 remove.setEnabled(false);
692 set_default.setEnabled(false);
693 }
694 else {
695 remove.setEnabled(true);
696 set_default.setEnabled(true);
697 }
698 }
699 }
700
701
702 private class IndexListCellRenderer
703 extends DefaultListCellRenderer {
704
705 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
706 StringBuffer text = new StringBuffer(value.toString());
707 // Retrieve the indexes name if any.
708 CollectionMeta metadata = manager.collectionmetadatum.getMetadata(value, manager.languages.getDefaultLanguage(), true);
709 if(metadata != null) {
710 text.append(" \"");
711 text.append(metadata.getValue());
712 text.append("\"");
713 }
714 return super.getListCellRendererComponent(list, text.toString(), index, isSelected, cellHasFocus);
715 }
716
717 }
718
719 }
720}
721
722
Note: See TracBrowser for help on using the repository browser.