Changeset 8607


Ignore:
Timestamp:
2004-11-19T16:12:04+13:00 (19 years ago)
Author:
mdewsnip
Message:

First cut at suggesting plugins to use for files dragged into a collection. Seems to work pretty well, although I'm hoping to get all the plugins added to the collection by default which will avoid the need for a non-trivial dialog which hasn't been created yet.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
3 edited

Legend:

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

    r8601 r8607  
    155155    }
    156156
     157
     158    public boolean doesProcessFile(File file)
     159    {
     160    // Check the filename against the plugin's process_exp and block_exp values
     161    ArrayList arguments = getArguments(true, true);
     162    for (int i = 0; i < arguments.size(); i++) {
     163        Argument argument = (Argument) arguments.get(i);
     164        if (argument.getName().equals("process_exp") || argument.getName().equals("block_exp")) {
     165        // Try the assigned value first, for when the user has manually set the value
     166        String regular_expression = argument.getValue();
     167        if (regular_expression == null || regular_expression.equals("")) {
     168            // Not set, so use the default value
     169            regular_expression = argument.getDefaultValue();
     170            if (regular_expression.equals("")) {
     171            continue;
     172            }
     173        }
     174
     175        // The $ at the end doesn't seem to work in Java, so need to add ".*" at the start
     176        if (regular_expression.startsWith("(?i)")) {
     177            // Don't mess up case-insensitive matching though
     178            regular_expression = "(?i)" + ".*" + regular_expression.substring("(?i)".length());
     179        }
     180        else {
     181            regular_expression = ".*" + regular_expression;
     182        }
     183
     184        // If the filename matches the regular expression, this plugin will deal with the file in some way
     185        if (file.getName().matches(regular_expression)) {
     186            return true;
     187        }
     188        }
     189    }
     190
     191    // This plugin (probably) will not deal with the specified file
     192    return false;
     193    }
     194
     195
    157196    /** Method to determine if two plugins are equal.
    158197     * @param object The plugin to test against, as an <strong>Object</strong>.
  • trunk/gli/src/org/greenstone/gatherer/cdm/PluginManager.java

    r8601 r8607  
    4444import org.greenstone.gatherer.gui.GComboBox;
    4545import org.greenstone.gatherer.gui.GLIButton;
     46import org.greenstone.gatherer.gui.WarningDialog;
    4647import org.greenstone.gatherer.util.StaticStrings;
    4748import org.greenstone.gatherer.util.Utility;
     
    130131    for (int i = 0; i < super.getSize(); i++) {
    131132        Plugin assigned_plugin = (Plugin) getElementAt(i);
    132         if (assigned_plugin.isSeparator() == false) {
    133         System.err.println("Assigned plugin: " + assigned_plugin);
    134         }
    135     }
    136 
    137     // System.err.println("Number of plugins assigned in the collection: " + super.getSize());
    138     System.err.println("Number of plugins loaded: " + library.size());
     133        if (assigned_plugin.isSeparator() == false && assigned_plugin.doesProcessFile(file) == true) {
     134        // This file will be processed by an assigned plugin, so no suggestion is necessary
     135        System.err.println("Processed by assigned plugin: " + assigned_plugin);
     136        return;
     137        }
     138    }
     139
     140    // Next try the plugins NOT already assigned in the collection
     141    ArrayList suitable_plugins = new ArrayList();
     142    Object[] unassigned_plugins = getAvailable();
     143    for (int i = 0; i < unassigned_plugins.length; i++) {
     144        Plugin unassigned_plugin = (Plugin) unassigned_plugins[i];
     145        if (unassigned_plugin.doesProcessFile(file) == true) {
     146        System.err.println("Processed by unassigned plugin: " + unassigned_plugin);
     147        suitable_plugins.add(unassigned_plugin);
     148        }
     149    }
     150
     151    // If there appear to be no suitable plugins, warn the user about this and be done
     152    if (suitable_plugins.size() == 0) {
     153        String[] args = new String[1];
     154        args[0] = file.getName();
     155        WarningDialog warning_dialog = new WarningDialog("warning.NoPluginExpectedToProcessFile", args, null, false);
     156        warning_dialog.display();
     157        warning_dialog.dispose();
     158        return;
     159    }
     160
     161    // Generate a dialog
     162    String[] args = new String[2];
     163    args[0] = file.getName();
     164    args[1] = ((Plugin) suitable_plugins.get(0)).toString();
     165    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PluginManager.SuggestedPluginList", args), Dictionary.get("CDM.PluginManager.SuggestedPluginListTitle"), JOptionPane.INFORMATION_MESSAGE);
    139166    }
    140167
     
    12381265    }
    12391266}
    1240 
  • trunk/gli/src/org/greenstone/gatherer/gui/WarningDialog.java

    r8606 r8607  
    5757    public WarningDialog(String full_property, String affected_property, boolean can_cancel)
    5858    {
     59    this(full_property, null, affected_property, can_cancel);
     60    }
     61
     62
     63    public WarningDialog(String full_property, String[] args, String affected_property, boolean can_cancel)
     64    {
    5965    super(Gatherer.g_man, "Warning", true);
    6066
     
    8389    text_area.setLineWrap(true);
    8490    text_area.setWrapStyleWord(true);
    85     Dictionary.setText(text_area, warning_name + ".Message");
     91    Dictionary.setText(text_area, warning_name + ".Message", args);
    8692
    8793    value_panel = new JPanel();
Note: See TracChangeset for help on using the changeset viewer.