aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/tests/book/TableHuge.java
blob: 9553e7cb9ec4a493584ab968daae6626544a8618 (plain)
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
/* 
@ITMillApache2LicenseForJavaFiles@
 */

package com.itmill.toolkit.tests.book;

import java.util.Collection;
import java.util.Vector;

import com.itmill.toolkit.data.Container;
import com.itmill.toolkit.data.Item;
import com.itmill.toolkit.data.Property;
import com.itmill.toolkit.data.Container.Indexed;
import com.itmill.toolkit.data.util.BeanItem;
import com.itmill.toolkit.data.util.ObjectProperty;
import com.itmill.toolkit.data.util.PropertysetItem;
import com.itmill.toolkit.ui.CustomComponent;
import com.itmill.toolkit.ui.Table;

public class TableHuge extends CustomComponent {

    /**
     * This is a virtual container that generates the items on the fly when
     * requested.
     */
    public class HugeContainer implements Container, Indexed {
        int numberofitems;

        public HugeContainer(int numberofitems) {
            this.numberofitems = numberofitems;
        }

        public boolean addContainerProperty(Object propertyId, Class type,
                Object defaultValue) throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        public Item addItem(Object itemId) throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        public Object addItem() throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        /**
         * This addItem method is specific for this container and allows adding
         * BeanItem objects. The BeanItems must be bound to MyBean objects.
         */
        public void addItem(BeanItem item) throws UnsupportedOperationException {
        }

        public boolean containsId(Object itemId) {
            if (itemId instanceof Integer) {
                int pos = ((Integer) itemId).intValue();
                if (pos >= 0 && pos < numberofitems) {
                    return true;
                }
            }
            return false;
        }

        /**
         * The Table will call this method to get the property objects for the
         * columns. It uses the property objects to determine the data types of
         * the columns.
         */
        public Property getContainerProperty(Object itemId, Object propertyId) {
            if (itemId instanceof Integer) {
                int pos = ((Integer) itemId).intValue();
                if (pos >= 0 && pos < numberofitems) {
                    return new ObjectProperty("This is the item " + pos
                            + " in the huge table");
                }
            }
            return null;
        }

        /** Table calls this to get the column names. */
        public Collection getContainerPropertyIds() {
            Vector ids = new Vector();
            ids.add("id");
            return ids;
        }

        public Item getItem(Object itemId) {
            if (itemId instanceof Integer) {
                int pos = ((Integer) itemId).intValue();
                if (pos >= 0 && pos < numberofitems) {
                    Item item = new PropertysetItem();
                    item.addItemProperty("id", new ObjectProperty(
                            "This is the item " + pos + " in the huge table"));
                    return item;
                }
            }
            return null;
        }

        public Collection getItemIds() {
            System.out.println("We can't do this.");
            return null;
        }

        public Class getType(Object propertyId) {
            return PropertysetItem.class;
        }

        public boolean removeAllItems() throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        public boolean removeContainerProperty(Object propertyId)
                throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        public boolean removeItem(Object itemId)
                throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }

        public int size() {
            return numberofitems;
        }

        public Object addItemAt(int index) throws UnsupportedOperationException {
            // TODO Auto-generated method stub
            return null;
        }

        public Item addItemAt(int index, Object newItemId)
                throws UnsupportedOperationException {
            // TODO Auto-generated method stub
            return null;
        }

        public Object getIdByIndex(int index) {
            return Integer.valueOf(index);
        }

        public int indexOfId(Object itemId) {
            return ((Integer) itemId).intValue();
        }

        public Object addItemAfter(Object previousItemId)
                throws UnsupportedOperationException {
            // TODO Auto-generated method stub
            return null;
        }

        public Item addItemAfter(Object previousItemId, Object newItemId)
                throws UnsupportedOperationException {
            // TODO Auto-generated method stub
            return null;
        }

        public Object firstItemId() {
            return new Integer(0);
        }

        public boolean isFirstId(Object itemId) {
            return ((Integer) itemId).intValue() == 0;
        }

        public boolean isLastId(Object itemId) {
            return ((Integer) itemId).intValue() == (numberofitems - 1);
        }

        public Object lastItemId() {
            return new Integer(numberofitems - 1);
        }

        public Object nextItemId(Object itemId) {
            int pos = indexOfId(itemId);
            if (pos >= numberofitems - 1) {
                return null;
            }
            return getIdByIndex(pos + 1);
        }

        public Object prevItemId(Object itemId) {
            int pos = indexOfId(itemId);
            if (pos <= 0) {
                return null;
            }
            return getIdByIndex(pos - 1);
        }
    }

    public TableHuge() {
        Table table = new Table("HUGE table, REALLY HUGE");
        table.setContainerDataSource(new HugeContainer(500000));
        table.setPageLength(20);

        setCompositionRoot(table);
    }
}