Question

How to add right-mouse click listener on a TableViewer item?

Était-ce utile?

La 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.

Autres conseils

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;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top