Difference between revisions of "Equinox Integration 2/Tutorial Extension Point"
From ADempiere
This Wiki is read-only for reference purposes to avoid broken links.
(backlink) |
m (credits to Joerg Viola) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | by [[User:Viola|Joerg Viola]] | ||
+ | |||
If you want to extract some functionality out of the core and | If you want to extract some functionality out of the core and | ||
provide a new extension point so that plug-ins can provide an extension, | provide a new extension point so that plug-ins can provide an extension, | ||
read on. | read on. | ||
− | Example: Let plugins implement how invoices are posted to | + | Example: Let plugins implement how invoices are posted to FACT. |
= Replace core code by call to service = | = Replace core code by call to service = | ||
− | * Navigate to Doc_Invoice. | + | * Navigate to Doc_Invoice.createFacts() |
− | * Insert the line <code>IInvoicePoster invoicePoster = Service. | + | * Insert the line <code>IInvoicePoster invoicePoster = Service.''locator()''.getInvoicePoster()</code>. Eclipse will highlight some errors, we will repeatedly use Code assist (Ctrl-1) to proceed. |
* Position the cursor on <code>IInvoicePoster</code>, create new interface using code assist. | * Position the cursor on <code>IInvoicePoster</code>, create new interface using code assist. | ||
** Create the interface in the package <code>org.adempiere.base</code> | ** Create the interface in the package <code>org.adempiere.base</code> | ||
− | ** In this package, all core interfaces should | + | ** In this package, all core interfaces should reside. |
** Create the (empty) interface and save. | ** Create the (empty) interface and save. | ||
* Back to Doc_Invoice, position the cursor on <code>getInvoicePoster()</code>, create new method using code assist. | * Back to Doc_Invoice, position the cursor on <code>getInvoicePoster()</code>, create new method using code assist. | ||
Line 32: | Line 34: | ||
</pre> | </pre> | ||
* The last step is defining the extension point. Open base/META-INF/MANIFEST.MF, the description of the base Plugin. | * The last step is defining the extension point. Open base/META-INF/MANIFEST.MF, the description of the base Plugin. | ||
− | ** Open the tab "Extension | + | ** Open the tab "Extension Points" |
** Click add. | ** Click add. | ||
** Enter the id given above, fill the other fields an click Finish. | ** Enter the id given above, fill the other fields an click Finish. | ||
Line 52: | Line 54: | ||
** Open tab "Extensions", add "org.adempiere.base.InvoicePoster" extension point | ** Open tab "Extensions", add "org.adempiere.base.InvoicePoster" extension point | ||
** On this point, add via context add a new "client" | ** On this point, add via context add a new "client" | ||
− | ** Via click on the label of the class attribute, create a new implementation of the interface InvoicePoster | + | ** Via click on the label of the class attribute, create a new implementation of the interface InvoicePoster, say MyInvoicePoster |
+ | ** look out! - it automagically has an empty <code>post()</code> method | ||
* Now Move the code from the original <code>createFacts()</code> method to the newly created <code>post</code> method. | * Now Move the code from the original <code>createFacts()</code> method to the newly created <code>post</code> method. | ||
** This step may include a little more work on sorting out modularity issues. | ** This step may include a little more work on sorting out modularity issues. |
Latest revision as of 17:14, 22 November 2010
by Joerg Viola
If you want to extract some functionality out of the core and provide a new extension point so that plug-ins can provide an extension, read on.
Example: Let plugins implement how invoices are posted to FACT.
Replace core code by call to service
- Navigate to Doc_Invoice.createFacts()
- Insert the line
IInvoicePoster invoicePoster = Service.locator().getInvoicePoster()
. Eclipse will highlight some errors, we will repeatedly use Code assist (Ctrl-1) to proceed. - Position the cursor on
IInvoicePoster
, create new interface using code assist.- Create the interface in the package
org.adempiere.base
- In this package, all core interfaces should reside.
- Create the (empty) interface and save.
- Create the interface in the package
- Back to Doc_Invoice, position the cursor on
getInvoicePoster()
, create new method using code assist.- The new method is inserted in the interface IServiceLocator. Save it.
- Back to Doc_Invoice, insert the line
invoicePoster.post()
- create new method post() using code assist.
- The method is inserted into the new interface
IInvoicePoster
- The method is inserted into the new interface
Locate and define extension point
- Notice there is now a compile error in
EquinoxServiceLocator
. This is the equinox implementation ofIServiceLocator
. It now lacks the implementation ofgetInvoicePoster()
.- We want to invoke an extension. So we look for extensions by an extension point id, say
org.adempiere.base.InvoicePoster
. - This is done by the
ExtensionList
(Beware! If more than one plugin will be installed providing extensions to InvoicePoster, only one will be executed this way. You can nevertheless iterate over all extension usingExtensionList
, if you want.):
- We want to invoke an extension. So we look for extensions by an extension point id, say
public Callout getInvoicePoster() { ExtensionList<IInvoicePoster> list = new ExtensionList<IInvoicePoster>(IInvoicePoster.class, "org.adempiere.base.InvoicePoster"); return list.first(); }
- The last step is defining the extension point. Open base/META-INF/MANIFEST.MF, the description of the base Plugin.
- Open the tab "Extension Points"
- Click add.
- Enter the id given above, fill the other fields an click Finish.
- The extension point schema opens. Enter some explanation and open tab "Definition".
- Click "New Element".
- Add New Element
- Name it client.
- On client, add a New Attribute
- Name it class, type is java, on implements, choose the interface
IInvoicePoster
- Select extension, add New Choice, from its context, add new client.
- Save all files, you're ready.
Write the plugin
- Now what is left? - We want the move code outside the core into a plugin. So lets do that.
- Create a New project, from "Plug-in Development", choose "Plug-in project".
- The manifest editor opens.
- Open tab "Dependencies", add "org.adempiere.base" as a required plugin.
- Open tab "Extensions", add "org.adempiere.base.InvoicePoster" extension point
- On this point, add via context add a new "client"
- Via click on the label of the class attribute, create a new implementation of the interface InvoicePoster, say MyInvoicePoster
- look out! - it automagically has an empty
post()
method
- Now Move the code from the original
createFacts()
method to the newly createdpost
method.- This step may include a little more work on sorting out modularity issues.
- Deploy your new plugin as well as the base plugin and watch it running.
- Congratulations, ADempiere core is now more modular, thank you!
Return to ADempiere/Equinox Integration 2