Friday, December 08, 2006

A Trisket, A Trasket, A Little Semantic Basket

Spent some time writing my first eclipse plug-in following the steps on the TopBraid Composer (TBC) Plug-in Development Guide, fun stuff! Plus I learned my new favorite eclipse command Ctrl+Shift+M which will automatically add the import for an unresolved class (keep your mouse over the class when hitting the sequence).

So I used the CreateInstanceAction skeleton and added my own JenaFu to find the resources I wanted from the loaded model, then printed the resources to System.out. It soon dawned on my that the snazier thing to do would be to send the resources to the "Basket" instead. Some inquiries to the TBC folks uncovered that the needed BasketView class was not exported from the jar in TBC 1.3, but they did export it in the 1.4 release that came out today. Thanks guys!

The tweaks needed:

import org.topbraidcomposer.ui.views.basket.BasketView;
:
IWorkbench wb = org.eclipse.ui.PlatformUI.getWorkbench();
IWorkbenchWindow wbw = wb.getActiveWorkbenchWindow();
IWorkbenchPage wbp = wbw.getActivePage();
:
try {
BasketView basket = (BasketView)wbp.showView("org.topbraidcomposer.ui.views.basket");
:
while (iter.hasNext) {
basket.add( (Resource)iter.next() );
}
:
}
catch(PartInitException ex) {
:
}

Some gotchas:

1) wb.getActiveWorkbenchWindow(); will return null if it is not invoked within a "UI Thread". So if these basket sending lines are in the "AbstractChange" class, or in another class that's called by the AbstractChange class, then you're in a UI Thread and it bombs.

2) code put after the TB.getSession().getChangeEngine().execute(change); will be executed before the line. Really.

3) you don't actually need the AbstractChange class and the corresponding TB...execute(change); line unless you've modified the loaded model.

4) if you do modify the model and want to send items to the basket, then invoke the TB...execute(change); line with an extra argument as per:

Runnable andThen = new Runnable() {
public void run() {
sendFoundStatementsToBasket();
}
};
TB.getSession().getChangeEngine().execute(change, andThen);

or with an anonymous runnable as the 2nd arg.

No comments: