Difference between revisions of "Plugin development"

From Freeplane - free mind mapping and knowledge management software
Line 67: Line 67:
  
 
The option names have to be added to <tt>Resource_en.properties</tt> (excerpt):
 
The option names have to be added to <tt>Resource_en.properties</tt> (excerpt):
</pre>
+
<pre>
 
OptionPanel.execute_scripts_without_asking = Scripts should be carried out without confirmation?
 
OptionPanel.execute_scripts_without_asking = Scripts should be carried out without confirmation?
 
OptionPanel.execute_scripts_without_asking.tooltip = <html>Freeplane scripts are principally able...
 
OptionPanel.execute_scripts_without_asking.tooltip = <html>Freeplane scripts are principally able...
Line 76: Line 76:
 
see <tt>org.freeplane.plugin.script.ScriptingRegistration</tt>:
 
see <tt>org.freeplane.plugin.script.ScriptingRegistration</tt>:
 
<groovy>
 
<groovy>
    private void addPropertiesToOptionPanel() {
+
private void addPropertiesToOptionPanel() {
        final URL preferences = this.getClass().getResource("preferences.xml");
+
    final URL preferences = this.getClass().getResource("preferences.xml");
        if (preferences == null)
+
    if (preferences == null)
            throw new RuntimeException("cannot open preferences");
+
        throw new RuntimeException("cannot open preferences");
        modeController.getOptionPanelBuilder().load(preferences);
+
    modeController.getOptionPanelBuilder().load(preferences);
    }
+
}
 
</groovy>
 
</groovy>
  
The options can be used like this:
+
The options can be queried like this:
 
<groovy>
 
<groovy>
 
String executeWithoutAsking = ResourceController.getResourceController()
 
String executeWithoutAsking = ResourceController.getResourceController()

Revision as of 21:36, 28 June 2010

Create a new Plugin

A simple tool helps to get started with the development of plugins. It's an Ant Task named 'create-plugin' that is available from the freeplane_framework/ant directory.

Interactive

The task reads all required parameters from the command line by default. The following transcript shows input and output of a create-plugin invocation (Windows/Cygwin):

/devel/freeplane-bazaar-repo/1_0_x/freeplane_framework/ant $ ant create-plugin
Buildfile: build.xml

create-plugin:
[create-plugin] => Please enter required plugin name:
helloworld
[create-plugin] => Optional: Does this plugin contribute to the GUI? (yes, no)
yes
[create-plugin] New plugin created in C:\devel\freeplane-bazaar-repo\1_0_x\freeplane_plugin_helloworld
[create-plugin] What next?
[create-plugin] * import plugin into Eclipse via Import... -> Existing Projects into Workspace
[create-plugin] * add required external jars to C:\devel\freeplane-bazaar-repo\1_0_x\freeplane_plugin_helloworld\lib
[create-plugin] * add required external jars and required Freeplane projects to classpath
[create-plugin] * search for "TODO" in the project and fill the gaps
[create-plugin] * add the following element to freeplane_framework/ant/build.xml:
[create-plugin]   <antcall target="makePlugin" inheritall="false">
[create-plugin]     <param name="anttarget" value="dist"/>
[create-plugin]     <param name="targetdir" value="plugins"/>
[create-plugin]     <param name="plugindir" value="freeplane_plugin_helloworld"/>
[create-plugin]     <param name="pluginname" value="org.freeplane.plugin.helloworld"/>
[create-plugin]   </antcall>

Follow the suggestions in the printed message.


Non-interactive

If you want to do it non-interactively instead you have to create your own (temporary) Ant task in freeplane_framework/ant/build.xml like this:

  <target name="create-plugin-batch">
    <create-plugin baseDir="." pluginname="helloworld" hasAction="true" />
  </target>


Tasks in Plugin development

Add options to the OptionPanel

The core plugins register their options via the configuration file freeplane/resources/xml/preferences.xml. Plugins can do it quite similar by defining their own preferences.xml (by convention in freeplane_plugin_<plugin>/org/freeplane/plugin/<plugin>/preferences.xml); here from the script plugin:

<?xml version="1.0" encoding="UTF-8"?>
<preferences_structure>
   <tabbed_pane>
      <tab name="plugins">
         <separator name="scripting">
            <boolean name="execute_scripts_without_asking" />
            <boolean name="execute_scripts_without_file_restriction" />
            <boolean name="execute_scripts_without_network_restriction" />
            <boolean name="execute_scripts_without_exec_restriction" />
            <boolean name="signed_script_are_trusted" />
            <string name="script_user_key_name_for_signing" />
            <string name="script_directories" />
         </separator>
      </tab>
   </tabbed_pane>
</preferences_structure>

The option names have to be added to Resource_en.properties (excerpt):

OptionPanel.execute_scripts_without_asking = Scripts should be carried out without confirmation?
OptionPanel.execute_scripts_without_asking.tooltip = <html>Freeplane scripts are principally able...
OptionPanel.execute_scripts_without_exec_restriction = Permit to Execute other Applications (NOT recommended)

For an example of how options can be registered at the option panel see org.freeplane.plugin.script.ScriptingRegistration: <groovy> private void addPropertiesToOptionPanel() {

   final URL preferences = this.getClass().getResource("preferences.xml");
   if (preferences == null)
       throw new RuntimeException("cannot open preferences");
   modeController.getOptionPanelBuilder().load(preferences);

} </groovy>

The options can be queried like this: <groovy> String executeWithoutAsking = ResourceController.getResourceController()

   .getProperty("execute_scripts_without_asking");

</groovy>