source: trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java@ 12635

Last change on this file since 12635 was 12635, checked in by mdewsnip, 18 years ago

Made some of the new plugins/classifiers code static in preparation for possibly moving it into new classes.

  • Property svn:keywords set to Author Date Id Revision
File size: 27.4 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.io.*;
32import java.net.*;
33import java.util.*;
34import java.util.jar.*;
35import javax.swing.*;
36import javax.swing.event.*;
37import org.apache.xerces.parsers.*;
38import org.greenstone.gatherer.Configuration;
39import org.greenstone.gatherer.DebugStream;
40import org.greenstone.gatherer.Dictionary;
41import org.greenstone.gatherer.Gatherer;
42import org.greenstone.gatherer.LocalGreenstone;
43import org.greenstone.gatherer.gui.DesignPaneHeader;
44import org.greenstone.gatherer.gui.GComboBox;
45import org.greenstone.gatherer.gui.GLIButton;
46import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
47import org.greenstone.gatherer.util.JarTools;
48import org.greenstone.gatherer.util.StaticStrings;
49import org.greenstone.gatherer.util.Utility;
50import org.greenstone.gatherer.util.XMLTools;
51import org.w3c.dom.*;
52import org.xml.sax.*;
53
54/** This class is responsible for keeping track of all the classifiers assigned to this collection, and providing methods for adding and removing them.
55 * @author John Thompson, Greenstone Digital Library, University of Waikato
56 * @version 2.3
57 */
58public class ClassifierManager
59 extends DOMProxyListModel
60{
61 // A list of all the classifiers in the core Greenstone "perllib/classify" folder (arguments may not be loaded)
62 static private ArrayList core_greenstone_classifiers_list = null;
63
64 /** The controls for editing the contents of this manager. */
65 private Control controls = null;
66
67 private DOMProxyListModel model;
68
69 /** Constructor.
70 * @see org.greenstone.gatherer.cdm.DynamicListModel
71 * @see org.greenstone.gatherer.collection.CollectionManager
72 */
73 public ClassifierManager() {
74 super(CollectionDesignManager.collect_config.getDocumentElement(), CollectionConfiguration.CLASSIFY_ELEMENT, new Classifier());
75 this.model = this;
76 DebugStream.println("ClassifierManager: " + getSize() + " classifiers parsed.");
77
78 core_greenstone_classifiers_list = loadClassifiersList();
79
80 // Force the assigned classifiers to be loaded and cached now
81 for (int i = 0; i < getSize(); i++) {
82 getElementAt(i);
83 }
84 }
85
86
87 // --------------------------------------------------------------------------------------------------------
88
89
90 /** Retrieve a list of the classifiers that are available to be added to the collection. */
91 private Object[] getAvailableClassifiers()
92 {
93 ArrayList available = new ArrayList();
94
95 // Add all the non-abstract core Greenstone classifiers
96 for (int i = 0; i < core_greenstone_classifiers_list.size(); i++) {
97 Classifier classifier = (Classifier) core_greenstone_classifiers_list.get(i);
98 if (!classifier.isAbstract()) {
99 available.add(classifier);
100 }
101 }
102
103 // Sort the available classifiers into alphabetical order
104 Collections.sort(available);
105
106 return available.toArray();
107 }
108
109
110 static public Classifier getClassifier(String classifier_name, boolean arguments_required)
111 {
112 for (int i = 0; i < core_greenstone_classifiers_list.size(); i++) {
113 Classifier classifier = (Classifier) core_greenstone_classifiers_list.get(i);
114 if (classifier.getName().equals(classifier_name)) {
115 if (arguments_required) {
116 if (classifier.getArguments().size() == 0) {
117 loadClassifierInfo(classifier);
118 }
119 else {
120 System.err.println("Already loaded arguments for " + classifier_name + "!");
121 }
122 }
123 return classifier;
124 }
125 }
126
127 return null;
128 }
129
130
131 static private void loadClassifierInfo(Classifier classifier)
132 {
133 System.err.println("Loading arguments for " + classifier.getName() + "...");
134
135 // Run classifierfo.pl to get the list of classifiers
136 try {
137 StringBuffer xml = null;
138 if (Gatherer.isGsdlRemote) {
139 // !! TO DO
140 }
141 else {
142 ArrayList args = new ArrayList();
143 if (Utility.isWindows()) {
144 args.add(Configuration.perl_path);
145 args.add("-S");
146 }
147 args.add(LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl");
148 args.add("-xml");
149 args.add("-language");
150 args.add(Configuration.getLanguage());
151 args.add(classifier.getName());
152
153 // Run the classinfo.pl process
154 Runtime runtime = Runtime.getRuntime();
155 Process process = runtime.exec((String[]) args.toArray(new String[] { }));
156 InputStream input_stream = process.getErrorStream();
157 xml = XMLTools.readXMLStream(input_stream);
158 }
159
160 if (xml.length() > 0) {
161 parseClassifierInfoXML(classifier, xml.toString());
162 }
163 else {
164 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_XML_Parse_Failed", classifier.getName()), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
165 }
166 }
167 catch (Exception exception) {
168 DebugStream.printStackTrace(exception);
169 }
170 }
171
172
173 private ArrayList loadClassifiersList()
174 {
175 System.err.println("In loadClassifiersList()...");
176
177 // Run classifierfo.pl to get the list of classifiers
178 try {
179 StringBuffer xml = null;
180 if (Gatherer.isGsdlRemote) {
181 String classinfo_output = RemoteGreenstoneServer.getScriptOptions("classinfo.pl", "&listall");
182 xml = new StringBuffer(classinfo_output);
183 }
184 else {
185 ArrayList args = new ArrayList();
186 if (Utility.isWindows()) {
187 args.add(Configuration.perl_path);
188 args.add("-S");
189 }
190 args.add(LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl");
191 args.add("-listall");
192 args.add("-xml");
193
194 // Run the classinfo.pl process
195 Runtime runtime = Runtime.getRuntime();
196 Process process = runtime.exec((String[]) args.toArray(new String[] { }));
197 InputStream input_stream = process.getErrorStream();
198 xml = XMLTools.readXMLStream(input_stream);
199 }
200
201 if (xml.length() > 0) {
202 return parseClassifiersListXML(xml.toString());
203 }
204 else {
205 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
206 }
207 }
208 catch (Exception exception) {
209 DebugStream.printStackTrace(exception);
210 }
211
212 return null;
213 }
214
215
216 static private void parseClassifierInfoXML(Classifier classifier, String xml)
217 {
218 Document document = XMLTools.parseXML(new StringReader(xml));
219 parseClassifierInfoXMLNode(classifier, document.getDocumentElement());
220 }
221
222
223 static private void parseClassifierInfoXMLNode(Classifier classifier, Node root_node)
224 {
225 for (Node node = root_node.getFirstChild(); node != null; node = node.getNextSibling()) {
226 String node_name = node.getNodeName();
227
228 if (node_name.equalsIgnoreCase("Name")) {
229 classifier.setName(XMLTools.getValue(node));
230 }
231 else if (node_name.equals("Desc")) {
232 classifier.setDescription(XMLTools.getValue(node));
233 }
234 else if (node_name.equals("Abstract")) {
235 classifier.setIsAbstract(XMLTools.getValue(node).equalsIgnoreCase(CollectionConfiguration.YES_STR));
236 }
237 // Parse the classifier arguments
238 else if (node_name.equalsIgnoreCase("Arguments")) {
239 for (Node argument_node = node.getFirstChild(); argument_node != null; argument_node = argument_node.getNextSibling()) {
240 // An option
241 if (argument_node.getNodeName().equalsIgnoreCase("Option")) {
242 Argument argument = new Argument();
243 argument.parseXML((Element) argument_node);
244 classifier.addArgument(argument);
245 }
246 }
247 }
248 // A super classifier class
249 else if (node_name.equalsIgnoreCase("ClassInfo")) {
250 Classifier super_classifier = new Classifier();
251 parseClassifierInfoXMLNode(super_classifier, node);
252 classifier.setSuper(super_classifier);
253 }
254 }
255 }
256
257
258 private ArrayList parseClassifiersListXML(String xml)
259 {
260 ArrayList classifiers_list = new ArrayList();
261
262 Document document = XMLTools.parseXML(new StringReader(xml));
263 Node root = document.getDocumentElement();
264 for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
265 String node_name = node.getNodeName();
266
267 if (node_name.equals("ClassInfo")) {
268 Classifier classifier = new Classifier();
269 parseClassifierInfoXMLNode(classifier, node);
270 classifiers_list.add(classifier);
271 }
272 }
273
274 return classifiers_list;
275 }
276
277
278 // --------------------------------------------------------------------------------------------------------
279
280
281 /** Method to assign a classifier.
282 * @param classifier The base <strong>Classifier</strong> to assign.
283 * @see org.greenstone.gatherer.cdm.DynamicListModel
284 */
285 private void assignClassifier(Classifier classifier) {
286 if(!contains(classifier)) {
287 Element element = classifier.getElement();
288 // Locate where we should insert this new classifier.
289 Node target_node = CollectionConfiguration.findInsertionPoint(element);
290 add(root, classifier, target_node);
291 Gatherer.c_man.configurationChanged();
292 }
293 }
294
295
296 /** Destructor. */
297 public void destroy()
298 {
299 if (controls != null) {
300 controls.destroy();
301 controls = null;
302 }
303 }
304
305
306 /** Method to retrieve the classifier with the given index.
307 * @param index The index of the desired classifier as an <i>int</i>.
308 * @return The requested Classifier or <i>null</i> if no such classifier exists.
309 */
310 public Classifier getClassifier(int index) {
311 if(0 <= index && index < getSize()) {
312 return (Classifier) getElementAt(index);
313 }
314 return null;
315 }
316
317 /** Method to retrieve the control for this manager.
318 * @return the Control for editing classifiers
319 */
320 public Control getControls() {
321 if(controls == null) {
322 // Build controls
323 this.controls = new ClassifierControl();
324 }
325 return controls;
326 }
327
328 /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden
329 * @param mode the new mode as an int
330 */
331 public void modeChanged(int mode) {
332
333 }
334
335
336
337 /** Determine if the Phind classifier has been assigned.
338 * @return true if it has, false otherwise
339 */
340 public boolean isPhindClassifierAssigned() {
341 for(int i = 0; i < getSize(); i++) {
342 Classifier classifier = (Classifier) getElementAt(i);
343 if(classifier.getName().equalsIgnoreCase(StaticStrings.PHIND_CLASSIFIER)) {
344 return true;
345 }
346 classifier = null;
347 }
348 return false;
349 }
350
351 /** Method to move a classifier in the list order.
352 * @param classifier the Classifier you want to move.
353 * @param direction true to move the classifier up, false to move it down.
354 * @param all true to move to move all the way, false for a single step.
355 */
356 private void moveClassifier(Classifier classifier, boolean direction, boolean all) {
357 if(getSize() < 2) {
358 DebugStream.println("Not enough classifiers to allow moving.");
359 return;
360 }
361 if(all) {
362 // Move to top
363 if(direction) {
364 // Remove the moving classifier
365 remove(classifier);
366 // Retrieve the first classifier
367 Classifier first_classifier = (Classifier) getElementAt(0);
368 // Add the moving classifier before the first classifier
369 addBefore(classifier, first_classifier);
370 first_classifier = null;
371 }
372 else {
373 // Remove the moving classifier
374 remove(classifier);
375 // And add after last classifier
376 add(getSize(), classifier);
377 }
378 }
379 else {
380 // Try to move the classifier one step in the desired direction.
381 int index = indexOf(classifier);
382 ///ystem.err.println("Index of " + classifier + " = " + index);
383 if(direction) {
384 index--;
385 if(index < 0) {
386 String args[] = new String[2];
387 args[0] = Dictionary.get("CDM.ClassifierManager.Classifier");
388 args[1] = classifier.getName();
389 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.Move.At_Top", args), Dictionary.get("CDM.Move.Title"), JOptionPane.ERROR_MESSAGE);
390 return;
391 }
392 remove(classifier);
393 add(index, classifier);
394 }
395 else {
396 index++;
397 if(index >= getSize()) {
398 String args[] = new String[2];
399 args[0] = Dictionary.get("CDM.ClassifierManager.Classifier_Str");
400 args[1] = classifier.getName();
401 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.Move.At_Bottom", args), Dictionary.get("CDM.Move.Title"), JOptionPane.ERROR_MESSAGE);
402 return;
403 }
404 remove(classifier);
405 add(index, classifier);
406 }
407 }
408
409 Gatherer.c_man.configurationChanged();
410 // tell the format manager to update the names of its format statements
411 Gatherer.c_man.getCollection().cdm.format_manager.refresh();
412 }
413
414 /** This method removes an assigned classifier. I was tempted to call it unassign, but remove is more consistant. Note that there is no way to remove a classifier from the library.
415 * @param classifier The Classifier to remove
416 * @see org.greenstone.gatherer.cdm.DynamicListModel
417 */
418 private void removeClassifier(Classifier classifier) {
419 remove(classifier);
420 Gatherer.c_man.configurationChanged();
421 }
422
423
424 /** A class which provides controls for assigned and editing classifiers. */
425 private class ClassifierControl
426 extends JPanel
427 implements Control {
428 /** A combobox containing all of the known classifiers, including those that may have already been assigned. */
429 private JComboBox classifier_combobox = null;
430 /** Button for adding classifiers. */
431 private JButton add = null;
432 /** Button for configuring the selected classifier. */
433 private JButton configure = null;
434 private JButton move_down_button;
435 private JButton move_up_button;
436
437 /** Button to remove the selected classifier. */
438 private JButton remove = null;
439
440 /** A list of assigned classifiers. */
441 private JList classifier_list = null;
442
443 /** Constructor.
444 * @see org.greenstone.gatherer.cdm.ClassifierManager.ClassifierControl.AddListener
445 * @see org.greenstone.gatherer.cdm.ClassifierManager.ClassifierControl.ConfigureListener
446 * @see org.greenstone.gatherer.cdm.ClassifierManager.ClassifierControl.RemoveListener
447 */
448 public ClassifierControl()
449 {
450 // Create
451 add = new GLIButton(Dictionary.get("CDM.ClassifierManager.Add"), Dictionary.get("CDM.ClassifierManager.Add_Tooltip"));
452
453 JPanel button_pane = new JPanel();
454 JPanel central_pane = new JPanel();
455
456configure = new GLIButton(Dictionary.get("CDM.ClassifierManager.Configure"), Dictionary.get("CDM.ClassifierManager.Configure_Tooltip"));
457 configure.setEnabled(false);
458
459 JPanel header_pane = new DesignPaneHeader("CDM.GUI.Classifiers", "classifiers");
460
461 ClassifierComboboxListener ccl = new ClassifierComboboxListener();
462 classifier_combobox = new JComboBox(getAvailableClassifiers());
463 classifier_combobox.setEditable(false);
464 if(classifier_combobox.getItemCount() > 0) {
465 classifier_combobox.setSelectedIndex(0);
466 ccl.itemStateChanged(new ItemEvent(classifier_combobox, 0, null, ItemEvent.SELECTED));
467 }
468
469 JLabel classifier_label = new JLabel(Dictionary.get("CDM.ClassifierManager.Classifier"));
470
471 classifier_list = new JList(model);
472 classifier_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
473 JLabel classifier_list_label = new JLabel(Dictionary.get("CDM.ClassifierManager.Assigned"));
474
475 classifier_list_label.setOpaque(true);
476
477 JPanel classifier_list_pane = new JPanel();
478 JPanel classifier_pane = new JPanel();
479 remove = new GLIButton(Dictionary.get("CDM.ClassifierManager.Remove"), Dictionary.get("CDM.ClassifierManager.Remove_Tooltip"));
480 remove.setEnabled(false);
481
482 JPanel temp = new JPanel(new BorderLayout());
483
484 JPanel move_button_pane = new JPanel();
485
486 move_up_button = new GLIButton(Dictionary.get("CDM.Move.Move_Up"), JarTools.getImage("arrow-up.gif"), Dictionary.get("CDM.Move.Move_Up_Tooltip"));
487 move_up_button.setEnabled(false);
488
489 move_down_button = new GLIButton(Dictionary.get("CDM.Move.Move_Down"), JarTools.getImage("arrow-down.gif"), Dictionary.get("CDM.Move.Move_Down_Tooltip"));
490 move_down_button.setEnabled(false);
491
492 // Listeners
493 add.addActionListener(new AddListener());
494 add.addActionListener(CollectionDesignManager.buildcol_change_listener);
495 classifier_combobox.addItemListener(ccl);
496 configure.addActionListener(new ConfigureListener());
497 configure.addActionListener(CollectionDesignManager.buildcol_change_listener);
498 remove.addActionListener(new RemoveListener());
499 remove.addActionListener(CollectionDesignManager.buildcol_change_listener);
500 classifier_list.addMouseListener(new ClickListener());
501 classifier_list.addListSelectionListener(new ListListener());
502 ccl = null;
503
504 MoveListener ml = new MoveListener();
505 move_down_button.addActionListener(ml);
506 move_down_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
507 move_up_button.addActionListener(ml);
508 move_up_button.addActionListener(CollectionDesignManager.buildcol_change_listener);
509
510 // Layout
511 move_button_pane.setLayout(new GridLayout(4,1));
512 move_button_pane.add(move_up_button);
513 move_button_pane.add(new JPanel());
514 move_button_pane.add(new JPanel());
515 move_button_pane.add(move_down_button);
516
517 classifier_list_label.setBorder(BorderFactory.createEmptyBorder(0,2,0,2));
518
519 classifier_list_pane.setLayout(new BorderLayout());
520 classifier_list_pane.add(classifier_list_label, BorderLayout.NORTH);
521 classifier_list_pane.add(new JScrollPane(classifier_list), BorderLayout.CENTER);
522 classifier_list_pane.add(move_button_pane, BorderLayout.EAST);
523
524 classifier_label.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
525
526 classifier_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
527 classifier_pane.setLayout(new BorderLayout(5,0));
528 classifier_pane.add(classifier_label, BorderLayout.WEST);
529 classifier_pane.add(classifier_combobox, BorderLayout.CENTER);
530
531 button_pane.setLayout(new GridLayout(1, 3));
532 button_pane.add(add);
533 button_pane.add(configure);
534 button_pane.add(remove);
535
536 temp.add(classifier_pane, BorderLayout.NORTH);
537 temp.add(button_pane, BorderLayout.SOUTH);
538
539 central_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
540 central_pane.setLayout(new BorderLayout());
541 central_pane.add(classifier_list_pane, BorderLayout.CENTER);
542 central_pane.add(temp, BorderLayout.SOUTH);
543
544 setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
545 setLayout(new BorderLayout());
546 add(header_pane, BorderLayout.NORTH);
547 add(central_pane, BorderLayout.CENTER);
548 }
549
550 /** Method which acts like a destructor, tidying up references to persistant objects.
551 */
552 public void destroy() {
553 add = null;
554 classifier_combobox = null;
555 classifier_list = null;
556 configure = null;
557 //instructions = null;
558 remove = null;
559 }
560
561 public void gainFocus() {
562 }
563
564 public void loseFocus() {
565 }
566
567 /** This class listens for actions upon the add button in the controls, and if detected calls the assignClassifier() method.
568 */
569 private class AddListener
570 implements ActionListener {
571 /** Any implementation of ActionListener must include this method so that we can be informed when an action has occured on one of our target controls, so that we can add the selected Classifier.
572 * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
573 * @see org.greenstone.gatherer.Gatherer
574 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration
575 * @see org.greenstone.gatherer.cdm.Classifier
576 */
577 public void actionPerformed(ActionEvent event) {
578 Object selected_object = classifier_combobox.getSelectedItem();
579 // If there is something in the combobox, but we haven't registered a selection, then add the object and select it!
580 if(selected_object != null) {
581 // Retrieve the base classifier
582 Classifier base_classifier = getClassifier(selected_object.toString(), true);
583
584 // Create a new element in the DOM
585 Element element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CLASSIFY_ELEMENT);
586 element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, base_classifier.getName());
587 Classifier new_classifier = new Classifier(element, base_classifier);
588
589 element = null;
590 // Automatically chain to configuration. This ensures required arguments are filled out.
591 ArgumentConfiguration ac = new ArgumentConfiguration(new_classifier);
592 if(ac.display()) {
593 if(!model.contains(new_classifier)) {
594 assignClassifier(new_classifier);
595 classifier_list.setSelectedValue(new_classifier, true);
596 }
597 else {
598 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
599 }
600 }
601 ac = null;
602 new_classifier = null;
603 }
604 }
605 }
606
607 /** This listener reacts to changes in the current selection of the classifier combobox. */
608 private class ClassifierComboboxListener
609 implements ItemListener {
610 /** When a user selects a certain classifier, update the tooltip to show the classifier description. */
611 public void itemStateChanged(ItemEvent event) {
612 if(event.getStateChange() == ItemEvent.SELECTED) {
613 // Retrieve the selected classifier
614 Classifier current_selection = (Classifier) classifier_combobox.getSelectedItem();
615 // And reset the tooltip.
616 classifier_combobox.setToolTipText(Utility.formatHTMLWidth(current_selection.getDescription(), 40));
617 current_selection = null;
618 }
619 }
620 }
621
622 /** Listens for double clicks apon the list and react as if the configure button was pushed. */
623 private class ClickListener
624 extends MouseAdapter {
625 /** Called whenever the mouse is clicked over a registered component, we use this to chain through to the configure prompt.
626 * @param event A <strong>MouseEvent</strong> containing information about the mouse click.
627 */
628 public void mouseClicked(MouseEvent event) {
629 if(event.getClickCount() == 2 ) {
630 if(!classifier_list.isSelectionEmpty()) {
631 Classifier classifier = (Classifier) classifier_list.getSelectedValue();
632 ArgumentConfiguration ac = new ArgumentConfiguration(classifier);
633 if(ac.display()) {
634 refresh(classifier);
635 }
636 ac.destroy();
637 ac = null;
638 // cos I can't be bothered checking every argument to see if it has changed or not, we'll asasume that the configuration has changed if someone has clicked configure
639 Gatherer.c_man.configurationChanged();
640 }
641 }
642 }
643 }
644
645 /** This class listens for actions upon the configure button in the controls, and if detected creates a new ArgumentConfiguration dialog box to allow for configuration.
646 */
647 private class ConfigureListener
648 implements ActionListener {
649 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
650 * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
651 * @see org.greenstone.gatherer.cdm.ArgumentConfiguration
652 * @see org.greenstone.gatherer.cdm.Classifier
653 */
654 public void actionPerformed(ActionEvent event) {
655 if(!classifier_list.isSelectionEmpty()) {
656 Classifier classifier = (Classifier) classifier_list.getSelectedValue();
657 ArgumentConfiguration ac = new ArgumentConfiguration(classifier);
658 if(ac.display()) {
659 refresh(classifier);
660 }
661 ac.destroy();
662 ac = null;
663 // cos I can't be bothered checking every argument to see if it has changed or not, we'll asasume that the configuration has changed if someone has clicked configure
664 Gatherer.c_man.configurationChanged();
665 }
666 }
667 }
668
669 /** listens for changes in the list selection and enables the configure and remove buttons if there is a selection, disables them if there is no selection */
670 private class ListListener
671 implements ListSelectionListener {
672
673 public void valueChanged(ListSelectionEvent e) {
674 if (!e.getValueIsAdjusting()) { // we get two events for one change in list selection - use the false one ( the second one)
675 if (classifier_list.isSelectionEmpty()) {
676 move_up_button.setEnabled(false);
677 move_down_button.setEnabled(false);
678 configure.setEnabled(false);
679 remove.setEnabled(false);
680 }
681 else {
682 configure.setEnabled(true);
683 remove.setEnabled(true);
684 int selected_index = classifier_list.getSelectedIndex();
685 move_up_button.setEnabled(selected_index !=0);
686 move_down_button.setEnabled(selected_index != model.getSize()-1);
687 }
688 }
689 }
690 }
691
692 /** Listens for actions apon the move buttons in the manager controls, and if detected calls the <i>moveClassifier()</i> method of the manager with the appropriate details. */
693 private class MoveListener
694 implements ActionListener {
695 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
696 * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
697 */
698 public void actionPerformed(ActionEvent event) {
699 if(!classifier_list.isSelectionEmpty()) {
700 Object object = classifier_list.getSelectedValue();
701 if(object instanceof Classifier) {
702 Classifier classifier = (Classifier) object;
703 if(event.getSource() == move_up_button) {
704 moveClassifier(classifier, true, false);
705 }
706 else if(event.getSource() == move_down_button) {
707 moveClassifier(classifier, false, false);
708 }
709 classifier_list.setSelectedValue(classifier, true);
710 }
711 }
712 }
713 }
714
715 /** This class listens for actions upon the remove button in the controls, and if detected calls the <i>removeClassifier()</i> method.
716 */
717 private class RemoveListener
718 implements ActionListener {
719 /** Any implementation of <i>ActionListener</i> must include this method so that we can be informed when an action has occured on one of our target controls.
720 * @param event An <strong>ActionEvent</strong> containing information garnered from the control action.
721 */
722 public void actionPerformed(ActionEvent event) {
723 if(classifier_list.isSelectionEmpty()) {
724 remove.setEnabled(false);
725 return;
726 }
727 int selected_index = classifier_list.getSelectedIndex();
728 Object selected_classifier = classifier_list.getSelectedValue();
729 if (!(selected_classifier instanceof Classifier)) {
730 return; // what else could we have here???
731 }
732 removeClassifier((Classifier)selected_classifier);
733
734 if (selected_index >= classifier_list.getModel().getSize()) {
735 selected_index--;
736 }
737 if (selected_index >=0) {
738 classifier_list.setSelectedIndex(selected_index);
739 } else {
740 // no more classifiers in the list
741 remove.setEnabled(false);
742 }
743 }
744 }
745 }
746}
Note: See TracBrowser for help on using the repository browser.