You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Chris Bartlett (JIRA)" <ji...@apache.org> on 2011/07/15 11:32:59 UTC

[jira] [Issue Comment Edited] (PIVOT-751) TabPaneSelectionListener#selectedIndexChanged called twice when first tab is inserted

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

Chris Bartlett edited comment on PIVOT-751 at 7/15/11 9:32 AM:
---------------------------------------------------------------

I did have quick look into it a while ago, but couldn't think of a clean way to implement it without too many changes.
This was due to handling of disabled tabs, and enabled tabs that might be prevented from being selected by veto logic in the 'previewSelectedIndexChange' event.
It seemed simpler to just allow the developer to consolidate their logic in one place and then reference it in the 'previewSelectedIndexChange' events and 'tabsRemoved' events as required.

Feel free to have another shot at it though!

      was (Author: cbartlett):
    I did have quick look into it a while ago, but couldn't think of a clean way to implement it without too many changes.
This was due to handling of disabled tabs, enabled tabs that prevented from being selected by veto logic in the 'previewSelectedIndexChange' event.
It seemed simpler to just allow the developer to consolidate their logic in one place and then reference it in the 'previewSelectedIndexChange' events and 'tabsRemoved' events as required.

Feel free to have another shot at it though!
  
> 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
>
>         Attachments: PIVOT751.java, PIVOT751.txt
>
>
> 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