• Post Reply Bookmark Topic Watch Topic
  • New Topic

JFace Tableviewer

 
Kevin Myers
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a requirement to enable both a single and double click function on a JFace Tableviewer. So I used a selectionChangedListener for the single, and doubleClickListener for the double.
Problem is that each double click also fires the selectionChangeListener, which I am trying to avoid.

Is there anyway to prevent this?

Thanks,
Kevin..
 
Darryl Burke
Bartender
Posts: 5152
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the selection change occurs before the double click, I don't think there could be any way to prevent triggering the SelectionChangedEvent. Depending on what exactly is done by the code in selectionChanged(...), I see two possibilities:

Cache the selection at the end of the doubleClick(...) event and compare it to the current selection at the start of the method. If not the same, a SelectionChangedEvent has been fired, so roll back (undo) any side effects of selectionChanged(...)

OR

At the start of selectionChanged(...), introduce a delay (using a one-shot timer -- NOT Thread#sleep(...)) equivalent to the double click delay. On a Windows system, you can obtain this from the AWT Desktop Property "awt.multiClickInterval". See
http://download.oracle.com/javase/1.4.2/docs/guide/swing/1.4/w2k_props.html

Then conditionally execute the program logic in selectionChanged(...) depending on a boolean flag which you set true at the start of doubleClick(...) and unconditionally reset to false at the end of selectionChanged(...).

(Note: I don't use JFace so the suggestions are based on a quick reading of the documentation and considering how I might approach this problem in Swing.)
 
Kevin Myers
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Darryl, I happened to find something that does exactly what you describe.

For anyone else, it can be found here: http://dev.eclipse.org/newslists/news.eclipse.platform.swt/msg17585.html
Obviously, it needs to be altered a bit to work with the tableviewer, but the idea is the same.
 
Darryl Burke
Bartender
Posts: 5152
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, and it's good to know that I was on the right track. I took a look at the JFace Display API, and I see it's much like java.awt.Toolkit, but has quite a bit more of useful methods like the two used in the code on the page you linked (timerExec and getDoubleClickTime)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!