Forums Register Login

JFace Tableviewer

+Pie Number of slices to send: Send
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..
+Pie Number of slices to send: Send
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.)
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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)
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2448 times.
Similar Threads
JTable events and listeners - prevent multiple executions
Add an image to tableviewer
SWT Print selective components
Using TableCursor & ICellModifier together
Jface tableviewer multi sort columns
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:10:39.