Changeset 12250 for trunk/gli/src
- Timestamp:
- 2006-07-19T15:22:32+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/PluginManager.java
r12123 r12250 408 408 for(int i = 0; i < library_size; i++) { 409 409 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)) { 411 412 available.add(plugin); 412 413 } … … 414 415 } 415 416 // 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 } 417 421 //DebugStream.println("There are a total of " + library.size() + " plugins in the library."); 418 422 //DebugStream.println("However " + children().size() + " are in use,"); … … 438 442 * @param plugin The plugin <strong>File</strong> you wish to load. 439 443 */ 440 private void loadPlugin(String plugin, String lang ) {444 private void loadPlugin(String plugin, String lang, String collection_name) { 441 445 Document document = null; 442 446 InputStream input_stream = null; … … 450 454 } 451 455 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)); 475 468 476 469 // Create the process. 477 470 Runtime runtime = Runtime.getRuntime(); 478 Process process = runtime.exec( args);471 Process process = runtime.exec((String[])args.toArray(new String [0])); 479 472 input_stream = process.getErrorStream(); 480 473 xml = XMLTools.readXMLStream(input_stream); … … 524 517 String directory = LocalGreenstone.getDirectoryPath(); 525 518 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 } 531 567 532 568 … … 565 601 566 602 String current_lang = Configuration.getLanguage(); 603 String collection_name = Gatherer.c_man.getCollection().getName(); 567 604 if (num_plugins>0) { 568 605 // Create a progress indicator. … … 574 611 // don't load GMLPlug or DBPlug for windows 575 612 } else { 576 loadPlugin(plugin, current_lang );613 loadPlugin(plugin, current_lang, collection_name); 577 614 } 578 615 … … 585 622 } 586 623 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 windows604 } 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 }615 624 616 625 private Plugin parseXML(Node root) { … … 679 688 private JButton remove = null; 680 689 /** 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; 682 691 /** The label next to the plugin combobox. */ 683 692 private JLabel plugin_label = null; … … 719 728 720 729 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)); 728 733 729 734 plugin_label = new JLabel(Dictionary.get("CDM.PlugInManager.PlugIn")); … … 750 755 move_up_button.addActionListener(ml); 751 756 move_up_button.addActionListener(CollectionDesignManager.all_change_listener); 752 plugin .addItemListener(picl);757 plugin_combobox.addItemListener(picl); 753 758 remove.addActionListener(new RemoveListener()); 754 759 remove.addActionListener(CollectionDesignManager.all_change_listener); … … 775 780 plugin_pane.setLayout(new BorderLayout(5,0)); 776 781 plugin_pane.add(plugin_label, BorderLayout.WEST); 777 plugin_pane.add(plugin , BorderLayout.CENTER);782 plugin_pane.add(plugin_combobox, BorderLayout.CENTER); 778 783 779 784 button_pane.setLayout(new GridLayout(1,3)); … … 841 846 */ 842 847 public void actionPerformed(ActionEvent event) { 843 Object selected_object = plugin .getSelectedItem();848 Object selected_object = plugin_combobox.getSelectedItem(); 844 849 if(selected_object != null) { 845 850 // Retrieve the base plugin if any … … 848 853 // Create a new element in the DOM 849 854 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 } 856 869 } 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; 880 872 base_plugin = null; 881 873 } … … 1059 1051 if(event.getStateChange() == ItemEvent.SELECTED) { 1060 1052 // Retrieve the selected plugin 1061 Object current_selection = plugin .getSelectedItem();1053 Object current_selection = plugin_combobox.getSelectedItem(); 1062 1054 // And reset the tooltip. If the plugin is null or is a string, then go back to the default message 1063 1055 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")); 1065 1057 } 1066 1058 else { 1067 1059 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)); 1069 1061 current_plugin = null; 1070 1062 } … … 1118 1110 } 1119 1111 // Refresh the available plugins 1120 plugin .setModel(new DefaultComboBoxModel(getAvailable()));1112 plugin_combobox.setModel(new DefaultComboBoxModel(getAvailable())); 1121 1113 } 1122 1114 else {
Note:
See TracChangeset
for help on using the changeset viewer.