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

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

Most of the functionality for obtaining plugin and classifier argument information dynamically (instead of using the awful plugins.dat and classifiers.dat files). Coming soon: collection-specific plugins/classifiers, and remote greenstone building support.

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