Subversion Repository Public Repository

litesoft

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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
/*
 * 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 java.io.*;
import java.util.*;

/**
 * A helper class that provides all of the inner classes used by
 * {@link TableModel}. These classes cannot be included in the
 * {@link TableModel} class itself because of a JDT error that prevents the GWT
 * RPC generator from creating implementations of remote services:
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=243820
 * <p/>
 * This class should be removed once this bug is fixed.
 */
public final class TableModelHelper {
    /**
     * Information about the sort order of a specific column in a table.
     */
    public static class ColumnSortInfo implements Serializable {
        /**
         * True if the sort order is ascending.
         */
        private boolean ascending;

        /**
         * The column index.
         */
        private int column;

        /**
         * Default constructor used for RPC.
         */
        public ColumnSortInfo() {
            this( 0, true );
        }

        /**
         * Construct a new {@link ColumnSortInfo}.
         *
         * @param column    the column index
         * @param ascending true if sorted ascending
         */
        public ColumnSortInfo( int column, boolean ascending ) {
            this.column = column;
            this.ascending = ascending;
        }

        @Override
        public boolean equals( Object obj ) {
            if ( obj instanceof ColumnSortInfo ) {
                return equals( (ColumnSortInfo) obj );
            }
            return false;
        }

        /**
         * Check if this object is equal to another. The objects are equal if the
         * column and ascending values are equal.
         *
         * @param csi the other object
         *
         * @return true if objects are the same
         */
        public boolean equals( ColumnSortInfo csi ) {
            if ( csi == null ) {
                return false;
            }
            return getColumn() == csi.getColumn() && isAscending() == csi.isAscending();
        }

        /**
         * @return the column index
         */
        public int getColumn() {
            return column;
        }

        @Override
        public int hashCode() {
            return super.hashCode();
        }

        /**
         * @return true if ascending, false if descending
         */
        public boolean isAscending() {
            return ascending;
        }

        /**
         * Set whether or not the sorting is ascending or descending.
         *
         * @param ascending true if ascending, false if descending
         */
        public void setAscending( boolean ascending ) {
            this.ascending = ascending;
        }

        /**
         * Set the column index.
         *
         * @param column the column index
         */
        public void setColumn( int column ) {
            this.column = column;
        }
    }

    /**
     * An ordered list of sorting info where each entry tells us how to sort a
     * single column. The first entry is the primary sort order, the second entry
     * is the first tie-breaker, and so on.
     */
    public static class ColumnSortList implements Serializable,
                                                  Iterable<ColumnSortInfo> {
        /**
         * A List used to manage the insertion/removal of {@link ColumnSortInfo}.
         */
        private List<ColumnSortInfo> infos = new ArrayList<ColumnSortInfo>();

        /**
         * Add a {@link ColumnSortInfo} to this list. If the column already exists,
         * it will be removed from its current position and placed at the start of
         * the list, becoming the primary sort info.
         * <p/>
         * This add method inserts an entry at the beginning of the list. It does
         * not append the entry to the end of the list.
         *
         * @param sortInfo the {@link ColumnSortInfo} to add
         */
        public void add( ColumnSortInfo sortInfo ) {
            add( 0, sortInfo );
        }

        /**
         * Inserts the specified {@link ColumnSortInfo} at the specified position in
         * this list. If the column already exists in the sort info, the index will
         * be adjusted to account for any removed entries.
         *
         * @param sortInfo the {@link ColumnSortInfo} to add
         */
        public void add( int index, ColumnSortInfo sortInfo ) {
            // Remove sort info for duplicate columns
            int column = sortInfo.getColumn();
            for ( int i = 0; i < infos.size(); i++ ) {
                ColumnSortInfo curInfo = infos.get( i );
                if ( curInfo.getColumn() == column ) {
                    infos.remove( i );
                    i--;
                    if ( column < index ) {
                        index--;
                    }
                }
            }

            // Insert the new sort info
            infos.add( index, sortInfo );
        }

        /**
         * Removes all of the elements from this list.
         */
        public void clear() {
            infos.clear();
        }

        @Override
        public boolean equals( Object obj ) {
            if ( obj instanceof ColumnSortList ) {
                return equals( (ColumnSortList) obj );
            }
            return false;
        }

        /**
         * Check if this object is equal to another.
         *
         * @param csl the other object
         *
         * @return true if objects are equal
         */
        public boolean equals( ColumnSortList csl ) {
            // Object is null
            if ( csl == null ) {
                return false;
            }

            // Check the size of the lists
            int size = size();
            if ( size != csl.size() ) {
                return false;
            }

            // Compare the entries
            for ( int i = 0; i < size; i++ ) {
                if ( !infos.get( i ).equals( csl.infos.get( i ) ) ) {
                    return false;
                }
            }

            // Everything is equal
            return true;
        }

        /**
         * Get the primary (first) {@link ColumnSortInfo}'s column index.
         *
         * @return the primary column or -1 if not sorted
         */
        public int getPrimaryColumn() {
            ColumnSortInfo primaryInfo = getPrimaryColumnSortInfo();
            if ( primaryInfo == null ) {
                return -1;
            }
            return primaryInfo.getColumn();
        }

        /**
         * Get the primary (first) {@link ColumnSortInfo}.
         *
         * @return the primary column sort info
         */
        public ColumnSortInfo getPrimaryColumnSortInfo() {
            if ( infos.size() > 0 ) {
                return infos.get( 0 );
            }
            return null;
        }

        @Override
        public int hashCode() {
            return super.hashCode();
        }

        /**
         * Get the primary (first) {@link ColumnSortInfo}'s sort order.
         *
         * @return true if ascending, false if descending
         */
        public boolean isPrimaryAscending() {
            ColumnSortInfo primaryInfo = getPrimaryColumnSortInfo();
            if ( primaryInfo == null ) {
                return true;
            }
            return primaryInfo.isAscending();
        }

        public Iterator<ColumnSortInfo> iterator() {
            return new ImmutableIterator<ColumnSortInfo>( infos.iterator() );
        }

        /**
         * Remove a {@link ColumnSortInfo} from the list.
         *
         * @param sortInfo the {@link ColumnSortInfo} to remove
         */
        public boolean remove( Object sortInfo ) {
            return infos.remove( sortInfo );
        }

        /**
         * @return the number of {@link ColumnSortInfo} in the list
         */
        public int size() {
            return infos.size();
        }

        /**
         * @return a duplicate of this list
         */
        ColumnSortList copy() {
            ColumnSortList copy = new ColumnSortList();
            for ( ColumnSortInfo info : this ) {
                copy.infos.add( new ColumnSortInfo( info.getColumn(), info.isAscending() ) );
            }
            return copy;
        }
    }

    /**
     * A {@link TableModelHelper} request.
     */
    public static class Request implements Serializable {
        private static final long serialVersionUID = 1L;

        /**
         * The number of rows to request.
         */
        private int numRows;

        /**
         * An ordered list of {@link ColumnSortInfo}.
         */
        private ColumnSortList columnSortList;

        /**
         * The first row of table data to request.
         */
        private int startRow;

        /**
         * Default constructor used for RPC.
         */
        public Request() {
            this( 0, 0, null );
        }

        /**
         * Construct a new {@link Request}.
         *
         * @param startRow the first row to request
         * @param numRows  the number of rows to request
         */
        public Request( int startRow, int numRows ) {
            this( startRow, numRows, null );
        }

        /**
         * Construct a new {@link Request} with information about the sort order of
         * columns.
         *
         * @param startRow       the first row to request
         * @param numRows        the number of rows to request
         * @param columnSortList a list of {@link ColumnSortInfo}
         */
        public Request( int startRow, int numRows, ColumnSortList columnSortList ) {
            this.startRow = startRow;
            this.numRows = numRows;
            this.columnSortList = columnSortList;
        }

        /**
         * @return the list of {@link ColumnSortInfo}
         */
        public ColumnSortList getColumnSortList() {
            return columnSortList;
        }

        /**
         * @return the number of requested rows
         */
        public int getNumRows() {
            return numRows;
        }

        /**
         * @return the first requested row
         */
        public int getStartRow() {
            return startRow;
        }
    }

    /**
     * A response from the {@link TableModelHelper}.
     *
     * @param <RowType> the data type of the row values
     */
    public abstract static class Response<RowType> {
        /**
         * Get the objects associated with the retrieved rows.
         *
         * @return the objects associated with the retrieved row
         */
        public abstract Iterator<RowType> getRowValues();
    }

    /**
     * A response from the {@link TableModelHelper} that is serializable, and can
     * by used over RPC.
     *
     * @param <RowType> the serializable data type of the row values
     */
    public static class SerializableResponse<RowType extends Serializable> extends Response<RowType> implements Serializable {
        /**
         * The {@link Collection} of row values.
         */
        private Collection<RowType> rowValues;

        /**
         * Default constructor used for RPC.
         */
        public SerializableResponse() {
            this( null );
        }

        /**
         * Create a new {@link SerializableResponse}.
         */
        public SerializableResponse( Collection<RowType> rowValues ) {
            this.rowValues = rowValues;
        }

        @Override
        public Iterator<RowType> getRowValues() {
            return rowValues.iterator();
        }
    }

    /**
     * Wrap an {@link Iterator} in an immutable iterator.
     */
    private static class ImmutableIterator<E> implements Iterator<E> {
        private Iterator<E> iterator;

        public ImmutableIterator( Iterator<E> iterator ) {
            this.iterator = iterator;
        }

        public boolean hasNext() {
            return iterator.hasNext();
        }

        public E next() {
            return iterator.next();
        }

        public void remove() {
            throw (new UnsupportedOperationException());
        }
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/TableModelHelper.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

849 Diff Diff GeorgeS picture GeorgeS Tue 11 Sep, 2012 17:11:59 +0000

Clean up serialization

620 Diff Diff GeorgeS picture GeorgeS Sun 18 Mar, 2012 21:55:14 +0000
475 Diff Diff GeorgeS picture GeorgeS Sat 03 Sep, 2011 13:54:51 +0000
282 GeorgeS picture GeorgeS Fri 17 Jun, 2011 13:54:39 +0000