Bug 516266 - provide better way to identify tree or table column in certain event like SWT.MenuDetect
Summary: provide better way to identify tree or table column in certain event like SWT...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.6   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-05 14:25 EDT by Espinosa CZ CLA
Modified: 2017-06-14 07:25 EDT (History)
2 users (show)

See Also:


Attachments
modified Snippet311 (4.75 KB, text/x-java)
2017-06-14 07:25 EDT, Lakshmi P Shanmugam CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Espinosa CZ CLA 2017-05-05 14:25:43 EDT
Please provide better way to identify tree or table column in certain event like SWT.MenuDetect (that is right mouse click event).

Also discussed here:
http://stackoverflow.com/questions/17289624/how-to-find-index-of-swt-table-column

Background:
In my app I have different context menus for different columns and different for table header and table main body. It is a directory viewer based on multi column TreeView. For Name column header, in the context menu, user can choose sorting details like "Name only" or "File Type and Name". On Date column header, there is a different context menu where they can choose date format, etc. When right clicked on Tree body, on regular rows, user is presented with yet a different context menu: standard file operations like file details, rename, copy, etc..

Problem:
Right click is captured by a Tree wide SWT.MenuDetect listener. Not very intuitive by the way, but it seems to be the only way. Luckily it also reacts on Tree/Table header, unlike let's say MouseDown. So far good.
Problem is, the Event handed down to listener contains very little information to identify column and header or body area. The Event.widget field references whole table, not a column like in SWT.Selection event. There is not other field like (column) index or column reference. 

The recommended way, seen in various examples*, uses table.getItem(point) to get  
TableItem. But that does not work for headers and empty tables. For header one can use workaround by randomly picking any TableItem, but for empty tables there is no work around, it a dead end. They simply have no TableItem in them.

[*] http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet3.java

So the only work around currently working is to use a "phony table item". A phony TableItem briefly added to the table in the event processing, added just to get column bounds and then quickly removed; ideally before UI notices any updates and can react by unwanted redraws.

It is a unintuitive, hackish approach, not worthy a RCP platform like Eclipse.

For anyone interested, you can see my implementation here:
http://stackoverflow.com/questions/17289624/how-to-find-index-of-swt-table-column/43795381#43795381

Proposed solution is to add a column reference, in any form, passed down to the handler with every MenuDetect event.

And/Or a method to convert a point to column index, working also for headers and empty tables.

And/Or a method providing column bounds, working also for empty tables and headers.
Comment 1 Lakshmi P Shanmugam CLA 2017-06-14 07:25:41 EDT
Created attachment 268904 [details]
modified Snippet311

There is no direct way to identify the column in the SWT.MenuDetect event.
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet311.java shows a way to identify MenuDetect event in Table header using the event co-ordinates. I've attached the modified version of the snippet which also identifies the column index in the MenuDetect event. It has been tested on Mac.