Community
Participate
Working Groups
I am implementing an action handler on the Table editor that should act on the selected column. The handler calls HandlerUtil.getCurrentStructuredSelection(event) to get the selection, which comes up as a DCell when the cell is applicable to the line (from which I can figure out the column), but a DLine when the cell is not applicable. What I would expect is to still be able to find the selected column in the latter case. This is possible for the framework's HideAction for example. I found a workaround via internal APIs as follows: val editor = HandlerUtil.getActiveEditor(event) as AbstractDTableEditor val viewer = editor.tableViewer as DTableViewerManager val index = viewer.activeColumn if (index > 0) { val line = object as DLine var container = line.container while (container instanceof DLine) { container = container.container } val column = (container as DTable).columns.get(index-1) return doExecute(event, column) } but of course I would rather not have to use internal API. I think there should be a way to determine the selected cell or column in all cases from action handlers.
Hi, I agree that you should be able to retrieve more easily the information. However you can reuse the current mechanism used to retrieve the active column if you want to avoid depending on internal: private int activeColumn; protected void triggerColumnSelectedColumn() { treeViewer.getTree().addMouseListener(new MouseAdapter() { @Override public void mouseDown(final MouseEvent event) { int x = 0; for (int i = 0; i < treeViewer.getTree().getColumnCount(); i++) { x += treeViewer.getTree().getColumn(i).getWidth(); if (event.x <= x) { activeColumn = i; break; } } } }); treeViewer.getTree().addKeyListener(new KeyListener() { @Override public void keyPressed(final KeyEvent e) { if (e.keyCode == SWT.ARROW_LEFT && activeColumn > 0) { activeColumn--; treeViewer.getTree().showColumn(treeViewer.getTree().getColumn(activeColumn)); } else if (e.keyCode == SWT.ARROW_RIGHT && activeColumn < treeViewer.getTree().getColumnCount() - 1) { activeColumn++; treeViewer.getTree().showColumn(treeViewer.getTree().getColumn(activeColumn)); } } @Override public void keyReleased(final KeyEvent e) { }; }); } You can get the treeviewer by casting the editor to org.eclipse.emf.common.ui.viewer.IViewerProvider and using the getViewer() method.