Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » CellEditor on DoubleCLick?
CellEditor on DoubleCLick? [message #1007877] Thu, 07 February 2013 21:53 Go to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 259
Registered: July 2012
Senior Member
The cellEditor is triggered on leftclick now.
Is it possible to trigger it on double click?
Re: CellEditor on DoubleCLick? [message #1007911 is a reply to message #1007877] Fri, 08 February 2013 07:19 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1719
Registered: July 2012
Senior Member
You need to register your own edit bindings. By default the DefaultEditBindings are registered via DefaultGridLayerConfiguration. And there the edit actions are binded against the first single click. You need to change this to registerFirstDoubleClickBinding(), then it should only open on double click. Remember that you have to avoid registering the default configuration.
Re: CellEditor on DoubleCLick? [message #1007913 is a reply to message #1007877] Fri, 08 February 2013 07:29 Go to previous messageGo to next message
Alexander Becher is currently offline Alexander BecherFriend
Messages: 4
Registered: July 2009
Junior Member
Try something like this:

addConfiguration(new DefaultEditBindings() {

	@Override
	public void configureUiBindings(UiBindingRegistry pUiBindingRegistry) {
		BodyCellEditorMouseEventMatcher mouseEventMatcher = new BodyCellEditorMouseEventMatcher(
				DelegatingCellEditor.class) {

			@Override
			public boolean matches(NatTable pNatTable,
					MouseEvent pEvent, LabelStack pRegionLabels) {
				if (pEvent != null && pEvent.button == 1) {
					return super.matches(pNatTable, pEvent,
							pRegionLabels);
				}
				return false;
			}

		};
		pUiBindingRegistry.registerDoubleClickBinding(
				mouseEventMatcher, new MouseEditAction());
		pUiBindingRegistry.registerFirstMouseDragMode(
				mouseEventMatcher, new CellEditDragMode());
		
		pUiBindingRegistry.registerKeyBinding(new SpecialCharacterKeyEventMatcher(),  new SpecialCharacterKeyEditAction());
		
		
	}

});


Cheers

Alex
Re: CellEditor on DoubleCLick? [message #1007936 is a reply to message #1007911] Fri, 08 February 2013 10:19 Go to previous messageGo to next message
Alex Kipling is currently offline Alex KiplingFriend
Messages: 259
Registered: July 2012
Senior Member
Thnx Dirk!
Thnx Alexander , it was very helpful!

[Updated on: Tue, 12 February 2013 16:31]

Report message to a moderator

Re: CellEditor on DoubleCLick? [message #1690370 is a reply to message #1007936] Thu, 26 March 2015 22:34 Go to previous messageGo to next message
Richard Dazzle is currently offline Richard DazzleFriend
Messages: 4
Registered: February 2015
Junior Member
Hi everyone
I would also like to have cell editor triggered on double-click, not single-click.

I tried to incorporate the above code fragment into my code, but confused by the "DelegatingCellEditor", "SpecialCharacterKeyEventMatcher", and "SpecialCharacterKeyEditAction".
Using NatTable 1.2.0 so maybe the above no longer appropriate?

Any help or hints much appreciated.
Many thanks Smile
Re: CellEditor on DoubleCLick? [message #1690500 is a reply to message #1690370] Fri, 27 March 2015 16:12 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1719
Registered: July 2012
Senior Member
Those classes were never part of NatTable. Those SpecialXxx classes seem to be used for activating editors on pressing special keys. The delegating class seems to wrap and combine several editors so you only need one configuration. Not sure if this is still needed.
Re: CellEditor on DoubleCLick? [message #1690707 is a reply to message #1690500] Mon, 30 March 2015 17:36 Go to previous messageGo to next message
Richard Dazzle is currently offline Richard DazzleFriend
Messages: 4
Registered: February 2015
Junior Member
Hi Dirk

Many thanks for the reply.
I pared-down the code to the following, but still get edit on single-click but now after short delay (presume to check was not double-click?).
Maybe previous bindings need unregistering first? If so how do I find out what they are?

addConfiguration( new DefaultEditBindings()
    {

      @Override
      public void configureUiBindings( UiBindingRegistry uiBindingRegistry )
      {

        uiBindingRegistry.registerDoubleClickBinding( new CellEditorMouseEventMatcher(), new MouseEditAction() );
        uiBindingRegistry.registerFirstMouseDragMode( new CellEditorMouseEventMatcher(), new CellEditDragMode() );

      }

    } );


Any help appreciated. Apologies if the questions are bit stupid!

PS. Congratulations on releasing NatTable 1.3.0 ! I will try it soon Smile
Re: CellEditor on DoubleCLick? [message #1690717 is a reply to message #1690707] Mon, 30 March 2015 19:30 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1719
Registered: July 2012
Senior Member
Are you using the GridLayer with default configuration turned on? There the DefaultEditBindings are registered. In that case you just add another set of bindings.
Re: CellEditor on DoubleCLick? [message #1691182 is a reply to message #1690717] Thu, 02 April 2015 22:14 Go to previous messageGo to next message
Richard Dazzle is currently offline Richard DazzleFriend
Messages: 4
Registered: February 2015
Junior Member
Still not managed to get it work.

Based on your comment "just add another set of bindings" this is my latest attempt.
    // create grid layer composite
    GridLayer grid = new GridLayer( viewport, colHeader, rowHeader, corner );

    // configure NatTable with grid, theme, and labels
    setLayer( grid );
    addConfiguration( m_theme );  // just slightly modified modern theme
    addConfiguration( m_labels );  // labels for style and enabling editing etc

    addConfiguration( new XEditBindings() );  // *** try to have cell editor on double-click ***

    configure();


Where XEditBindings is (based on DefaultEditBindings)
public class XEditBindings extends AbstractUiBindingConfiguration
{

  @Override
  public void configureUiBindings( UiBindingRegistry uiBindingRegistry )
  {
    // configure the space key to activate a cell editor via keyboard
    // this is especially useful for changing the value for a checkbox
    uiBindingRegistry.registerKeyBinding( new KeyEventMatcher( SWT.NONE, 32 ), new KeyEditAction() );
    uiBindingRegistry.registerKeyBinding( new KeyEventMatcher( SWT.NONE, SWT.F2 ), new KeyEditAction() );
    uiBindingRegistry.registerKeyBinding( new LetterOrDigitKeyEventMatcher(), new KeyEditAction() );
    uiBindingRegistry.registerKeyBinding( new LetterOrDigitKeyEventMatcher( SWT.SHIFT ), new KeyEditAction() );

    uiBindingRegistry.registerDoubleClickBinding( new CellEditorMouseEventMatcher( GridRegion.BODY ),
        new MouseEditAction() );

    uiBindingRegistry.registerSingleClickBinding( new CellEditorMouseEventMatcher( GridRegion.BODY ),
        new SelectCellAction() );

    uiBindingRegistry.registerMouseDragMode( new CellEditorMouseEventMatcher( GridRegion.BODY ),
        new CellSelectionDragMode() );

    uiBindingRegistry.registerFirstSingleClickBinding( new CellPainterMouseEventMatcher( GridRegion.BODY,
        MouseEventMatcher.LEFT_BUTTON, CheckBoxPainter.class ), new SelectCellAction() );

    uiBindingRegistry.registerFirstMouseDragMode( new CellPainterMouseEventMatcher( GridRegion.BODY,
        MouseEventMatcher.LEFT_BUTTON, CheckBoxPainter.class ), new CellSelectionDragMode() );
  }
}


Cells on single click get selected fine, then after about quarter-of-second the cell editor starts!
Re: CellEditor on DoubleCLick? [message #1691192 is a reply to message #1691182] Fri, 03 April 2015 05:41 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1719
Registered: July 2012
Senior Member
You are creating the GridLayer with the default configuration turned on. It needs to be turned off, since otherwise you have two edit bindings configured!

Regarding the delay. You register editing on double click and selection in single click. The system therefore waits if a double click happens. But selection is handled by the SelectionLayer configuration and it is triggered on mouseDown. There is no need for you to register that.
Re: CellEditor on DoubleCLick? [message #1691193 is a reply to message #1691192] Fri, 03 April 2015 06:12 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1719
Registered: July 2012
Senior Member
To be more precise, create the GridLayer with autoconfigure = false and remove the binding for single click in your edit configuration.
Re: CellEditor on DoubleCLick? [message #1691217 is a reply to message #1691193] Fri, 03 April 2015 14:00 Go to previous message
Richard Dazzle is currently offline Richard DazzleFriend
Messages: 4
Registered: February 2015
Junior Member
Excellent, many thanks Dirk - now all working correctly!

For others trying to do same thing he's my working code
    // create grid layer composite
    GridLayer grid = new GridLayer( viewport, colHeader, rowHeader, corner, false );
    grid.addConfiguration( new XGridLayerConfiguration() );

    // configure NatTable with grid, theme, and labels
    setLayer( grid );
    addConfiguration( m_theme );  // just slightly modified modern theme
    addConfiguration( m_labels );  // labels for style and enabling editing etc
    configure();

And
public class XGridLayerConfiguration extends AggregateConfiguration
{
  public XGridLayerConfiguration()
  {
    // add default editing handler config
    addConfiguration( new DefaultEditConfiguration() );

    // instead of default editing UI config "DefaultEditBindings"
    addConfiguration( new AbstractUiBindingConfiguration()
    {
      @Override
      public void configureUiBindings( UiBindingRegistry uiBindingRegistry )
      {
        uiBindingRegistry.registerKeyBinding( new KeyEventMatcher( SWT.NONE, SWT.F2 ), new KeyEditAction() );
        uiBindingRegistry.registerKeyBinding( new LetterOrDigitKeyEventMatcher(), new KeyEditAction() );
        uiBindingRegistry.registerKeyBinding( new LetterOrDigitKeyEventMatcher( SWT.SHIFT ), new KeyEditAction() );

        uiBindingRegistry.registerFirstDoubleClickBinding( new CellEditorMouseEventMatcher( GridRegion.BODY ),
            new MouseEditAction() );
      }
    } );

    // add default print UI bindings
    addConfiguration( new DefaultPrintBindings() );

    // add default excel export UI bindings
    addConfiguration( new DefaultExportBindings() );
  }

[Updated on: Fri, 03 April 2015 14:02]

Report message to a moderator

Previous Topic:Static Filter event trigger
Next Topic:column span - disappearing
Goto Forum:
  


Current Time: Thu Jul 02 23:23:56 GMT 2015

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

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