Example usage for com.google.gwt.user.client.ui DeckPanel getVisibleWidget

List of usage examples for com.google.gwt.user.client.ui DeckPanel getVisibleWidget

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui DeckPanel getVisibleWidget.

Prototype

public int getVisibleWidget() 

Source Link

Document

Gets the index of the currently-visible widget.

Usage

From source file:rocket.widget.client.tabpanel.TabPanel.java

License:Apache License

public void select(final int index) {
    final TabItem newlySelectedItem = this.get(index);
    TabItem previousSelection = null;/*  ww  w.  ja  v a  2 s  .  co  m*/
    final int previouslySelectedIndex = this.getSelectedIndex();
    if (-1 != previouslySelectedIndex) {
        previousSelection = this.get(previouslySelectedIndex);
    }

    final BeforeTabSelectEvent beforeSelected = new BeforeTabSelectEvent();
    beforeSelected.setCurrentSelection(previousSelection);
    beforeSelected.setNewSelection(newlySelectedItem);

    final TabListenerCollection listeners = this.getTabListeners();
    listeners.fireBeforeTabSelected(beforeSelected);

    if (false == beforeSelected.isCancelled()) {
        final String selectedStyle = this.getTabBarItemSelectedStyleName();

        final TabBarPanel tabBarPanel = this.getTabBarPanel();
        final DeckPanel contentPanel = this.getContentPanel();

        // find the previously selected tab. and unselect it.
        final int previousIndex = contentPanel.getVisibleWidget();
        TabItem previouslySelectedTabItem = null;
        if (-1 != previousIndex) {
            final Widget tab = tabBarPanel.getWidget(previousIndex + 1);
            tab.removeStyleName(selectedStyle);
            previouslySelectedTabItem = this.get(previousIndex);
        }

        // apply the style to the new tab.
        final Widget tabBarItemPanel = tabBarPanel.getWidget(index + 1);
        tabBarItemPanel.addStyleName(selectedStyle);

        // tell the deckPanel to select a new sub-widget.
        contentPanel.showWidget(index);

        final TabSelectEvent selectedEvent = new TabSelectEvent();
        selectedEvent.setPreviouslySelected(previouslySelectedTabItem);
        selectedEvent.setCurrentSelection(newlySelectedItem);

        listeners.fireTabSelected(selectedEvent);
    }
}