Subversion Repository Public Repository

litesoft

Diff Revisions 282 vs 475 for /trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/TableModel.java

Diff revisions: vs.
  @@ -15,149 +15,151 @@
15 15 */
16 16 package com.google.gwt.gen2.table.client;
17 17
18 - import com.google.gwt.gen2.event.shared.AbstractEvent;
19 - import com.google.gwt.gen2.event.shared.EventHandler;
20 - import com.google.gwt.gen2.event.shared.HandlerManager;
21 - import com.google.gwt.gen2.event.shared.HandlerRegistration;
22 - import com.google.gwt.gen2.table.client.TableModelHelper.Request;
23 - import com.google.gwt.gen2.table.client.TableModelHelper.Response;
24 - import com.google.gwt.gen2.table.event.client.HasRowCountChangeHandlers;
25 - import com.google.gwt.gen2.table.event.client.RowCountChangeEvent;
26 - import com.google.gwt.gen2.table.event.client.RowCountChangeHandler;
18 + import com.google.gwt.gen2.event.shared.*;
19 + import com.google.gwt.gen2.table.client.TableModelHelper.*;
20 + import com.google.gwt.gen2.table.event.client.*;
27 21
28 22 /**
29 23 * A class to retrieve row data to be used in a table.
30 - *
24 + *
31 25 * @param <RowType> the data type of the row values
32 26 */
33 - public abstract class TableModel<RowType> implements HasRowCountChangeHandlers {
34 - /**
35 - * Callback for {@link TableModel}. Every {@link Request} should be associated
36 - * with a {@link TableModel.Callback} that should be called after a
37 - * {@link Response} is generated.
38 - *
39 - * @param <RowType> the data type of the row values
40 - */
41 - public static interface Callback<RowType> {
42 - /**
43 - * Called when an error occurs and the rows cannot be loaded.
44 - *
45 - * @param caught the exception that was thrown
46 - */
47 - void onFailure(Throwable caught);
48 -
49 - /**
50 - * Consume the data created by {@link TableModel} in response to a Request.
51 - *
52 - * @param request the request
53 - * @param response the response
54 - */
55 - void onRowsReady(Request request, Response<RowType> response);
56 - }
57 -
58 - /**
59 - * Use the ALL_ROWS value in place of the numRows variable when requesting all
60 - * rows.
61 - */
62 - public static final int ALL_ROWS = -1;
63 -
64 - /**
65 - * Indicates that the number of rows is unknown, and therefore unbounded.
66 - */
67 - public static final int UNKNOWN_ROW_COUNT = -1;
68 -
69 - /**
70 - * The manager of events.
71 - */
72 - private HandlerManager handlers = new HandlerManager(this);
73 -
74 - /**
75 - * The total number of rows available in the model.
76 - */
77 - private int rowCount = UNKNOWN_ROW_COUNT;
78 -
79 - public HandlerRegistration addRowCountChangeHandler(
80 - RowCountChangeHandler handler) {
81 - return addHandler(RowCountChangeEvent.TYPE, handler);
82 - }
83 -
84 - /**
85 - * Return the total number of rows. If the number is not known, return
86 - * {@link #UNKNOWN_ROW_COUNT}.
87 - *
88 - * @return the total number of rows, or {@link #UNKNOWN_ROW_COUNT}
89 - */
90 - public int getRowCount() {
91 - return rowCount;
92 - }
93 -
94 - /**
95 - * Generate a {@link Response} based on a specific {@link Request}. The
96 - * response is passed into the {@link Callback}.
97 - *
98 - * @param request the {@link Request} for row data
99 - * @param callback the {@link Callback} to use for the {@link Response}
100 - */
101 - public abstract void requestRows(Request request, Callback<RowType> callback);
102 -
103 - /**
104 - * Set the total number of rows.
105 - *
106 - * @param rowCount the row count
107 - */
108 - public void setRowCount(int rowCount) {
109 - if (this.rowCount != rowCount) {
110 - int oldRowCount = this.rowCount;
111 - this.rowCount = rowCount;
112 - fireEvent(new RowCountChangeEvent(oldRowCount, rowCount));
113 - }
114 - }
115 -
116 - /**
117 - * Adds this handler to the widget.
118 - *
119 - * @param key the event key
120 - * @param handler the handler
121 - */
122 - protected <HandlerType extends EventHandler> HandlerRegistration addHandler(
123 - AbstractEvent.Type<?, HandlerType> key, final HandlerType handler) {
124 - return handlers.addHandler(key, handler);
125 - }
126 -
127 - /**
128 - * Fires an event.
129 - *
130 - * @param event the event
131 - */
132 - protected void fireEvent(AbstractEvent event) {
133 - handlers.fireEvent(event);
134 - }
135 -
136 - /**
137 - * Returns this widget's {@link HandlerManager} used for event management.
138 - */
139 - protected final HandlerManager getHandlerManager() {
140 - return handlers;
141 - }
142 -
143 - /**
144 - * Is the event handled by one or more handlers?
145 - */
146 - protected final boolean isEventHandled(AbstractEvent.Type key) {
147 - return handlers.isEventHandled(key);
148 - }
149 -
150 - /**
151 - * Removes the given handler from the specified event key. Normally,
152 - * applications should call {@link HandlerRegistration#removeHandler()}
153 - * instead. This method is provided primary to support the deprecated
154 - * listeners api.
155 - *
156 - * @param key the event key
157 - * @param handler the handler
158 - */
159 - protected <T extends EventHandler> void removeHandler(
160 - AbstractEvent.Type<?, T> key, final T handler) {
161 - handlers.removeHandler(key, handler);
162 - }
27 + public abstract class TableModel<RowType> implements HasRowCountChangeHandlers
28 + {
29 + /**
30 + * Callback for {@link TableModel}. Every {@link Request} should be associated
31 + * with a {@link TableModel.Callback} that should be called after a
32 + * {@link Response} is generated.
33 + *
34 + * @param <RowType> the data type of the row values
35 + */
36 + public static interface Callback<RowType>
37 + {
38 + /**
39 + * Called when an error occurs and the rows cannot be loaded.
40 + *
41 + * @param caught the exception that was thrown
42 + */
43 + void onFailure( Throwable caught );
44 +
45 + /**
46 + * Consume the data created by {@link TableModel} in response to a Request.
47 + *
48 + * @param request the request
49 + * @param response the response
50 + */
51 + void onRowsReady( Request request, Response<RowType> response );
52 + }
53 +
54 + /**
55 + * Use the ALL_ROWS value in place of the numRows variable when requesting all
56 + * rows.
57 + */
58 + public static final int ALL_ROWS = -1;
59 +
60 + /**
61 + * Indicates that the number of rows is unknown, and therefore unbounded.
62 + */
63 + public static final int UNKNOWN_ROW_COUNT = -1;
64 +
65 + /**
66 + * The manager of events.
67 + */
68 + private HandlerManager handlers = new HandlerManager( this );
69 +
70 + /**
71 + * The total number of rows available in the model.
72 + */
73 + private int rowCount = UNKNOWN_ROW_COUNT;
74 +
75 + public HandlerRegistration addRowCountChangeHandler( RowCountChangeHandler handler )
76 + {
77 + return addHandler( RowCountChangeEvent.TYPE, handler );
78 + }
79 +
80 + /**
81 + * Return the total number of rows. If the number is not known, return
82 + * {@link #UNKNOWN_ROW_COUNT}.
83 + *
84 + * @return the total number of rows, or {@link #UNKNOWN_ROW_COUNT}
85 + */
86 + public int getRowCount()
87 + {
88 + return rowCount;
89 + }
90 +
91 + /**
92 + * Generate a {@link Response} based on a specific {@link Request}. The
93 + * response is passed into the {@link Callback}.
94 + *
95 + * @param request the {@link Request} for row data
96 + * @param callback the {@link Callback} to use for the {@link Response}
97 + */
98 + public abstract void requestRows( Request request, Callback<RowType> callback );
99 +
100 + /**
101 + * Set the total number of rows.
102 + *
103 + * @param rowCount the row count
104 + */
105 + public void setRowCount( int rowCount )
106 + {
107 + if ( this.rowCount != rowCount )
108 + {
109 + int oldRowCount = this.rowCount;
110 + this.rowCount = rowCount;
111 + fireEvent( new RowCountChangeEvent( oldRowCount, rowCount ) );
112 + }
113 + }
114 +
115 + /**
116 + * Adds this handler to the widget.
117 + *
118 + * @param key the event key
119 + * @param handler the handler
120 + */
121 + protected <HandlerType extends EventHandler> HandlerRegistration addHandler( AbstractEvent.Type<?, HandlerType> key, final HandlerType handler )
122 + {
123 + return handlers.addHandler( key, handler );
124 + }
125 +
126 + /**
127 + * Fires an event.
128 + *
129 + * @param event the event
130 + */
131 + protected void fireEvent( AbstractEvent event )
132 + {
133 + handlers.fireEvent( event );
134 + }
135 +
136 + /**
137 + * Returns this widget's {@link HandlerManager} used for event management.
138 + */
139 + protected final HandlerManager getHandlerManager()
140 + {
141 + return handlers;
142 + }
143 +
144 + /**
145 + * Is the event handled by one or more handlers?
146 + */
147 + protected final boolean isEventHandled( AbstractEvent.Type key )
148 + {
149 + return handlers.isEventHandled( key );
150 + }
151 +
152 + /**
153 + * Removes the given handler from the specified event key. Normally,
154 + * applications should call {@link HandlerRegistration#removeHandler()}
155 + * instead. This method is provided primary to support the deprecated
156 + * listeners api.
157 + *
158 + * @param key the event key
159 + * @param handler the handler
160 + */
161 + protected <T extends EventHandler> void removeHandler( AbstractEvent.Type<?, T> key, final T handler )
162 + {
163 + handlers.removeHandler( key, handler );
164 + }
163 165 }