<< Websphere Terminology for newcomers | Home | How to extend Notes 8: coupling LiveText to a Java action >>

How to extend Notes 8: coupling text selection to Java action

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.

For this first post I'll touch on one of my favorite features of Notes 8 that is MyWidgets and LiveText. From the user interface you may create a number of widget types (web, Notes etc.) that act on selected text but what if you wanted to perform an action that didn't lend itself to one of these widget types? What if you wanted to couple text selection to a Java action? Well look no further. In this post I'll show you how to combine the org.eclipse.ui.popupMenus extension point with a org.eclipse.jface.text.ITextSelection object contribution to do what is transparently done using MyWidgets.

Let me preface this by saying that it's still far easier to do this using MyWidgets but still this isn't rocket science.

To accomplish this task you'll need two pieces. First of you need the code to execute. This is done using an action class that implements org.eclipse.ui.IObjectActionDelegate. This means you need to implement three methods:

  • public void setActivePart(IAction action, IWorkbenchPart part)
    Called when what's called the part is changed in Eclipse. You can leave this method blank.
  • public void selectionChanged(IAction action, ISelection selection)
    Called when you select some text in the Notes client and select your action. The purpose of this method is to extract the selected text and make it available to the run method (see below).
  • public void run(IAction action)
    This is the workhorse of the class and it's called whenever the action is selected from the context menu. The action will act on the selected text you extracted in the selectionChanged method.

The run-method isn't as interesting as it just performs the action. The method is called in the UI thread. The selectionChanged-method is more fun as this is where you extract the selected text. Below is a snippet of code on how to do it.

public void selectionChanged(IAction action, ISelection selection) {
   StructuredSelection sel = (StructuredSelection)selection;
   try {
      IAdapterManager amgr = Platform.getAdapterManager(); 
      Object obj1 = sel.getFirstElement();
      Object obj2 = amgr.getAdapter(obj1, ITextSelection.class);
      if (obj2 instanceof org.eclipse.jface.text.ITextSelection) {
         ITextSelection txtSelection = (ITextSelection)obj2;
         this.selection = txtSelection.getText();
   } catch (Throwable t) {
      this.selection = null;

The second piece to the puzzle is to tell the platform when you would like your action to be listed ie. when select is selected. This is done in the plugin.xml using the org.eclipse.ui.popupMenus extension point and by doing an object contribution as shown below. The italic text (the id's and the action label) may be changed to your liking. The bold/italic text is the class name of your action which should be changed to match your action class.

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
   <extension point="org.eclipse.ui.popupMenus">
               label="Perform action from selected text">

The next post (which will be published tomorrow) will show you how to act upon LiveText that is couple your Java action to text that the Notes client recognizes and highlights for you. Stay tuned...

Avatar: Keith Brooks

Re: How to extend Notes 8: coupling text selection to Java action

When you get a minute, can you edit these posts, which I think are great ideas, in a way that your average Admin can figure out what you are talking about and how to achieve it?
OK I admit it, again, I am not a developer.

Add a comment Send a TrackBack