Class PluginFactory

  • Direct Known Subclasses:
    PluginFactory

    @PublicAPI
    public class PluginFactory
    extends Object
    Plugin factroy: responsible for plugin parameter panel and plugin creation and central management.
    Since:
    Marvin 4.0
    • Field Detail

      • PRELOAD

        @Deprecated
        public static final String PRELOAD
        Deprecated.
        Not used.
        Preload sign in property file: if present then the plugin loader and the plugin should be preloaded, otherwise both are loaded when first used.
        See Also:
        Constant Field Values
      • NOPARAMS

        public static final String NOPARAMS
        No parameter panel sign in property file: if present then no parameter panel belongs to the plugin.
        See Also:
        Constant Field Values
      • SEPARATOR

        public static final String SEPARATOR
        Menuitem separator in Tools menu: if present then separator will be added to the Tools menu after the plugin menuitem.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PluginFactory

        public PluginFactory()
        Constructor.
    • Method Detail

      • setOKActionListener

        public void setOKActionListener​(ActionListener okActionListener)
        Sets the "OK" button pressed action listener. If set, the factory generates option pane with "OK" button, setting the "OK" button action command to "plugin_" and adds this action listener to the button.
        Parameters:
        okActionListener - is the "OK" button pressed action listener
      • setParentComponent

        public void setParentComponent​(Component parent)
        Sets the parent component - this is used to set options panes positions.
        Parameters:
        parent - is parent component
      • createDefaultParameterPanel

        public static ParameterPanelHandler createDefaultParameterPanel​(String cl,
                                                                        Component parent)
                                                                 throws PluginException
        Creates default parameter panel based on XML config. This is a ParameterPanel object based on the <plugin class name>Parameters.xml configuration XML read from CalculatorPlugin.PLUGIN_DIR, with user parameter settings read from $HOME/chemaxon/<plugin class name>Parameters.properties (Windows), or $HOME/.chemaxon/<plugin class name>Parameters.properties (UNIX / Linux). Returns null (no paramter panel for this plugin) if the configuration XML is not found.
        Parameters:
        cl - the full plugin class name
        Returns:
        the parameter panel, or null if no XML config file found
        Throws:
        PluginException
      • load

        public void load​(String file,
                         String alterfile)
                  throws PluginException
        Loads plugin data from property file. There is a line for each plugin in the property file according to the following syntax:
         key=$<plugin class name>$<plugin JAR URL>$<menu>$<mnemonics>$<group>$<groupmnemonic>$<NOPARAMS>
         
        The first character in the value (after the '=' sign) is the delimiter - can be any ASCII character that does not occur in the value string. The '$' character is appropriate in most cases. Plugins will be sorted by key. At least one of the plugin class name and the plugin JAR has to be specified, all other entries are optional. Omitted fields should be denoted by empty strings.

        Creating the plugin parameter panel:

        1. First a configuration XML is searched in the CLASSPATH. Its name is generated from the plugin class name without the package name: <plugin name>Parameters.xml. If this file is found then a generic parameter panel is generated,
        2. otherwise the plugin should be created to fetch its specific parameter panel by plugin.getParameterPanel().
        Initial parameter values in the parameter panel are set from $HOME/chemaxon/<plugin name>Parameters.properties (Windows) or $HOME/.chemaxon/<plugin name>Parameters.properties (UNIX / Linux) if exists, otherwise default initial values are set from the configuration XML or in plugin.getParameterPanel().

        Creating the plugin:

        1. If the plugin class name is specified then first the plugin is attempted to be instantiated from the current CLASSPATH. Continue with next step on failure.
        2. If the plugin JAR is specified then the plugin is instantiated from the JAR. If the plugin class name is not specified then it is read from the Plugin-Class attribute of the JAR manifest.
        Plugin and parameter panels are created as needed.
        Parameters:
        file - is the config file name as resource, relative to the CLASSPATH
        alterfile - the optional config file name as resource, relative to the CLASSPATH, set it to null to prefer the default config file
        Throws:
        PluginException - on error
      • load

        public void load​(Properties props)
                  throws PluginException
        Loads plugin data from properties. Format:
         key=$<plugin class name>$<plugin JAR URL>$<menu>$<mnemonics>$<group>$<groupmnemonic>$<NOPARAMS>
         
        The first character in the value (after the '=' sign) is the delimiter - can be any ASCII character that does not occur in the value string. The '$' character is appropriate in most cases. Plugins will be sorted by key. At least one of the plugin class name and the plugin JAR has to be specified, all other entries are optional. Omitted fields should be denoted by empty strings.

        Creating the plugin parameter panel:

        1. First a configuration XML is searched in the CLASSPATH. Its name is generated from the plugin class name without the package name: plugin/<plugin name>Parameters.xml. If this file is found then a generic parameter panel is generated,
        2. otherwise the plugin should be created to fetch its specific parameter panel by plugin.getParameterPanel().
        Initial parameter values in the parameter panel are set from $HOME/chemaxon/<plugin name>Parameters.properties (Windows) or $HOME/.chemaxon/<plugin name>Parameters.properties (UNIX / Linux) if exists, otherwise default initial values are set from the configuration XML or in plugin.getParameterPanel().

        Creating the plugin:

        1. If the plugin class name is specified then first the plugin is attempted to be instantiated from the current CLASSPATH. Continue with next step on failure.
        2. If the plugin JAR is specified then the plugin is instantiated from the JAR. If the plugin class name is not specified then it is read from the Plugin-Class attribute of the JAR manifest.
        Plugin and parameter panels are created as needed.
        Parameters:
        props - is the property object storing the plugin configuration
        Throws:
        PluginException - on error
      • saveParameterSettings

        public void saveParameterSettings()
        Saves plugin parameter settings to file $HOME/chemaxon/<plugin class name>Parameters.properties (Windows), or $HOME/.chemaxon/<plugin class name>Parameters.properties (UNIX / Linux).
      • getCount

        public int getCount()
        Returns the number of plugin records.
        Returns:
        the number of plugin records
      • getMenu

        public String getMenu​(int index)
        Gets the menu string for a plugin.
        Parameters:
        index - is the plugin record index
        Returns:
        the plugin menu string
      • getKey

        public String getKey​(int index)
        Gets the menu key for a plugin.
        Parameters:
        index - is the plugin record index
        Returns:
        the menu key
      • getMnemonic

        public char getMnemonic​(int index)
        Gets the menu mnemonic for a plugin.
        Parameters:
        index - is the plugin record index
        Returns:
        the menu mnemonic
      • getGroup

        public String getGroup​(int index)
        Gets the menu group for a plugin.
        Parameters:
        index - is the plugin record index
        Returns:
        the menu group
      • getGroupMnemonic

        public char getGroupMnemonic​(int index)
        Gets the group mnemonic for a plugin.
        Parameters:
        index - is the plugin record index
        Returns:
        the menu mnemonic
      • getSeparator

        public boolean getSeparator​(int index)
        Gets if a separator is required after the plugin menuitem in the Tools menu.
        Parameters:
        index - is the plugin record index
        Returns:
        true if separator is needed, false otherwise
        Since:
        Marvin 5.4
      • getParameterPanel

        public ParameterPanelHandler getParameterPanel​(int index)
                                                throws PluginException
        Gets the parameter panel for a plugin, loads it if needed.
        Parameters:
        index - is the plugin record index
        Returns:
        the parameter panel
        Throws:
        PluginException - on error
      • getOptionsPane

        public OptionsPane getOptionsPane​(int index)
                                   throws PluginException
        Gets the options pane for a plugin, loads it if needed.
        Parameters:
        index - is the plugin record index
        Returns:
        the options pane
        Throws:
        PluginException - on error
      • hasParameters

        public boolean hasParameters​(int index)
        Returns true if plugin has parameter panel, false otherwise.
        Returns:
        whether plugin has parameter panel
      • isOptionsPaneLoaded

        public boolean isOptionsPaneLoaded​(int index)
        Returns true is options pane is loaded for plugin, false otherwise.
        Returns:
        whether potions pane is loaded for plugin
      • getPluginIndex

        public int getPluginIndex​(String key)
        Gets a plugin index from record key.
        Parameters:
        key - is the plugin record key
        Returns:
        the plugin record index, or -1 for non-existent key