Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » CellEditor activation on double click
CellEditor activation on double click [message #300362] Tue, 07 March 2006 22:44 Go to next message
Fabrizio Bertocci is currently offline Fabrizio BertocciFriend
Messages: 10
Registered: July 2009
Junior Member
Hi,
This question has been already asked in the past, but still I couldn't
find an answer to this:
Does anybody know how can I enable the CellEditor of a table only after
a double click instead of a single click?
I would like to have the capability to select a row with a single click
and edit a cell by double-clicking at it.

Any help is appreciated!
Fabrizio
Re: CellEditor activation on double click [message #300448 is a reply to message #300362] Thu, 09 March 2006 08:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: address.starts.after.hyphen-martin.umgeher.joanneum.at

Fabrizio Bertocci wrote:
> Hi,
> This question has been already asked in the past, but still I couldn't
> find an answer to this:
> Does anybody know how can I enable the CellEditor of a table only after
> a double click instead of a single click?
> I would like to have the capability to select a row with a single click
> and edit a cell by double-clicking at it.
>
> Any help is appreciated!
> Fabrizio

I also would like to do that, have posted this question several times,
never got an answer. There is a bug report that looks promising:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=87733

But it's from March 2005, and the only comment (from Veronika Irvine)
says 'This behaviour is provided by JFace. Moving to the UI component.'
which I don't understand: does it work, and I just can't find the
functionality? Or will it be possible in the next eclipse release?

If someone could shed some light on that subject, I'd be very thankful.

Regards,
M
Re: CellEditor activation on double click [message #300540 is a reply to message #300448] Fri, 10 March 2006 23:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: _NOSPAM_fabrizio.rti.com

Martin (& everybody else is interested to hear about this),
I gave a look at the Jface source code, and I now understand what does
that comment (in Bugzilla) means.

The TableViewer object uses this TableEditorImpl (so, not a
TableViewerImpl as stated in the bug report) to manage the low-level
interaction with the cell editor.

The TableEditorImpl sucks big time... these are some functions from that
file:
____________________________________________________
/**
* Handles the mouse down event; activates the cell editor.
* @param event the mouse event that should be handled
*/
public void handleMouseDown(MouseEvent event) {
if (event.button != 1)
return;

if (cellEditor != null)
applyEditorValue();

// activate the cell editor immediately. If a second mouseDown
// is received prior to the expiration of the doubleClick time then
// the cell editor will be deactivated and a doubleClick event will
// be processed.
//
doubleClickExpirationTime = event.time
+ Display.getCurrent().getDoubleClickTime();

Item[] items = getSelection();
// Do not edit if more than one row is selected.
if (items.length != 1) {
tableItem = null;
return;
}
tableItem = items[0];
activateCellEditor(event);
}

____________________________________________________
the 'activateCellEditor(event)' make sure that the click happens over an
editable cell and calculate which cell to edit, set some globals, then
pass the control to
'activateCellEditor()' (without arguments) that:
- implements the real activation of the cell editor
- installs a MouseListener to check if another click happens before
the double-click time. If this happen it 'cancel editing' and call the
TableViewer method 'handleDoubleClickEvent' (that fire up a 'double
click event' to the StructuredViewer (base class of TableViewer).


So, bottom line here, is that is not that simple to make this behavior
configurable, because there are a bunch of other classes that depends on
this behavior, and the entire API is designed around this behavior...
See, the method called to the TableViewer is 'handleDoubleClickEvent' ->
The entire class and interface structure is specifically designed to
work in this way...

Don't misunderstand me, I'm sure it is a perfectly possible job, but not
in 10 minutes (at least for me).

Fabrizio




martin wrote:
> Fabrizio Bertocci wrote:
>
>> Hi,
>> This question has been already asked in the past, but still I couldn't
>> find an answer to this:
>> Does anybody know how can I enable the CellEditor of a table only
>> after a double click instead of a single click?
>> I would like to have the capability to select a row with a single
>> click and edit a cell by double-clicking at it.
>>
>> Any help is appreciated!
>> Fabrizio
>
>
> I also would like to do that, have posted this question several times,
> never got an answer. There is a bug report that looks promising:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=87733
>
> But it's from March 2005, and the only comment (from Veronika Irvine)
> says 'This behaviour is provided by JFace. Moving to the UI component.'
> which I don't understand: does it work, and I just can't find the
> functionality? Or will it be possible in the next eclipse release?
>
> If someone could shed some light on that subject, I'd be very thankful.
>
> Regards,
> M
Re: CellEditor activation on double click [message #300545 is a reply to message #300540] Sat, 11 March 2006 17:10 Go to previous messageGo to next message
Stepan Rutz is currently offline Stepan RutzFriend
Messages: 52
Registered: July 2009
Member
Proposed workaround:

Add a new empty column at the beginning of the table/tree. This column
shows no content or the number of the record or a small icon like a small
4x4 pixel square. Also that column can be colored differently with an
ITableColorProvider or such.

The purpose of this non-editable column at the first position is to
provide a way to select columns. Its quite intuitive and users will find
out very soon that they can use it to select columns. A width of approx.
24 or 32 pixels will do so not much screen-estate is wasted.

Its just a workaround, since I myself ran into the hardwired behavior of
"single-click-always-edits"-problem.

/Stepan
Re: CellEditor activation on double click [message #300641 is a reply to message #300545] Tue, 14 March 2006 15:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: address.starts.after.hyphen-martin.umgeher.joanneum.at

Stepan Rutz wrote:
> Proposed workaround:
>
> Add a new empty column at the beginning of the table/tree. This column
> shows no content or the number of the record or a small icon like a
> small 4x4 pixel square. Also that column can be colored differently with
> an ITableColorProvider or such.
>
> The purpose of this non-editable column at the first position is to
> provide a way to select columns. Its quite intuitive and users will find
> out very soon that they can use it to select columns. A width of approx.
> 24 or 32 pixels will do so not much screen-estate is wasted.
>
> Its just a workaround, since I myself ran into the hardwired behavior of
> "single-click-always-edits"-problem.
>
> /Stepan
>
>


I played around a bit with this stuff and came up with a solution that
seems to work but is far from perfect. Class TableViewerSupport
implements the SWT Listener interface so that it gets the double-click
event and knows on what cell the action occured (thx to snippet 3). It
also implements ICellModifier and acts as a proxy for the actual
modifier of the TableViewer, only allowing cell modification during a
double-click event and delegating all other functionality. It's still
quite ugly (I don't like top-level classes implementing listener
interfaces, for example), but as I said---it seems to work.

To use it, pass your TableViewer instance to the static method
TableViewerSupport.enableDoubleClickEditing. I hope this helps someone.
If you find a big *ooups* in there, please tell me :)

Regards,
M

P.S. I'd still love to see the 'edit on double-click' functionality to
be part of SWT/jFace.



import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableItem;

public class TableViewerSupport implements Listener, ICellModifier {
private final TableViewer viewer;
private final ICellModifier modifier;
private boolean isEditingEnabled = false;

public static void enableDoubleClickEditing(TableViewer viewer) {
new TableViewerSupport(viewer);
}

private TableViewerSupport(TableViewer viewer) {
this.viewer = viewer;
modifier = viewer.getCellModifier();
viewer.setCellModifier(this);
viewer.getTable().addListener(SWT.MouseDoubleClick, this);
}

public void handleEvent(Event event) {
final Point pt = new Point(event.x, event.y);
final TableItem item = viewer.getTable().getItem(pt);
if (item != null) {
for (int column = 0; column < viewer.getTable().getColumnCount();
column++) {
Rectangle rect = item.getBounds(column);
if (rect.contains(pt)) {
isEditingEnabled = true;
viewer.editElement(item.getData(), column);
isEditingEnabled = false;
return;
}
}
}
}

public boolean canModify(Object element, String property) {
return isEditingEnabled && modifier.canModify(element, property);
}

public Object getValue(Object element, String property) {
return modifier.getValue(element, property);
}

public void modify(Object element, String property, Object value) {
modifier.modify(element, property, value);
}
}
Re: CellEditor activation on double click [message #1843719 is a reply to message #300641] Sun, 15 August 2021 23:30 Go to previous message
Marco Lopes is currently offline Marco LopesFriend
Messages: 61
Registered: September 2010
Member
In 2021 i found your workaround PERFECT!

I was hacking in a similar way, BUT was using the cancelEditing() method (NOT the desired effect at all, because the cell was first edited)

Thanks!

EDIT: Spoke too soon! :\ This blocks all the input through the keyboard... only the mouse events work.

[Updated on: Mon, 16 August 2021 00:55]

Report message to a moderator

Previous Topic:Unable to create the selected preference page.
Next Topic:PerspectiveSwitcher
Goto Forum:
  


Current Time: Tue Jul 23 05:18:57 GMT 2024

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

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

Back to the top