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
- 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:
Post a Comment