Child pages
  • Creating Client Plugins

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example This is an example of a Java project called WhoisPlugin, and the Servoy libraries added to it.

Implementing

...

the Plugin

Create

...

a New Package

...

under the Java Project

A package is a neat way in Java to organize libraries coming from arbitrary sources and make them work together without problems of "Name collision".

...

This is an example of naming a package: com.servoy.plugins.whois  - where 'com.servoy' is a prefix which follows the rule listed above, and 'whois' is the plugin name.

Implement

...

the Plugin Interface

In order to implement a client plugin, you need to create a class that implements one or more of the three interfaces: IServerPlugin, ISmartClientPlugin, and IClientPlugin.

...

Code Block
public class WhoisPlugin implements IClientPlugin {

    public static final String PLUGIN_NAME = "whois";
    private WhoisPluginProvider provider;
    
    @Override
    public Properties getProperties() {
        Properties props = new Properties();
        props.put(DISPLAY_NAME, getName());
        return props;
    }

    @Override
    public void load() throws PluginException {
        // ignore
    }

    @Override
    public void unload() throws PluginException {
        provider = null;
    }

    @Override
    public void propertyChange(PropertyChangeEvent arg0) {
        // ignore
    }

    @Override
    public IScriptable getScriptObject() {
        if (provider == null) {
            provider = new WhoisPluginProvider();
        } 
        return provider;
    }

    @Override
    public Icon getImage() {
        URL iconUrl = getClass().getResource("images/whois.png"); //the image is added under a package 'com.servoy.plugins.whois.images' added to the WhoisPlugin project.
        if (iconUrl != null) {
            return new ImageIcon(iconUrl);
        } else {
            return null;
        }
    }

    @Override
    public String getName() {
        return PLUGIN_NAME;
    }

    @Override
    public void initialize(IClientPluginAccess arg0) throws PluginException {
        // ignore
    }
}

Implement

...

the Script Object

The method getStriptObject inherited by IClientPlugin from IScriptableProvider interface, returns the object that will provide the plugin with scripting properties and methods. So, by convention, it is called a Provider.

...

Create a class which implements the two interfaces. This class will provide methods representing the plugin behavior.

Code

...

the Plugin Main Behavior

In order to specify which methods are what, you need to use the JavaDoc annotations system which identifies getter/setter methods for plugin properties, as well as function methods for the plugin functions. The JavaDoc annotation system is also used for documenting the plugin.

For a proper understanding of how to use JavaDoc and how to build the documentation of your plugin, see Documenting your plugin Api.

Example

This example shows the implementation of the WhoisPluginProvider - the scriptable object which provides the behavior for the "whois" plugin.

...

Code Block
titleMETA-INF/services/com.servoy.j2db.plugins.IPlugin
com.servoy.plugins.whois.WhoisPlugin

Package

...

the Plugin

  • Right click on the project and choose Export > Java > JAR file.

  • Click Next

    Note

    You can deselect the .classpath and .project files to avoid polluting your jar with unwanted files only used by Eclipse.

    Select the export destination. You may choose to export the jar directly into your /{servoyInstall}/application_server/plugins directory.

  • Click Next

    Leave the 2 'Export class files…' checked, and check the 'Save the description of this JAR in the workspace'. Use the browse button to navigate to your project, and give a name to your definition. Eclipse automatically adds the 'jardesc' extension.

    Info

    What is nice about this option is that the next time you will want to deploy your jar (with modified sources for example), all you will have to do is right-click on the file 'xxx.jardesc' in the Package explorer and choose 'Create JAR' in the menu, with no need to go through all the Export dialogs each time you change something in your plugin.

  • Click Next once more. You may leave it as is, or choose other options.

  • Finish.

Testing

...

the Plugin

When opening the Servoy Developer, you should see the plugin under Plugins node in Solution Explorer.

...