Question

I have a TableViewer within my View and I would like to use the org.eclipse.ui.edit.selectAll command to select all rows using the standard Ctrl+A shortcut.

When I put tracing on I can see the HandlerAuthority class resolves some conflicts and the output looks like this:

HANDLERS >>> Command('org.eclipse.ui.edit.selectAll') has changed to 'org.eclipse.ui.internal.handlers.SelectAllHandler' as its handler
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=org.eclipse.ui.edit.selectAll,
    handler=org.eclipse.ui.internal.handlers.SelectAllHandler@2a3e58,
    expression=,sourcePriority=0)
HANDLERS >>> Resolved conflict detected.  The following activation won: 
HANDLERS >>>     HandlerActivation(commandId=org.eclipse.ui.edit.selectAll,
    handler=org.eclipse.ui.internal.handlers.SelectAllHandler@2a3e58,
    expression=,sourcePriority=0)
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=org.eclipse.ui.edit.selectAll,
    handler=org.eclipse.ui.internal.handlers.SelectAllHandler@2a3e58,
    expression=,sourcePriority=0)
HANDLERS >>> Resolved conflict detected.  The following activation won: 
HANDLERS >>>     HandlerActivation(commandId=org.eclipse.ui.edit.selectAll,
    handler=org.eclipse.ui.internal.handlers.SelectAllHandler@2a3e58,
    expression=,sourcePriority=0)
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=org.eclipse.ui.edit.selectAll,
    handler=ActionHandler(RetargetAction(selectAll)),
    expression=ActiveShellExpression(Shell {SPL v0.1.2 (VYVOJ) (DB TEST)}),sourcePriority=17408)
HANDLERS >>>     resolveConflicts: eval: HandlerActivation(commandId=org.eclipse.ui.edit.selectAll,
    handler=org.eclipse.ui.internal.handlers.SelectAllHandler@2a3e58,
    expression=,sourcePriority=0)
HANDLERS >>> Resolved conflict detected.  The following activation won: 
HANDLERS >>>     HandlerActivation(commandId=org.eclipse.ui.edit.selectAll,
    handler=ActionHandler(RetargetAction(selectAll)),
    expression=ActiveShellExpression(Shell {SPL v0.1.2 (VYVOJ) (DB TEST)}),sourcePriority=17408)
HANDLERS >>> Command('org.eclipse.ui.edit.selectAll') has changed to 'ActionHandler(RetargetAction(selectAll))' as its handler

When I press Ctrl+A I can see:

KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 9403459, character = 0x0)
    KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x61, time = 9403553, character = 0x1)
    KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+A])
    KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'org.eclipse.ui.edit.selectAll', parameters = {})
    KEYS >>>     not handled

Debugging the RetargetAction I found that the Action is not handled because it has no handler set.

So my question is, why the HandlerAuthority sets an RetargetAction as a handler for the org.eclipse.ui.edit.selectAll command? I would like to use the default one (org.eclipse.ui.internal.handlers.SelectAllHandler).

Was it helpful?

Solution

All actions which are intended to be implemented by multiple views and editors use RetargetAction. You hook in to the retarget action in your view like this:

IActionBars bars = getViewSite().getActionBars();

bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAllAction);

where selectionAllAction is an Action that does the select all on your table. The action might look like:

class SelectAllAction extends Action
{
  private final TableViewer tableViewer;

  SelectAllAction(final TreeViewer viewer)
  {
    tableViewer = viewer;
  }


  @Override
  public void run()
  {
    tableViewer.getTable().selectAll();

    // Get table view selection synchronized with table selection

    tableViewer.setSelection(tableViewer.getSelection());
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top