As I briefly described in my last post (“How to extend Notes 8: dynamic extensions using Java“) it’s possible to create new extensions to Lotus Notes using Java and hence inject functionality into the client dynamically. It’s very cool functionality and it allows you to inject anything from content types and recognizers to sidebar panels.
In this post I’ll build on three previous posts and show you how to use dynamic extensions in Lotus Notes in combination with a Java action that uses multiple capture groups for an end-to-end solution that may be deployed as a single Java extension (aka plugin). The result is a plugin that may be deployed to a client workstations which allows you to act on text recognized by the LiveText sub-system but where you have the power of Java for processing.
All the posts in the series may be found under the extending_notes8 tag.
We need three pieces of information:
- The code to dynamically inject our custom recognizer and content type into Lotus Notes without the need for an extension.xml file. This is what the LiveText sub-system uses to highlight the text for us.
- The Java action to act on the LiveText selection.
- The plugin.xml file to bind it all together.
The first piece is the code that injects the custom recognizer and content type under a known id. This code may be run in lots of ways but to make it easy for this example I choose a sidebar panel. Below is the createPartControl-method from that class.
public void createPartControl(final Composite parent) {
try {
// define XML
final String extensionXml = ...;
// get extension registry and load extension
// into registry
final IExtensionRegistry reg = Platform.getExtensionRegistry();
InputStream ins = new ByteArrayInputStream(extensionXml.getBytes());
Bundle bundle = Activator.getDefault().getBundle();
IContributor contr = ContributorFactoryOSGi.createContributor(bundle);
reg.addContribution(ins, contr, false, null, null, null);
} catch (Throwable t) {
t.printStackTrace();
}
}
The above code injects the recognizer and content type with an id of DCCT.ExampleContentType.1234567890 into the client.
The next part we need is the action class (again implementing org.eclipse.ui.IObjectActionDelegate) to act on the LiveText selection. Most of the code you’ve seen before in a previous post but again it goes and get the text from the underlying document as document properties.
public void selectionChanged(IAction action, ISelection selection) {
IDocumentContent doc = null;
// cast/adapt selection
if (selection instanceof StructuredSelection) {
Object sel = ((StructuredSelection)selection).getFirstElement();
if (sel instanceof IDocumentContent) {
doc = (IDocumentContent)sel;
}
} else if (selection instanceof IDocumentContent) {
doc = (IDocumentContent)selection;
} else {
// try and adapt
IAdapterManager amgr = Platform.getAdapterManager();
doc = (IDocumentContent)amgr.getAdapter(selection,
IDocumentContent.class);
}
if (null == doc) {
this.contents = null;
this.prodFamily = null;
this.partNumber = null;
return;
}
// get data from document property
this.contents = doc.getProperties().getProperty("contents");
this.prodFamily = doc.getProperties().getProperty("pf");
this.partNumber = doc.getProperties().getProperty("pn");
}
The last piece is the plugin.xml to put it all together using the org.eclipse.ui.popupMenus extension point. Notice how we use the content type id we know (bold text below) from our dynamically deployed content type.
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
id="com.lekkimworld.extnotes8.dynext.objCtr1"
objectClass="com.ibm.rcp.content.IDocumentContent">
<visibility>
<and>
<objectState
name="content.type"
value="DCCT.ExampleContentType.1234567890">
</objectState>
<objectState
name="contents"
value="*">
</objectState>
</and>
</visibility>
<action
class="com.lekkimworld.extnotes8.dynext.MyAction"
enablesFor="*"
id="com.lekkimworld.extnotes8.dynext.action1"
label="Do me!">
</action>
</objectContribution>
</extension>
The result when deployed to a Lotus Notes client is something like the screenshot below where you get a Java action to act on a LiveText recognition. Only change this time is that all the functionality is provided from your plugin. No separate extension.xml is necessary for the recognizer or the content type.
That’s how it’s done. I’ve uploaded an Eclipse project to the blog so you can download it and install it in your Eclipse as a demo. You can download the project here.