View Javadoc
1   package com.github.celldynamics.quimp.plugin;
2   
3   import com.github.celldynamics.quimp.QuimpException;
4   import com.github.celldynamics.quimp.QuimpException.MessageSinkTypes;
5   
6   /**
7    * General purpose plugin template for UI plugins.
8    * 
9    * <p>This template handle typical plugin that shows UI if run without parameters or run in
10   * background (without UI) if valid parameter string is passed to {@link #run(String)}.
11   * 
12   * <p>Following workflow specified in {@link AbstractPluginBase}, this implementation calls
13   * {@link #runPlugin()} from {@link #executer()}.
14   * 
15   * @author p.baniukiewicz
16   *
17   */
18  public abstract class AbstractPluginTemplate extends AbstractPluginBase {
19  
20    /**
21     * This default constructor must be overridden in concrete class. It is called by IJ when plugin
22     * instance is created. A concrete instance of {@link AbstractPluginOptions} class should be
23     * created there and then passed to
24     * {@link #AbstractPluginTemplate(AbstractPluginOptions, String)}.
25     */
26    protected AbstractPluginTemplate() {
27      super();
28    }
29  
30    /**
31     * Default constructor.
32     * 
33     * <p>Set api call to false and assign provided options to object.
34     * 
35     * @param options Reference to plugin configuration container.
36     * @param pluginName name of the plugin that will be displayed in Macro Recorder
37     */
38    protected AbstractPluginTemplate(AbstractPluginOptions options, String pluginName) {
39      super(options, pluginName);
40    }
41  
42    /**
43     * Constructor that allows to provide own parameters.
44     * 
45     * <p>Intended to run from API. Set {@link #apiCall} to true and {@link #errorSink} to
46     * {@link MessageSinkTypes#CONSOLE}.
47     * {@link AbstractPluginOptions} is initialised from specified string and assigned to this
48     * instance.
49     * 
50     * @param argString parameters string like that passed in macro. If it is empty string or null
51     *        constructor exits before deserialisation.
52     * @param options Reference to plugin configuration container.
53     * @param pluginName name of the plugin that will be displayed in Macro Recorder
54     * @throws QuimpPluginException on any error in plugin execution.
55     */
56    public AbstractPluginTemplate(String argString, AbstractPluginOptions options, String pluginName)
57            throws QuimpPluginException {
58      super(argString, options, pluginName);
59    }
60  
61    /*
62     * (non-Javadoc)
63     * 
64     * @see com.github.celldynamics.quimp.plugin.AbstractPluginBase#executer()
65     */
66    @Override
67    protected void executer() throws QuimpException {
68      runPlugin();
69    }
70  
71    /**
72     * Main plugin logic.
73     * 
74     * @throws QuimpPluginException on any error, handled by {@link #run(String)}
75     */
76    protected abstract void runPlugin() throws QuimpPluginException;
77  
78  }