donderdag 26 maart 2009

Perspective lifecycle

Some actions need to appear in every view, like a help button that will open a page on an online help system like a Wiki.
You can add that action programmatically by intercepting perspective lifecyle events using a PerspectiveAdapter.

Set up a help listener in ApplicationWorkbenchWindowAdvisor.postWindowOpen():
public void postWindowOpen() {
// setup perspective change listener

In the HelpManager class you add the listener:
public static void setUpHelpListener() {
Display display = Display.getDefault();
if (null != display) {
display.asyncExec(new Runnable() {
public void run() {
final IWorkbench workbench = PlatformUI.getWorkbench();
// listen for changes that may occur
addPerspectiveListener(new PerspectiveAdapter() {

public void perspectiveChanged(IWorkbenchPage page,
IPerspectiveDescriptor perspective,
IWorkbenchPartReference partRef, String changeId) {

if ((partRef instanceof IViewReference)
&& (changeId == IWorkbenchPage.CHANGE_VIEW_SHOW)) {
IViewReference viewRef = (IViewReference) partRef;
String id = viewRef.getId();
addhelpAction(workbench, id);

if (changeId == IWorkbenchPage.CHANGE_RESET_COMPLETE) {

public void perspectiveOpened(IWorkbenchPage page,
IPerspectiveDescriptor perspective) {

public void perspectiveActivated(IWorkbenchPage page,
IPerspectiveDescriptor perspective) {
// System.out.println("PerspectiveChangeListener installed");

} else {
// TODO error handling
// System.out.println("PerspectiveChangeListener installation failed");

And in scanAllViews you scan the registered views:
private void IWorkbench scanAllViews() {
final IWorkbench workbench = PlatformUI.getWorkbench();
// add to all existing views
IViewDescriptor[] views = workbench.getViewRegistry().getViews();
for (IViewDescriptor view : views) {
String id = view.getId();
addhelpAction(workbench, id);

Setting up the help actions can be done like this:
private static void addhelpAction(final IWorkbench workbench, String id) {
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
if(null == activeWorkbenchWindow)
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if(null == activePage)
IViewPart viewPart = activePage.findView(id);
if (null == viewPart)
IToolBarManager toolBarManager = viewPart.getViewSite().
IAction action = ViewHelpUrlAction.createInstance(viewPart);
if (null == toolBarManager.find(ViewHelpUrlAction.ID)) {
// System.out.println("ADDING TB: " + id);
if (null == toolBarManager.find(IWorkbenchActionConstants.MB_ADDITIONS)) {
toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
toolBarManager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, action);
IMenuManager menuManager = viewPart.getViewSite().getActionBars().getMenuManager();
if (null == menuManager.find(ViewHelpUrlAction.ID)) {
// System.out.println("ADDING MB: " + id);
if (null == menuManager.find(IWorkbenchActionConstants.MB_ADDITIONS)) {
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menuManager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, action);

That's it! Your action can then take the desired action, like opening a page on a Wiki with the view name as key.

vrijdag 20 maart 2009

Dutch Eclipse User Group started

Linkedin hosts a Dutch Eclipse User Group as group for Eclipse users located in the Netherlands.

I was contacted two years ago by a fellow Dutchman, because my email address in an eclipse bug report had a .nl suffix.

With many people having multiple email addresses and everybody using his gmail or yahoo for online contacts, we need new ways to determine the union between compatriots and Eclipse users. If only to meet every now and then and talk about Eclipse.

donderdag 19 maart 2009

RCP Default Perspective and Workspace

Setting the default perspective in an RCP application is something I needed for a specialist toolset I'm developing.

I first came to Eclipse when I needed a specialist editor to edit EULUMDAT files, the standard photometric data format in the European lighting industry.

I needed to edit large sets, so I came to Eclipse and before I knew it I had my own editor and verification builder running and published it as an Eclipse plugin.

Many people are scared of by the magnitude of Eclipse, so I now offer an RCP version for Windows and Mac as well, but an RCP version based on the Eclipse IDE. Naturally I want to start up in my own perspective rather than the Resource perspective and store the projects in my own space:

You need to add the following directives to your products config.ini file:

#Product Runtime Configuration File