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
/*
 * 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.table.client.property.*;

/**
 * A definition of a column in a table.
 *
 * @param <RowType> the type of the row value
 * @param <ColType> the data type of the column
 */
public abstract class AbstractColumnDefinition<RowType, ColType> implements ColumnDefinition<RowType, ColType> {

    /**
     * The default {@link CellRenderer} to use when the
     * {@link AbstractColumnDefinition} does not specify one.
     */
    private static final CellRenderer DEFAULT_CELL_RENDERER = new DefaultCellRenderer();

    /**
     * The cell editor used to edit the contents of this column.
     */
    private CellEditor<ColType> cellEditor = null;

    /**
     * The renderer used to render the contents of this column.
     */
    private CellRenderer<RowType, ColType> cellRenderer = DEFAULT_CELL_RENDERER;

    /**
     * The properties assigned to this column.
     */
    private ColumnPropertyManager properties = new ColumnPropertyManager();

    public CellEditor<ColType> getCellEditor() {
        return cellEditor;
    }

    public CellRenderer<RowType, ColType> getCellRenderer() {
        return cellRenderer;
    }

    public abstract ColType getCellValue( RowType rowValue );

    public <P extends ColumnProperty> P getColumnProperty( ColumnProperty.Type<P> type ) {
        return properties.getColumnProperty( type );
    }

    /**
     * Get the footer at the given row index.
     *
     * @param row the row index from the top
     *
     * @return the footer for the given row
     */
    public Object getFooter( int row ) {
        return getColumnProperty( FooterProperty.TYPE ).getFooter( row );
    }

    /**
     * @return get the number of footers below the column
     */
    public int getFooterCount() {
        return getColumnProperty( FooterProperty.TYPE ).getFooterCount();
    }

    /**
     * Get the header at the given row index.
     *
     * @param row the row index from the bottom.
     *
     * @return the header for the given row
     */
    public Object getHeader( int row ) {
        return getColumnProperty( HeaderProperty.TYPE ).getHeader( row );
    }

    /**
     * @return get the number of headers above the column
     */
    public int getHeaderCount() {
        return getColumnProperty( HeaderProperty.TYPE ).getHeaderCount();
    }

    /**
     * Get the maximum width of the column. A return value of -1 indicates that
     * the column has no maximum width, but the consumer of the data may impose
     * one anyway.
     *
     * @return the maximum allowable width of the column
     */
    public int getMaximumColumnWidth() {
        return getColumnProperty( MaximumWidthProperty.TYPE ).getMaximumColumnWidth();
    }

    /**
     * Get the minimum width of the column. A return value of -1 indicates that
     * the column has no minimum width, but the consumer of the data may impose
     * one anyway.
     *
     * @return the minimum allowable width of the column
     */
    public int getMinimumColumnWidth() {
        return getColumnProperty( MinimumWidthProperty.TYPE ).getMinimumColumnWidth();
    }

    /**
     * Returns the preferred width of the column in pixels. Views should respect
     * the preferred column width and attempt to size the column to its preferred
     * width. If the column must be resized, the preferred width should serve as a
     * weight relative to the preferred widths of other ColumnDefinitions.
     *
     * @return the preferred width of the column
     */
    public int getPreferredColumnWidth() {
        return getColumnProperty( PreferredWidthProperty.TYPE ).getPreferredColumnWidth();
    }

    /**
     * Returns true if the column is sortable, false if it is not.
     *
     * @return true if the column is sortable, false if it is not sortable
     */
    public boolean isColumnSortable() {
        return getColumnProperty( SortableProperty.TYPE ).isColumnSortable();
    }

    /**
     * @return true if the column is truncatable, false if not
     */
    public boolean isColumnTruncatable() {
        return getColumnProperty( TruncationProperty.TYPE ).isColumnTruncatable();
    }

    /**
     * @return true if the footer table is truncatable, false if not
     */
    public boolean isFooterTruncatable() {
        return getColumnProperty( TruncationProperty.TYPE ).isFooterTruncatable();
    }

    /**
     * @return true if the header table is truncatable, false if not
     */
    public boolean isHeaderTruncatable() {
        return getColumnProperty( TruncationProperty.TYPE ).isHeaderTruncatable();
    }

    /**
     * Remove an existing {@link ColumnProperty} if it has already been added.
     *
     * @param type the type of the property to remove
     */
    public <P extends ColumnProperty> P removeColumnProperty( ColumnProperty.Type<P> type ) {
        return properties.removeColumnProperty( type );
    }

    /**
     * Set the {@link CellEditor} that should be used to edit cells in this
     * column.
     *
     * @param cellEditor the {@link CellEditor} to use for this column
     */
    public void setCellEditor( CellEditor<ColType> cellEditor ) {
        this.cellEditor = cellEditor;
    }

    /**
     * Set the {@link CellRenderer} that should be used to render cells in this
     * column.
     *
     * @param cellRenderer the {@link CellRenderer} to use for this column
     */
    public void setCellRenderer( CellRenderer<RowType, ColType> cellRenderer ) {
        assert cellRenderer != null : "cellRenderer cannot be null";
        this.cellRenderer = cellRenderer;
    }

    public abstract void setCellValue( RowType rowValue, ColType cellValue );

    /**
     * Set a {@link ColumnProperty}.
     *
     * @param <P>      the column property type
     * @param type     the {@link ColumnProperty} type
     * @param property the property to set
     */
    public <P extends ColumnProperty> void setColumnProperty( ColumnProperty.Type<P> type, P property ) {
        properties.setColumnProperty( type, property );
    }

    /**
     * Set whether or not this column is sortable.
     *
     * @param sortable true to make sortable, false to make unsortable
     */
    public void setColumnSortable( boolean sortable ) {
        setColumnProperty( SortableProperty.TYPE, new SortableProperty( sortable ) );
    }

    /**
     * Set whether or not this column is truncatable.
     *
     * @param truncatable true to make truncatable, false to make non truncatable
     */
    public void setColumnTruncatable( boolean truncatable ) {
        TruncationProperty prop = properties.getColumnProperty( TruncationProperty.TYPE, false );
        if ( prop == null ) {
            prop = new TruncationProperty( truncatable );
            setColumnProperty( TruncationProperty.TYPE, prop );
        } else {
            prop.setColumnTruncatable( truncatable );
        }
    }

    /**
     * Set the footer below this column. The row index starts with the top row,
     * such that index 0 is directly below the data table. The footerCount will
     * automatically be increased to accommodate the row.
     *
     * @param row    the row index from the top
     * @param footer the footer
     */
    public void setFooter( int row, Object footer ) {
        FooterProperty prop = properties.getColumnProperty( FooterProperty.TYPE, false );
        if ( prop == null ) {
            prop = new FooterProperty();
            setColumnProperty( FooterProperty.TYPE, prop );
        }
        prop.setFooter( row, footer );
    }

    /**
     * Set the number of footers below the column.
     *
     * @param footerCount the number of footers
     */
    public void setFooterCount( int footerCount ) {
        FooterProperty prop = properties.getColumnProperty( FooterProperty.TYPE, false );
        if ( prop == null ) {
            prop = new FooterProperty();
            setColumnProperty( FooterProperty.TYPE, prop );
        }
        prop.setFooterCount( footerCount );
    }

    /**
     * Set whether or not this column is truncatable in the footer.
     *
     * @param truncatable true to make truncatable, false to make non truncatable
     */
    public void setFooterTruncatable( boolean truncatable ) {
        TruncationProperty prop = properties.getColumnProperty( TruncationProperty.TYPE, false );
        if ( prop == null ) {
            prop = new TruncationProperty();
            setColumnProperty( TruncationProperty.TYPE, prop );
        }
        prop.setFooterTruncatable( truncatable );
    }

    /**
     * Set the header above this column. The row index starts with the bottom row,
     * which is reverse of a normal table. The headerCount will automatically be
     * increased to accommodate the row.
     *
     * @param row    the row index from the bottom
     * @param header the header
     */
    public void setHeader( int row, Object header ) {
        HeaderProperty prop = properties.getColumnProperty( HeaderProperty.TYPE, false );
        if ( prop == null ) {
            prop = new HeaderProperty();
            setColumnProperty( HeaderProperty.TYPE, prop );
        }
        prop.setHeader( row, header );
    }

    /**
     * Set the number of headers above the column.
     *
     * @param headerCount the number of headers
     */
    public void setHeaderCount( int headerCount ) {
        HeaderProperty prop = properties.getColumnProperty( HeaderProperty.TYPE, false );
        if ( prop == null ) {
            prop = new HeaderProperty();
            setColumnProperty( HeaderProperty.TYPE, prop );
        }
        prop.setHeaderCount( headerCount );
    }

    /**
     * Set whether or not this column is truncatable in the header.
     *
     * @param truncatable true to make truncatable, false to make non truncatable
     */
    public void setHeaderTruncatable( boolean truncatable ) {
        TruncationProperty prop = properties.getColumnProperty( TruncationProperty.TYPE, false );
        if ( prop == null ) {
            prop = new TruncationProperty();
            setColumnProperty( TruncationProperty.TYPE, prop );
        }
        prop.setHeaderTruncatable( truncatable );
    }

    /**
     * Set the maximum width of the column.
     *
     * @param maxWidth the max width
     */
    public void setMaximumColumnWidth( int maxWidth ) {
        setColumnProperty( MaximumWidthProperty.TYPE, new MaximumWidthProperty( maxWidth ) );
    }

    /**
     * Set the minimum width of the column.
     *
     * @param minWidth the min width
     */
    public void setMinimumColumnWidth( int minWidth ) {
        setColumnProperty( MinimumWidthProperty.TYPE, new MinimumWidthProperty( minWidth ) );
    }

    /**
     * Set the preferred width of the column.
     *
     * @param preferredWidth the preferred width
     *
     * @see #getPreferredColumnWidth()
     */
    public void setPreferredColumnWidth( int preferredWidth ) {
        setColumnProperty( PreferredWidthProperty.TYPE, new PreferredWidthProperty( preferredWidth ) );
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/com/google/gwt/gen2/table/client/AbstractColumnDefinition.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

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