[ 
https://issues.apache.org/jira/browse/PIVOT-751?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13065717#comment-13065717
 ] 

Chris Bartlett commented on PIVOT-751:
--------------------------------------

Does anyone have any comments on this?

According to the javadocs, the previousSelectedIndex value of the 
selectedIndexChanged event will represent the previously selected index or the 
currently selected index depending on whether the change was direct/indirect.
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/TabPaneSelectionListener.html#selectedIndexChanged(org.apache.pivot.wtk.TabPane,
 int)

I feel that a single event should be fired as there is only actually one change 
of the selected index value, but am not sure which of the two it should be.  My 
initial thought was that it should be the first event, but after reading the 
javadoc, think it should be the second one.


The first event that is currently fired has a previousSelectedIndex value of 
-1.  This is the actual previous selection index value, and according to the 
javadocs, should arise from a direct/explicit selection change.

The second event that is currently fired has a previousSelectedIndex value of 
0.  This is the current selection index value, and according to the javadocs, 
should arise from an indirect selection change.  That certainly seems to 
describe this scenario as no explicit selection change was made, rather a new 
tab was added.

So perhaps it should actually be the first event that is suppressed rather than 
the second one?

> TabPaneSelectionListener#selectedIndexChanged called twice when first tab is 
> inserted
> -------------------------------------------------------------------------------------
>
>                 Key: PIVOT-751
>                 URL: https://issues.apache.org/jira/browse/PIVOT-751
>             Project: Pivot
>          Issue Type: Bug
>          Components: wtk
>    Affects Versions: 2.0
>            Reporter: Edvin Syse
>            Priority: Minor
>             Fix For: 2.0.1
>
>
> If you add a tab to an _empty_ tabpane, two selectedIndexChanged events are 
> called. I.e, when you add a TabPaneSelectionListener to a tabpane and call:
> tabpane.getTabs().add(component);
> .. the listener fires twice, with previousSelectedIndex set to -1 and then 0.
> The two events are fired by line 68 and 72 in TabPane.java:
> 68            tabPaneListeners.tabInserted(TabPane.this, index);
> 69
> 70            // Fire selection change event, if necessary
> 71            if (selectedIndex != previousSelectedIndex) {
> 72 tabPaneSelectionListeners.selectedIndexChanged(TabPane.this, 
> selectedIndex);
> 73            }
> This could be fixed by taking into account that previousSelectedIndex might 
> have been -1 when invoked, like this:
> if (selectedIndex != previousSelectedIndex && previousSelectedIndex > -1) { 
> See this thread for more info: 
> http://apache-pivot-users.399431.n3.nabble.com/TabPaneSelectionListener-selectedIndexChanged-called-twice-when-first-tab-is-inserted-td3022515.html
> PS: According to Chris, CardPane and Accordion behave in the same way, so any 
> changes to TabPane should also be made to these for consistency.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to