Ignore:
Timestamp:
2006-07-19T15:22:32+12:00 (18 years ago)
Author:
kjdon
Message:

changed the way the pluginfo.pl command is built up - uses an Arraylist not a String []. changed the name of plugin to plugin_combobox, and made it a JComboBox rather than a GComboBox. It is no longer editable. When loading plugins, it now looks in the collections perllib directory too to get collection specific plugins. at the moment, cos we still have plugins.dat, this coll specific info only works for the first collection. Michael is going to fix this. Also, in specialist and expert modes, you can add the same plugin more than once

File:
1 edited

Legend:

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

    r12123 r12250  
    408408    for(int i = 0; i < library_size; i++) {
    409409        Plugin plugin = (Plugin) library.get(i);
    410         if(!plugin.isAbstract()) {
     410        String plugin_name = plugin.getName();
     411        if(!plugin.isAbstract() && !plugin_name.equals(StaticStrings.ARCPLUG_STR) && !plugin_name.equals(StaticStrings.RECPLUG_STR)) {
    411412        available.add(plugin);
    412413        }
     
    414415    }
    415416    // Now go through the assigned plugins, and remove any that match.
    416     available.removeAll(children());
     417    // only for < lib sys specialist mode
     418    if (Configuration.getMode()<=Configuration.SYSTEMS_MODE) {
     419        available.removeAll(children());
     420    }
    417421    //DebugStream.println("There are a total of " + library.size() + " plugins in the library.");
    418422    //DebugStream.println("However " + children().size() + " are in use,");
     
    438442     * @param plugin The plugin <strong>File</strong> you wish to load.
    439443     */
    440     private void loadPlugin(String plugin, String lang) {
     444    private void loadPlugin(String plugin, String lang, String collection_name) {
    441445    Document document = null;
    442446    InputStream input_stream = null;
     
    450454        }
    451455        else {
    452         String args[] = null;
    453         if(Utility.isWindows()) {
    454             args = new String[6];
    455             if(Configuration.perl_path != null) {
    456             args[0] = Configuration.perl_path;
    457             }
    458             else {
    459             args[0] = "Perl.exe";
    460             }
    461             args[1] = LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl";
    462             args[2] = "-xml";
    463             args[3] = "-language";
    464             args[4] = lang;
    465             args[5] = getPluginName(plugin);
    466         }
    467         else {
    468             args = new String[5];
    469             args[0] = "pluginfo.pl";
    470             args[1] = "-xml";
    471             args[2] = "-language";
    472             args[3] = lang;
    473             args[4] = getPluginName(plugin);
    474         }
     456        ArrayList args = new ArrayList();
     457        if (Utility.isWindows()) {
     458            args.add(Configuration.perl_path);
     459            args.add("-S");
     460        }
     461        args.add(LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl");
     462        args.add("-xml");
     463        args.add("-language");
     464        args.add(lang);
     465        args.add("-collect");
     466        args.add(collection_name);
     467        args.add(getPluginName(plugin));
    475468
    476469        // Create the process.
    477470        Runtime runtime = Runtime.getRuntime();
    478         Process process = runtime.exec(args);
     471        Process process = runtime.exec((String[])args.toArray(new String [0]));
    479472        input_stream = process.getErrorStream();
    480473        xml = XMLTools.readXMLStream(input_stream);
     
    524517        String directory = LocalGreenstone.getDirectoryPath();
    525518        directory = directory + "perllib" + File.separator + "plugins" + File.separator;
    526         loadPlugins(new File(directory));
    527         }
    528     }
    529     }
    530 
     519        String current_lang = Configuration.getLanguage();
     520        String collection_name = Gatherer.c_man.getCollection().getName();
     521
     522        boolean is_windows = Utility.isWindows();
     523        boolean is_mac = Utility.isMac();
     524   
     525        File files[] = (new File(directory)).listFiles();
     526        File coll_files[] = (new File(Gatherer.c_man.getCollectionPluginsDirectoryPath())).listFiles();
     527        int num_files = 0;
     528        if (files != null) {
     529            num_files += files.length;
     530        }
     531        if (coll_files != null) {
     532            num_files += coll_files.length;
     533        }
     534        if(num_files > 0) {
     535       
     536            // Create a progress indicator.
     537            ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.PlugInManager.Parsing.Title"), Dictionary.get("CDM.PlugInManager.Parsing.Message"), num_files);
     538            if (coll_files != null) {
     539            for (int i=0; i<coll_files.length; i++) {   
     540                if(coll_files[i].getName().endsWith(".pm")) {
     541                loadPlugin(coll_files[i].getName(), current_lang, collection_name);
     542                }
     543                progress.inc();
     544            }
     545            }
     546
     547            if (files != null) {
     548            for(int i = 0; i < files.length; i++) {
     549                // We only want to check Perl Modules.
     550                if(files[i].getName().endsWith(".pm")) {
     551                if (files[i].getName().equals("GMLPlug.pm") || ((is_windows || is_mac) && files[i].getName().equals("DBPlug.pm"))) {
     552                    // don't load GMLPlug or DBPlug for windows
     553                } else {
     554                    loadPlugin(files[i].getName(), current_lang, collection_name);
     555                }
     556                }
     557                progress.inc();
     558            }
     559            }
     560            progress.dispose();
     561            progress.destroy();
     562            progress = null;
     563        }   
     564        }
     565    }
     566    }
    531567
    532568
     
    565601
    566602    String current_lang = Configuration.getLanguage();
     603    String collection_name = Gatherer.c_man.getCollection().getName();
    567604    if (num_plugins>0) {
    568605        // Create a progress indicator.
     
    574611            // don't load GMLPlug or DBPlug for windows
    575612        } else {
    576             loadPlugin(plugin, current_lang);
     613            loadPlugin(plugin, current_lang, collection_name);
    577614        }
    578615       
     
    585622    }
    586623
    587 
    588     /** Method to load plug-in information from a specified directory. Of course no plug-ins may be found at this location.
    589      * @param directory A <strong>File</strong> indicating the directory to be scanned for plug-ins.
    590      */
    591     private void loadPlugins(File directory) {
    592     File files[] = directory.listFiles();
    593     boolean is_windows = Utility.isWindows();
    594     boolean is_mac = Utility.isMac();
    595     String current_lang = Configuration.getLanguage();
    596     if(files != null) {
    597         // Create a progress indicator.
    598         ParsingProgress progress = new ParsingProgress(Dictionary.get("CDM.PlugInManager.Parsing.Title"), Dictionary.get("CDM.PlugInManager.Parsing.Message"), files.length);
    599         for(int i = 0; i < files.length; i++) {
    600         // We only want to check Perl Modules.
    601         if(files[i].getName().endsWith(".pm")) {
    602             if (files[i].getName().equals("GMLPlug.pm") || ((is_windows || is_mac) && files[i].getName().equals("DBPlug.pm"))) {
    603             // don't load GMLPlug or DBPlug for windows
    604             } else {
    605             loadPlugin(files[i].getName(), current_lang);
    606             }
    607         }
    608         progress.inc();
    609         }
    610         progress.dispose();
    611         progress.destroy();
    612         progress = null;
    613     }
    614     }
    615624
    616625    private Plugin parseXML(Node root) {
     
    679688    private JButton remove = null;
    680689    /** A combobox containing all of the known plugins, including those that may have already been assigned. */
    681     private GComboBox plugin = null;
     690    private JComboBox plugin_combobox = null;
    682691    /** The label next to the plugin combobox. */
    683692    private JLabel plugin_label = null;
     
    719728
    720729        PluginComboboxListener picl = new PluginComboboxListener();
    721         plugin = new GComboBox(getAvailable());
    722         plugin.setBackgroundNonSelectionColor(Configuration.getColor("coloring.editable_background", false));
    723         plugin.setBackgroundSelectionColor(Configuration.getColor("coloring.collection_selection_background", false));
    724         plugin.setEditable(true);
    725         plugin.setTextNonSelectionColor(Configuration.getColor("coloring.workspace_tree_foreground", false));
    726         plugin.setTextSelectionColor(Configuration.getColor("coloring.collection_selection_foreground", false));
    727         picl.itemStateChanged(new ItemEvent(plugin, 0, null, ItemEvent.SELECTED));
     730        plugin_combobox = new JComboBox(getAvailable());
     731        plugin_combobox.setEditable(false);
     732        picl.itemStateChanged(new ItemEvent(plugin_combobox, 0, null, ItemEvent.SELECTED));
    728733
    729734        plugin_label = new JLabel(Dictionary.get("CDM.PlugInManager.PlugIn"));
     
    750755        move_up_button.addActionListener(ml);
    751756        move_up_button.addActionListener(CollectionDesignManager.all_change_listener);
    752         plugin.addItemListener(picl);
     757        plugin_combobox.addItemListener(picl);
    753758        remove.addActionListener(new RemoveListener());
    754759        remove.addActionListener(CollectionDesignManager.all_change_listener);
     
    775780        plugin_pane.setLayout(new BorderLayout(5,0));
    776781        plugin_pane.add(plugin_label, BorderLayout.WEST);
    777         plugin_pane.add(plugin, BorderLayout.CENTER);
     782        plugin_pane.add(plugin_combobox, BorderLayout.CENTER);
    778783
    779784        button_pane.setLayout(new GridLayout(1,3));
     
    841846         */
    842847        public void actionPerformed(ActionEvent event) {
    843         Object selected_object = plugin.getSelectedItem();
     848        Object selected_object = plugin_combobox.getSelectedItem();
    844849        if(selected_object != null) {
    845850            // Retrieve the base plugin if any
     
    848853            // Create a new element in the DOM
    849854            Element element = CollectionDesignManager.collect_config.document.createElement(CollectionConfiguration.PLUGIN_ELEMENT);
    850             // Remember that the plugin supplied might be a custom string rather than a base plugin
    851             Plugin new_plugin = null;
    852             if(base_plugin != null) {
    853             //DebugStream.println("New Plugin based on existing Plugin");
    854             element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, base_plugin.getName());
    855             new_plugin = new Plugin(element, base_plugin);
     855            element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, base_plugin.getName());
     856            Plugin new_plugin = new Plugin(element, base_plugin);
     857            element = null;
     858           
     859            // Automatically chain to configuration. This ensures required arguments are filled out.
     860            ArgumentConfiguration ac = new ArgumentConfiguration(new_plugin);
     861            if(ac.display()) {
     862            assignPlugin(new_plugin);
     863            plugin_list.setSelectedValue(new_plugin, true);
     864            // Since we weren't cancelled, if we are in a low mode, remove the plugin from the available list (except for UnknownPlug
     865            if(base_plugin != null && Configuration.getMode() <= Configuration.SYSTEMS_MODE && !base_plugin.getName().equals(StaticStrings.UNKNOWNPLUG_STR)) {
     866                plugin_combobox.removeItem(base_plugin);
     867                plugin_combobox.setSelectedIndex(0);
     868            }
    856869            }
    857             else {
    858             //DebugStream.println("New Custom Plugin");
    859             element.setAttribute(CollectionConfiguration.TYPE_ATTRIBUTE, selected_object.toString());
    860             new_plugin = new Plugin(element, null);
    861             }
    862             if(!model.contains(new_plugin) || new_plugin.getName().equals(StaticStrings.UNKNOWNPLUG_STR)) {
    863             // Automatically chain to configuration. This ensures required arguments are filled out.
    864             ArgumentConfiguration ac = new ArgumentConfiguration(new_plugin);
    865             if(ac.display()) {
    866                 assignPlugin(new_plugin);
    867                 plugin_list.setSelectedValue(new_plugin, true);
    868                 // Since we weren't cancelled, and if there was a base plugin, ensure it no longer is shown as available, unless it is the UnknownPlugin which can be added several times
    869                 if(base_plugin != null && !base_plugin.getName().equals(StaticStrings.UNKNOWNPLUG_STR)) {
    870                 plugin.removeItem(base_plugin);
    871                 }
    872             }
    873             ac = null;
    874             new_plugin = null;
    875             plugin.setSelectedIndex(0);
    876             }
    877             else {
    878             JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    879             }
     870            ac = null;
     871            new_plugin = null;
    880872            base_plugin = null;
    881873        }
     
    10591051            if(event.getStateChange() == ItemEvent.SELECTED) {
    10601052                // Retrieve the selected plugin
    1061                 Object current_selection = plugin.getSelectedItem();
     1053                Object current_selection = plugin_combobox.getSelectedItem();
    10621054                // And reset the tooltip. If the plugin is null or is a string, then go back to the default message
    10631055                if(current_selection == null || current_selection instanceof String) {
    1064             plugin.setToolTipText(Dictionary.get("CDM.PlugInManager.PlugIn_Tooltip"));
     1056            plugin_combobox.setToolTipText(Dictionary.get("CDM.PlugInManager.PlugIn_Tooltip"));
    10651057                }
    10661058                else {
    10671059                    Plugin current_plugin = (Plugin) current_selection;
    1068             plugin.setToolTipText(Utility.formatHTMLWidth(current_plugin.getDescription(), 40));
     1060            plugin_combobox.setToolTipText(Utility.formatHTMLWidth(current_plugin.getDescription(), 40));
    10691061                    current_plugin = null;
    10701062                }
     
    11181110            }
    11191111            // Refresh the available plugins
    1120             plugin.setModel(new DefaultComboBoxModel(getAvailable()));
     1112            plugin_combobox.setModel(new DefaultComboBoxModel(getAvailable()));
    11211113        }
    11221114        else {
Note: See TracChangeset for help on using the changeset viewer.