litesoft
@ 948
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 |
/* * Copyright 2008 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.gen2.table.client; import com.google.gwt.gen2.event.shared.*; import com.google.gwt.gen2.table.client.TableModelHelper.*; import com.google.gwt.gen2.table.event.client.*; /** * A class to retrieve row data to be used in a table. * * @param <RowType> the data type of the row values */ public abstract class TableModel<RowType> implements HasRowCountChangeHandlers { /** * Callback for {@link TableModel}. Every {@link Request} should be associated * with a {@link TableModel.Callback} that should be called after a * {@link Response} is generated. * * @param <RowType> the data type of the row values */ public static interface Callback<RowType> { /** * Called when an error occurs and the rows cannot be loaded. * * @param caught the exception that was thrown */ void onFailure( Throwable caught ); /** * Consume the data created by {@link TableModel} in response to a Request. * * @param request the request * @param response the response */ void onRowsReady( Request request, Response<RowType> response ); } /** * Use the ALL_ROWS value in place of the numRows variable when requesting all * rows. */ public static final int ALL_ROWS = -1; /** * Indicates that the number of rows is unknown, and therefore unbounded. */ public static final int UNKNOWN_ROW_COUNT = -1; /** * The manager of events. */ private HandlerManager handlers = new HandlerManager( this ); /** * The total number of rows available in the model. */ private int rowCount = UNKNOWN_ROW_COUNT; public HandlerRegistration addRowCountChangeHandler( RowCountChangeHandler handler ) { return addHandler( RowCountChangeEvent.TYPE, handler ); } /** * Return the total number of rows. If the number is not known, return * {@link #UNKNOWN_ROW_COUNT}. * * @return the total number of rows, or {@link #UNKNOWN_ROW_COUNT} */ public int getRowCount() { return rowCount; } /** * Generate a {@link Response} based on a specific {@link Request}. The * response is passed into the {@link Callback}. * * @param request the {@link Request} for row data * @param callback the {@link Callback} to use for the {@link Response} */ public abstract void requestRows( Request request, Callback<RowType> callback ); /** * Set the total number of rows. * * @param rowCount the row count */ public void setRowCount( int rowCount ) { if ( this.rowCount != rowCount ) { int oldRowCount = this.rowCount; this.rowCount = rowCount; fireEvent( new RowCountChangeEvent( oldRowCount, rowCount ) ); } } /** * Adds this handler to the widget. * * @param key the event key * @param handler the handler */ protected <HandlerType extends EventHandler> HandlerRegistration addHandler( AbstractEvent.Type<?, HandlerType> key, final HandlerType handler ) { return handlers.addHandler( key, handler ); } /** * Fires an event. * * @param event the event */ protected void fireEvent( AbstractEvent event ) { handlers.fireEvent( event ); } /** * Returns this widget's {@link HandlerManager} used for event management. */ protected final HandlerManager getHandlerManager() { return handlers; } /** * Is the event handled by one or more handlers? */ protected final boolean isEventHandled( AbstractEvent.Type key ) { return handlers.isEventHandled( key ); } /** * Removes the given handler from the specified event key. Normally, * applications should call {@link HandlerRegistration#removeHandler()} * instead. This method is provided primary to support the deprecated * listeners api. * * @param key the event key * @param handler the handler */ protected <T extends EventHandler> void removeHandler( AbstractEvent.Type<?, T> key, final T handler ) { handlers.removeHandler( key, handler ); } } |