Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to detect double mouse click in table cell?
How to detect double mouse click in table cell? [message #463351] Fri, 04 November 2005 00:39 Go to next message
Eclipse User
Originally posted by: siegfried.heintze.com

The following code works with a single click. How do I modify it so my
listener only executes when a single table cell has been double clicked?

I tried adding a MouseListener but that will only give me coordinates and
not the contents of the table cell. If I have coordinates, how do I get the
table cell contents?

Thanks,
Siegfried

table = new Table(this, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
data = new FormData();
data.top = new FormAttachment(0, 0);
data.bottom = new FormAttachment(100, 0);
data.left = new FormAttachment(sash, 0);
data.right = new FormAttachment(100, 0);
table.setLayoutData(data);
table.setHeaderVisible(true);
table.setLinesVisible(true);
table.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent event){
if(table.getSelectionCount()==1){
TableItem item =table.getSelection()[0];
String urlTarget = item.getText();
}
}
});

new TableColumn(table, 0).setText("Name");
new TableColumn(table, 1).setText("Value");
new TableColumn(table, 2).setText("Text");
Re: How to detect double mouse click in table cell? [message #463363 is a reply to message #463351] Fri, 04 November 2005 05:59 Go to previous messageGo to next message
venkataramana m is currently offline venkataramana m
Messages: 86
Registered: July 2009
Member
Check the code of JDT refactoring wizard.
org.eclipse.jdt.internal.ui.refactoring.ChangeParametersCont rol

May give you hints on what you need.

(Take help of "Navigation" > "Open Type" to open the class mentioned above)

Thanks
Venkat
Re: How to detect double mouse click in table cell? [message #463365 is a reply to message #463351] Fri, 04 November 2005 06:17 Go to previous messageGo to next message
Ricky is currently offline Ricky
Messages: 204
Registered: July 2009
Senior Member
> table.addSelectionListener(new SelectionAdapter(){
> public void widgetSelected(SelectionEvent event){
> if(table.getSelectionCount()==1){
> TableItem item =table.getSelection()[0];
> String urlTarget = item.getText();
> }
> }
> });

Overwrite widgetDefaultSelected(...) instead of widgetSelected(...). Let
me be suggest you to implement interfaces from scratch the first time you
use them. This way you figure out what information is provided by the
event source. The Adapter classes are for convenience only when you know
what you do not want implement.

Ricky
Re: How to detect double mouse click in table cell? [message #463369 is a reply to message #463365] Fri, 04 November 2005 10:50 Go to previous messageGo to next message
Eclipse User
Originally posted by: siegfried.heintze.com

Ricky,
That worked! Now, why is it that getSelection returns me an array of 1? I
can only get the contents of the first column! How do I get the second
column?
Thanks,
Siegfried
"Ricky" <ImmortalRick@gmx.de> wrote in message
news:op.szpqz32maudqvk@localhost.localdomain...
> > table.addSelectionListener(new SelectionAdapter(){
> > public void widgetSelected(SelectionEvent event){
> > if(table.getSelectionCount()==1){
> > TableItem item =table.getSelection()[0];
> > String urlTarget = item.getText();
> > }
> > }
> > });
>
> Overwrite widgetDefaultSelected(...) instead of widgetSelected(...). Let
> me be suggest you to implement interfaces from scratch the first time you
> use them. This way you figure out what information is provided by the
> event source. The Adapter classes are for convenience only when you know
> what you do not want implement.
>
> Ricky
Re: How to detect double mouse click in table cell? [message #463371 is a reply to message #463369] Fri, 04 November 2005 11:39 Go to previous message
Ricky is currently offline Ricky
Messages: 204
Registered: July 2009
Senior Member
> That worked! Now, why is it that getSelection returns me an array of 1? I
> can only get the contents of the first column! How do I get the second
> column?

The TableItem you receive from getSelection contains every column and you
get the contents of each one with getText(int).

This is only a guess as I havent done this myself and I dont know why you
want the column contents anyway. The SWT table is remarkable low level and
your data should be stored in a model. Then you need a class which can
convert your model object to a string suitable for a table column and a
class to put these strings into the table. When a row is selected get the
index of the row and resolve it back to your domain object in your model.

I will abandon the Table in favor of TableViewer and hope it is easier to
manage.

Ricky
Previous Topic:how to get current cursor location relative to current editor
Next Topic:ComboBoxCellEditor and TableViewer
Goto Forum:
  


Current Time: Thu Aug 28 09:14:42 EDT 2014

Powered by FUDForum. Page generated in 0.06333 seconds