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
/*
 * 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.util.*;

/**
 * A collection of {@link ColumnDefinition ColumnDefinitions} that define a
 * table.
 *
 * @param <RowType> the type of the row values
 */
public class DefaultTableDefinition<RowType> implements TableDefinition<RowType> {
    /**
     * The default {@link RowRenderer} to use when the
     * {@link DefaultTableDefinition} does not specify one.
     */
    private static final RowRenderer DEFAULT_ROW_RENDERER = new DefaultRowRenderer();

    /**
     * The ordered list of {@link ColumnDefinition ColumnDefinitions} used by this
     * renderer.
     */
    private List<ColumnDefinition<RowType, ?>> columnDefs;

    /**
     * A list of visible columns.
     */
    private Set<ColumnDefinition<RowType, ?>> hiddenColumnDefs;

    /**
     * The renderer used to render rows.
     */
    private RowRenderer<RowType> rowRenderer = DEFAULT_ROW_RENDERER;

    /**
     * Create a new {@link TableDefinition}.
     */
    public DefaultTableDefinition() {
        this( new ArrayList<ColumnDefinition<RowType, ?>>() );
    }

    /**
     * Create a new {@link TableDefinition} with a list of
     * {@link ColumnDefinition ColumnDefinitions}.
     *
     * @param columnDefs the {@link ColumnDefinition ColumnDefinitions} to render
     */
    public DefaultTableDefinition( List<ColumnDefinition<RowType, ?>> columnDefs ) {
        this.columnDefs = columnDefs;
        hiddenColumnDefs = new HashSet<ColumnDefinition<RowType, ?>>();
    }

    /**
     * Add a {@link ColumnDefinition}.
     *
     * @param columnDef the {@link ColumnDefinition} to add
     */
    public void addColumnDefinition( ColumnDefinition<RowType, ?> columnDef ) {
        columnDefs.add( columnDef );
    }

    /**
     * Insert a {@link ColumnDefinition} at a specific index.
     *
     * @param index     the index to place the {@link ColumnDefinition}
     * @param columnDef the {@link ColumnDefinition} to add
     */
    public void addColumnDefinition( int index, ColumnDefinition<RowType, ?> columnDef ) {
        columnDefs.add( index, columnDef );
    }

    /**
     * Get the {@link ColumnDefinition} for a given column.
     *
     * @param column the column index
     *
     * @return the {@link ColumnDefinition} for the column
     *
     * @throws IndexOutOfBoundsException if the column is not defined
     */
    public ColumnDefinition<RowType, ?> getColumnDefinition( int column )
            throws IndexOutOfBoundsException {
        return columnDefs.get( column );
    }

    /**
     * @return the number of {@link ColumnDefinition ColumnDefinitions}.
     */
    public int getColumnDefinitionCount() {
        return columnDefs.size();
    }

    public RowRenderer<RowType> getRowRenderer() {
        return rowRenderer;
    }

    public List<ColumnDefinition<RowType, ?>> getVisibleColumnDefinitions() {
        List<ColumnDefinition<RowType, ?>> visibleColumns = new ArrayList<ColumnDefinition<RowType, ?>>();
        for ( ColumnDefinition<RowType, ?> columnDef : columnDefs ) {
            if ( isColumnVisible( columnDef ) ) {
                visibleColumns.add( columnDef );
            }
        }
        return visibleColumns;
    }

    /**
     * Check if a column is visible or not.
     *
     * @param colDef the {@link ColumnDefinition}
     *
     * @return true if visible, false if hidden
     */
    public boolean isColumnVisible( ColumnDefinition<RowType, ?> colDef ) {
        return !hiddenColumnDefs.contains( colDef );
    }

    /**
     * Remove a {@link ColumnDefinition}.
     *
     * @param columnDef the {@link ColumnDefinition} to remove
     */
    public void removeColumnDefinition( ColumnDefinition<RowType, ?> columnDef ) {
        columnDefs.remove( columnDef );
    }

    public void renderRows( int startRowIndex, Iterator<RowType> rowValues, AbstractRowView<RowType> view ) {
        List<ColumnDefinition<RowType, ?>> visibleColumns = getVisibleColumnDefinitions();
        view.renderRowsImpl( startRowIndex, rowValues, rowRenderer, visibleColumns );
    }

    /**
     * Hide or show a column.
     *
     * @param colDef  the {@link ColumnDefinition}
     * @param visible true to show it, false to hide
     */
    public void setColumnVisible( ColumnDefinition<RowType, ?> colDef, boolean visible ) {
        if ( visible ) {
            hiddenColumnDefs.remove( colDef );
        } else {
            hiddenColumnDefs.add( colDef );
        }
    }

    /**
     * Set the {@link RowRenderer} used to render rows.
     */
    public void setRowRenderer( RowRenderer<RowType> rowRenderer ) {
        assert rowRenderer != null : "rowRenderer cannot be null";
        this.rowRenderer = rowRenderer;
    }
}

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

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

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