You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by ccp999 <cc...@hotmail.com> on 2013/03/05 04:47:45 UTC

IndexOutOfBoundException in TableView when Highlight is set to true

Hi,

I have ShowHighlight and VariableRowHigh to true. And when mouseOut event
occurs, I get  IndexOutOfBoundException.  

<http://apache-pivot-users.399431.n3.nabble.com/file/n4022474/Screen_Shot_2013-03-05_at_11.10.57_AM.png> 

 I did a bit of trace and found the function getRowAt in TerraTableViewSkin
incorrectly return 1 when the y ordinate is greater than all rows.

the problem is the with code line in 585, 586 and 587.  After the binary
search return a -2 when y is bigger than the rowBoundaries 
the code in 587 modified it index to 1.
In my case, where only one row, so IndexOutOfBoundException.

Any advice?

Brendan



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/IndexOutOfBoundException-in-TableView-when-Highlight-is-set-to-true-tp4022474.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by Brendan <cc...@hotmail.com>.
Ok. Thanks Roger!



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/IndexOutOfBoundException-in-TableView-when-Highlight-is-set-to-true-tp4022474p4022492.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
I have committed this change:
Sending
wtk-terra\src\org\apache\pivot\wtk\skin\terra\TerraTableViewSkin.java
Transmitting file data .
Committed revision 1453906.

The code now will make the same check in both fixed and variable row
height case and return -1 if the index is beyond the end of the data.

Brendan, can you check your code with the latest svn version?  

~Roger Whitcomb

-----Original Message-----
From: Sandro Martini [mailto:sandro.martini@gmail.com] 
Sent: Thursday, March 07, 2013 12:59 AM
To: user@pivot.apache.org
Subject: Re: IndexOutOfBoundException in TableView when Highlight is set
to true

Hi all,
to me this looks good ...

Roger, do you think it would be good (maybe) to add just before the
return to add a check that rowIndex is inside a valid range ?
Anyway, go with the commit ...

Bye

Re: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by Sandro Martini <sa...@gmail.com>.
Hi all,
to me this looks good ...

Roger, do you think it would be good (maybe) to add just before the
return to add a check that rowIndex is inside a valid range ?
Anyway, go with the commit ...

Bye

RE: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
> Te usage of ArrayList.BinarySearch isn't what I think the
documentation
describes, for example:
array of [21, 43, 65] and y is 64 should result a positive 2 but it
return
-3.  As this, we have to do the -(x + 1) every time.

Actually, this is exactly what the documentation describes:  the
negative number returned means the value was not found, but the -(index
+ 1) is the slot where the value should go.

> In case, we want to keep using BinarySearch.  I also figure out a
simpler
way of doing it:

rowIndex = -1;
for (int i = 0; i < rowBoundaries.getLength(); i++)
if (y < rowBoundaries.get(i).intValue())
  return rowIndex = i;

>not sure in terms of performance, is this really so much poorer? but
for
sure, it more clear and less problem.

I'm thinking this would be better:
        int rowIndex;
        if (variableRowHeight) {
            if (y == 0) {
                rowIndex = 0;
            } else {
                rowIndex = ArrayList.binarySearch(rowBoundaries, y);
                if (rowIndex < 0) {
                    rowIndex = -(rowIndex + 1);
                }
            }
        } else {
            rowIndex = (y / (fixedRowHeight + 1));
        }

        List<Object> tableData = (List<Object>)tableView.getTableData();
        if (rowIndex >= tableData.getLength()) {
            rowIndex = -1;
        }

This way the same test for index past the end of the table gets applied
in both the fixed and variable row height cases.


~Roger

Re: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by Brendan <cc...@hotmail.com>.
Sorry Roger,  I should have done more test before agreed with you.

Te usage of ArrayList.BinarySearch isn't what I think the documentation
describes, for example:
array of [21, 43, 65] and y is 64 should result a positive 2 but it return
-3.  As this, we have to do the -(x + 1) every time.

and of course, the greater the array scope will have to determine
separately.  so I coded it this way:

<http://apache-pivot-users.399431.n3.nabble.com/file/n4022484/Screen_Shot_2013-03-06_at_10.32.11_AM.png> 

In case, we want to keep using BinarySearch.  I also figure out a simpler
way of doing it:

rowIndex = -1;
for (int i = 0; i < rowBoundaries.getLength(); i++)
if (y < rowBoundaries.get(i).intValue())
  return rowIndex = i;

not sure in terms of performance, is this really so much poorer? but for
sure, it more clear and less problem.

Brendan



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/IndexOutOfBoundException-in-TableView-when-Highlight-is-set-to-true-tp4022474p4022484.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by Roger Whitcomb <Ro...@rbwhitcomb.com>.
Okay I'll commit this in the morning and let you know when it's in so you can try it. 

Thanks!

~Roger


RE: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by Brendan <cc...@hotmail.com>.
Hi Roger,

I agree the change.

Brendan



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/IndexOutOfBoundException-in-TableView-when-Highlight-is-set-to-true-tp4022474p4022481.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
> Roger (and all others :-) ) what do you think ?

Looks to me like the code in "getRowAt" should look like this, to make
the fixed and variable height cases work the same way:
        int rowIndex;
        if (variableRowHeight) {
            if (y == 0) {
                rowIndex = 0;
            } else {
                rowIndex = ArrayList.binarySearch(rowBoundaries, y);
                if (rowIndex < 0) {
                    rowIndex = -1;
                }
            }
        } else {
            rowIndex = (y / (fixedRowHeight + 1));

            List<Object> tableData =
(List<Object>)tableView.getTableData();
            if (rowIndex >= tableData.getLength()) {
                rowIndex = -1;
            }
        }

> And maybe then the same even in the getColumnAt() method ...

I think "getColumnAt" is okay as-is.

~Roger

Re: IndexOutOfBoundException in TableView when Highlight is set to true

Posted by Sandro Martini <sa...@gmail.com>.
Hi Brendan,

> I have ShowHighlight and VariableRowHigh to true. And when mouseOut event
> occurs, I get  IndexOutOfBoundException.
I think that it's something problematic in your data model ... some
week ago I didn't add a small fix to prevent a
IndexOutOfBoundException in case of something strange in table data,
but didn't apply because I think it's better to get the exception and
fix the problem (instead of simply ignoring it, maybe writing
something in log to console) ...

>  I did a bit of trace and found the function getRowAt in TerraTableViewSkin
> incorrectly return 1 when the y ordinate is greater than all rows.
>
> the problem is the with code line in 585, 586 and 587.  After the binary
> search return a -2 when y is bigger than the rowBoundaries
> the code in 587 modified it index to 1.
> In my case, where only one row, so IndexOutOfBoundException.
>
If there aren't objections I think could be safer to force the range
of the returned row in the [0 .. numberOfRows] before the end of the
getRowAt() method ... and maybe write a warning in console logs (but
probably not, unless we'll have a pluggable logging system).
And maybe then the same even in the getColumnAt() method ...
Roger (and all others :-) ) what do you think ?

Anyway, Brendan, if you have a minimal sample that we can run, to
better ensure all will be fixed ... or you can take a look at (under
tests) table_view_test2.bxml and table_view_test3.bxml as a minimal
sample with variableRowHeight:true , and maybe help us reproduce the
issue.

Tell me.
Thank you for now.

Bye,
Sandro