Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

Plugins



A Plugin is a jar library which contain functionalities to use with the application. A Plugin has:
  • A Manifest file, with specific MDIFramework properties
  • A Plugin class which will be called by the application

Overview

Plugins can perform a lot of functionalities by themselves: There are no dependencies from the main application to plugins. If you don't provide a Plugin, the main application will still work correctly.

Plugins directory

By default the Plugins are jar files in a "plugins" directory relative to the user directory. It is safe to have other jar files in the directory because files which do not have the MDIPluginClass won't be loaded.

There are two ways to specify the Plugins directory or directories:

Plugin Manifest

The Plugin manifest must contain at least the following property:
  • MDIPluginClass: the path of the Plugin class

Defining an alternative Plugin class depending on the application ID

It is possible to load alternative Plugin classes depending on the application ID. The format of the "MDIPluginClass" Manifest property is:
      MDIPluginClass: <appliID1>:<Plugin class Path>;<appliID2>:<Plugin class Path>...
For example:
      MDIPluginClass: appli1;the.Plugin1;appli2;the.Plugin2
The Plugin class will be chosen depending on the Application ID. The Application ID can be set by the MDIApplication.getApplicationID() method[1]
By default this method returns null
.

Allowing only specified Plugin types

The "MDIPluginType" Manifest property is used to restrict the allowed Plugins depending on their type. The list of allowed types can be set through the application AbstractApplication.setAllowedPluginTypes(Map) method. Plugins for which the Map value are not allowed will not be loaded. That way several applications can share the same Plugin directory or directories.

Example

      MDIPluginClass: my.plugin.MyPluginClass
      MDIPluginType: myType

Plugin class

The Plugin class must implement the Plugin interface. Note that as the Plugin will be instanciated by reflection, the Plugin class must have a constructor with no arguments else the instanciation will fail.

Plugin name

The Plugin.getPluginName() returns the name of the Plugin. The name is very important because it is the key for the Plugins list. No two Plugins can have the same name.

Plugin properties

Main Article: Plugin properties

The Plugin.getProperty(Object) is called by the PluginsManager to retrieve the plugin characteristics. The minimum elements to return are:

Plugin dependencies

Main Article: Plugins dependencies

Additionally, the PluginElementTypes.PROPERTY_DEPEND property allow to specify other plugins (by their name) on which the Plugin depend on. It can contain a single String or a List of Strings. If one of the Plugins on which a Plugins depends on is not present or is disabled, the dependent Plugin will be disabled.

Plugins activation process

Main Article: Plugins activation

The activation of the plugins is performed through these ordered steps[2]
Note that each of these steps will be performed for each Plugin, so a step will be performed for all Plugins before going on to the next step
:
  1. Instanciation and Registering the Plugin: The instanciation is performed through reflection using the MDIPluginClass path declared in the Plugin Manifest. The retrieval of Plugin characteristic and Registering of the Plugin will allow to declare the Plugin in the framework
  2. After this step, Plugins which have declared dependencies on other Plugins but for which some of the Plugins on which they depend are not present will be discarded
  3. If a Configuration manager exists for the application, Deserialize the Plugin configuration
  4. Reset the Plugin settings
  5. Initialize the Plugin
  6. For all GUI Plugins (instances of GUI Plugins), initialize the Plugin GUI

Registering the Plugin

This step consists for each Plugin in:

Registering the Plugin is performed through the Plugin.register(MDIApplication) method. The Plugin is not required to perform anything in this method, but it allows to pass the application to the Plugin.

Example

      public String getPluginName() {
        return "MyPlugin";
      }

      public Object getPluginProperty(String prop) {
        if (prop.equals(PluginElementTypes.PROPERTY_DATE)) {
          return "26/07/2016";
        } else if (prop.equals(PluginElementTypes.PROPERTY_DESC)) {
          return "My Plugin description";
        } else if (prop.equals(PluginElementTypes.PROPERTY_VERSION)) {
          return "1.0";
        } else {
          return null;
        }
      }

Serializing and deserializing the Plugin configuration

Main Article: Plugins configuration

The configuration for a Plugin will be automatically retrieved by the application by calling the Plugin.getPluginConfiguration() method. By default this method returns null, which eans that the Plugin has no configuration.

For example:
      public class OpenImagePlugin extends AbstractMDIPlugin {

        public OpenImagePlugin() {
        }

        public Configuration getPluginConfiguration() {
          return MyConfiguration.getInstance();
        }

Reset the Plugin settings

The Plugin.resetSettings() method is called during the Plugins activation. It is up to the Plugin to decide what to do.

Initialize the Plugin


The Plugin initialization is performed through two consecutive methods: Note that for MDIPlugin, the MDIPlugin.initAfterGUI(MDIApplication) method will be called after the GUI of the application has been created and initialized.

Notes

  1. ^ By default this method returns null
  2. ^ Note that each of these steps will be performed for each Plugin, so a step will be performed for all Plugins before going on to the next step
  3. ^ Loading the resources in this method is not mandatory, but it makes it simpler. Note that by default the method does nothing

See also


Categories: javafx | plugins | swing

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences