Tuesday, March 3, 2009

Listening for selected Lotus Notes documents

If you want to react when documents are selected in the Notes client, you will use the Eclipse Selection Service.

When listening you can reference the some of the document summary classes
  • DocumentSummary (base class for selections)
  • NotesDocumentSummary (document selection in view or when opened)
  • NotesOpenDocumentSummary (only when opened)
  • NotesFieldSelection (field activation in open document)
  • NotesLiveNameSelection (live name field activation in open document)
  • And many others
The classes are located in the following plug-ins
  • com.ibm.csi
  • com.ibm.notes.client

Creating the listener


// Prepare the selection listening. Start by getting the selection service.
ISelectionService ss = getSite().getWorkbenchWindow().getSelectionService();

// Create a selection listener
listener = new ISelectionListener() {

public void selectionChanged(IWorkbenchPart part, ISelection selection) {

// Is the selection a structured selection
if (selection instanceof IStructuredSelection) {

// Get the selection (could contain multiple selected objects)
IStructuredSelection ss = (IStructuredSelection) selection;

// Are the any objects in the selection?
if (ss.isEmpty()) return;

// Let's test the first selected object
Object e = ss.getFirstElement();

// Is the object a NotesOpenDocumentSummary?
if (e instanceof NotesOpenDocumentSummary) {
NotesOpenDocumentSummary ds = (NotesOpenDocumentSummary)e;
String title = ds.getTitle();
String url = ds.getUrl();

//...

}
}
}
};

// Add a post selection listener, so we don't have to listen to
// insignificant UP and DOWN keystroke selection triggering,

// we just need the final selection.

ss.addPostSelectionListener( listener);

Removing the listener
Remember to remove you listener when done.

// Do the following in the dispose() method of the view part or alike.

public void dispose() {
if (listener != null) {
ISelectionService ss = getSite().getWorkbenchWindow().getSelectionService();
ss.removePostSelectionListener(listener);
}
super.dispose();
}

No comments:

Search This Blog

Eclipse Live: Equinox Ganymede

The creator of an Eclipse Bible, introduces Equinox and its building blocks for creating applications. We overview the architecture and technology, and demonstrate many of the building blocks.
by Jeff McAffer (Code 9)