You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by David Keen <DK...@sigtec.com> on 2011/12/21 00:48:41 UTC

ListViewItemEditor issue with consuming mouseDown events

Hi,

I have implemented a subclass of TableViewRowEditor which doesn't allow the user to close the editor if the input is not valid (along the lines of http://apache-pivot-users.399431.n3.nabble.com/TextInput-and-Validator-issues-tp2641141p2648160.html).

I have been attempting to do the same with a ListViewItemEditor and found what looks like a bug.  I didn't subclass the editor as it would require me to override nearly every method, so I just copied the code into my own class.

The issue is that I can open the item for editing but can't stop the editor from closing if the input is invalid.  Pressing enter or escape is fine - the editor remains open and focussed, but I'm not prevented from clicking anywhere else with the mouse (editor still remains open, but not focussed).

Having a look at the code, I believe the issue is in the mouseDown method of displayMouseHandler.  When I changed the code there to mirror that of TableViewRowEditor, the issue is resolved for me.  It looks like the mouse click is not consumed when it should be.

As an aside, there were 2 commits (revisions 1041913 and 1079009) which changed this code in TableViewRowEditor to the current code.  Looking briefly at TreeViewNodeEditor leads me to suspect that it too would benefit from this fix (although I haven't used it so can't confirm that).

So the fix that I did was to change this:

        @Override
        public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
            Display display = (Display)container;
            Window window = (Window)display.getComponentAt(x, y);

            if (window != ListViewItemEditor.this) {
                endEdit(true);
            }

            return false;
        }

To this:

        @Override
        public boolean mouseDown(Container container, Mouse.Button button, int x, int y) {
            Display display = (Display)container;
            Window window = (Window)display.getComponentAt(x, y);

            boolean consumed;
            if (window != ListViewItemEditor.this
                && (window == null || !isOwner(window))) {
                endEdit(true);
                consumed = true;
            } else {
                consumed = false;
            }

            return consumed;
        }

Regards,
David

Re: ListViewItemEditor issue with consuming mouseDown events

Posted by Chris Bartlett <cb...@gmail.com>.
I just took a very quick look at this.

Am I right in thinking that when editing a row in a TableView, the
current functionality results in the row being saved (ie, not
cancelled) if a mouse click is made away from the editor, but if that
mouse click is within the TableView another row will not be selected?

So the editor is closed, but no other rows will be selected until a
subsequent mouse click or keyboard event, and that this is the
behaviour you are looking for with ListView?

If so, my quickly hacked together example combined with your change
does seem to result in the same behavior with a ListView by consuming
the mouse click.


However looking at the KitchenSink & TableRowEditor demos, ListView
and TreeView behave differently to TableView during editing.
http://pivot.apache.org/demos/table-row-editor.html
http://pivot.apache.org/demos/kitchen-sink.html
Lists -> Editable
Trees -> Editable

Personally I would have expected the ListView & TreeView behaviour
over the TableView behaviour, but that is probably a separate debate
worthy of its own thread.  I think the important thing is for as much
consistency as possible between TableView, ListView & TreeView.

Chris

On 21 December 2011 10:19, Chris Bartlett <cb...@gmail.com> wrote:
> David,
>
> Around a year ago there were a number of changes made to
> TableViewRowEditor its usage.  It went through a few different designs
> in a short period of time in order to accommodate use cases like
> yours.  From memory I couldn't tell you where the design ended up or
> whether it should actually be considered a final design, but it
> wouldn't surprise me if the changes were not mirrored to the ListView
> & TreeView components.  In general, a change to any one of TableView,
> ListView or TreeView might need to be repeated for the other two in
> order to maintain consistency, so your observations sound plausible.
>
> This is one old thread that might be relevant
> http://apache-pivot-users.399431.n3.nabble.com/TableView-selectedRowChanged-tp1992938p1992938.html
>
> Chris
>
> On 21 December 2011 06:48, David Keen <DK...@sigtec.com> wrote:
>> Hi,
>>
>>
>>
>> I have implemented a subclass of TableViewRowEditor which doesn’t allow the
>> user to close the editor if the input is not valid (along the lines of
>> http://apache-pivot-users.399431.n3.nabble.com/TextInput-and-Validator-issues-tp2641141p2648160.html).
>>
>>
>>
>> I have been attempting to do the same with a ListViewItemEditor and found
>> what looks like a bug.  I didn’t subclass the editor as it would require me
>> to override nearly every method, so I just copied the code into my own
>> class.
>>
>>
>>
>> The issue is that I can open the item for editing but can’t stop the editor
>> from closing if the input is invalid.  Pressing enter or escape is fine –
>> the editor remains open and focussed, but I’m not prevented from clicking
>> anywhere else with the mouse (editor still remains open, but not focussed).
>>
>>
>>
>> Having a look at the code, I believe the issue is in the mouseDown method of
>> displayMouseHandler.  When I changed the code there to mirror that of
>> TableViewRowEditor, the issue is resolved for me.  It looks like the mouse
>> click is not consumed when it should be.
>>
>>
>>
>> As an aside, there were 2 commits (revisions 1041913 and 1079009) which
>> changed this code in TableViewRowEditor to the current code.  Looking
>> briefly at TreeViewNodeEditor leads me to suspect that it too would benefit
>> from this fix (although I haven’t used it so can’t confirm that).
>>
>>
>>
>> So the fix that I did was to change this:
>>
>>
>>
>>         @Override
>>
>>         public boolean mouseDown(Container container, Mouse.Button button,
>> int x, int y) {
>>
>>             Display display = (Display)container;
>>
>>             Window window = (Window)display.getComponentAt(x, y);
>>
>>
>>
>>             if (window != ListViewItemEditor.this) {
>>
>>                 endEdit(true);
>>
>>             }
>>
>>
>>
>>             return false;
>>
>>         }
>>
>>
>>
>> To this:
>>
>>
>>
>>         @Override
>>
>>         public boolean mouseDown(Container container, Mouse.Button button,
>> int x, int y) {
>>
>>             Display display = (Display)container;
>>
>>             Window window = (Window)display.getComponentAt(x, y);
>>
>>
>>
>>             boolean consumed;
>>
>>             if (window != ListViewItemEditor.this
>>
>>                 && (window == null || !isOwner(window))) {
>>
>>                 endEdit(true);
>>
>>                 consumed = true;
>>
>>             } else {
>>
>>                 consumed = false;
>>
>>             }
>>
>>
>>
>>             return consumed;
>>
>>         }
>>
>>
>>
>> Regards,
>>
>> David

Re: ListViewItemEditor issue with consuming mouseDown events

Posted by Chris Bartlett <cb...@gmail.com>.
David,

Around a year ago there were a number of changes made to
TableViewRowEditor its usage.  It went through a few different designs
in a short period of time in order to accommodate use cases like
yours.  From memory I couldn't tell you where the design ended up or
whether it should actually be considered a final design, but it
wouldn't surprise me if the changes were not mirrored to the ListView
& TreeView components.  In general, a change to any one of TableView,
ListView or TreeView might need to be repeated for the other two in
order to maintain consistency, so your observations sound plausible.

This is one old thread that might be relevant
http://apache-pivot-users.399431.n3.nabble.com/TableView-selectedRowChanged-tp1992938p1992938.html

Chris

On 21 December 2011 06:48, David Keen <DK...@sigtec.com> wrote:
> Hi,
>
>
>
> I have implemented a subclass of TableViewRowEditor which doesn’t allow the
> user to close the editor if the input is not valid (along the lines of
> http://apache-pivot-users.399431.n3.nabble.com/TextInput-and-Validator-issues-tp2641141p2648160.html).
>
>
>
> I have been attempting to do the same with a ListViewItemEditor and found
> what looks like a bug.  I didn’t subclass the editor as it would require me
> to override nearly every method, so I just copied the code into my own
> class.
>
>
>
> The issue is that I can open the item for editing but can’t stop the editor
> from closing if the input is invalid.  Pressing enter or escape is fine –
> the editor remains open and focussed, but I’m not prevented from clicking
> anywhere else with the mouse (editor still remains open, but not focussed).
>
>
>
> Having a look at the code, I believe the issue is in the mouseDown method of
> displayMouseHandler.  When I changed the code there to mirror that of
> TableViewRowEditor, the issue is resolved for me.  It looks like the mouse
> click is not consumed when it should be.
>
>
>
> As an aside, there were 2 commits (revisions 1041913 and 1079009) which
> changed this code in TableViewRowEditor to the current code.  Looking
> briefly at TreeViewNodeEditor leads me to suspect that it too would benefit
> from this fix (although I haven’t used it so can’t confirm that).
>
>
>
> So the fix that I did was to change this:
>
>
>
>         @Override
>
>         public boolean mouseDown(Container container, Mouse.Button button,
> int x, int y) {
>
>             Display display = (Display)container;
>
>             Window window = (Window)display.getComponentAt(x, y);
>
>
>
>             if (window != ListViewItemEditor.this) {
>
>                 endEdit(true);
>
>             }
>
>
>
>             return false;
>
>         }
>
>
>
> To this:
>
>
>
>         @Override
>
>         public boolean mouseDown(Container container, Mouse.Button button,
> int x, int y) {
>
>             Display display = (Display)container;
>
>             Window window = (Window)display.getComponentAt(x, y);
>
>
>
>             boolean consumed;
>
>             if (window != ListViewItemEditor.this
>
>                 && (window == null || !isOwner(window))) {
>
>                 endEdit(true);
>
>                 consumed = true;
>
>             } else {
>
>                 consumed = false;
>
>             }
>
>
>
>             return consumed;
>
>         }
>
>
>
> Regards,
>
> David