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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package org.litesoft.GWT.client.widgets;

import java.util.*;

import com.google.gwt.user.client.ui.*;
import org.litesoft.GWT.client.widgets.nonpublic.*;

public class SizeableTabPanel extends AbstractSizeableComposite implements TabListener,
                                                                           SourcesTabEvents,
                                                                           HasWidgets,
                                                                           IndexedPanel,
                                                                           ISizeableTabPanel
{
    private WidgetCollection mChildren = new WidgetCollection( this );
    private SizeableDeckPanel mDeck = new SizeableDeckPanel();
    private WidgetTabBar mTabBar = new WidgetTabBar();
    private TabListenerCollection mTabListeners;
    private static final String STYLE_TAB_NON_ERROR = "gwt-TabBarItem-NonError";
    private static final String STYLE_TAB_ERROR = "gwt-TabBarItem-Error";
    private boolean mErrorable;

    public SizeableTabPanel()
    {
        this( false );
    }

    public SizeableTabPanel( boolean pErrorable )
    {
        mErrorable = pErrorable;
        SizeableVerticalPanel vp = new SizeableVerticalPanel( true );

        vp.add( mTabBar );
        vp.add( mDeck );

        initWidget( vp );

        style( "LayoutSizeableTabPanel" );
        style( "gwt-TabPanel" );
        mDeck.style( "gwt-TabPanelBottom" );

        mTabBar.addTabListener( this );
    }

    public SizeableTabPanel style( String pStyleName )
    {
        addStyleName( pStyleName );
        return this;
    }

    public void add( Widget w )
    {
        throw new UnsupportedOperationException( "A tabText parameter must be specified with add()." );
    }

    /**
     * Inserts a widget into the tab panel.
     *
     * @param pBeforeIndex the index before which it will be inserted
     * @param pLabelText   the text to be shown on its tab
     * @param pWidget      the widget to be inserted
     */
    public void insertTab( int pBeforeIndex, String pLabelText, Widget pWidget )
    {
        insertTab( pBeforeIndex, pLabelText, false, pWidget );
    }

    /**
     * Inserts a widget into the tab panel.
     *
     * @param pBeforeIndex the index before which it will be inserted
     * @param pLabelText   the text to be shown on its tab
     * @param pAsHTML      <code>true</code> to treat the specified text as HTML
     * @param pWidget      the widget to be inserted
     */
    public void insertTab( int pBeforeIndex, String pLabelText, boolean pAsHTML, Widget pWidget )
    {
        pWidget.removeFromParent();
    	pBeforeIndex = Helper.normalizeBeforeIndex( pBeforeIndex, this );
        mChildren.insert( pWidget, pBeforeIndex );
        mTabBar.insertTab( Helper.augment( pLabelText, mErrorable ), true, pBeforeIndex );
        mDeck.insert( pWidget, pBeforeIndex );
        forceTabSelection( -1, mTabBar.getSelectedTab() );
    }

    public void removeTab( int pIndex )
    {
        if ( Helper.indexOK( pIndex, this ) )
        {
            remove( pIndex );
        }
    }

    /**
     * Adds a widget to the tab panel.
     *
     * @param pLabelText
     * @param pWidget
     */
    public void addTab( String pLabelText, Widget pWidget )
    {
        insertTab( getWidgetCount(), pLabelText, pWidget );
    }

    /**
     * Adds a widget to the tab panel.
     *
     * @param pLabelText the text to be shown on its tab
     * @param pAsHTML    <code>true</code> to treat the specified text as HTML
     * @param pWidget    the widget to be added
     */
    public void addTab( String pLabelText, boolean pAsHTML, Widget pWidget )
    {
        insertTab( getWidgetCount(), pLabelText, pAsHTML, pWidget );
    }

    public int getTabCount()
    {
        return getWidgetCount();
    }

    public int getSelectedTab()
    {
        return mTabBar.getSelectedTab();
    }

    /**
     * Programmatically selects the specified tab.
     *
     * @param pIndex the index of the tab to be selected
     */
    public void selectTab( int pIndex )
    {
        if ( Helper.indexOK( pIndex, this ) )
        {
            mTabBar.selectTab( pIndex );
        }
    }

    public void addTabListener( TabListener listener )
    {
        if ( mTabListeners == null )
        {
            mTabListeners = new TabListenerCollection();
        }
        //noinspection unchecked
        mTabListeners.add( listener );
    }

    public void clear()
    {
        while ( getWidgetCount() > 0 )
        {
            remove( getWidget( 0 ) );
        }
    }

    public Iterator<Widget> iterator()
    {
        return mChildren.iterator();
    }

    public boolean onBeforeTabSelected( SourcesTabEvents sender, int tabIndex )
    {
        return (mTabListeners == null) || mTabListeners.fireBeforeTabSelected( this, tabIndex );
    }

    public void onTabSelected( SourcesTabEvents sender, int tabIndex )
    {
        mDeck.showWidget( tabIndex );
        if ( mTabListeners != null )
        {
            mTabListeners.fireTabSelected( this, tabIndex );
        }
    }

    public Widget getWidget( int index )
    {
        return mChildren.get( index );
    }

    public int getWidgetCount()
    {
        return mChildren.size();
    }

    public int getWidgetIndex( Widget widget )
    {
        return mChildren.indexOf( widget );
    }

    public boolean remove( int pIndex )
    {
        if ( Helper.indexOK( pIndex, this ) )
        {
            int prevSelectedTab = mTabBar.getSelectedTab();
            mChildren.remove( pIndex );
            mTabBar.removeTab( pIndex );
            mDeck.remove( pIndex );
            forceTabSelection( pIndex, prevSelectedTab );
            return true;
        }
        return false;
    }

    /**
     * Removes the given widget, and its associated tab.
     *
     * @param widget the widget to be removed
     */
    public boolean remove( Widget widget )
    {
        return remove( getWidgetIndex( widget ) );
    }

    public void removeTabListener( TabListener listener )
    {
        if ( mTabListeners != null )
        {
            mTabListeners.remove( listener );
        }
    }

    private void forceTabSelection( int pRemovedIndex, int pPrevSelectedTab )
    {
        int count = mTabBar.getTabCount();
        if ( (count > 0) && (pRemovedIndex == pPrevSelectedTab) )
        {
            int toSelect = (pPrevSelectedTab < 0) ? //
                           0 : //
                           (pPrevSelectedTab < count) ? //
                           pPrevSelectedTab : //
                           count - 1;
            selectTab( toSelect );
        }
    }

    //****** Implementation Code Block to support delegation to AbsoluteSizeHelper

    public SizeableTabPanel stretchable()
    {
        LLstretchable();
        mDeck.stretchable();
        return this;
    }

    public SizeableTabPanel stretchableVertically()
    {
        LLstretchableVertically();
        mDeck.stretchableVertically();
        return this;
    }

    public SizeableTabPanel stretchableHorizontally()
    {
        LLstretchableHorizontally();
        mDeck.stretchableHorizontally();
        return this;
    }

    public void setWidth( String width )
    {
        super.setWidth( width ); // for stacktrace Debugging
    }

    public void setHeight( String height )
    {
        super.setHeight( height ); // for stacktrace Debugging
    }

    public void setError( int pIndex, boolean pError )
    {
        if ( Helper.indexOK( pIndex, this ) )
        {
            Widget widget = mTabBar.getWidget( pIndex );
            if ( pError )
            {
                widget.removeStyleName( STYLE_TAB_NON_ERROR );
                widget.addStyleName( STYLE_TAB_ERROR );
            }
            else
            {
                widget.removeStyleName( STYLE_TAB_ERROR );
                widget.addStyleName( STYLE_TAB_NON_ERROR );
            }
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/SizeableTabPanel.java

Diff revisions: vs.
Revision Author Commited Message
2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000