Honoring single click support

The General Preferences allow users to specify whether views should open their objects on single or double click.

General "Open mode" preferences with disclaimer that the preference may not take effect in all views

Why the disclaimer about this preference not working for all views?  Because views contributed by plug-ins must explicitly support this preference in their implementation.

Recall that a view can be implemented by creating SWT controls and writing standard SWT code, or by using JFace viewers to handle the low level details.  Honoring the single click preference can be done at either level.  Most views that open other objects present them in a structured, list-like view.  We'll focus on that kind of view for now.  If your view displays objects in a different manner, you'll likely use the SWT-level concepts to support single click.

Single click in JFace viewers

If you are using a JFace list-oriented viewer to present your objects, supporting single click is straightforward.  Instead of using addDoubleClickListener to trigger opening the items in your view, use addOpenListener.  The open listener honors the current workbench preference, firing the open event when the specified mouse event occurs.

You may still wish to use addDoubleClickListener for non-open actions, such as expanding the items in a tree on double-click.

Single click in SWT controls

JFace provides a utility class, OpenStrategy, to handle the logistics of single and double click at the SWT control level.  The OpenStrategy is configured by the General Preferences dialog so that it honors the current workbench open preference. In fact, the JFace viewers use this class to implement the open listener. 

You must create an OpenStrategy and associate it with your SWT control.  The OpenStrategy will hook the appropriate events and interpret them based on the user preferences.  Your job is to add an open listener to the strategy that implements the code for open.  In this way, you are shielded from knowledge about which widget event triggered the open event.

OpenStrategy openHandler = new OpenStrategy(control);
openHandler.addOpenListener(new IOpenEventListener() {
	public void handleOpen(SelectionEvent e) {
	// code to handle the open event.

The other workbench preferences for open (select on hover, open using arrow keys) are also handled by OpenStrategy.  This means that the "right thing" will happen if you use JFace viewers or the OpenStrategy class to implement open behavior.

Activating editors on open

When handling an open event, you should use OpenStrategy.activateOnOpen() to determine whether an opened editor should be activated by default.  Activating an editor switches the focus from the view to the editor, which can be particularly confusing and undesirable in single click mode.