litesoft
@ 947
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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.widgets; import java.util.*; import org.litesoft.GWT.client.widgets.nonpublic.*; import com.google.gwt.user.client.ui.*; 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(); 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; } @Override 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 */ @Override 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 */ @Override 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() ); } @Override public void removeTab( int pIndex ) { if ( Helper.indexOK( pIndex, this ) ) { remove( pIndex ); } } /** * Adds a widget to the tab panel. * * @param pLabelText * @param pWidget */ @Override 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 */ @Override public void addTab( String pLabelText, boolean pAsHTML, Widget pWidget ) { insertTab( getWidgetCount(), pLabelText, pAsHTML, pWidget ); } @Override public int getTabCount() { return getWidgetCount(); } @Override public int getSelectedTab() { return mTabBar.getSelectedTab(); } /** * Programmatically selects the specified tab. * * @param pIndex the index of the tab to be selected */ @Override public void selectTab( int pIndex ) { if ( Helper.indexOK( pIndex, this ) ) { mTabBar.selectTab( pIndex ); } } @Override public void addTabListener( TabListener listener ) { if ( mTabListeners == null ) { mTabListeners = new TabListenerCollection(); } //noinspection unchecked mTabListeners.add( listener ); } @Override public void clear() { while ( getWidgetCount() > 0 ) { remove( getWidget( 0 ) ); } } @Override public Iterator<Widget> iterator() { return mChildren.iterator(); } @Override public boolean onBeforeTabSelected( SourcesTabEvents sender, int tabIndex ) { return (mTabListeners == null) || mTabListeners.fireBeforeTabSelected( this, tabIndex ); } @Override public void onTabSelected( SourcesTabEvents sender, int tabIndex ) { mDeck.showWidget( tabIndex ); if ( mTabListeners != null ) { mTabListeners.fireTabSelected( this, tabIndex ); } } @Override public Widget getWidget( int index ) { return mChildren.get( index ); } @Override public int getWidgetCount() { return mChildren.size(); } @Override public int getWidgetIndex( Widget widget ) { return mChildren.indexOf( widget ); } @Override 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 */ @Override public boolean remove( Widget widget ) { return remove( getWidgetIndex( widget ) ); } @Override 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; } @Override public void setWidth( String width ) { super.setWidth( width ); // for stacktrace Debugging } @Override public void setHeight( String height ) { super.setHeight( height ); // for stacktrace Debugging } @Override 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
Revision | Author | Commited | Message |
---|---|---|---|
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
247 Diff | GeorgeS | Mon 06 Jun, 2011 04:59:03 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
23 Diff | GeorgeS | Wed 24 Feb, 2010 00:34:32 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |