Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.temp.client.foundation.widget;

import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.ui.*;
import com.google.web.bindery.event.shared.*;

import java.util.*;

/**
 * By placing a TabPanelNavPanel widget inside a tabbed panel, it'd render
 * a back and next button that handles switching between tabs within the tab panel
 *
 * @author ngchihou
 */
public class TabPanelNavPanel extends HorizontalPanel {
    private NamedLabel next;
    private NamedLabel back;
    private int tabIndex;
    private TabPanel masterTabPanel;
    private boolean hideNextButton;
    private boolean hideBackButton;
    private HandlerRegistration nextRegistrationHandler;
    private HandlerRegistration backRegistrationHandler;
    private final String BUTTON_STYLE = "tab-nav-button";

    public TabPanelNavPanel() {
        next = new NamedLabel( "Next >>" );
        next.setStyleName( BUTTON_STYLE );
        nextRegistrationHandler = next.addClickHandler( new ClickHandler() {
            @Override
            public void onClick( ClickEvent event ) {
                if ( masterTabPanel != null && tabIndex + 1 < masterTabPanel.getTabBar().getTabCount() ) {
                    masterTabPanel.getTabBar().selectTab( tabIndex + 1 );
                }
            }
        } );

        back = new NamedLabel( "<< Back" );
        back.setStyleName( BUTTON_STYLE );
        backRegistrationHandler = back.addClickHandler( new ClickHandler() {
            @Override
            public void onClick( ClickEvent event ) {
                if ( masterTabPanel != null && tabIndex - 1 >= 0 ) {
                    masterTabPanel.getTabBar().selectTab( tabIndex - 1 );
                }
            }
        } );

        add( back );
        add( new LeftRightSiblings() );
        add( next );
    }

    /**
     * Set a custom click handler for the next button
     *
     * @param handler
     */
    public void addNextClickHandler( ClickHandler handler ) {
        if ( handler != null ) {
            nextRegistrationHandler.removeHandler();
            next.addClickHandler( handler );
        }
    }

    /**
     * Set a custom click handler for the back button
     *
     * @param handler
     */
    public void addBackClickHandler( ClickHandler handler ) {
        if ( handler != null ) {
            backRegistrationHandler.removeHandler();
            back.addClickHandler( handler );
        }
    }

    @Override
    protected void onAttach() {
        super.onAttach();

        // Get the reference to the TabPanel obj as well as the
        // Tab that this TabPanelNavPanel obj resides in
        // With these two pieces of info we can derive the tab
        // index which this nav panel is in
        Widget tab = null;
        Widget parent = getParent();
        while ( parent != null ) {
            if ( parent instanceof TabPanel ) {
                masterTabPanel = (TabPanel) parent;
                break;
            } else if ( parent.getParent() != null && parent.getParent() instanceof DeckPanel ) {
                tab = parent;
            }

            parent = parent.getParent();
        }

        if ( masterTabPanel != null && tab != null ) {
            Iterator<Widget> widgets = masterTabPanel.iterator();
            int wIndex = 0;
            while ( widgets.hasNext() ) {
                Widget w = widgets.next();
                if ( w == tab ) {
                    tabIndex = wIndex;
                    break;
                }
                wIndex++;
            }

            if ( tabIndex == 0 ) {
                back.setVisible( false );
            }
        }

        // Hide the button if necessary
        if ( hideNextButton ) {
            next.setVisible( false );
        }
        if ( hideBackButton ) {
            back.setVisible( false );
        }
    }

    public boolean isHideNextButton() {
        return hideNextButton;
    }

    public void setHideNextButton( boolean hideNextButton ) {
        this.hideNextButton = hideNextButton;
    }

    public boolean isHideBackButton() {
        return hideBackButton;
    }

    public void setHideBackButton( boolean hideBackButton ) {
        this.hideBackButton = hideBackButton;
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/TabPanelNavPanel.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000