Eclipse RCP right click event
-
06-07-2021 - |
Question
How to add right-mouse click listener on a TableViewer
item?
Solution
If you are referring to a JFace TableViewer
, you can use the following approach assuming viewer
is your TableViewer
.
MenuManager manager = new MenuManager();
viewer.getControl().setMenu(manager.createContextMenu(viewer.getControl()));
manager.add(new Action("MENU ITEM TEXT", ImageDescriptor.createFromImage(YOUR_IMAGE)) {
@Override
public void run() {
// get the current selection of the tableviewer
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
// do something
}
});
Otherwise, please clarify your question.
OTHER TIPS
You can get the Table of the TableViewer and call
public void addMouseListener (MouseListener listener)
the MouseEvent will tell you which mouse-button was pressed
/**
* the button that was pressed or released; 1 for the
* first button, 2 for the second button, and 3 for the
* third button, etc.
*/
public int button;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow