« Andere agenda's tonen in je eigen agenda | Main| Ubuntu en Notes »

Showing notes data in a plugin for ND8/85

Category
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 

ND8, based on eclipse and expeditor, makes it possible to build eclipse plugins and use them in the Notes client (in a composite application). IBM has a wiki with a lot of information on how to create a plugin. But there's a lot to know about the subject, and it's not al there. I've been busy with eclipse plugins for composite applications since the beta's of ND8. As a result we won the Best Lotus Notes 8 Composite Application Award at LotuSphere in January. Time to share some of that knowledge.


The Jface TreeViewer,as described in this article, is a nice way to display data from notes. The resulting view could look like this: books.gif
But how to populate it with Notes data? You can add a TreeContentProvider to a TreeView class. The contentprovider is responsible for fetching the content. treeViewer.setContentProvider(new TreeContentProvider());
I'll let the ContentProvider fetch data trough its constructor. My contentProvider has a fillNodes method. That method uses a NotesJob, an extension to the Eclipse Job class, to retrieve data from a background thread. Using a background thread means that te application doesn't "hang" while it fetches data.

public void fillNodes() {
NotesJob job = new NotesJob("NotesJob-BuildTree") {
protected IStatus runInNotesThread(IProgressMonitor arg0)
throws NotesException {

Session session;
session = NotesPlatform.getInstance().getSession();
final DbManager dbm = new DbManager(session);

nodes = dbm.getNodes();

return Status.OK_STATUS;

}
};
job.addJobChangeListener(this);
job.setPriority(Job.SHORT);
job.schedule();
}


I'll let my ContentProvider class implement the IJobChangeListener, which lets me implement some methods for tracking a Job's status, for example when the job finished running. When my Job is finished it has collected all the data from Notes, and the TreeContentProvider is ready to populate the TreeView with it. But I should let the TreeView know that there's data ready for it to show. When the Job is done I'll start a new thread to update the TreeView.


public void done(IJobChangeEvent arg0) {
Thread t = new Thread() {
public void run() {
treeview.refresh();
}
};
treeview.getControl().getDisplay().asyncExec(t);

}

When you call the refresh method of a Treeviewer it calls it's contentprovider to populate it with data. The contentProvider has a private List nodes; That List is filled by the NotesJob. The contentProvider uses the public Object[] getChildren(Object parentElement) to get all elements. In this case that method returns return nodes.toArray(); Thats' enough for the TreeViewer to pass to the LabelProvider to populate it's columns.



The flow of the plugin:
// create a new TreeViewer
tree = new Tree(client, SWT.FULL_SELECTION);
treeViewer = new TreeViewer(tree);
// add a contentprovider and a label provider
treeViewer.setContentProvider(new TreeContentProvider());
//The constructor of the contentProvider calls the fillNodes method. As soon as the job.schedule is done the program returns, it doesn't wait for the job to finish, so it goes on with adding the LabelProvider and the code that follows. That also means the ui keeps responsive.
treeViewer.setLabelProvider(new TreeLabelProvider());


As soon as the Job that's scheduled is finished the TreeContentProvider calls the treeView to let it update it's contents.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

OpenNTF random projects

PlanetLotus