Changeset 12248


Ignore:
Timestamp:
2006-07-19T14:57:21+12:00 (18 years ago)
Author:
kjdon
Message:

changed the way the classinfo.pl command is built up - uses an Arraylist not a String []. changed the name of classifier to classifier_combobox, and made it a JComboBox rather than a GComboBox. It is no longer editable. When loading classifiers, it now looks in the collections perllib directory too to get collection specific classifiers. at the moment, cos we still have classifiers.dat, this coll specific info only works for the first collection. Michael is going to fix this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/ClassifierManager.java

    r12123 r12248  
    298298     * @param classifier The classifier <strong>File</strong> you wish to load.
    299299     */
    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);
    302302    Document document = null;
    303303    InputStream input_stream = null;
     
    313313        }
    314314        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));
    338327
    339328        // Create the process.
    340329        Runtime runtime = Runtime.getRuntime();
    341         Process process = runtime.exec(args);
     330        Process process = runtime.exec((String[])args.toArray(new String [0]));
    342331
    343332        input_stream = process.getErrorStream();
     
    391380
    392381        String current_lang = Configuration.getLanguage();
     382        String collection_name = Gatherer.c_man.getCollection().getName();
    393383        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) {
    395393            // 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();
    401402            }
    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            }
    403412            }
    404413            progress.dispose();
     
    420429
    421430    // 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");
    427434    int num_classifiers = Integer.parseInt(num_classifiers_str);
    428435    String class_list[] = new String[num_classifiers];
     
    431438    int i = 0;
    432439    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);
    437442        i++;       
    438443        }
     
    440445        node = node.getNextSibling();
    441446    }
    442 
     447   
    443448    String current_lang = Configuration.getLanguage();
     449    String collection_name = Gatherer.c_man.getCollection().getName();
    444450    if (num_classifiers>0) {
    445451        // Create a progress indicator.
     
    448454        for (i=0; i<num_classifiers; i++) {
    449455        String classifier = class_list[i];
    450         loadClassifier(classifier, current_lang);
     456        loadClassifier(classifier, current_lang, collection_name);
    451457        progress.inc();
    452458        }
     
    515521    implements Control {
    516522    /** 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;
    518524    /** Button for adding classifiers. */
    519525    private JButton add = null;
     
    548554
    549555        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));
    559561        }
    560562
     
    585587        add.addActionListener(new AddListener());
    586588        add.addActionListener(CollectionDesignManager.buildcol_change_listener);
    587         classifier.addItemListener(ccl);
     589        classifier_combobox.addItemListener(ccl);
    588590        configure.addActionListener(new ConfigureListener());
    589591        configure.addActionListener(CollectionDesignManager.buildcol_change_listener);
     
    619621        classifier_pane.setLayout(new BorderLayout(5,0));
    620622        classifier_pane.add(classifier_label, BorderLayout.WEST);
    621         classifier_pane.add(classifier, BorderLayout.CENTER);
     623        classifier_pane.add(classifier_combobox, BorderLayout.CENTER);
    622624
    623625        button_pane.setLayout(new GridLayout(1, 3));
     
    644646    public void destroy() {
    645647        add = null;
    646         classifier = null;
     648        classifier_combobox = null;
    647649        classifier_list = null;
    648650        configure = null;
     
    668670         */
    669671        public void actionPerformed(ActionEvent event) {
    670         Object selected_object = classifier.getSelectedItem();
     672        Object selected_object = classifier_combobox.getSelectedItem();
    671673        // If there is something in the combobox, but we haven't registered a selection, then add the object and select it!
    672674        if(selected_object != null) {
     
    677679            Element element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.CLASSIFY_ELEMENT);
    678680            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           
    691684            element = null;
    692685            // Automatically chain to configuration. This ensures required arguments are filled out.
     
    714707            if(event.getStateChange() == ItemEvent.SELECTED) {
    715708                // 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;
    727713            }
    728714        }
Note: See TracChangeset for help on using the changeset viewer.