Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » right-click on TableItem
right-click on TableItem [message #462139] Fri, 07 October 2005 06:47 Go to next message
Eclipse UserFriend
Originally posted by: fabian.eberhardt.sap.com

Hi,

I've got a Table, TableView, LabelProvider, ContentProvider, TableCursor.
How can I detect a right-click on a tableItem and provide a context menu?

With
addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
}
public void mouseDoubleClick(MouseEvent e){
}
public void mouseUp(MouseEvent e) {
}
});
I can add this Listener to the TableCursor. But I can't detect a
right-click.

Any ideas?

Regards,
Fabian
Re: right-click on TableItem [message #462162 is a reply to message #462139] Fri, 07 October 2005 13:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ddana78ar.yahoo.com.ar

table.addMouseListener(new MouseListener() {
public void mouseUp(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
if (event.button==3){
Menu menu = new Menu (table.getShell(), SWT.POP_UP);
MenuItem item = new MenuItem (menu, SWT.PUSH);
item.setText ("item 1");

//draws pop up menu:
Point pt = new Point (event.x, event.y);
pt = table.toDisplay (pt);
menu.setLocation (pt.x, pt.y);
menu.setVisible (true);
}
}
public void mouseDoubleClick(MouseEvent e) {
}
});
Re: right-click on TableItem [message #462179 is a reply to message #462162] Fri, 07 October 2005 15:02 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Ideally the listener should be SWT.MenuDetect, in order to preserve native
menu-show behaviour differences.

Grant

"DD" <ddana78ar@yahoo.com.ar> wrote in message
news:14443634.1128690409290.JavaMail.root@cp1.javalobby.org...
> table.addMouseListener(new MouseListener() {
> public void mouseUp(MouseEvent e) {
> }
> public void mouseDown(MouseEvent e) {
> if (event.button==3){
> Menu menu = new Menu (table.getShell(), SWT.POP_UP);
> MenuItem item = new MenuItem (menu, SWT.PUSH);
> item.setText ("item 1");
>
> //draws pop up menu:
> Point pt = new Point (event.x, event.y);
> pt = table.toDisplay (pt);
> menu.setLocation (pt.x, pt.y);
> menu.setVisible (true);
> }
> }
> public void mouseDoubleClick(MouseEvent e) {
> }
> });
Re: right-click on TableItem [message #462187 is a reply to message #462179] Fri, 07 October 2005 16:05 Go to previous message
James Cornett is currently offline James CornettFriend
Messages: 3
Registered: July 2009
Junior Member
This is what I'm doing.

private void init() {
PopupListener listner = new PopupListener();
setPopupListener(listener);
Menu menu = new Menu(tree);

MenuItem item = new MenuItem(menu, SWT.NONE);
item.setText("Do Something");
item.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e)
{
}
public void widgetSelected(SelectionEvent e)
{
fireDoSomething();
}
});
}

public void setPopupMenu(Menu menu)
{
popupMenu = menu;
}

public void setPopupListener(Listener listener)
{
tree.removeListener(SWT.MenuDetect, popupListener);
popupListener = listener;
tree.addListener(SWT.MenuDetect, popupListener);
}

class PopupListener implements Listener
{
public void handleEvent(Event event)
{
if ( (tree.getSelection().length > 0) && (popupMenu != null) &&
(!popupMenu.isDisposed())) {

popupMenu.setLocation(event.x, event.y);
popupMenu.setVisible(true);

while (!popupMenu.isDisposed() && popupMenu.isVisible()) {
if (!Display.getCurrent().readAndDispatch())
Display.getCurrent().sleep();
}
}
}
}



"Grant Gayed" <grant_gayed@ca.ibm.com> wrote in message
news:di62mr$vrg$1@news.eclipse.org...
> Ideally the listener should be SWT.MenuDetect, in order to preserve native
> menu-show behaviour differences.
>
> Grant
>
> "DD" <ddana78ar@yahoo.com.ar> wrote in message
> news:14443634.1128690409290.JavaMail.root@cp1.javalobby.org...
>> table.addMouseListener(new MouseListener() {
>> public void mouseUp(MouseEvent e) {
>> }
>> public void mouseDown(MouseEvent e) {
>> if (event.button==3){
>> Menu menu = new Menu (table.getShell(), SWT.POP_UP);
>> MenuItem item = new MenuItem (menu, SWT.PUSH);
>> item.setText ("item 1");
>>
>> //draws pop up menu:
>> Point pt = new Point (event.x, event.y);
>> pt = table.toDisplay (pt);
>> menu.setLocation (pt.x, pt.y);
>> menu.setVisible (true);
>> }
>> }
>> public void mouseDoubleClick(MouseEvent e) {
>> }
>> });
>
>
Previous Topic:menu accelerators
Next Topic:Is an editor maximized or not ?
Goto Forum:
  


Current Time: Tue Sep 29 23:50:43 GMT 2020

Powered by FUDForum. Page generated in 0.02546 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top