|
@@ -15,38 +15,32 @@ |
15 |
15 |
|
*/ |
16 |
16 |
|
package com.google.gwt.gen2.table.client; |
17 |
17 |
|
|
18 |
|
- |
import java.util.*; |
19 |
|
- |
|
20 |
18 |
|
import com.google.gwt.gen2.table.client.TableModelHelper.*; |
21 |
19 |
|
|
|
20 |
+ |
import java.util.*; |
|
21 |
+ |
|
22 |
22 |
|
/** |
23 |
23 |
|
* A {@link MutableTableModel} used when the data source can be accessed |
24 |
24 |
|
* synchronously. |
25 |
25 |
|
*/ |
26 |
|
- |
public abstract class ClientTableModel extends MutableTableModel<List<Object>> |
27 |
|
- |
{ |
|
26 |
+ |
public abstract class ClientTableModel extends MutableTableModel<List<Object>> { |
28 |
27 |
|
/** |
29 |
28 |
|
* Convenience class to support custom iterators. |
30 |
29 |
|
*/ |
31 |
|
- |
private abstract static class StubIterator<E> implements Iterator<E> |
32 |
|
- |
{ |
|
30 |
+ |
private abstract static class StubIterator<E> implements Iterator<E> { |
33 |
31 |
|
int index; |
34 |
32 |
|
E next; |
35 |
33 |
|
boolean done = false; |
36 |
34 |
|
|
37 |
35 |
|
protected abstract E computeNext(); |
38 |
36 |
|
|
39 |
|
- |
public boolean hasNext() |
40 |
|
- |
{ |
41 |
|
- |
if ( done ) |
42 |
|
- |
{ |
|
37 |
+ |
public boolean hasNext() { |
|
38 |
+ |
if ( done ) { |
43 |
39 |
|
return false; |
44 |
40 |
|
} |
45 |
|
- |
if ( next == null ) |
46 |
|
- |
{ |
|
41 |
+ |
if ( next == null ) { |
47 |
42 |
|
next = computeNext(); |
48 |
|
- |
if ( next == null ) |
49 |
|
- |
{ |
|
43 |
+ |
if ( next == null ) { |
50 |
44 |
|
done = true; |
51 |
45 |
|
return false; |
52 |
46 |
|
} |
|
@@ -54,33 +48,26 @@ |
54 |
48 |
|
return true; |
55 |
49 |
|
} |
56 |
50 |
|
|
57 |
|
- |
public E next() |
58 |
|
- |
{ |
59 |
|
- |
if ( !hasNext() ) |
60 |
|
- |
{ |
|
51 |
+ |
public E next() { |
|
52 |
+ |
if ( !hasNext() ) { |
61 |
53 |
|
throw new NoSuchElementException(); |
62 |
|
- |
} |
63 |
|
- |
else |
64 |
|
- |
{ |
|
54 |
+ |
} else { |
65 |
55 |
|
E accum = next; |
66 |
56 |
|
next = null; |
67 |
57 |
|
return accum; |
68 |
58 |
|
} |
69 |
59 |
|
} |
70 |
60 |
|
|
71 |
|
- |
public void remove() |
72 |
|
- |
{ |
|
61 |
+ |
public void remove() { |
73 |
62 |
|
throw new UnsupportedOperationException(); |
74 |
63 |
|
} |
75 |
64 |
|
} |
76 |
65 |
|
|
77 |
|
- |
private class ColumnIterator extends StubIterator<Object> |
78 |
|
- |
{ |
|
66 |
+ |
private class ColumnIterator extends StubIterator<Object> { |
79 |
67 |
|
private int row = 0; |
80 |
68 |
|
|
81 |
69 |
|
@Override |
82 |
|
- |
public Object computeNext() |
83 |
|
- |
{ |
|
70 |
+ |
public Object computeNext() { |
84 |
71 |
|
return getCell( row, index++ ); |
85 |
72 |
|
} |
86 |
73 |
|
} |
|
@@ -88,26 +75,20 @@ |
88 |
75 |
|
/** |
89 |
76 |
|
* An iterator over the rows of of client data. |
90 |
77 |
|
*/ |
91 |
|
- |
private class RowIterator extends StubIterator<List<Object>> |
92 |
|
- |
{ |
|
78 |
+ |
private class RowIterator extends StubIterator<List<Object>> { |
93 |
79 |
|
private int max; |
94 |
80 |
|
|
95 |
|
- |
public RowIterator( Request request ) |
96 |
|
- |
{ |
|
81 |
+ |
public RowIterator( Request request ) { |
97 |
82 |
|
index = request.getStartRow(); |
98 |
|
- |
if ( request.getNumRows() == -1 ) |
99 |
|
- |
{ |
|
83 |
+ |
if ( request.getNumRows() == -1 ) { |
100 |
84 |
|
max = Integer.MAX_VALUE; |
101 |
|
- |
} |
102 |
|
- |
else |
103 |
|
- |
{ |
|
85 |
+ |
} else { |
104 |
86 |
|
max = request.getNumRows() + index; |
105 |
87 |
|
} |
106 |
88 |
|
} |
107 |
89 |
|
|
108 |
90 |
|
@Override |
109 |
|
- |
protected List<Object> computeNext() |
110 |
|
- |
{ |
|
91 |
+ |
protected List<Object> computeNext() { |
111 |
92 |
|
// Reset column iterator rather than creating new one. |
112 |
93 |
|
final ColumnIterator colIt = new ColumnIterator(); |
113 |
94 |
|
colIt.index = 0; |
|
@@ -116,17 +97,13 @@ |
116 |
97 |
|
colIt.next = null; |
117 |
98 |
|
|
118 |
99 |
|
// Now check for next. |
119 |
|
- |
if ( colIt.hasNext() && colIt.row < max ) |
120 |
|
- |
{ |
|
100 |
+ |
if ( colIt.hasNext() && colIt.row < max ) { |
121 |
101 |
|
List<Object> next = new ArrayList<Object>(); |
122 |
|
- |
while ( colIt.hasNext() ) |
123 |
|
- |
{ |
|
102 |
+ |
while ( colIt.hasNext() ) { |
124 |
103 |
|
next.add( colIt.next() ); |
125 |
104 |
|
} |
126 |
105 |
|
return next; |
127 |
|
- |
} |
128 |
|
- |
else |
129 |
|
- |
{ |
|
106 |
+ |
} else { |
130 |
107 |
|
return null; |
131 |
108 |
|
} |
132 |
109 |
|
} |
|
@@ -144,14 +121,11 @@ |
144 |
121 |
|
public abstract Object getCell( int rowNum, int colNum ); |
145 |
122 |
|
|
146 |
123 |
|
@Override |
147 |
|
- |
public void requestRows( Request request, Callback<List<Object>> callback ) |
148 |
|
- |
{ |
|
124 |
+ |
public void requestRows( Request request, Callback<List<Object>> callback ) { |
149 |
125 |
|
final RowIterator rowIter = new RowIterator( request ); |
150 |
|
- |
Response<List<Object>> response = new Response<List<Object>>() |
151 |
|
- |
{ |
|
126 |
+ |
Response<List<Object>> response = new Response<List<Object>>() { |
152 |
127 |
|
@Override |
153 |
|
- |
public Iterator<List<Object>> getRowValues() |
154 |
|
- |
{ |
|
128 |
+ |
public Iterator<List<Object>> getRowValues() { |
155 |
129 |
|
return rowIter; |
156 |
130 |
|
} |
157 |
131 |
|
}; |