We will use the classical Hello world as the first simple example
of an extension. This extension will add a new menu item in the
menu which displays a popup with the text "Hello world!" when
selected. Copy the XML code below and save it to a file in
the /WEB-INF/extensions
directory. The filename must end with .xml
.
If you have enabled automatic installation just wait a few seconds and the
extension will be installed automatically. Otherwise you may have to do a manual scan:
( → ).
When the extension has been installed you should have a new menu item:
→ which pops up a message in a Javascript window.Note | |
---|---|
You may have to logout and login again to see the new menu item. |
<?xml version="1.0" encoding="UTF-8" ?> <extensions xmlns="http://base.thep.lu.se/extensions.xsd"> <extension id="net.sf.basedb.clients.web.menu.extensions.helloworld" extends="net.sf.basedb.clients.web.menu.extensions" > <index>1</index> <about> <name>Hello world</name> <description> The very first extensions example. Adds a "Hello world" menu item that displays "Hello world" in a javascript popup when selected. </description> </about> <action-factory> <factory-class> net.sf.basedb.clients.web.extensions.menu.FixedMenuItemFactory </factory-class> <parameters> <title>Hello world!</title> <tooltip>This is to test the extensions system</tooltip> <onClick>alert('Hello world!')</onClick> <icon>/images/info.gif</icon> </parameters> </action-factory> </extension> </extensions>
The <extensions>
tag is the root
tag and is needed to set up the namespace and schema validation.
The <extension>
defines a new
extension. It must have an id
attribute that
is unique among all installed extensions and an extends
attribute which id the ID of the extension point. For the id
attribute we recommend using the same naming conventions as for java
packages. See Java naming
conventions from Sun.
The <about>
tag is optional and
can be used to provide meta information about the extension. We
recommend that all extensions are given at least a
<name>
. Other supported subtags are:
<description>
<version>
<copyright>
<contact>
<email>
<url>
Global about tag | |
---|---|
|
The <action-factory>
tag is required and
so is the <factory-class>
subtag. It tells
the extension system which factory to use for creating actions. The
FixedMenuItemFactory
PermissionMenuItemFactory
The <parameters>
subtag is used to
provide initialisation parameters to the factory. Different factories
supports different parameters and you will have to check the javadoc documentation
for each factory to get information about which parameters that are supported.
Tip | |
---|---|
In case the factory is poorly documented you can always assume that public
methods the start with |
A single extension can extend multiple extension points as long as their
action classes are compatible. This is for, for example, the case when
you want to add a button to more than one toolbar.
To do this use the <extends>
tag with multiple <ref>
tags.
You can skip the extends
attribute in the main tag.
<extension id="net.sf.basedb.clients.web.menu.extensions.history-edit" > <extends> <ref index="2">net.sf.basedb.clients.web.tabcontrol.edit.sample</ref> <ref index="2">net.sf.basedb.clients.web.tabcontrol.edit.extract</ref> </extends> ... </extension>
This is a feature of the XML format only. Behind the scenes two extensions will be created (one for each extension point). The extensions will share the same action and renderer factory instances. Since the id for an extension must be unique a new id will be generated by combining the original id with the parts of the id's from the extension points.