litesoft
@ 950
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.GWT.client.widgets.datatables; import org.litesoft.GWT.client.*; import org.litesoft.GWT.client.widgets.Button; import org.litesoft.GWT.client.widgets.*; import org.litesoft.bo.*; import org.litesoft.bo.views.*; import org.litesoft.commonfoundation.base.*; import org.litesoft.core.util.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.gen2.table.client.TableModelHelper.*; import com.google.gwt.user.client.ui.*; import java.util.*; /** * List mutations are not supported. */ public class FilteringTableModel<RowType extends IViewObject> extends ListTableModel<RowType> implements SearchStateDefaultRequestable, BoAccessorFilter, FilterManager.CallBacks<RowType> { private static final String STYLE_STATUS = "QBEstatus"; private static final String QBE_MSG = "QBEmsg"; private static final String STYLE_HAS_MSG = "HasMsg"; private static final String STYLE_NO_MSG = "NoMsg"; private FilterManager<RowType> mFilterManager; private TableClickCommand<RowType> mDefaultSingleRowTableClickCommand, mDefaultNoRowTableClickCommand; private boolean mUnique, mSearching = false; private TableDataReloadable mReloadable = null; private MessageLabel mMessage = new MessageLabel(); private Button mNewButton, mSelectButton; private ButtonHelper mNewButtonHelper, mSelectButtonHelper; private boolean mShowing = false; private int mRealtimeUpdatingSuppressed = 0; private boolean mUpdateRequested = false; public FilteringTableModel( VoDataProvider<RowType> pDataProvider, boolean pUnique, // TableClickCommand<RowType> pDefaultSingleRowTableClickCommand, // TableClickCommand<RowType> pDefaultNoRowTableClickCommand, boolean pNewAllowed ) { mFilterManager = new DataProviderFilterManager<RowType>( pDataProvider, this ); mDefaultSingleRowTableClickCommand = pDefaultSingleRowTableClickCommand; mDefaultNoRowTableClickCommand = pDefaultNoRowTableClickCommand; mUnique = pUnique; mNewButtonHelper = new ButtonHelper( pNewAllowed, mNewButton = NewButton.factory().enabledToolTip( "Create New Record" ).add( new ClickHandler() { @Override public void onClick( ClickEvent event ) { requestNew(); } } ).create() ); updateNewButton(); mSelectButtonHelper = new ButtonHelper( true, mSelectButton = SelectButton.factory().enabledToolTip( "Single Row Select" ).add( new ClickHandler() { @Override public void onClick( ClickEvent event ) { requestSingle(); } } ).create() ); updateSelectButton(); } private void updateNewButton() { mNewButtonHelper.update( !mUnique || mList.isEmpty() ); } private void updateSelectButton() { mSelectButtonHelper.update( mList.size() == 1 ); } public Widget addReloadable( TableDataReloadable pReloadable ) { SizeableHorizontalPanel zStatusBar = new SizeableHorizontalPanel().style( STYLE_STATUS ).stretchableHorizontally(); zStatusBar.setVerticalAlignment( HasVerticalAlignment.ALIGN_MIDDLE ); zStatusBar.add( mNewButton ); zStatusBar.add( new Spacer().width( 20 ) ); zStatusBar.add( mMessage ); zStatusBar.add( new Spacer().width( 20 ) ); zStatusBar.add( mSelectButton ); SizeableVerticalPanel zPanel = new SizeableVerticalPanel().stretchable(); zPanel.add( (Widget) (mReloadable = pReloadable) ); zPanel.add( zStatusBar ); return zPanel; } @Override public void setSearching( boolean pSearching ) { if ( mSearching != pSearching ) { mSearching = pSearching; updateNewButton(); updateSelectButton(); } } @Override public boolean defaultRequested() { if ( mSearching ) { switch ( mList.size() ) { case 0: return requestNew(); case 1: return requestSingle(); default: break; } } return false; } private boolean requestSingle() { if ( (mDefaultSingleRowTableClickCommand != null) && (mList.size() == 1) ) { mDefaultSingleRowTableClickCommand.execute( mList.get( 0 ) ); return true; } return false; } private boolean requestNew() { if ( mDefaultNoRowTableClickCommand != null ) { mDefaultNoRowTableClickCommand.execute( null ); return true; } return false; } @Override public boolean isRealtimeUpdatingSuppressed() { return mRealtimeUpdatingSuppressed != 0; } @Override public void suppressRealtimeUpdating() { mRealtimeUpdatingSuppressed++; } @Override public void releaseRealtimeUpdating() { if ( 0 > --mRealtimeUpdatingSuppressed ) { mRealtimeUpdatingSuppressed = 0; } chkList(); } @Override public void showResults( boolean pShow ) { mShowing = pShow; chkList(); } @Override public void clearCache() { mFilterManager.clearCache(); } @Override public void clearAllFilterValues() { if ( mFilterManager.clear() ) { chkList(); } } @Override public void filterValueChanged( BoAccessorFilterType pFilterType, String pAttributeName, String pValue ) { if ( mFilterManager.setFilter( pFilterType, pAttributeName, pValue ) ) { chkList(); } } @Override public int activeFilters() { return mFilterManager.activeFilters(); } private void chkList() { if ( mShowing && !isRealtimeUpdatingSuppressed() && (mReloadable != null) ) { boolean zPrevState = mUpdateRequested; mUpdateRequested = true; if ( !mFilterManager.updateList() ) { mUpdateRequested = zPrevState; } } } @Override public ImmutableArrayList<RowType> filterRows( ImmutableArrayList<RowType> pRows ) { return pRows; } @Override public void setNewList( List<RowType> pList, String pMsgText ) { mUpdateRequested = false; mMessage.setText( pMsgText ); if ( mAsyncPending == null ) { mNewList = pList; if ( mReloadable != null ) { mReloadable.loadData(); } } else { mNewList = null; // just in case AsyncPending<RowType> zPending = mAsyncPending; mAsyncPending = null; updateUnderlyingList( pList, zPending.getRequest(), zPending.getCallback() ); } } private void updateUnderlyingList( List<RowType> pList, Request pRequest, Callback<RowType> pCallback ) { mList = pList; updateRowCount(); updateNewButton(); updateSelectButton(); super.requestRows( pRequest, pCallback ); } private static class AsyncPending<RowType> { private Request mRequest; private Callback<RowType> mCallback; private AsyncPending( Request pRequest, Callback<RowType> pCallback ) { mRequest = pRequest; mCallback = pCallback; } public Request getRequest() { return mRequest; } public Callback<RowType> getCallback() { return mCallback; } } private AsyncPending<RowType> mAsyncPending = null; private List<RowType> mNewList = null; @Override public void requestRows( Request pRequest, Callback<RowType> pCallback ) { if ( mNewList != null ) { List<RowType> zNewList = mNewList; mNewList = null; updateUnderlyingList( zNewList, pRequest, pCallback ); } else if ( mUpdateRequested ) { mAsyncPending = new AsyncPending<RowType>( pRequest, pCallback ); } else { super.requestRows( pRequest, pCallback ); } } private ImmutableArrayList<RowType> getImmutableArrayList() { return new ImmutableArrayList<RowType>( mList ); } @Override public Iterator<RowType> iterator() { return getImmutableArrayList().iterator(); } @Override public ListIterator<RowType> listIterator() { return getImmutableArrayList().listIterator(); } @Override public ListIterator<RowType> listIterator( int pIndex ) { return getImmutableArrayList().listIterator( pIndex ); } @Override @Deprecated public void add( int pIndex, RowType pElement ) { throw new UnsupportedOperationException(); } @Override @Deprecated public boolean add( RowType pO ) { throw new UnsupportedOperationException(); } @Override @Deprecated public boolean addAll( Collection<? extends RowType> pC ) { throw new UnsupportedOperationException(); } @Override @Deprecated public boolean addAll( int pIndex, Collection<? extends RowType> pC ) { throw new UnsupportedOperationException(); } @Override @Deprecated public void clear() { throw new UnsupportedOperationException(); } @Override @Deprecated public RowType remove( int pIndex ) { throw new UnsupportedOperationException(); } @Override @Deprecated public boolean remove( Object pO ) { throw new UnsupportedOperationException(); } @Override @Deprecated public boolean removeAll( Collection<?> pC ) { throw new UnsupportedOperationException(); } @Override @Deprecated public boolean retainAll( Collection<?> pC ) { throw new UnsupportedOperationException(); } @Override @Deprecated public RowType set( int pIndex, RowType pElement ) { throw new UnsupportedOperationException(); } private static class MessageLabel extends SizeableLabel { private MessageLabel() { super( FilterManager.NOTHING_ENTERED, false ); addStyleName( STYLE_HAS_MSG ); addStyleName( QBE_MSG ); stretchableHorizontally(); } @Override public void setText( String pLabelText ) { pLabelText = ConstrainTo.significantOrNull( pLabelText ); if ( pLabelText == null ) { removeStyleName( STYLE_HAS_MSG ); addStyleName( STYLE_NO_MSG ); super.setText( " " ); } else { removeStyleName( STYLE_NO_MSG ); addStyleName( STYLE_HAS_MSG ); super.setText( pLabelText ); } } } private class ButtonHelper { private boolean mVisible = true; private boolean mEnabled = true; private boolean mAllowed; private Button mButton; public ButtonHelper( boolean pAllowed, Button pButton ) { mAllowed = pAllowed; mButton = pButton; } public void update( boolean pPossiblyEnable ) { if ( !mAllowed ) { if ( mVisible ) { UtilsGwt.setHidden( mButton, !(mVisible = false) ); } return; } if ( mSearching != mVisible ) { UtilsGwt.setHidden( mButton, !(mVisible = mSearching) ); if ( !mVisible ) { return; } } boolean zEnabled = pPossiblyEnable && !mFilterManager.isEmpty(); if ( mEnabled != zEnabled ) { mButton.setEnabled( mEnabled = zEnabled ); } } } } |
Commits for litesoft/trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/datatables/FilteringTableModel.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
801 Diff | GeorgeS | Wed 15 Aug, 2012 03:59:02 +0000 | |
221 Diff | GeorgeS | Fri 20 May, 2011 16:39:20 +0000 | |
216 Diff | GeorgeS | Wed 18 May, 2011 13:44:57 +0000 | |
199 Diff | GeorgeS | Tue 10 May, 2011 00:55:21 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
135 | GeorgeS | Wed 09 Mar, 2011 15:19:54 +0000 |