How can I write my own plugins/modules?

Put into the installation directory, subdirectory lib, a JAR named UserServices.jar with one ore more implementations of org.jphototagger.api.plugin.Plugin or org.jphototagger.api.modules.Module or other interfaces called e.g. for thumbnails generation or reading/writing XMP sidecar files and publish them through the Java Service Provider Interface (SPI).

To avoid compiler errors, the minimum JAR file in the class path you need, is API.jar. If you do not want manually create the META-INF/services folder and keep relaxed during refactorings, you should include org-openide-util-lookup.jar and use the @ServiceProvider annotations. If you want receive messages, include eventbus.jar. To access domain objects, such as stored metadata info, include Domain.jar. Some other common used library is jsl.jar. All JARs located in the lib sub directory of JPhotoTagger's installation directory.

User Services' project skeleton

A project named JPhotoTagger: UserServices is located in the version control repository. It has already dependencies to the most important projects/libraries and builds the file UserServices.jar. You cann add/remove dependencies in NetBeans through right clicking on the project and selecting Properties > Libraries.

After building JPhotoTagger: UserServices , you can add the generated UserServices.jar to the installation directory as described obove. Every build of JPhotoTagger: Program deletes UserServices.jar from it's dist/lib directory through build.xml! So either use a separate directory or always re-copy it from JPhotoTagger: UserServices after building JPhotoTagger: Program or modify build.xml.

Hints

The best way to find reference implementations, is browsing the source code. Even better is, clone it and open in in the NetBeans IDE. The clone contains all source code and libraries.

Minimum Example for a user defined Module (Displays a message as soon as the module is loaded):

Within the UserServices.jar you can implement as many Plugins/Modules as you need.

package org.myorg.jphototaggerplugin;

import javax.swing.JOptionPane;
import org.openide.util.lookup.ServiceProvider;
import org.jphototagger.api.modules.Module;

@ServiceProvider(service = Module.class)
public final class MyModule implements Module {

    @Override
    public void init() {
        JOptionPane.showMessageDialog(null, "My module");
    }

    @Override
    public void remove() {
    }
}

Author: Elmar
Write e-Mail
Status of this document: 2012-07-30