Bug 540408 - Allow action handlers to get the active column when non-applicable cell is selected
Summary: Allow action handlers to get the active column when non-applicable cell is se...
Status: NEW
Alias: None
Product: Sirius
Classification: Modeling
Component: Table (show other bugs)
Version: 6.1.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2018-10-23 14:38 EDT by Maged Elaasar CLA
Modified: 2019-01-08 11:48 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maged Elaasar CLA 2018-10-23 14:38:59 EDT
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.
Comment 1 Pierre Guilet CLA 2019-01-08 11:48:59 EST
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.