My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes    
 
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
/*
* Copyright 2010
*
* 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.gwt2go.dev.client.ui;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import com.google.gwt.cell.client.FieldUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.view.client.ListDataProvider;
import com.gwt2go.dev.client.ui.table.ImagesColumn;

/**
* Cell table sorting view implementation for GWT2.3
*
* @author L.Pelov
*/
public class CellTableSortingView23Impl extends Composite implements
CellTableSortingView23 {

SimplePanel viewPanel = new SimplePanel();
Element nameSpan = DOM.createSpan();
Presenter presenter;
SimplePager pager;

// A simple data type that represents a contact.
private static class Contact {
private final String address;
private final String name;
private final String color;

public Contact(String name, String address, String color) {
this.name = name;
this.address = address;
this.color = color;
}
}

// The list of data to display.
private static List<Contact> CONTACTS = Arrays.asList(new Contact("John",
"123 Fourth Road", "red;"), new Contact("Mary", "222 Lancer Lane", "green;"),
new Contact("Zander", "94 Road Street", "blue;"));

public CellTableSortingView23Impl() {
// -- START TABLE
// Create a CellTable.
CellTable<Contact> table = new CellTable<Contact>();

// Create name column.
TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact contact) {
return contact.name;
}
};

// Make the name column sortable.
nameColumn.setSortable(true);

// Create address column.
TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact contact) {
return contact.address;
}
};

ImagesColumn<Contact> imagesColumn = new ImagesColumn<Contact>(){
@Override
public String getValue(Contact object) {
return object.color;
}
};

// try to use the filed updater to call the value updater!!!
imagesColumn.setFieldUpdater(new FieldUpdater<CellTableSortingView23Impl.Contact, String>() {

@Override
public void update(int index, Contact object, String value) {

Window.alert("This is the field updater, with value: " + value + " Index: " + index + " Contact: " + object.name);

}
});


// Add the columns.
table.addColumn(nameColumn, "Name");
table.addColumn(addressColumn, "Address");
table.addColumn(imagesColumn, "Export to");


// Create a data provider.
ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

// Connect the table to the data provider.
dataProvider.addDataDisplay(table);

// Add the data to the data provider, which automatically pushes it to the
// widget.
List<Contact> list = dataProvider.getList();
for (Contact contact : CONTACTS) {
list.add(contact);
}

// Add a ColumnSortEvent.ListHandler to connect sorting to the
// java.util.List.
ListHandler<Contact> columnSortHandler = new ListHandler<Contact>(
list);
columnSortHandler.setComparator(nameColumn,
new Comparator<Contact>() {
public int compare(Contact o1, Contact o2) {
if (o1 == o2) {
return 0;
}

// Compare the name columns.
if (o1 != null) {
return (o2 != null) ? o1.name.compareTo(o2.name) : 1;
}
return -1;
}
});
table.addColumnSortHandler(columnSortHandler);

// We know that the data is sorted alphabetically by default.
table.getColumnSortList().push(nameColumn);

// -- END TABLE

viewPanel.getElement().appendChild(nameSpan);

viewPanel.add(table);

initWidget(viewPanel);


}

@Override
public void setName(String tableName) {
nameSpan.setInnerText("Table name: " + tableName);
}

@Override
public void setPresenter(Presenter presenter) {
this.presenter = presenter;

}

}

Change log

r46 by lyudmil.pelov on Nov 4, 2011   Diff
change column name
Go to: 

Older revisions

r45 by lyudmil.pelov on Nov 4, 2011   Diff
image cell with multiple images
r42 by lyudmil.pelov on Oct 26, 2011   Diff
experiment with custom cells
r25 by lyudmil.pelov on Jun 24, 2011   Diff
add new table sorting for gwt 2.3
example and play with GWT WYSIWYG
Editor
All revisions of this file

File info

Size: 5276 bytes, 173 lines

File properties

svn:mime-type
text/plain
Powered by Google Project Hosting