Eclipse Search

Loading

Sep 30, 2008

Generic Collapse All Handler

Eclipse 3.4 provides a generic Collapse All handler which you could use with any TreeViewer. CollapseAll is just a matter of calling treeViewer.collapseAll(), so why does it needs a special handler? The reason is simple: Uniformity. If every TreeViewer uses this handler, you could use the same key binding across all the TreeViewers. For example, the default key binding for this command is Ctrl+Shift+Numeric_Divide. Unfortunately, my laptop doesn't have a numeric keypad. So I can configure it to something like Ctrl+Shift+Y (oh, boy. With loads of plugins in my workspace, its hard to find an unused key binding!), and start using it in every TreeViewer.

The code is pretty simple - Create an instance of the handler with the TreeViewer; get the IHandlerService and activate the handler:

collapseAllHandler = new CollapseAllHandler(treeViewer);
IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class);
service.activateHandler(CollapseAllHandler.COMMAND_ID, collapseAllHandler);

0 comments:

Post a Comment