Child pages
  • Creating Client Plugins
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Custom Plugins

Custom Plugins are java classes contained in jar files from plugins folder that inherit IServerPlugin, ISmartClientPlugin or IClientPlugin. The plugin jar can use Java Service Provider to expose Servoy Plugin classes. There should be a file inside jar at path: META-INF/services/com.servoy.j2db.plugins.IPlugin which contains a line for each plugin that jar should expose (a class that implements IPlugin). The plugin should also have a default constructor (with no parameters). If file com.servoy.j2db.plugins.IPlugin is missing or contains invalid entries Servoy will scan the jar for all classes that implement interface IPlugin. An example of file content (for mail plugin) is:

com.servoy.extensions.plugins.mail.MailServer
com.servoy.extensions.plugins.mail.client.MailPlugin


Java Code Example

This is an example of a plugin that delivers a converter from joda time (which has support for time persiods) to java-util-date (which is supported by Servoy UI elements) time.

private static final IUIConverter[] UI_CONVERTERS = new IUIConverter[] { JodaToDateConverter.INSTANCE };
 
public IUIConverter[] getUIConverters()
{
    return UI_CONVERTERS;
}
 
static class NrToJodaConverter implements ITypedColumnConverter
{
    static final NrToJodaConverter INSTANCE = new NrToJodaConverter();
 
    public Object convertToObject(Map<String, String> props, int column_type, Object dbvalue) throws Exception
    {
        if (dbvalue == null)
        {
            return null;
        }
        return new DateTime(Utils.getAsLong(dbvalue));
    }
 
    public Object convertFromObject(Map<String, String> props, int column_type, Object obj) throws Exception
    {
        if (obj instanceof DateTime)
        {
            return Long.valueOf(((DateTime)obj).getMillis());
        }
        return obj; // or throw an exception??
    }
 
    public Map<String, String> getDefaultProperties()
    {
        return null;
    }
 
    public int[] getSupportedColumnTypes()
    {
        return new int[] { IColumnTypes.INTEGER };
    }
 
    public String getName()
    {
        return getClass().getSimpleName();
    }
 
    public int getToObjectType(Map<String, String> props)
    {
        // Servoy does not understand joda time natively. 
        return IColumnTypes.MEDIA;
    }
}
 
static class JodaToDateConverter implements IUIConverter
{
    static final JodaToDateConverter INSTANCE = new JodaToDateConverter();
 
    public Object convertFromObject(Map<String, String> props, int input_type, Object converted) throws Exception
    {
        if (converted instanceof Date)
        {
            return new DateTime(((Date)converted).getTime());
        }
        return converted; // or return null or throw an exception??
    }
 
    public Object convertToObject(Map<String, String> props, int input_type, Object input) throws Exception
    {
        if (input instanceof DateTime)
        {
            return new Date(((DateTime)input).getMillis());
        }
        return input; // or return null or throw an exception??
    }
 
    public Map<String, String> getDefaultProperties()
    {
        return null;
    }
 
    public int[] getSupportedDataproviderTypes()
    {
        // Servoy does not understand joda time natively.
        return new int[] { IColumnTypes.MEDIA };
    }
 
    public String getName()
    {
        return getClass().getSimpleName();
    }
 
    public int getToObjectType(Map<String, String> props)
    {
        return IColumnTypes.DATETIME;
    }
}
  • No labels