Bug 573716 - [CDateTime] Exception if using CDateTime widget in NatTable
Summary: [CDateTime] Exception if using CDateTime widget in NatTable
Status: CLOSED FIXED
Alias: None
Product: NatTable
Classification: Technology
Component: Nebula Extension (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Dirk Fauth CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-23 12:21 EDT by Ralf Heydenreich CLA
Modified: 2021-06-07 06:52 EDT (History)
3 users (show)

See Also:


Attachments
fix for FocusOut bug in MacOS (2.04 KB, patch)
2021-05-23 16:49 EDT, Ralf Heydenreich CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Heydenreich CLA 2021-05-23 12:21:24 EDT
I've tried org.eclipse.nebula.widgets.nattable.examples._400_Configuration._440_Editing._448_CDateTimeEditorExample in a MacOS environment. By clicking on the Date button I expected that the dropdown appears. But there's only the following exception:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.internal.cocoa.NSView.isHiddenOrHasHiddenAncestor()" because "view" is null
	at org.eclipse.swt.widgets.Control.calculateVisibleRegion(Control.java:772)
	at org.eclipse.swt.widgets.Control.getVisibleRegion(Control.java:2060)
	at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:2190)
	at org.eclipse.swt.graphics.GC.<init>(GC.java:262)
	at org.eclipse.swt.graphics.GC.<init>(GC.java:223)
	at org.eclipse.nebula.cwt.v.VControl.computeSize(VControl.java:332)
	at org.eclipse.nebula.cwt.v.VControl.computeSize(VControl.java:274)
	at org.eclipse.nebula.cwt.v.VGridLayout.loadChildSizes(VGridLayout.java:416)
	at org.eclipse.nebula.cwt.v.VGridLayout.layout(VGridLayout.java:401)
	at org.eclipse.nebula.cwt.v.VPanel.layout(VPanel.java:189)
	at org.eclipse.nebula.cwt.v.VPanel.layout(VPanel.java:185)
	at org.eclipse.nebula.widgets.cdatetime.DatePicker.updateHeader(DatePicker.java:1380)
	at org.eclipse.nebula.widgets.cdatetime.DatePicker.updateLabels(DatePicker.java:1390)
	at org.eclipse.nebula.widgets.cdatetime.DatePicker.setFields(DatePicker.java:1021)
	at org.eclipse.nebula.widgets.cdatetime.CDateTime.createPicker(CDateTime.java:522)
	at org.eclipse.nebula.widgets.cdatetime.CDateTime.setOpen(CDateTime.java:1726)
	at org.eclipse.nebula.widgets.cdatetime.CDateTime.setOpen(CDateTime.java:1719)
	at org.eclipse.nebula.cwt.base.BaseCombo$3.handleEvent(BaseCombo.java:486)
	at org.eclipse.nebula.cwt.v.VControl.notifyListeners(VControl.java:633)
	at org.eclipse.nebula.cwt.v.VButton.filterEvent(VButton.java:121)
	at org.eclipse.nebula.cwt.v.VControl.handleEvent(VControl.java:213)
	at org.eclipse.nebula.cwt.v.VControl$1.handleEvent(VControl.java:160)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4441)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1512)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1535)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1520)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1324)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4227)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3837)
	at org.eclipse.nebula.widgets.nattable.examples.runner.TabbedNatExampleRunner.run(TabbedNatExampleRunner.java:114)
	at org.eclipse.nebula.widgets.nattable.examples.runner.TabbedNatExampleRunner.run(TabbedNatExampleRunner.java:62)
	at org.eclipse.nebula.widgets.nattable.examples.NatTableExamples.main(NatTableExamples.java:53)

After that, the aplication freezes and can only be killed. 

If I try the same example in a Windows environment it works nice (also in a Linux environment). So i did some effort to find the source of this error and it seems that MacOS fires a FocusOut event right after the click on the Button. There's a "suspicious" comment in org.eclipse.swt.widgets.Display.checkFocus():

		/*
		* Bug in Cocoa. On Mac 10.8, a control loses and gains focus
		* when its bounds changes.  The fix is to ignore these events.
		* See Bug 388574 & 433275.
		*/

But I'm not sure if this is really the reason of the bug. Would be nice if the bug could be fixed. At least I'll investigate it and try to find a solution (or workaround).
Comment 1 Dirk Fauth CLA 2021-05-23 12:41:33 EDT
You should assign this ticket to the Nebula project as it seems to be an issue in CDateTime and not NatTable. Maybe it is already fixed in a current version. Have you tried to use a newer Nebula version locally?
Comment 2 Ralf Heydenreich CLA 2021-05-23 14:12:33 EDT
I've tried the current Nebula master branch, same effect. If I use the CDateTime widget outside NatTable it works fine. So I assume that it has to do with the org.eclipse.nebula.widgets.nattable.extension.nebula.cdatetime.CDateTimeCellEditor. I've just created an ugly hack to verify my assumption: 


    private long currentTime = System.currentTimeMillis();

    @Override
    public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit) {
        if (SWT.getPlatform() == "cocoa") {
            long myTime = System.currentTimeMillis();
            long timeDiff = myTime - this.currentTime;
            System.err.println(timeDiff);
            if (timeDiff < 5000) {
                System.err.println("No Commit!");
                return false;
            }
            System.err.println("Commit!");
            this.currentTime = myTime;
        }
        return super.commit(direction, closeAfterCommit);
    }

If I place this code in the CDateTimeCellEditor the NPE only come up once. Hitting the button for the DateTime a second time launches the Calendar widget. So it seems to be any kind of focus error (I assume that the CDateTimeCellEditor lost focus and therefore the close-cascade is triggered).
Comment 3 Dirk Fauth CLA 2021-05-23 14:58:37 EDT
The NatTable framework adds a focus listener to close the editor if it looses the focus. Maybe that listener needs to be adjusted to ignore the event if the button is clicked.
Comment 4 Ralf Heydenreich CLA 2021-05-23 16:49:32 EDT
Created attachment 286441 [details]
fix for FocusOut bug in MacOS
Comment 5 Ralf Heydenreich CLA 2021-05-23 16:50:45 EDT
The attached patch seems to fix the problem.
Comment 6 Dirk Fauth CLA 2021-05-24 01:45:58 EDT
Thanks for the patch. Unfortunately I can't accept patches attached to the ticket. Please follow the contribution guideline and provide a patch via Gerrit so I can review it, a verification build is triggered and the contribution is automatically added to the contribution documents needed for the license stuff.
Comment 7 Eclipse Genie CLA 2021-05-31 17:20:30 EDT
New Gerrit change created: https://git.eclipse.org/r/c/nattable/org.eclipse.nebula.widgets.nattable/+/181201
Comment 8 Ralf Heydenreich CLA 2021-05-31 17:25:03 EDT
Hi Dirk, thanks for applying the patch. I didn't find the time to do it for myself, sorry. 

Want to give a +1
Comment 10 Dirk Fauth CLA 2021-05-31 17:31:46 EDT
I have taken your patch and added it manually as you did not respond here. I set you as the author to satisfy the process. Hope that is also fine. Although I am not happy with that setup, as it is much more work for the review.
Comment 11 Dirk Fauth CLA 2021-06-07 06:52:12 EDT
Released with 2.0.1