<< How to extend Notes 8: coupling LiveText to a Java action | Home | How to extend Notes 8: coupling custom LiveText recognisers to a Java action >>

How to extend Notes 8: using the other built in LiveText recognisers with Java actions

I get so many question on how to extend Notes 8 that I finally decided to create a series of blog posts on how to do it. All the posts in the series may be found under the extending_notes8 tag. In all of the examples I assume a working knowledge of Eclipse and Java programming and how to work with extension points.

This second post builds upon the "How to extend Notes 8: coupling LiveText to a Java action"-post posted earlier. Most of the post is the same but you'll need to change the content type to act on. Read on.

My Notes 8.5 client comes with the follow built in recognizers:

RecognizerContent type
Phone numbercontent.phone
Addresscontent.address
Organizationcontent.org
Personcontent.person
Web sitecontent.web
The trick is to couple our definitions in plugin.xml to the right content type. So to attach to a recognized web address you need to specify content.web as the content type as shown below:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
  <extension point="org.eclipse.ui.popupMenus">
    <objectContribution
          id="com.lekkimworld.livetext.objectContribution2"
          objectClass="com.ibm.rcp.content.IDocumentContent">
       <action
             class="com.lekkimworld.livetext.Action1"
             id="com.lekkimworld.livetext.action2"
             label="Do stuff with web address!">
       </action>
       <visibility>
          <and>
             <objectState name="content.type" value="content.web" />
             <objectState name="contents" value="*" />
          </and>
       </visibility>
    </objectContribution>
  </extension>
</plugin>

Now also change your action to extract the right property from the document. All the IBM recognizers stick the recognized text in the "contents" property so simply grab that. Some of the recognizers (person and address) also have some sub-parts you could extract but I find the recognizers so flaky that I haven't invested much time in using them. I find the web and phone recognizers the only useful ones. Below is some sample code for the selectionChanged method.

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.selection = null;
      return;
   }
   
   // get text from document property
   this.selection = doc.getProperties().getProperty("contents");
}




Add a comment Send a TrackBack