Hi All, we have an app with a TableViewer containing a check box (image) and our users have requested we provide them the ability to just "swipe" select each row, rather than having to individually click on each one. To be specific, the want to just hold down the left mouse button and drag it over the checkbox cells, to quickly select many of them.
I don't think there is an SSCCE yet. But I think I know what Kevin M means.
The old way: you click a check box. You click the one below. You click the one below. Continue until done.
The preferred way: you click on a check box. You drag the mouse down. All check boxes encountered while pressed become checked. Continue until the mouse is released.
If this is done with a JTable then a MouseListener / MouseMotionListener (hooray for MouseInputListener!) could help.
Step 1: mouseClicked. Translate the point to a cell (using JTable's rowAtPoint and columnAtPoint methods). Check the current contents. Flip the boolean, store that, set that for the cell.
Step 2: mouseDragged. Again, translate, then set the stored value for the cell.
Step 3: mouseReleased. Well, you're done.
Keep in mind to only do this for the right columns.
I've got most of it implemented (no I'm not going to post code; we are NotACodeMill. In essence it's as I described though). First I encountered the issue where the cell where the mouse was pressed was not changed; the others were. I found out this is caused by the cell editor that's still active. After getting rid of that behaviour (either by canceling the editing or by making isCellEditable return false for that column; the listener will handle the toggling, even on single clicks). However, now the dragging also selects the cells. I'm sure someone can help solve that.
Joined: Aug 17, 2010
Thanks for the responses Kevin & Rob.
What Rob suggested is what I'm looking for...(although I'm not sure how it's different then what Kevin said).
Anyway, now I'm a bit confused, which is probably due to being very new at this stuff....but isn't JTable a swing component?
I was actually trying to implement this using an swt/jface table.
Joined: Sep 28, 2010
Kevin Myers wrote:(although I'm not sure how it's different then what Kevin said).
If I understand Rob (and myself) accurately, we're talking about two different things: the selections (highlighted or not highlighted) of the table rows, and the selections (checked or not checked) of the checkboxes in a specific column of the table rows.
Kevin Myers wrote:I was actually trying to implement this using an swt/jface table.
That's another reason I suggested an SSCCE. I couldn't tell what components you were actually working with.
I think the same technique can be used. Replace java.awt.event.MouseListener with org.eclipse.swt.event.MouseListener and java.awt.event.MouseMotionListener with org.eclipse.swt.event.MouseMoveListener. The major difference is that that one doesn't have a dragged event, so you'll need to use the moved event and store whether or not the mouse is down (if this isn't stored in MouseEvent's stateMask field).