Changeset 12248
- Timestamp:
- 2006-07-19T14:57:21+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java
r12123 r12248 298 298 * @param classifier The classifier <strong>File</strong> you wish to load. 299 299 */ 300 private void loadClassifier(String classifier, String lang ) {301 ///ystem.err.println("Attempting to parse " + classifier );300 private void loadClassifier(String classifier, String lang, String collection) { 301 ///ystem.err.println("Attempting to parse " + classifier + " for collection "+collection); 302 302 Document document = null; 303 303 InputStream input_stream = null; … … 313 313 } 314 314 else { 315 String args[] = null; 316 if(Utility.isWindows()) { 317 args = new String[6]; 318 if(Configuration.perl_path != null) { 319 args[0] = Configuration.perl_path; 320 } 321 else { 322 args[0] = "Perl.exe"; 323 } 324 args[1] = LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl"; 325 args[2] = "-xml"; 326 args[3] = "-language"; 327 args[4] = lang; 328 args[5] = getClassifierName(classifier); 329 } 330 else { 331 args = new String[5]; 332 args[0] = "classinfo.pl"; 333 args[1] = "-xml"; 334 args[2] = "-language"; 335 args[3] = lang; 336 args[4] = getClassifierName(classifier); 337 } 315 ArrayList args = new ArrayList(); 316 if (Utility.isWindows()) { 317 args.add(Configuration.perl_path); 318 args.add("-S"); 319 } 320 args.add(LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl"); 321 args.add("-xml"); 322 args.add("-language"); 323 args.add(lang); 324 args.add("-collect"); 325 args.add(collection); 326 args.add(getClassifierName(classifier)); 338 327 339 328 // Create the process. 340 329 Runtime runtime = Runtime.getRuntime(); 341 Process process = runtime.exec( args);330 Process process = runtime.exec((String[])args.toArray(new String [0])); 342 331 343 332 input_stream = process.getErrorStream(); … … 391 380 392 381 String current_lang = Configuration.getLanguage(); 382 String collection_name = Gatherer.c_man.getCollection().getName(); 393 383 File files[] = (new File(directory)).listFiles(); 394 if(files != null) { 384 File coll_files[] = (new File(Gatherer.c_man.getCollectionClassifiersDirectoryPath())).listFiles(); 385 int num_files =0; 386 if (files != null) { 387 num_files += files.length; 388 } 389 if (coll_files != null) { 390 num_files += coll_files.length; 391 } 392 if(num_files > 0) { 395 393 // Create a progress indicator. 396 ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.ClassifierManager.Parsing.Title"), Dictionary.get("CDM.ClassifierManager.Parsing.Message"), files.length); 397 for(int i = 0; i < files.length; i++) { 398 // We only want to check Perl Modules. 399 if(files[i].getName().endsWith(".pm")) { 400 loadClassifier(files[i].getName(), current_lang); 394 ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.ClassifierManager.Parsing.Title"), Dictionary.get("CDM.ClassifierManager.Parsing.Message"), num_files); 395 if (coll_files != null) { 396 for (int i=0; i<coll_files.length; i++) { 397 398 if(coll_files[i].getName().endsWith(".pm")) { 399 loadClassifier(coll_files[i].getName(), current_lang, collection_name); 400 } 401 progress.inc(); 401 402 } 402 progress.inc(); 403 } 404 if (files != null) { 405 for(int i = 0; i < files.length; i++) { 406 // We only want to check Perl Modules. 407 if(files[i].getName().endsWith(".pm")) { 408 loadClassifier(files[i].getName(), current_lang, collection_name); 409 } 410 progress.inc(); 411 } 403 412 } 404 413 progress.dispose(); … … 420 429 421 430 // Parse XML to build up list of classifier names 422 Node root = document.getDocumentElement(); 423 424 NamedNodeMap attributes = root.getAttributes(); 425 Node length_node = attributes.getNamedItem("length"); 426 String num_classifiers_str = length_node.getNodeValue(); 431 Element root = document.getDocumentElement(); 432 433 String num_classifiers_str = root.getAttribute("length"); 427 434 int num_classifiers = Integer.parseInt(num_classifiers_str); 428 435 String class_list[] = new String[num_classifiers]; … … 431 438 int i = 0; 432 439 while (node != null) { 433 String node_name = node.getNodeName(); 434 if (node_name.equalsIgnoreCase("ClassifyName")) { 435 String name = XMLTools.getValue(node); 436 class_list[i] = name; 440 if (node.getNodeName().equalsIgnoreCase("ClassifyName")) { 441 class_list[i] = XMLTools.getValue(node); 437 442 i++; 438 443 } … … 440 445 node = node.getNextSibling(); 441 446 } 442 447 443 448 String current_lang = Configuration.getLanguage(); 449 String collection_name = Gatherer.c_man.getCollection().getName(); 444 450 if (num_classifiers>0) { 445 451 // Create a progress indicator. … … 448 454 for (i=0; i<num_classifiers; i++) { 449 455 String classifier = class_list[i]; 450 loadClassifier(classifier, current_lang );456 loadClassifier(classifier, current_lang, collection_name); 451 457 progress.inc(); 452 458 } … … 515 521 implements Control { 516 522 /** A combobox containing all of the known classifiers, including those that may have already been assigned. */ 517 private GComboBox classifier= null;523 private JComboBox classifier_combobox = null; 518 524 /** Button for adding classifiers. */ 519 525 private JButton add = null; … … 548 554 549 555 ClassifierComboboxListener ccl = new ClassifierComboboxListener(); 550 classifier = new GComboBox(getAvailable()); 551 classifier.setBackgroundNonSelectionColor(Configuration.getColor("coloring.editable_background", false)); 552 classifier.setBackgroundSelectionColor(Configuration.getColor("coloring.collection_selection_background", false)); 553 classifier.setEditable(true); 554 classifier.setTextNonSelectionColor(Configuration.getColor("coloring.workspace_tree_foreground", false)); 555 classifier.setTextSelectionColor(Configuration.getColor("coloring.collection_selection_foreground", false)); 556 if(classifier.getItemCount() > 0) { 557 classifier.setSelectedIndex(0); 558 ccl.itemStateChanged(new ItemEvent(classifier, 0, null, ItemEvent.SELECTED)); 556 classifier_combobox = new JComboBox(getAvailable()); 557 classifier_combobox.setEditable(false); 558 if(classifier_combobox.getItemCount() > 0) { 559 classifier_combobox.setSelectedIndex(0); 560 ccl.itemStateChanged(new ItemEvent(classifier_combobox, 0, null, ItemEvent.SELECTED)); 559 561 } 560 562 … … 585 587 add.addActionListener(new AddListener()); 586 588 add.addActionListener(CollectionDesignManager.buildcol_change_listener); 587 classifier .addItemListener(ccl);589 classifier_combobox.addItemListener(ccl); 588 590 configure.addActionListener(new ConfigureListener()); 589 591 configure.addActionListener(CollectionDesignManager.buildcol_change_listener); … … 619 621 classifier_pane.setLayout(new BorderLayout(5,0)); 620 622 classifier_pane.add(classifier_label, BorderLayout.WEST); 621 classifier_pane.add(classifier , BorderLayout.CENTER);623 classifier_pane.add(classifier_combobox, BorderLayout.CENTER); 622 624 623 625 button_pane.setLayout(new GridLayout(1, 3)); … … 644 646 public void destroy() { 645 647 add = null; 646 classifier = null;648 classifier_combobox = null; 647 649 classifier_list = null; 648 650 configure = null; … … 668 670 */ 669 671 public void actionPerformed(ActionEvent event) { 670 Object selected_object = classifier .getSelectedItem();672 Object selected_object = classifier_combobox.getSelectedItem(); 671 673 // If there is something in the combobox, but we haven't registered a selection, then add the object and select it! 672 674 if(selected_object != null) { … … 677 679 Element element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CLASSIFY_ELEMENT); 678 680 Classifier new_classifier = null; 679 if(base_classifier != null) { 680 DebugStream.println("Creating Classifier based on existing Classifer."); 681 element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, base_classifier.getName()); 682 new_classifier = new Classifier(element, base_classifier); 683 } 684 else { 685 DebugStream.println("Creating new custom Classifier."); 686 element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, selected_object.toString()); 687 new_classifier = new Classifier(element, null); 688 // Also we add the custom classifier name to the combobox for convienence. 689 classifier.addItem(selected_object); 690 } 681 element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, base_classifier.getName()); 682 new_classifier = new Classifier(element, base_classifier); 683 691 684 element = null; 692 685 // Automatically chain to configuration. This ensures required arguments are filled out. … … 714 707 if(event.getStateChange() == ItemEvent.SELECTED) { 715 708 // Retrieve the selected plugin 716 Object current_selection = classifier.getSelectedItem(); 717 // And reset the tooltip. If the plugin is null or is a string, then go back to the default message 718 if(current_selection == null || current_selection instanceof String) { 719 classifier.setToolTipText(Dictionary.get("CDM.ClassifierManager.Classifier_Tooltip")); 720 } 721 else { 722 Classifier current_classifier = (Classifier) current_selection; 723 classifier.setToolTipText(Utility.formatHTMLWidth(current_classifier.getDescription(), 40)); 724 current_classifier = null; 725 } 726 current_selection = null; 709 Classifier current_selection = (Classifier) classifier_combobox.getSelectedItem(); 710 // And reset the tooltip. 711 classifier_combobox.setToolTipText(Utility.formatHTMLWidth(current_selection.getDescription(), 40)); 712 current_selection = null; 727 713 } 728 714 }
Note:
See TracChangeset
for help on using the changeset viewer.