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