Difference between revisions of "Plugin development"

From Freeplane - free mind mapping and knowledge management software
Line 1: Line 1:
 +
----
 +
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 +
----
 +
=[http://erihybomex.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 +
----
 +
=[http://erihybomex.co.cc CLICK HERE]=
 +
----
 +
</div>
 
=Create a new Plugin=
 
=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 <tt>freeplane_framework/ant</tt> directory.
+
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 &lt;tt&gt;freeplane_framework/ant&lt;/tt&gt; directory.
  
 
===Interactive===
 
===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):
 
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):
<pre>
+
&lt;pre&gt;
 
/devel/freeplane-bazaar-repo/1_0_x/freeplane_framework/ant $ ant create-plugin
 
/devel/freeplane-bazaar-repo/1_0_x/freeplane_framework/ant $ ant create-plugin
 
Buildfile: build.xml
 
Buildfile: build.xml
  
 
create-plugin:
 
create-plugin:
[create-plugin] => Please enter required plugin name:
+
[create-plugin] =&gt; Please enter required plugin name:
 
helloworld
 
helloworld
[create-plugin] => Optional: Does this plugin contribute to the GUI? (yes, no)
+
[create-plugin] =&gt; Optional: Does this plugin contribute to the GUI? (yes, no)
 
yes
 
yes
 
[create-plugin] New plugin created in C:\devel\freeplane-bazaar-repo\1_0_x\freeplane_plugin_helloworld
 
[create-plugin] New plugin created in C:\devel\freeplane-bazaar-repo\1_0_x\freeplane_plugin_helloworld
 
[create-plugin] What next?
 
[create-plugin] What next?
[create-plugin] * import plugin into Eclipse via Import... -> Existing Projects into Workspace
+
[create-plugin] * import plugin into Eclipse via Import... -&gt; 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 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] * add required external jars and required Freeplane projects to classpath
[create-plugin] * search for "TODO" in the project and fill the gaps
+
[create-plugin] * search for &quot;TODO&quot; in the project and fill the gaps
 
[create-plugin] * add the following element to freeplane_framework/ant/build.xml:
 
[create-plugin] * add the following element to freeplane_framework/ant/build.xml:
[create-plugin]  <antcall target="makePlugin" inheritall="false">
+
[create-plugin]  &lt;antcall target=&quot;makePlugin&quot; inheritall=&quot;false&quot;&gt;
[create-plugin]    <param name="anttarget" value="dist"/>
+
[create-plugin]    &lt;param name=&quot;anttarget&quot; value=&quot;dist&quot;/&gt;
[create-plugin]    <param name="targetdir" value="plugins"/>
+
[create-plugin]    &lt;param name=&quot;targetdir&quot; value=&quot;plugins&quot;/&gt;
[create-plugin]    <param name="plugindir" value="freeplane_plugin_helloworld"/>
+
[create-plugin]    &lt;param name=&quot;plugindir&quot; value=&quot;freeplane_plugin_helloworld&quot;/&gt;
[create-plugin]    <param name="pluginname" value="org.freeplane.plugin.helloworld"/>
+
[create-plugin]    &lt;param name=&quot;pluginname&quot; value=&quot;org.freeplane.plugin.helloworld&quot;/&gt;
[create-plugin]  </antcall>
+
[create-plugin]  &lt;/antcall&gt;
</pre>
+
&lt;/pre&gt;
  
 
Follow the suggestions in the printed message.
 
Follow the suggestions in the printed message.
Line 34: Line 42:
 
===Non-interactive===
 
===Non-interactive===
  
If you want to do it non-interactively instead you have to create your own (temporary) Ant task in <tt>freeplane_framework/ant/build.xml</tt> like this:
+
If you want to do it non-interactively instead you have to create your own (temporary) Ant task in &lt;tt&gt;freeplane_framework/ant/build.xml&lt;/tt&gt; like this:
<pre>
+
&lt;pre&gt;
   <target name="create-plugin-batch">
+
   &lt;target name=&quot;create-plugin-batch&quot;&gt;
     <create-plugin baseDir="." pluginname="helloworld" hasAction="true" />
+
     &lt;create-plugin baseDir=&quot;.&quot; pluginname=&quot;helloworld&quot; hasAction=&quot;true&quot; /&gt;
   </target>
+
   &lt;/target&gt;
</pre>
+
&lt;/pre&gt;
  
  
Line 46: Line 54:
 
==Add options to the OptionPanel==
 
==Add options to the OptionPanel==
  
The core plugins register their options via the configuration file <tt>freeplane/resources/xml/preferences.xml</tt>. Plugins can do it quite similar by defining their own <tt>preferences.xml</tt> (by convention in <tt>freeplane_plugin_<plugin>/org/freeplane/plugin/<plugin>/preferences.xml</tt>); here from the ''script'' plugin:
+
The core plugins register their options via the configuration file &lt;tt&gt;freeplane/resources/xml/preferences.xml&lt;/tt&gt;. Plugins can do it quite similar by defining their own &lt;tt&gt;preferences.xml&lt;/tt&gt; (by convention in &lt;tt&gt;freeplane_plugin_&lt;plugin&gt;/org/freeplane/plugin/&lt;plugin&gt;/preferences.xml&lt;/tt&gt;); here from the ''script'' plugin:
<pre>
+
&lt;pre&gt;
<?xml version="1.0" encoding="UTF-8"?>
+
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
<preferences_structure>
+
&lt;preferences_structure&gt;
   <tabbed_pane>
+
   &lt;tabbed_pane&gt;
       <tab name="plugins">
+
       &lt;tab name=&quot;plugins&quot;&gt;
         <separator name="scripting">
+
         &lt;separator name=&quot;scripting&quot;&gt;
             <boolean name="execute_scripts_without_asking" />
+
             &lt;boolean name=&quot;execute_scripts_without_asking&quot; /&gt;
             <boolean name="execute_scripts_without_file_restriction" />
+
             &lt;boolean name=&quot;execute_scripts_without_file_restriction&quot; /&gt;
             <boolean name="execute_scripts_without_network_restriction" />
+
             &lt;boolean name=&quot;execute_scripts_without_network_restriction&quot; /&gt;
             <boolean name="execute_scripts_without_exec_restriction" />
+
             &lt;boolean name=&quot;execute_scripts_without_exec_restriction&quot; /&gt;
             <boolean name="signed_script_are_trusted" />
+
             &lt;boolean name=&quot;signed_script_are_trusted&quot; /&gt;
             <string name="script_user_key_name_for_signing" />
+
             &lt;string name=&quot;script_user_key_name_for_signing&quot; /&gt;
             <string name="script_directories" />
+
             &lt;string name=&quot;script_directories&quot; /&gt;
         </separator>
+
         &lt;/separator&gt;
       </tab>
+
       &lt;/tab&gt;
   </tabbed_pane>
+
   &lt;/tabbed_pane&gt;
</preferences_structure>
+
&lt;/preferences_structure&gt;
</pre>
+
&lt;/pre&gt;
  
The option names have to be added to <tt>Resource_en.properties</tt> (excerpt):
+
The option names have to be added to &lt;tt&gt;Resource_en.properties&lt;/tt&gt; (excerpt):
<pre>
+
&lt;pre&gt;
 
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 = &lt;html&gt;Freeplane scripts are principally able...
 
OptionPanel.execute_scripts_without_exec_restriction = Permit to Execute other Applications (NOT recommended)
 
OptionPanel.execute_scripts_without_exec_restriction = Permit to Execute other Applications (NOT recommended)
</pre>
+
&lt;/pre&gt;
  
 
For an example of how options can be registered at the option panel
 
For an example of how options can be registered at the option panel
see <tt>org.freeplane.plugin.script.ScriptingRegistration</tt>:
+
see &lt;tt&gt;org.freeplane.plugin.script.ScriptingRegistration&lt;/tt&gt;:
<groovy>
+
&lt;groovy&gt;
 
private void addPropertiesToOptionPanel() {
 
private void addPropertiesToOptionPanel() {
     final URL preferences = this.getClass().getResource("preferences.xml");
+
     final URL preferences = this.getClass().getResource(&quot;preferences.xml&quot;);
 
     if (preferences == null)
 
     if (preferences == null)
         throw new RuntimeException("cannot open preferences");
+
         throw new RuntimeException(&quot;cannot open preferences&quot;);
 
     modeController.getOptionPanelBuilder().load(preferences);
 
     modeController.getOptionPanelBuilder().load(preferences);
 
}
 
}
</groovy>
+
&lt;/groovy&gt;
  
 
The options can be queried like this:
 
The options can be queried like this:
<groovy>
+
&lt;groovy&gt;
 
String executeWithoutAsking = ResourceController.getResourceController()
 
String executeWithoutAsking = ResourceController.getResourceController()
     .getProperty("execute_scripts_without_asking");
+
     .getProperty(&quot;execute_scripts_without_asking&quot;);
</groovy>
+
&lt;/groovy&gt;
  
  
 
[[Category:Developer_Documentation]]
 
[[Category:Developer_Documentation]]

Revision as of 03:54, 24 November 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 <tt>freeplane_framework/ant</tt> 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): <pre> /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> </pre>

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 <tt>freeplane_framework/ant/build.xml</tt> like this: <pre>

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

</pre>


Tasks in Plugin development

Add options to the OptionPanel

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

The option names have to be added to <tt>Resource_en.properties</tt> (excerpt): <pre> 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) </pre>

For an example of how options can be registered at the option panel see <tt>org.freeplane.plugin.script.ScriptingRegistration</tt>: <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>