|
@@ -1,8 +1,6 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.GWT.client.widgets.datatables; |
3 |
3 |
|
|
4 |
|
- |
import java.util.*; |
5 |
|
- |
|
6 |
4 |
|
import org.litesoft.GWT.client.*; |
7 |
5 |
|
import org.litesoft.GWT.client.event.*; |
8 |
6 |
|
import org.litesoft.GWT.client.widgets.datatables.RowSelectionPolicy.*; |
|
@@ -26,8 +24,9 @@ |
26 |
24 |
|
import com.google.gwt.user.client.ui.HasHorizontalAlignment.*; |
27 |
25 |
|
import com.google.gwt.widgetideas.client.*; |
28 |
26 |
|
|
29 |
|
- |
public class Table<RowType> extends Composite implements HasSelectionHandlers<RowType> |
30 |
|
- |
{ |
|
27 |
+ |
import java.util.*; |
|
28 |
+ |
|
|
29 |
+ |
public class Table<RowType> extends Composite implements HasSelectionHandlers<RowType> { |
31 |
30 |
|
private final FixedWidthFlexTable mHeaderTable = new FixedWidthFlexTable(); |
32 |
31 |
|
private final DataTable mDataTable = new DataTable(); |
33 |
32 |
|
private final TableImpl<RowType> mTable; |
|
@@ -37,15 +36,13 @@ |
37 |
36 |
|
|
38 |
37 |
|
private RowSelectionPolicy mSelectionPolicy = RowSelectionPolicy.MULTI; // important: initialized to match PagingScrollingTable's default value |
39 |
38 |
|
|
40 |
|
- |
public Table( ListTableModel<RowType> pTableModel, TableDefinitionPlus<RowType> pTableDefinition, TableClickCommand<RowType> pRowClickCommand ) |
41 |
|
- |
{ |
|
39 |
+ |
public Table( ListTableModel<RowType> pTableModel, TableDefinitionPlus<RowType> pTableDefinition, TableClickCommand<RowType> pRowClickCommand ) { |
42 |
40 |
|
mRowClickCommand = pRowClickCommand; |
43 |
41 |
|
FlexCellFormatter headerCellFormatter = mHeaderTable.getFlexCellFormatter(); |
44 |
42 |
|
final List<ColumnDefinition<RowType, ?>> colDefs = pTableDefinition.getVisibleColumnDefinitions(); |
45 |
43 |
|
int colCount = colDefs.size(); |
46 |
44 |
|
mDataTable.resizeColumns( colCount ); |
47 |
|
- |
for ( int col = 0; col < colCount; col++ ) |
48 |
|
- |
{ |
|
45 |
+ |
for ( int col = 0; col < colCount; col++ ) { |
49 |
46 |
|
ColumnDefinition<RowType, ?> colDef = colDefs.get( col ); |
50 |
47 |
|
mHeaderTable.setHTML( 0, col, (String) colDef.getColumnProperty( HeaderProperty.TYPE ).getHeader( 0 ) ); |
51 |
48 |
|
Style style = headerCellFormatter.getElement( 0, col ).getStyle(); |
|
@@ -56,8 +53,7 @@ |
56 |
53 |
|
style.setPropertyPx( "paddingTop", colDef.getColumnProperty( PaddingProperty.TOP ).getValue() ); |
57 |
54 |
|
style.setPropertyPx( "paddingBottom", colDef.getColumnProperty( PaddingProperty.BOTTOM ).getValue() ); |
58 |
55 |
|
String colStyleName = colDef.getColumnProperty( ColStyleNameProperty.TYPE ).getValue(); |
59 |
|
- |
if ( colStyleName != null ) |
60 |
|
- |
{ |
|
56 |
+ |
if ( colStyleName != null ) { |
61 |
57 |
|
mHeaderTable.getColumnFormatter().addStyleName( col, colStyleName ); |
62 |
58 |
|
mDataTable.getColumnFormatter().addStyleName( col, colStyleName ); |
63 |
59 |
|
} |
|
@@ -67,37 +63,29 @@ |
67 |
63 |
|
mTable.setResizePolicy( ResizePolicy.FILL_WIDTH ); |
68 |
64 |
|
mTable.setSortPolicy( SortPolicy.DISABLED ); |
69 |
65 |
|
setSelectionPolicy( RowSelectionPolicy.SINGLE ); |
70 |
|
- |
if ( mRowClickCommand != null ) |
71 |
|
- |
{ |
|
66 |
+ |
if ( mRowClickCommand != null ) { |
72 |
67 |
|
setClickCommand(); |
73 |
68 |
|
} |
74 |
|
- |
final TableHelper.GridHelper gridHelper = new TableHelper.GridHelper( mDataTable ) |
75 |
|
- |
{ |
|
69 |
+ |
final TableHelper.GridHelper gridHelper = new TableHelper.GridHelper( mDataTable ) { |
76 |
70 |
|
@Override |
77 |
|
- |
protected int getRowIndex( com.google.gwt.user.client.Element pRowElement ) |
78 |
|
- |
{ |
|
71 |
+ |
protected int getRowIndex( com.google.gwt.user.client.Element pRowElement ) { |
79 |
72 |
|
return mDataTable.getRowIndex( pRowElement ); |
80 |
73 |
|
} |
81 |
74 |
|
|
82 |
75 |
|
@Override |
83 |
|
- |
protected int getCellIndex( com.google.gwt.user.client.Element pRowElement, com.google.gwt.user.client.Element pCellElement ) |
84 |
|
- |
{ |
|
76 |
+ |
protected int getCellIndex( com.google.gwt.user.client.Element pRowElement, com.google.gwt.user.client.Element pCellElement ) { |
85 |
77 |
|
return mDataTable.getCellIndex( pRowElement, pCellElement ); |
86 |
78 |
|
} |
87 |
79 |
|
}; |
88 |
|
- |
mDataTable.addClickHandler( new TableHelper.GridClickHandler<RowType>( 0, gridHelper, colDefs ) |
89 |
|
- |
{ |
|
80 |
+ |
mDataTable.addClickHandler( new TableHelper.GridClickHandler<RowType>( 0, gridHelper, colDefs ) { |
90 |
81 |
|
@Override |
91 |
|
- |
public void onClick( ClickEvent pEvent ) |
92 |
|
- |
{ |
|
82 |
+ |
public void onClick( ClickEvent pEvent ) { |
93 |
83 |
|
super.onClick( pEvent ); |
94 |
84 |
|
boolean checkBox = mSelectionPolicy == RowSelectionPolicy.CHECKBOX; |
95 |
85 |
|
boolean radio = mSelectionPolicy == RowSelectionPolicy.RADIO; |
96 |
|
- |
if ( checkBox || radio ) |
97 |
|
- |
{ |
|
86 |
+ |
if ( checkBox || radio ) { |
98 |
87 |
|
TableHelper.Cell cell = gridHelper.getCellForEvent( Event.as( pEvent.getNativeEvent() ) ); |
99 |
|
- |
if ( cell != null ) |
100 |
|
- |
{ |
|
88 |
+ |
if ( cell != null ) { |
101 |
89 |
|
/* |
102 |
90 |
|
* ctrlKey = false for RADIO to workaround table bug |
103 |
91 |
|
* where deselection of old row does not update UI |
|
@@ -109,85 +97,71 @@ |
109 |
97 |
|
} |
110 |
98 |
|
|
111 |
99 |
|
@Override |
112 |
|
- |
protected RowType getRowValue( int pRow ) |
113 |
|
- |
{ |
|
100 |
+ |
protected RowType getRowValue( int pRow ) { |
114 |
101 |
|
return mTable.getRowValue( pRow ); |
115 |
102 |
|
} |
116 |
103 |
|
} ); |
117 |
104 |
|
initWidget( mTable ); |
118 |
105 |
|
} |
119 |
106 |
|
|
120 |
|
- |
public TableModel<RowType> getModel() |
121 |
|
- |
{ |
|
107 |
+ |
public TableModel<RowType> getModel() { |
122 |
108 |
|
return mTable.getTableModel(); |
123 |
109 |
|
} |
124 |
110 |
|
|
125 |
|
- |
public ImmutableArrayList<RowType> getAllRows() |
126 |
|
- |
{ |
|
111 |
+ |
public ImmutableArrayList<RowType> getAllRows() { |
127 |
112 |
|
return new ImmutableArrayList<RowType>( mTable.getRowValues() ); |
128 |
113 |
|
} |
129 |
114 |
|
|
130 |
|
- |
public void selectAll() |
131 |
|
- |
{ |
|
115 |
+ |
public void selectAll() { |
132 |
116 |
|
mTable.getDataTable().selectAllRows(); |
133 |
117 |
|
} |
134 |
118 |
|
|
135 |
|
- |
public void deselectAll() |
136 |
|
- |
{ |
|
119 |
+ |
public void deselectAll() { |
137 |
120 |
|
mTable.getDataTable().deselectAllRows(); |
138 |
121 |
|
} |
139 |
122 |
|
|
140 |
123 |
|
/** |
141 |
124 |
|
* @return true if pPossibleRowValue is in the table (and is now selected) |
142 |
125 |
|
*/ |
143 |
|
- |
public boolean selectRow( RowType pPossibleRowValue ) |
144 |
|
- |
{ |
|
126 |
+ |
public boolean selectRow( RowType pPossibleRowValue ) { |
145 |
127 |
|
return mTable.selectRow( pPossibleRowValue ); |
146 |
128 |
|
} |
147 |
129 |
|
|
148 |
|
- |
public RowSelectionPolicy getSelectionPolicy() |
149 |
|
- |
{ |
|
130 |
+ |
public RowSelectionPolicy getSelectionPolicy() { |
150 |
131 |
|
return mSelectionPolicy; |
151 |
132 |
|
} |
152 |
133 |
|
|
153 |
|
- |
public Set<RowType> getSelectedValues() |
154 |
|
- |
{ |
|
134 |
+ |
public Set<RowType> getSelectedValues() { |
155 |
135 |
|
return mTable.getSelectedRowValues(); |
156 |
136 |
|
} |
157 |
137 |
|
|
158 |
|
- |
public void setSelectionPolicy( RowSelectionPolicy pSelectionPolicy ) |
159 |
|
- |
{ |
160 |
|
- |
if ( mSelectionPolicy != pSelectionPolicy ) |
161 |
|
- |
{ |
|
138 |
+ |
public void setSelectionPolicy( RowSelectionPolicy pSelectionPolicy ) { |
|
139 |
+ |
if ( mSelectionPolicy != pSelectionPolicy ) { |
162 |
140 |
|
mSelectionPolicy = pSelectionPolicy; |
163 |
141 |
|
SelectionPolicy oldSelectionPolicy = mDataTable.getSelectionPolicy(); |
164 |
142 |
|
SelectionPolicy newSelectionPolicy = pSelectionPolicy.getSelectionPolicy(); |
165 |
143 |
|
boolean hasSelectionColumn = oldSelectionPolicy == SelectionPolicy.CHECKBOX || oldSelectionPolicy == SelectionPolicy.RADIO; |
166 |
144 |
|
boolean needsSelectionColumn = newSelectionPolicy == SelectionPolicy.CHECKBOX || newSelectionPolicy == SelectionPolicy.RADIO; |
167 |
145 |
|
|
168 |
|
- |
if ( oldSelectionPolicy == newSelectionPolicy && !hasSelectionColumn ) |
169 |
|
- |
{ |
|
146 |
+ |
if ( oldSelectionPolicy == newSelectionPolicy && !hasSelectionColumn ) { |
170 |
147 |
|
return; |
171 |
148 |
|
} |
172 |
149 |
|
|
173 |
150 |
|
mDataTable.setSelectionEnabled( pSelectionPolicy.isSelectionEnabled() ); |
174 |
151 |
|
mDataTable.setSelectionPolicy( (newSelectionPolicy != null) ? newSelectionPolicy : SelectionPolicy.ONE_ROW ); |
175 |
|
- |
if ( hasSelectionColumn && !needsSelectionColumn ) |
176 |
|
- |
{ |
|
152 |
+ |
if ( hasSelectionColumn && !needsSelectionColumn ) { |
177 |
153 |
|
mHeaderTable.removeCell( 0, 0 ); |
178 |
154 |
|
Element colGroup = mHeaderTable.getElement().getFirstChildElement(); |
179 |
155 |
|
colGroup.removeChild( colGroup.getFirstChildElement() ); |
180 |
|
- |
} |
181 |
|
- |
else if ( needsSelectionColumn && !hasSelectionColumn ) |
182 |
|
- |
{ |
|
156 |
+ |
} else if ( needsSelectionColumn && !hasSelectionColumn ) { |
183 |
157 |
|
Element colGroup = mHeaderTable.getElement().getFirstChildElement(); |
184 |
158 |
|
colGroup.insertBefore( Document.get().createColElement(), colGroup.getFirstChildElement() ); |
185 |
159 |
|
mHeaderTable.insertCell( 0, 0 ); |
186 |
|
- |
mHeaderTable.getCellFormatter().getElement( 0, 0 ).getStyle().setProperty( "textAlign", HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString() ); |
|
160 |
+ |
mHeaderTable.getCellFormatter().getElement( 0, 0 ).getStyle() |
|
161 |
+ |
.setProperty( "textAlign", HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString() ); |
187 |
162 |
|
mHeaderTable.setColumnWidth( 0, mDataTable.getInputColumnWidth() ); |
188 |
163 |
|
} |
189 |
|
- |
if ( needsSelectionColumn ) |
190 |
|
- |
{ |
|
164 |
+ |
if ( needsSelectionColumn ) { |
191 |
165 |
|
// can be called if hasSelectionColumn=true but the label has changed |
192 |
166 |
|
Widget colLabel = ((RowSelectionPolicy.Column) pSelectionPolicy).getColLabel(); |
193 |
167 |
|
|
|
@@ -195,8 +169,7 @@ |
195 |
169 |
|
* If no selection col label is specified, set a "select all" |
196 |
170 |
|
* checkbox in the header. |
197 |
171 |
|
*/ |
198 |
|
- |
if ( colLabel == null && pSelectionPolicy.getType() == Type.CheckBox ) |
199 |
|
- |
{ |
|
172 |
+ |
if ( colLabel == null && pSelectionPolicy.getType() == Type.CheckBox ) { |
200 |
173 |
|
colLabel = mSelectAllCheckBox = new SelectAllCheckBox(); |
201 |
174 |
|
} |
202 |
175 |
|
mHeaderTable.setWidget( 0, 0, colLabel ); |
|
@@ -210,31 +183,25 @@ |
210 |
183 |
|
* selected items on this class. |
211 |
184 |
|
*/ |
212 |
185 |
|
@Override |
213 |
|
- |
public HandlerRegistration addSelectionHandler( SelectionHandler<RowType> pHandler ) |
214 |
|
- |
{ |
215 |
|
- |
return new IncubatorHandlerRegistrationAdaptor2( addHandler( pHandler, SelectionEvent.getType() ), mDataTable.addRowSelectionHandler( new RowSelectionHandler() |
216 |
|
- |
{ |
217 |
|
- |
@Override |
218 |
|
- |
public void onRowSelection( RowSelectionEvent pEvent ) |
219 |
|
- |
{ |
220 |
|
- |
Set<Integer> selectionSet = mDataTable.getSelectedRows(); |
221 |
|
- |
RowType selection; |
222 |
|
- |
if ( selectionSet.size() > 0 ) |
223 |
|
- |
{ |
224 |
|
- |
int selectedIndex = selectionSet.iterator().next(); |
225 |
|
- |
selection = mTable.getRowValue( selectedIndex ); |
226 |
|
- |
} |
227 |
|
- |
else |
228 |
|
- |
{ |
229 |
|
- |
selection = null; |
230 |
|
- |
} |
231 |
|
- |
SelectionEvent.fire( Table.this, selection ); |
232 |
|
- |
} |
233 |
|
- |
} ) ); |
|
186 |
+ |
public HandlerRegistration addSelectionHandler( SelectionHandler<RowType> pHandler ) { |
|
187 |
+ |
return new IncubatorHandlerRegistrationAdaptor2( addHandler( pHandler, SelectionEvent.getType() ), |
|
188 |
+ |
mDataTable.addRowSelectionHandler( new RowSelectionHandler() { |
|
189 |
+ |
@Override |
|
190 |
+ |
public void onRowSelection( RowSelectionEvent pEvent ) { |
|
191 |
+ |
Set<Integer> selectionSet = mDataTable.getSelectedRows(); |
|
192 |
+ |
RowType selection; |
|
193 |
+ |
if ( selectionSet.size() > 0 ) { |
|
194 |
+ |
int selectedIndex = selectionSet.iterator().next(); |
|
195 |
+ |
selection = mTable.getRowValue( selectedIndex ); |
|
196 |
+ |
} else { |
|
197 |
+ |
selection = null; |
|
198 |
+ |
} |
|
199 |
+ |
SelectionEvent.fire( Table.this, selection ); |
|
200 |
+ |
} |
|
201 |
+ |
} ) ); |
234 |
202 |
|
} |
235 |
203 |
|
|
236 |
|
- |
public boolean isScrollVertically() |
237 |
|
- |
{ |
|
204 |
+ |
public boolean isScrollVertically() { |
238 |
205 |
|
return mTable.isScrollVertically(); |
239 |
206 |
|
} |
240 |
207 |
|
|
|
@@ -244,77 +211,63 @@ |
244 |
211 |
|
* |
245 |
212 |
|
* @throws IllegalStateException if called after {@link #loadData()} |
246 |
213 |
|
*/ |
247 |
|
- |
public void setScrollVertically( boolean pScrollVertically ) |
248 |
|
- |
{ |
|
214 |
+ |
public void setScrollVertically( boolean pScrollVertically ) { |
249 |
215 |
|
mTable.setScrollVertically( pScrollVertically ); |
250 |
216 |
|
} |
251 |
217 |
|
|
252 |
|
- |
public TableRowCountCallback getRowCountCallback() |
253 |
|
- |
{ |
|
218 |
+ |
public TableRowCountCallback getRowCountCallback() { |
254 |
219 |
|
return mTable.getRowCountCallback(); |
255 |
220 |
|
} |
256 |
221 |
|
|
257 |
|
- |
public void setRowCountCallback( TableRowCountCallback pRowCountCallback ) |
258 |
|
- |
{ |
|
222 |
+ |
public void setRowCountCallback( TableRowCountCallback pRowCountCallback ) { |
259 |
223 |
|
mTable.setRowCountCallback( pRowCountCallback ); |
260 |
224 |
|
} |
261 |
225 |
|
|
262 |
|
- |
public boolean isHeaderVisible() |
263 |
|
- |
{ |
|
226 |
+ |
public boolean isHeaderVisible() { |
264 |
227 |
|
return mHeaderTable.isVisible(); |
265 |
228 |
|
} |
266 |
229 |
|
|
267 |
|
- |
public void setHeaderVisible( boolean pVisible ) |
268 |
|
- |
{ |
|
230 |
+ |
public void setHeaderVisible( boolean pVisible ) { |
269 |
231 |
|
mHeaderTable.setVisible( pVisible ); |
270 |
232 |
|
} |
271 |
233 |
|
|
272 |
|
- |
public Widget getEmptyTableWidget() |
273 |
|
- |
{ |
|
234 |
+ |
public Widget getEmptyTableWidget() { |
274 |
235 |
|
return mTable.getEmptyTableWidget(); |
275 |
236 |
|
} |
276 |
237 |
|
|
277 |
|
- |
public void setEmptyTableWidget( Widget pEmptyTableWidget ) |
278 |
|
- |
{ |
|
238 |
+ |
public void setEmptyTableWidget( Widget pEmptyTableWidget ) { |
279 |
239 |
|
mTable.setEmptyTableWidget( pEmptyTableWidget ); |
280 |
240 |
|
} |
281 |
241 |
|
|
282 |
|
- |
public void loadData() |
283 |
|
- |
{ |
|
242 |
+ |
public void loadData() { |
284 |
243 |
|
mTable.loadPage(); |
285 |
244 |
|
} |
286 |
245 |
|
|
287 |
246 |
|
@SuppressWarnings({"deprecation"}) |
288 |
|
- |
private void setClickCommand() |
289 |
|
- |
{ |
290 |
|
- |
mDataTable.addTableListener( new com.google.gwt.user.client.ui.TableListener() |
291 |
|
- |
{ |
|
247 |
+ |
private void setClickCommand() { |
|
248 |
+ |
mDataTable.addTableListener( new com.google.gwt.user.client.ui.TableListener() { |
292 |
249 |
|
@Override |
293 |
|
- |
public void onCellClicked( com.google.gwt.user.client.ui.SourcesTableEvents pSender, int pRow, int pCol ) |
294 |
|
- |
{ |
|
250 |
+ |
public void onCellClicked( com.google.gwt.user.client.ui.SourcesTableEvents pSender, int pRow, int pCol ) { |
295 |
251 |
|
mRowClickCommand.execute( ((ListTableModel<RowType>) mTable.getTableModel()).get( pRow ) ); |
296 |
252 |
|
} |
297 |
253 |
|
} ); |
298 |
254 |
|
} |
299 |
255 |
|
|
300 |
|
- |
public void simulateUserClickHeader( int pCol, KeyboardKeyModifier pModifiers ) |
301 |
|
- |
{ |
|
256 |
+ |
public void simulateUserClickHeader( int pCol, KeyboardKeyModifier pModifiers ) { |
302 |
257 |
|
pModifiers = KeyboardKeyModifier.deNull( pModifiers ); |
303 |
258 |
|
NativeEvent event = Document.get().createClickEvent( 0, 0, 0, 0, 0, pModifiers.isCtrl(), pModifiers.isAlt(), pModifiers.isShift(), pModifiers.isMeta() ); |
304 |
259 |
|
com.google.gwt.user.client.Element zElement = mHeaderTable.getCellFormatter().getElement( 0, pCol ); |
305 |
260 |
|
zElement.dispatchEvent( event ); |
306 |
261 |
|
} |
307 |
262 |
|
|
308 |
|
- |
public void simulateUserClickDataGrid( int pRow, int pCol, KeyboardKeyModifier pModifiers ) |
309 |
|
- |
{ |
|
263 |
+ |
public void simulateUserClickDataGrid( int pRow, int pCol, KeyboardKeyModifier pModifiers ) { |
310 |
264 |
|
pModifiers = KeyboardKeyModifier.deNull( pModifiers ); |
311 |
265 |
|
NativeEvent event = Document.get().createClickEvent( 0, 0, 0, 0, 0, pModifiers.isCtrl(), pModifiers.isAlt(), pModifiers.isShift(), pModifiers.isMeta() ); |
312 |
266 |
|
com.google.gwt.user.client.Element zElement = mDataTable.getCellFormatter().getElement( pRow, pCol ); |
313 |
267 |
|
zElement.dispatchEvent( event ); |
314 |
268 |
|
} |
315 |
269 |
|
|
316 |
|
- |
private static class TableImpl<RowType> extends PagingScrollTable<RowType> |
317 |
|
- |
{ |
|
270 |
+ |
private static class TableImpl<RowType> extends PagingScrollTable<RowType> { |
318 |
271 |
|
private boolean mScrollVertically = true; // important: initialized to match PagingScrollingTable's default value |
319 |
272 |
|
private TableRowCountCallback mRowCountCallback = null; |
320 |
273 |
|
private TableRowElement mGridRow; |
|
@@ -325,11 +278,10 @@ |
325 |
278 |
|
private int mPrototypeRowHeight = 0; |
326 |
279 |
|
private boolean mLoadPageCalled = false; |
327 |
280 |
|
|
328 |
|
- |
public TableImpl( TableModel<RowType> pTableModel, FixedWidthGrid pDataTable, FixedWidthFlexTable pHeaderTable, TableDefinitionPlus<RowType> pTableDefinition ) |
329 |
|
- |
{ |
|
281 |
+ |
public TableImpl( TableModel<RowType> pTableModel, FixedWidthGrid pDataTable, FixedWidthFlexTable pHeaderTable, |
|
282 |
+ |
TableDefinitionPlus<RowType> pTableDefinition ) { |
330 |
283 |
|
super( pTableModel, pDataTable, pHeaderTable, pTableDefinition ); |
331 |
|
- |
if ( BrowserFamily.IE.equals( UserAgent.getInstance().getFamily() ) ) |
332 |
|
- |
{ |
|
284 |
+ |
if ( BrowserFamily.IE.equals( UserAgent.getInstance().getFamily() ) ) { |
333 |
285 |
|
/* |
334 |
286 |
|
* Hack the header spacer so it does not prevent interaction w/ the column resize handles in IE (Issue 66). |
335 |
287 |
|
* |
|
@@ -353,29 +305,24 @@ |
353 |
305 |
|
mGridRow = mockTableResult.mPrototypeRow; |
354 |
306 |
|
getElement().insertBefore( mockTableResult.mTable, getElement().getFirstChild() ); |
355 |
307 |
|
|
356 |
|
- |
ResizableWidgetCollection.get().add( new ResizableWidgetAdaptor( this, getDataWrapper() ) |
357 |
|
- |
{ |
|
308 |
+ |
ResizableWidgetCollection.get().add( new ResizableWidgetAdaptor( this, getDataWrapper() ) { |
358 |
309 |
|
@Override |
359 |
|
- |
public void onResize( int pViewportWidth, int pViewportHeight ) |
360 |
|
- |
{ |
|
310 |
+ |
public void onResize( int pViewportWidth, int pViewportHeight ) { |
361 |
311 |
|
mViewportHeight = pViewportHeight; |
362 |
312 |
|
updateMaxVisibleRows(); |
363 |
313 |
|
} |
364 |
314 |
|
} ); |
365 |
315 |
|
|
366 |
|
- |
ResizableWidgetCollection.get().add( new TemporaryResizableWidgetAdaptor( this, mGridRow.<com.google.gwt.user.client.Element>cast() ) |
367 |
|
- |
{ |
|
316 |
+ |
ResizableWidgetCollection.get().add( new TemporaryResizableWidgetAdaptor( this, mGridRow.<com.google.gwt.user.client.Element>cast() ) { |
368 |
317 |
|
@Override |
369 |
|
- |
protected void onSizeInitialized( int pRowWidth, int pRowHeight ) |
370 |
|
- |
{ |
|
318 |
+ |
protected void onSizeInitialized( int pRowWidth, int pRowHeight ) { |
371 |
319 |
|
mPrototypeRowHeight = pRowHeight; |
372 |
320 |
|
updateMaxVisibleRows(); |
373 |
321 |
|
} |
374 |
322 |
|
} ); |
375 |
323 |
|
} |
376 |
324 |
|
|
377 |
|
- |
public boolean isScrollVertically() |
378 |
|
- |
{ |
|
325 |
+ |
public boolean isScrollVertically() { |
379 |
326 |
|
return mScrollVertically; |
380 |
327 |
|
} |
381 |
328 |
|
|
|
@@ -385,10 +332,8 @@ |
385 |
332 |
|
* |
386 |
333 |
|
* @throws IllegalStateException if called after {@link #loadData()} |
387 |
334 |
|
*/ |
388 |
|
- |
public void setScrollVertically( boolean pScrollVertically ) |
389 |
|
- |
{ |
390 |
|
- |
if ( mLoadPageCalled ) |
391 |
|
- |
{ |
|
335 |
+ |
public void setScrollVertically( boolean pScrollVertically ) { |
|
336 |
+ |
if ( mLoadPageCalled ) { |
392 |
337 |
|
throw new IllegalStateException( "Table: must call set setScrollVertically() before loadData()" ); |
393 |
338 |
|
} |
394 |
339 |
|
|
|
@@ -396,46 +341,35 @@ |
396 |
341 |
|
} |
397 |
342 |
|
|
398 |
343 |
|
@Override |
399 |
|
- |
public void setScrollPolicy( ScrollPolicy pScrollPolicy ) |
400 |
|
- |
{ |
|
344 |
+ |
public void setScrollPolicy( ScrollPolicy pScrollPolicy ) { |
401 |
345 |
|
throw new UnsupportedOperationException(); |
402 |
346 |
|
} |
403 |
347 |
|
|
404 |
|
- |
public void loadPage() |
405 |
|
- |
{ |
|
348 |
+ |
public void loadPage() { |
406 |
349 |
|
mLoadPageCalled = true; |
407 |
|
- |
if ( isSizeInitialized() ) |
408 |
|
- |
{ |
|
350 |
+ |
if ( isSizeInitialized() ) { |
409 |
351 |
|
gotoPage( 0, true ); |
410 |
|
- |
} |
411 |
|
- |
else |
412 |
|
- |
{ |
|
352 |
+ |
} else { |
413 |
353 |
|
mFetchDataWaitingForSize = true; |
414 |
354 |
|
} |
415 |
355 |
|
} |
416 |
356 |
|
|
417 |
|
- |
public TableRowCountCallback getRowCountCallback() |
418 |
|
- |
{ |
|
357 |
+ |
public TableRowCountCallback getRowCountCallback() { |
419 |
358 |
|
return mRowCountCallback; |
420 |
359 |
|
} |
421 |
360 |
|
|
422 |
|
- |
public void setRowCountCallback( TableRowCountCallback pRowCountCallback ) |
423 |
|
- |
{ |
|
361 |
+ |
public void setRowCountCallback( TableRowCountCallback pRowCountCallback ) { |
424 |
362 |
|
mRowCountCallback = pRowCountCallback; |
425 |
363 |
|
} |
426 |
364 |
|
|
427 |
365 |
|
/** |
428 |
366 |
|
* @return true if pPossibleRowValue is in the table (and is now selected) |
429 |
367 |
|
*/ |
430 |
|
- |
public boolean selectRow( RowType pPossibleRowValue ) |
431 |
|
- |
{ |
432 |
|
- |
if ( pPossibleRowValue != null ) |
433 |
|
- |
{ |
|
368 |
+ |
public boolean selectRow( RowType pPossibleRowValue ) { |
|
369 |
+ |
if ( pPossibleRowValue != null ) { |
434 |
370 |
|
List<RowType> zRows = getRowValues(); |
435 |
|
- |
for ( int i = 0; i < zRows.size(); i++ ) |
436 |
|
- |
{ |
437 |
|
- |
if ( pPossibleRowValue.equals( zRows.get( i ) ) ) |
438 |
|
- |
{ |
|
371 |
+ |
for ( int i = 0; i < zRows.size(); i++ ) { |
|
372 |
+ |
if ( pPossibleRowValue.equals( zRows.get( i ) ) ) { |
439 |
373 |
|
getDataTable().selectRow( i, false ); // todo: Do we need to do some kind of page adjustment? |
440 |
374 |
|
return true; |
441 |
375 |
|
} |
|
@@ -448,8 +382,7 @@ |
448 |
382 |
|
* Override to gain access |
449 |
383 |
|
*/ |
450 |
384 |
|
@Override |
451 |
|
- |
protected List<RowType> getRowValues() |
452 |
|
- |
{ |
|
385 |
+ |
protected List<RowType> getRowValues() { |
453 |
386 |
|
return super.getRowValues(); |
454 |
387 |
|
} |
455 |
388 |
|
|
|
@@ -457,8 +390,7 @@ |
457 |
390 |
|
* Override to gain access |
458 |
391 |
|
*/ |
459 |
392 |
|
@Override |
460 |
|
- |
protected void setEmptyTableWidgetVisible( boolean pVisible ) |
461 |
|
- |
{ |
|
393 |
+ |
protected void setEmptyTableWidgetVisible( boolean pVisible ) { |
462 |
394 |
|
super.setEmptyTableWidgetVisible( pVisible ); |
463 |
395 |
|
} |
464 |
396 |
|
|
|
@@ -466,33 +398,27 @@ |
466 |
398 |
|
* Called by superclass after {@link TableModel} calls callback w/ data. |
467 |
399 |
|
*/ |
468 |
400 |
|
@Override |
469 |
|
- |
protected void setData( int pFirstRow, Iterator<RowType> pRows ) |
470 |
|
- |
{ |
|
401 |
+ |
protected void setData( int pFirstRow, Iterator<RowType> pRows ) { |
471 |
402 |
|
super.setData( pFirstRow, (mScrollVertically) ? pRows : new LimitingIteratorWrapper<RowType>( pRows, mMaxVisibleRows ) ); |
472 |
403 |
|
int rowCount = getTableModel().getRowCount(); |
473 |
|
- |
if ( mRowCount != rowCount ) |
474 |
|
- |
{ |
|
404 |
+ |
if ( mRowCount != rowCount ) { |
475 |
405 |
|
mRowCount = rowCount; |
476 |
406 |
|
fireRowCountChanged(); |
477 |
407 |
|
} |
478 |
408 |
|
} |
479 |
409 |
|
|
480 |
410 |
|
@Override |
481 |
|
- |
public void onResize( int pTableWidth, int pTableHeight ) |
482 |
|
- |
{ |
|
411 |
+ |
public void onResize( int pTableWidth, int pTableHeight ) { |
483 |
412 |
|
super.onResize( pTableWidth, pTableHeight ); |
484 |
413 |
|
updateMaxVisibleRows(); |
485 |
414 |
|
} |
486 |
415 |
|
|
487 |
|
- |
private boolean isSizeInitialized() |
488 |
|
- |
{ |
|
416 |
+ |
private boolean isSizeInitialized() { |
489 |
417 |
|
return mViewportHeight > 0 && mPrototypeRowHeight > 0; |
490 |
418 |
|
} |
491 |
419 |
|
|
492 |
|
- |
private void updateMaxVisibleRows() |
493 |
|
- |
{ |
494 |
|
- |
if ( isSizeInitialized() ) |
495 |
|
- |
{ |
|
420 |
+ |
private void updateMaxVisibleRows() { |
|
421 |
+ |
if ( isSizeInitialized() ) { |
496 |
422 |
|
/* |
497 |
423 |
|
* Require a minimum of 1 row. Otherwise outer element |
498 |
424 |
|
* (AbstractScrollTable.absoluteElem) can get stuck at header |
|
@@ -500,37 +426,29 @@ |
500 |
426 |
|
* available. |
501 |
427 |
|
*/ |
502 |
428 |
|
int maxVisibleRows = Math.max( 1, mViewportHeight / mPrototypeRowHeight ); |
503 |
|
- |
if ( mMaxVisibleRows != maxVisibleRows ) |
504 |
|
- |
{ |
|
429 |
+ |
if ( mMaxVisibleRows != maxVisibleRows ) { |
505 |
430 |
|
mMaxVisibleRows = maxVisibleRows; |
506 |
431 |
|
setPageSize( mMaxVisibleRows ); |
507 |
|
- |
if ( mFetchDataWaitingForSize ) |
508 |
|
- |
{ |
|
432 |
+ |
if ( mFetchDataWaitingForSize ) { |
509 |
433 |
|
mFetchDataWaitingForSize = false; |
510 |
434 |
|
super.gotoFirstPage(); |
511 |
|
- |
} |
512 |
|
- |
else |
513 |
|
- |
{ |
|
435 |
+ |
} else { |
514 |
436 |
|
fireRowCountChanged(); |
515 |
437 |
|
} |
516 |
438 |
|
} |
517 |
439 |
|
} |
518 |
440 |
|
} |
519 |
441 |
|
|
520 |
|
- |
private void fireRowCountChanged() |
521 |
|
- |
{ |
522 |
|
- |
if ( mRowCountCallback != null ) |
523 |
|
- |
{ |
|
442 |
+ |
private void fireRowCountChanged() { |
|
443 |
+ |
if ( mRowCountCallback != null ) { |
524 |
444 |
|
int visibleRows = Math.min( mRowCount, mMaxVisibleRows ); |
525 |
445 |
|
mRowCountCallback.rowCountChanged( visibleRows, mRowCount, mMaxVisibleRows ); |
526 |
446 |
|
} |
527 |
447 |
|
} |
528 |
448 |
|
} |
529 |
449 |
|
|
530 |
|
- |
private static class DataTable extends FixedWidthGrid |
531 |
|
- |
{ |
532 |
|
- |
public HandlerRegistration addClickHandler( ClickHandler pHandler ) |
533 |
|
- |
{ |
|
450 |
+ |
private static class DataTable extends FixedWidthGrid { |
|
451 |
+ |
public HandlerRegistration addClickHandler( ClickHandler pHandler ) { |
534 |
452 |
|
return addDomHandler( pHandler, ClickEvent.getType() ); |
535 |
453 |
|
} |
536 |
454 |
|
|
|
@@ -538,8 +456,7 @@ |
538 |
456 |
|
* Override to gain access |
539 |
457 |
|
*/ |
540 |
458 |
|
@Override |
541 |
|
- |
protected int getInputColumnWidth() |
542 |
|
- |
{ |
|
459 |
+ |
protected int getInputColumnWidth() { |
543 |
460 |
|
return super.getInputColumnWidth(); |
544 |
461 |
|
} |
545 |
462 |
|
|
|
@@ -547,8 +464,7 @@ |
547 |
464 |
|
* Override to gain access |
548 |
465 |
|
*/ |
549 |
466 |
|
@Override |
550 |
|
- |
protected int getRowIndex( com.google.gwt.user.client.Element pRowElem ) |
551 |
|
- |
{ |
|
467 |
+ |
protected int getRowIndex( com.google.gwt.user.client.Element pRowElem ) { |
552 |
468 |
|
return super.getRowIndex( pRowElem ); |
553 |
469 |
|
} |
554 |
470 |
|
|
|
@@ -556,16 +472,13 @@ |
556 |
472 |
|
* Override to gain access |
557 |
473 |
|
*/ |
558 |
474 |
|
@Override |
559 |
|
- |
protected int getCellIndex( com.google.gwt.user.client.Element pRowElem, com.google.gwt.user.client.Element pCellElem ) |
560 |
|
- |
{ |
|
475 |
+ |
protected int getCellIndex( com.google.gwt.user.client.Element pRowElem, com.google.gwt.user.client.Element pCellElem ) { |
561 |
476 |
|
return super.getCellIndex( pRowElem, pCellElem ); |
562 |
477 |
|
} |
563 |
478 |
|
|
564 |
479 |
|
@Override |
565 |
|
- |
public void onBrowserEvent( Event pEvent ) |
566 |
|
- |
{ |
567 |
|
- |
if ( pEvent.getTypeInt() == Event.ONCLICK ) |
568 |
|
- |
{ |
|
480 |
+ |
public void onBrowserEvent( Event pEvent ) { |
|
481 |
+ |
if ( pEvent.getTypeInt() == Event.ONCLICK ) { |
569 |
482 |
|
// the current incubator HTMLTable does not call super() |
570 |
483 |
|
DomEvent.fireNativeEvent( pEvent, this, getElement() ); |
571 |
484 |
|
} |
|
@@ -573,23 +486,16 @@ |
573 |
486 |
|
} |
574 |
487 |
|
} |
575 |
488 |
|
|
576 |
|
- |
public class SelectAllCheckBox extends CheckBox |
577 |
|
- |
{ |
|
489 |
+ |
public class SelectAllCheckBox extends CheckBox { |
578 |
490 |
|
private HandlerRegistration mSelectionHandlerRegistration; |
579 |
491 |
|
|
580 |
|
- |
public SelectAllCheckBox() |
581 |
|
- |
{ |
582 |
|
- |
addValueChangeHandler( new ValueChangeHandler<Boolean>() |
583 |
|
- |
{ |
|
492 |
+ |
public SelectAllCheckBox() { |
|
493 |
+ |
addValueChangeHandler( new ValueChangeHandler<Boolean>() { |
584 |
494 |
|
@Override |
585 |
|
- |
public void onValueChange( ValueChangeEvent<Boolean> pEvent ) |
586 |
|
- |
{ |
587 |
|
- |
if ( pEvent.getValue() ) |
588 |
|
- |
{ |
|
495 |
+ |
public void onValueChange( ValueChangeEvent<Boolean> pEvent ) { |
|
496 |
+ |
if ( pEvent.getValue() ) { |
589 |
497 |
|
selectAll(); |
590 |
|
- |
} |
591 |
|
- |
else |
592 |
|
- |
{ |
|
498 |
+ |
} else { |
593 |
499 |
|
deselectAll(); |
594 |
500 |
|
} |
595 |
501 |
|
} |
|
@@ -597,29 +503,24 @@ |
597 |
503 |
|
update(); |
598 |
504 |
|
} |
599 |
505 |
|
|
600 |
|
- |
public void update() |
601 |
|
- |
{ |
|
506 |
+ |
public void update() { |
602 |
507 |
|
int selectionCount = getSelectedValues().size(); |
603 |
508 |
|
setValue( selectionCount > 0 && getSelectedValues().size() == getModel().getRowCount() ); |
604 |
509 |
|
} |
605 |
510 |
|
|
606 |
511 |
|
@Override |
607 |
|
- |
protected void onLoad() |
608 |
|
- |
{ |
|
512 |
+ |
protected void onLoad() { |
609 |
513 |
|
super.onLoad(); |
610 |
|
- |
mSelectionHandlerRegistration = addSelectionHandler( new SelectionHandler<RowType>() |
611 |
|
- |
{ |
|
514 |
+ |
mSelectionHandlerRegistration = addSelectionHandler( new SelectionHandler<RowType>() { |
612 |
515 |
|
@Override |
613 |
|
- |
public void onSelection( SelectionEvent<RowType> pEvent ) |
614 |
|
- |
{ |
|
516 |
+ |
public void onSelection( SelectionEvent<RowType> pEvent ) { |
615 |
517 |
|
update(); |
616 |
518 |
|
} |
617 |
519 |
|
} ); |
618 |
520 |
|
} |
619 |
521 |
|
|
620 |
522 |
|
@Override |
621 |
|
- |
protected void onUnload() |
622 |
|
- |
{ |
|
523 |
+ |
protected void onUnload() { |
623 |
524 |
|
mSelectionHandlerRegistration.removeHandler(); |
624 |
525 |
|
} |
625 |
526 |
|
} |