aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
blob: ecf3d53385a57ed1dbd94f0fd3f49e2242271f9e (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
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
/*
 * Copyright 2000-2014 Vaadin Ltd.
 * 
 * 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.vaadin.tests.components.grid.basicfeatures;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Random;

import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.data.sort.Sort;
import com.vaadin.data.sort.SortOrder;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.event.SelectionEvent;
import com.vaadin.event.SelectionEvent.SelectionListener;
import com.vaadin.event.SortEvent;
import com.vaadin.event.SortEvent.SortListener;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.shared.ui.grid.GridStaticCellType;
import com.vaadin.shared.ui.grid.HeightMode;
import com.vaadin.tests.components.AbstractComponentTest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.CellReference;
import com.vaadin.ui.Grid.CellStyleGenerator;
import com.vaadin.ui.Grid.Column;
import com.vaadin.ui.Grid.ColumnReorderEvent;
import com.vaadin.ui.Grid.ColumnReorderListener;
import com.vaadin.ui.Grid.ColumnVisibilityChangeEvent;
import com.vaadin.ui.Grid.ColumnVisibilityChangeListener;
import com.vaadin.ui.Grid.DetailsGenerator;
import com.vaadin.ui.Grid.FooterCell;
import com.vaadin.ui.Grid.HeaderCell;
import com.vaadin.ui.Grid.HeaderRow;
import com.vaadin.ui.Grid.MultiSelectionModel;
import com.vaadin.ui.Grid.RowReference;
import com.vaadin.ui.Grid.RowStyleGenerator;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.Grid.SelectionModel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.renderers.DateRenderer;
import com.vaadin.ui.renderers.HtmlRenderer;
import com.vaadin.ui.renderers.NumberRenderer;

/**
 * Tests the basic features like columns, footers and headers
 * 
 * @since
 * @author Vaadin Ltd
 */
public class GridBasicFeatures extends AbstractComponentTest<Grid> {

    public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4 = "Row numbers for 3/4";
    public static final String ROW_STYLE_GENERATOR_NONE = "None";
    public static final String ROW_STYLE_GENERATOR_ROW_NUMBERS = "Row numbers";
    public static final String ROW_STYLE_GENERATOR_EMPTY = "Empty string";
    public static final String ROW_STYLE_GENERATOR_NULL = "Null";
    public static final String CELL_STYLE_GENERATOR_NONE = "None";
    public static final String CELL_STYLE_GENERATOR_PROPERTY_TO_STRING = "Property to string";
    public static final String CELL_STYLE_GENERATOR_SPECIAL = "Special for 1/4 Column 1";
    public static final String CELL_STYLE_GENERATOR_EMPTY = "Empty string";
    public static final String CELL_STYLE_GENERATOR_NULL = "Null";
    private static final int MANUALLY_FORMATTED_COLUMNS = 5;
    public static final int COLUMNS = 12;
    public static final int EDITABLE_COLUMNS = COLUMNS - 1;
    public static final int ROWS = 1000;

    private int containerDelay = 0;

    private boolean singleSelectAllowDeselect = true;

    private IndexedContainer ds;
    private Grid grid;
    private SelectionListener selectionListener = new SelectionListener() {

        @Override
        public void select(SelectionEvent event) {
            Iterator<Object> iter = event.getAdded().iterator();
            Object addedRow = (iter.hasNext() ? iter.next() : "none");
            iter = event.getRemoved().iterator();
            Object removedRow = (iter.hasNext() ? iter.next() : "none");
            log("SelectionEvent: Added " + addedRow + ", Removed " + removedRow);
        }
    };

    private ItemClickListener itemClickListener = new ItemClickListener() {

        @Override
        public void itemClick(ItemClickEvent event) {
            log("Item " + (event.isDoubleClick() ? "double " : "")
                    + "click on " + event.getPropertyId() + ", item "
                    + event.getItemId());
        }
    };

    private ColumnReorderListener columnReorderListener = new ColumnReorderListener() {

        @Override
        public void columnReorder(ColumnReorderEvent event) {
            log("Columns reordered, userOriginated: "
                    + event.isUserOriginated());
        }
    };

    private ColumnVisibilityChangeListener columnVisibilityListener = new ColumnVisibilityChangeListener() {
        @Override
        public void columnVisibilityChanged(ColumnVisibilityChangeEvent event) {
            log("Visibility changed: "//
                    + "propertyId: " + event.getColumn().getPropertyId() //
                    + ", isHidden: " + event.getColumn().isHidden() //
                    + ", userOriginated: " + event.isUserOriginated());
        }
    };

    private Panel detailsPanel;

    private final DetailsGenerator detailedDetailsGenerator = new DetailsGenerator() {
        @Override
        public Component getDetails(final RowReference rowReference) {
            CssLayout cssLayout = new CssLayout();
            cssLayout.setHeight("200px");
            cssLayout.setWidth("100%");

            Item item = rowReference.getItem();
            for (Object propertyId : item.getItemPropertyIds()) {
                Property<?> prop = item.getItemProperty(propertyId);
                String string = prop.getValue().toString();
                cssLayout.addComponent(new Label(string));
            }

            final int rowIndex = grid.getContainerDataSource().indexOfId(
                    rowReference.getItemId());
            ClickListener clickListener = new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Notification.show("You clicked on the "
                            + "button in the details for " + "row " + rowIndex);
                }
            };
            cssLayout.addComponent(new Button("Press me", clickListener));
            return cssLayout;
        }
    };

    private final DetailsGenerator watchingDetailsGenerator = new DetailsGenerator() {
        private int id = 0;

        @Override
        public Component getDetails(RowReference rowReference) {
            return new Label("You are watching item id "
                    + rowReference.getItemId() + " (" + (id++) + ")");
        }
    };

    private final DetailsGenerator hierarchicalDetailsGenerator = new DetailsGenerator() {
        @Override
        public Component getDetails(RowReference rowReference) {
            detailsPanel = new Panel();
            detailsPanel.setContent(new Label("One"));
            return detailsPanel;
        }
    };

    @Override
    @SuppressWarnings("unchecked")
    protected Grid constructComponent() {

        // Build data source
        ds = new IndexedContainer() {
            @Override
            public List<Object> getItemIds(int startIndex, int numberOfIds) {
                log("Requested items " + startIndex + " - "
                        + (startIndex + numberOfIds));
                if (containerDelay > 0) {
                    try {
                        Thread.sleep(containerDelay);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                return super.getItemIds(startIndex, numberOfIds);
            }
        };

        {
            int col = 0;
            for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; col++) {
                ds.addContainerProperty(getColumnProperty(col), String.class,
                        "");
            }

            ds.addContainerProperty(getColumnProperty(col++), Integer.class,
                    Integer.valueOf(0));
            ds.addContainerProperty(getColumnProperty(col++), Date.class,
                    new Date());
            ds.addContainerProperty(getColumnProperty(col++), String.class, "");

            // Random numbers
            ds.addContainerProperty(getColumnProperty(col++), Integer.class, 0);
            ds.addContainerProperty(getColumnProperty(col++), Integer.class, 0);

        }

        {
            Random rand = new Random();
            rand.setSeed(13334);
            long timestamp = 0;
            for (int row = 0; row < ROWS; row++) {
                Item item = ds.addItem(Integer.valueOf(row));
                int col = 0;
                for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; col++) {
                    item.getItemProperty(getColumnProperty(col)).setValue(
                            "(" + row + ", " + col + ")");
                }
                item.getItemProperty(getColumnProperty(1)).setReadOnly(true);

                item.getItemProperty(getColumnProperty(col++)).setValue(
                        Integer.valueOf(row));
                item.getItemProperty(getColumnProperty(col++)).setValue(
                        new Date(timestamp));
                timestamp += 91250000; // a bit over a day, just to get
                                       // variation
                item.getItemProperty(getColumnProperty(col++)).setValue(
                        "<b>" + row + "</b>");

                // Random numbers
                item.getItemProperty(getColumnProperty(col++)).setValue(
                        rand.nextInt());
                // Random between 0 - 5 to test multisorting
                item.getItemProperty(getColumnProperty(col++)).setValue(
                        rand.nextInt(5));
            }
        }

        // Create grid
        Grid grid = new Grid(ds);

        {
            int col = grid.getContainerDataSource().getContainerPropertyIds()
                    .size()
                    - MANUALLY_FORMATTED_COLUMNS;
            grid.getColumn(getColumnProperty(col++)).setRenderer(
                    new NumberRenderer(new DecimalFormat("0,000.00",
                            DecimalFormatSymbols.getInstance(new Locale("fi",
                                    "FI")))));
            grid.getColumn(getColumnProperty(col++)).setRenderer(
                    new DateRenderer(new SimpleDateFormat("dd.MM.yy HH:mm")));
            grid.getColumn(getColumnProperty(col++)).setRenderer(
                    new HtmlRenderer());
            grid.getColumn(getColumnProperty(col++)).setRenderer(
                    new NumberRenderer());
            grid.getColumn(getColumnProperty(col++)).setRenderer(
                    new NumberRenderer());
        }

        // Create footer
        grid.appendFooterRow();
        grid.setFooterVisible(false);

        // Add footer values (header values are automatically created)
        for (int col = 0; col < COLUMNS; col++) {
            grid.getFooterRow(0).getCell(getColumnProperty(col))
                    .setText("Footer " + col);
        }

        // Set varying column widths
        for (int col = 0; col < COLUMNS; col++) {
            Column column = grid.getColumn(getColumnProperty(col));
            column.setWidth(100 + col * 50);
            column.setHidable(isColumnHidableByDefault(col));
        }

        grid.addSortListener(new SortListener() {
            @Override
            public void sort(SortEvent event) {

                log("SortOrderChangeEvent: isUserOriginated? "
                        + event.isUserOriginated());
            }
        });

        grid.setSelectionMode(SelectionMode.NONE);

        grid.getColumn(getColumnProperty(2)).getEditorField().setReadOnly(true);
        grid.getColumn(getColumnProperty(3)).setEditable(false);

        createGridActions();

        createColumnActions();

        createPropertyActions();

        createHeaderActions();

        createFooterActions();

        createRowActions();

        createEditorActions();

        addHeightActions();

        addFilterActions();

        addInternalActions();

        createDetailsActions();

        this.grid = grid;
        return grid;
    }

    protected boolean isColumnHidableByDefault(int col) {
        return false;
    }

    protected boolean isColumnHiddenByDefault(int col) {
        return false;
    }

    private void addInternalActions() {
        createClickAction("Update column order without updating client",
                "Internals", new Command<Grid, Void>() {
                    @Override
                    public void execute(Grid grid, Void value, Object data) {
                        List<Column> columns = grid.getColumns();
                        grid.setColumnOrder(columns.get(1).getPropertyId(),
                                columns.get(0).getPropertyId());
                        grid.getUI().getConnectorTracker().markClean(grid);
                    }
                }, null);
    }

    private void addFilterActions() {
        createClickAction("Column 1 starts with \"(23\"", "Filter",
                new Command<Grid, Void>() {
                    @Override
                    public void execute(Grid grid, Void value, Object data) {
                        ds.addContainerFilter(new Filter() {

                            @Override
                            public boolean passesFilter(Object itemId, Item item)
                                    throws UnsupportedOperationException {
                                return item.getItemProperty("Column 1")
                                        .getValue().toString()
                                        .startsWith("(23");
                            }

                            @Override
                            public boolean appliesToProperty(Object propertyId) {
                                return propertyId.equals("Column 1");
                            }
                        });
                    }
                }, null);

        createClickAction("Add impassable filter", "Filter",
                new Command<Grid, Void>() {
                    @Override
                    public void execute(Grid c, Void value, Object data) {
                        ds.addContainerFilter(new Filter() {
                            @Override
                            public boolean passesFilter(Object itemId, Item item)
                                    throws UnsupportedOperationException {
                                return false;
                            }

                            @Override
                            public boolean appliesToProperty(Object propertyId) {
                                return true;
                            }
                        });
                    }
                }, null);
    }

    protected void createGridActions() {
        LinkedHashMap<String, String> primaryStyleNames = new LinkedHashMap<String, String>();
        primaryStyleNames.put("v-grid", "v-grid");
        primaryStyleNames.put("v-escalator", "v-escalator");
        primaryStyleNames.put("my-grid", "my-grid");

        createMultiClickAction("Primary style name", "State",
                primaryStyleNames, new Command<Grid, String>() {

                    @Override
                    public void execute(Grid grid, String value, Object data) {
                        grid.setPrimaryStyleName(value);

                    }
                }, primaryStyleNames.get("v-grid"));

        LinkedHashMap<String, SelectionMode> selectionModes = new LinkedHashMap<String, Grid.SelectionMode>();
        selectionModes.put("single", SelectionMode.SINGLE);
        selectionModes.put("multi", SelectionMode.MULTI);
        selectionModes.put("none", SelectionMode.NONE);
        createSelectAction("Selection mode", "State", selectionModes, "none",
                new Command<Grid, Grid.SelectionMode>() {
                    @Override
                    public void execute(Grid grid, SelectionMode selectionMode,
                            Object data) {
                        grid.setSelectionMode(selectionMode);
                        if (selectionMode == SelectionMode.SINGLE) {
                            grid.addSelectionListener(selectionListener);

                            ((SelectionModel.Single) grid.getSelectionModel())
                                    .setDeselectAllowed(singleSelectAllowDeselect);
                        } else {
                            grid.removeSelectionListener(selectionListener);
                        }
                    }
                });

        LinkedHashMap<String, Integer> selectionLimits = new LinkedHashMap<String, Integer>();
        selectionLimits.put("2", Integer.valueOf(2));
        selectionLimits.put("1000", Integer.valueOf(1000));
        selectionLimits.put("Integer.MAX_VALUE",
                Integer.valueOf(Integer.MAX_VALUE));
        createSelectAction("Selection limit", "State", selectionLimits, "1000",
                new Command<Grid, Integer>() {
                    @Override
                    public void execute(Grid grid, Integer limit, Object data) {
                        if (!(grid.getSelectionModel() instanceof MultiSelectionModel)) {
                            grid.setSelectionMode(SelectionMode.MULTI);
                        }

                        ((MultiSelectionModel) grid.getSelectionModel())
                                .setSelectionLimit(limit.intValue());
                    }
                });

        LinkedHashMap<String, List<SortOrder>> sortableProperties = new LinkedHashMap<String, List<SortOrder>>();
        for (Object propertyId : ds.getSortableContainerPropertyIds()) {
            sortableProperties.put(propertyId + ", ASC", Sort.by(propertyId)
                    .build());
            sortableProperties.put(propertyId + ", DESC",
                    Sort.by(propertyId, SortDirection.DESCENDING).build());
        }
        createSelectAction("Sort by column", "State", sortableProperties,
                "Column 9, ascending", new Command<Grid, List<SortOrder>>() {
                    @Override
                    public void execute(Grid grid, List<SortOrder> sortOrder,
                            Object data) {
                        grid.setSortOrder(sortOrder);
                    }
                });

        createBooleanAction("Reverse Grid Columns", "State", false,
                new Command<Grid, Boolean>() {

                    @Override
                    public void execute(Grid c, Boolean value, Object data) {
                        List<Object> ids = new ArrayList<Object>();
                        ids.addAll(ds.getContainerPropertyIds());
                        if (!value) {
                            c.setColumnOrder(ids.toArray());
                        } else {
                            Object[] idsArray = new Object[ids.size()];
                            for (int i = 0; i < ids.size(); ++i) {
                                idsArray[i] = ids.get((ids.size() - 1) - i);
                            }
                            c.setColumnOrder(idsArray);
                        }
                    }
                });

        LinkedHashMap<String, CellStyleGenerator> cellStyleGenerators = new LinkedHashMap<String, CellStyleGenerator>();
        LinkedHashMap<String, RowStyleGenerator> rowStyleGenerators = new LinkedHashMap<String, RowStyleGenerator>();
        rowStyleGenerators.put(ROW_STYLE_GENERATOR_NONE, null);
        rowStyleGenerators.put(ROW_STYLE_GENERATOR_ROW_NUMBERS,
                new RowStyleGenerator() {
                    @Override
                    public String getStyle(RowReference rowReference) {
                        return "row" + rowReference.getItemId();
                    }
                });
        rowStyleGenerators.put(ROW_STYLE_GENERATOR_ROW_NUMBERS_FOR_3_OF_4,
                new RowStyleGenerator() {
                    @Override
                    public String getStyle(RowReference rowReference) {
                        int rowIndex = ((Integer) rowReference.getItemId())
                                .intValue();

                        if (rowIndex % 4 == 0) {
                            return null;
                        } else {
                            return "row" + rowReference.getItemId();
                        }
                    }
                });
        rowStyleGenerators.put(ROW_STYLE_GENERATOR_EMPTY,
                new RowStyleGenerator() {

                    @Override
                    public String getStyle(RowReference rowReference) {
                        return "";
                    }
                });
        rowStyleGenerators.put(ROW_STYLE_GENERATOR_NULL,
                new RowStyleGenerator() {

                    @Override
                    public String getStyle(RowReference rowReference) {
                        return null;
                    }
                });
        cellStyleGenerators.put(CELL_STYLE_GENERATOR_NONE, null);
        cellStyleGenerators.put(CELL_STYLE_GENERATOR_PROPERTY_TO_STRING,
                new CellStyleGenerator() {
                    @Override
                    public String getStyle(CellReference cellReference) {
                        return cellReference.getPropertyId().toString()
                                .replace(' ', '-');
                    }
                });
        cellStyleGenerators.put(CELL_STYLE_GENERATOR_SPECIAL,
                new CellStyleGenerator() {
                    @Override
                    public String getStyle(CellReference cellReference) {
                        int rowIndex = ((Integer) cellReference.getItemId())
                                .intValue();
                        Object propertyId = cellReference.getPropertyId();
                        if (rowIndex % 4 == 1) {
                            return null;
                        } else if (rowIndex % 4 == 3
                                && "Column 1".equals(propertyId)) {
                            return null;
                        }
                        return propertyId.toString().replace(' ', '_');
                    }
                });
        cellStyleGenerators.put(CELL_STYLE_GENERATOR_EMPTY,
                new CellStyleGenerator() {
                    @Override
                    public String getStyle(CellReference cellReference) {
                        return "";
                    }
                });
        cellStyleGenerators.put(CELL_STYLE_GENERATOR_NULL,
                new CellStyleGenerator() {
                    @Override
                    public String getStyle(CellReference cellReference) {
                        return null;
                    }
                });

        createSelectAction("Row style generator", "State", rowStyleGenerators,
                CELL_STYLE_GENERATOR_NONE,
                new Command<Grid, RowStyleGenerator>() {
                    @Override
                    public void execute(Grid grid, RowStyleGenerator generator,
                            Object data) {
                        grid.setRowStyleGenerator(generator);
                    }
                });

        createSelectAction("Cell style generator", "State",
                cellStyleGenerators, CELL_STYLE_GENERATOR_NONE,
                new Command<Grid, CellStyleGenerator>() {
                    @Override
                    public void execute(Grid grid,
                            CellStyleGenerator generator, Object data) {
                        grid.setCellStyleGenerator(generator);
                    }
                });

        LinkedHashMap<String, Integer> frozenOptions = new LinkedHashMap<String, Integer>();
        for (int i = -1; i <= COLUMNS; i++) {
            frozenOptions.put(String.valueOf(i), Integer.valueOf(i));
        }
        /*
         * This line below is a workaround for a FF24 bug regarding submenu
         * handling - it makes the sub menu wider.
         */
        frozenOptions.put("-1 for unfreezing selection column", -1);
        createSelectAction("Frozen column count", "State", frozenOptions, "0",
                new Command<Grid, Integer>() {
                    @Override
                    public void execute(Grid c, Integer value, Object data) {
                        c.setFrozenColumnCount(value.intValue());
                    }
                });

        LinkedHashMap<String, Integer> containerDelayValues = new LinkedHashMap<String, Integer>();
        for (int delay : new int[] { 0, 500, 2000, 10000 }) {
            containerDelayValues.put(String.valueOf(delay),
                    Integer.valueOf(delay));
        }

        createSelectAction("Container delay", "State", containerDelayValues,
                "0", new Command<Grid, Integer>() {
                    @Override
                    public void execute(Grid grid, Integer delay, Object data) {
                        containerDelay = delay.intValue();
                    }
                });

        createBooleanAction("ItemClickListener", "State", false,
                new Command<Grid, Boolean>() {

                    @Override
                    public void execute(Grid c, Boolean value, Object data) {
                        if (!value) {
                            c.removeItemClickListener(itemClickListener);
                        } else {
                            c.addItemClickListener(itemClickListener);
                        }
                    }

                });
        createBooleanAction("ColumnReorderListener", "State", false,
                new Command<Grid, Boolean>() {

                    @Override
                    public void execute(Grid grid, Boolean value, Object data) {
                        if (value) {
                            grid.addColumnReorderListener(columnReorderListener);
                        } else {
                            grid.removeColumnReorderListener(columnReorderListener);
                        }
                    }
                });
        createBooleanAction("ColumnVisibilityChangeListener", "State", false,
                new Command<Grid, Boolean>() {
                    @Override
                    public void execute(Grid grid, Boolean value, Object data) {
                        if (value) {
                            grid.addColumnVisibilityChangeListener(columnVisibilityListener);
                        } else {
                            grid.removeColumnVisibilityChangeListener(columnVisibilityListener);
                        }
                    }
                });

        createBooleanAction("Single select allow deselect", "State",
                singleSelectAllowDeselect, new Command<Grid, Boolean>() {
                    @Override
                    public void execute(Grid c, Boolean value, Object data) {
                        singleSelectAllowDeselect = value.booleanValue();

                        SelectionModel model = c.getSelectionModel();
                        if (model instanceof SelectionModel.Single) {
                            ((SelectionModel.Single) model)
                                    .setDeselectAllowed(singleSelectAllowDeselect);
                        }
                    }
                });
        createBooleanAction("Column Reordering Allowed", "State", false,
                new Command<Grid, Boolean>() {

                    @Override
                    public void execute(Grid c, Boolean value, Object data) {
                        c.setColumnReorderingAllowed(value);
                    }
                });
    }

    protected void createHeaderActions() {
        createCategory("Header", null);

        createBooleanAction("Visible", "Header", true,
                new Command<Grid, Boolean>() {

                    @Override
                    public void execute(Grid grid, Boolean value, Object data) {
                        grid.setHeaderVisible(value);
                    }
                });

        LinkedHashMap<String, String> defaultRows = new LinkedHashMap<String, String>();
        defaultRows.put("Top", "Top");
        defaultRows.put("Bottom", "Bottom");
        defaultRows.put("Unset", "Unset");

        createMultiClickAction("Default row", "Header", defaultRows,
                new Command<Grid, String>() {

                    @Override
                    public void execute(Grid grid, String value, Object data) {
                        HeaderRow defaultRow = null;
                        if (value.equals("Top")) {
                            defaultRow = grid.getHeaderRow(0);
                        } else if (value.equals("Bottom")) {
                            defaultRow = grid.getHeaderRow(grid
                                    .getHeaderRowCount() - 1);
                        }
                        grid.setDefaultHeaderRow(defaultRow);
                    }

                }, defaultRows.get("Top"));

        createClickAction("Prepend row", "Header", new Command<Grid, Object>() {

            @Override
            public void execute(Grid grid, Object value, Object data) {
                grid.prependHeaderRow();
            }

        }, null);
        createClickAction("Append row", "Header", new Command<Grid, Object>() {

            @Override
            public void execute(Grid grid, Object value, Object data) {
                grid.appendHeaderRow();
            }

        }, null);

        createClickAction("Remove top row", "Header",
                new Command<Grid, Object>() {

                    @Override
                    public void execute(Grid grid, Object value, Object data) {
                        grid.removeHeaderRow(0);
                    }

                }, null);
        createClickAction("Remove bottom row", "Header",
                new Command<Grid, Object>() {

                    @Override
                    public void execute(Grid grid, Object value, Object data) {
                        grid.removeHeaderRow(grid.getHeaderRowCount() - 1);
                    }

                }, null);
    }

    protected void createFooterActions() {
        createCategory("Footer", null);

        createBooleanAction("Visible", "Footer", false,
                new Command<Grid, Boolean>() {

                    @Override
                    public void execute(Grid grid, Boolean value, Object data) {
                        grid.setFooterVisible(value);
                    }
                });

        createClickAction("Prepend row", "Footer", new Command<Grid, Object>() {

            @Override
            public void execute(Grid grid, Object value, Object data) {
                grid.prependFooterRow();
            }

        }, null);
        createClickAction("Append row", "Footer", new Command<Grid, Object>() {

            @Override
            public void execute(Grid grid, Object value, Object data) {
                grid.appendFooterRow();
            }

        }, null);

        createClickAction("Remove top row", "Footer",
                new Command<Grid, Object>() {

                    @Override
                    public void execute(Grid grid, Object value, Object data) {
                        grid.removeFooterRow(0);
                    }

                }, null);
        createClickAction("Remove bottom row", "Footer",
                new Command<Grid, Object>() {

                    @Override
                    public void execute(Grid grid, Object value, Object data) {
                        grid.removeFooterRow(grid.getFooterRowCount() - 1);
                    }

                }, null);
    }

    @SuppressWarnings("boxing")
    protected void createColumnActions() {
        createCategory("Columns", null);
        for (int c = 0; c < COLUMNS; c++) {
            final int index = c;
            createCategory(getColumnProperty(c), "Columns");

            createClickAction("Add / Remove", getColumnProperty(c),
                    new Command<Grid, String>() {

                        boolean wasHidable;
                        boolean wasHidden;
                        String wasColumnHidingToggleCaption;

                        @Override
                        public void execute(Grid grid, String value, Object data) {
                            String columnProperty = getColumnProperty((Integer) data);
                            Column column = grid.getColumn(columnProperty);
                            if (column == null) {
                                column = grid.addColumn(columnProperty);
                                column.setHidable(wasHidable);
                                column.setHidden(wasHidden);
                                column.setHidingToggleCaption(wasColumnHidingToggleCaption);
                            } else {
                                wasHidable = column.isHidable();
                                wasHidden = column.isHidden();
                                wasColumnHidingToggleCaption = column
                                        .getHidingToggleCaption();
                                grid.removeColumn(columnProperty);
                            }
                        }
                    }, null, c);
            createClickAction("Move left", getColumnProperty(c),
                    new Command<Grid, String>() {

                        @Override
                        public void execute(Grid grid, String value, Object data) {
                            final String columnProperty = getColumnProperty((Integer) data);
                            List<Column> cols = grid.getColumns();
                            List<Object> reordered = new ArrayList<Object>();
                            boolean addAsLast = false;
                            for (int i = 0; i < cols.size(); i++) {
                                Column col = cols.get(i);
                                if (col.getPropertyId().equals(columnProperty)) {
                                    if (i == 0) {
                                        addAsLast = true;
                                    } else {
                                        reordered.add(i - 1, columnProperty);
                                    }
                                } else {
                                    reordered.add(col.getPropertyId());
                                }
                            }
                            if (addAsLast) {
                                reordered.add(columnProperty);
                            }
                            grid.setColumnOrder(reordered.toArray());
                        }
                    }, null, c);

            createBooleanAction("Sortable", getColumnProperty(c), true,
                    new Command<Grid, Boolean>() {

                        @Override
                        public void execute(Grid grid, Boolean value,
                                Object columnIndex) {
                            Object propertyId = getColumnProperty((Integer) columnIndex);
                            Column column = grid.getColumn(propertyId);
                            column.setSortable(value);
                        }
                    }, c);

            createBooleanAction("Hidable", getColumnProperty(c),
                    isColumnHidableByDefault(c), new Command<Grid, Boolean>() {
                        @Override
                        public void execute(Grid c, Boolean hidable,
                                Object propertyId) {
                            grid.getColumn(propertyId).setHidable(hidable);
                        }
                    }, getColumnProperty(c));

            createBooleanAction("Hidden", getColumnProperty(c),
                    isColumnHiddenByDefault(c), new Command<Grid, Boolean>() {
                        @Override
                        public void execute(Grid c, Boolean hidden,
                                Object propertyId) {
                            grid.getColumn(propertyId).setHidden(hidden);
                        }
                    }, getColumnProperty(c));
            createClickAction("Change hiding toggle caption",
                    getColumnProperty(c), new Command<Grid, String>() {
                        int count = 0;

                        @Override
                        public void execute(Grid grid, String value, Object data) {
                            final String columnProperty = getColumnProperty((Integer) data);
                            grid.getColumn(columnProperty)
                                    .setHidingToggleCaption(
                                            columnProperty + " caption "
                                                    + count++);
                        }
                    }, null, c);

            createCategory("Column " + c + " Width", getColumnProperty(c));

            createClickAction("Auto", "Column " + c + " Width",
                    new Command<Grid, Integer>() {

                        @Override
                        public void execute(Grid grid, Integer value,
                                Object columnIndex) {
                            Object propertyId = getColumnProperty((Integer) columnIndex);
                            Column column = grid.getColumn(propertyId);
                            column.setWidthUndefined();
                        }
                    }, -1, c);

            createClickAction("25.5px", "Column " + c + " Width",
                    new Command<Grid, Void>() {
                        @Override
                        public void execute(Grid grid, Void value,
                                Object columnIndex) {
                            grid.getColumns().get((Integer) columnIndex)
                                    .setWidth(25.5);
                        }
                    }, null, c);

            for (int w = 50; w < 300; w += 50) {
                createClickAction(w + "px", "Column " + c + " Width",
                        new Command<Grid, Integer>() {

                            @Override
                            public void execute(Grid grid, Integer value,
                                    Object columnIndex) {
                                Object propertyId = getColumnProperty((Integer) columnIndex);
                                Column column = grid.getColumn(propertyId);
                                column.setWidth(value);
                            }
                        }, w, c);
            }

            LinkedHashMap<String, GridStaticCellType> defaultRows = new LinkedHashMap<String, GridStaticCellType>();
            defaultRows.put("Text Header", GridStaticCellType.TEXT);
            defaultRows.put("Html Header ", GridStaticCellType.HTML);
            defaultRows.put("Widget Header", GridStaticCellType.WIDGET);

            createMultiClickAction("Header Type", getColumnProperty(c),
                    defaultRows, new Command<Grid, GridStaticCellType>() {

                        @Override
                        public void execute(Grid grid,
                                GridStaticCellType value, Object columnIndex) {
                            final Object propertyId = getColumnProperty((Integer) columnIndex);
                            final HeaderCell cell = grid.getDefaultHeaderRow()
                                    .getCell(propertyId);
                            switch (value) {
                            case TEXT:
                                cell.setText("Text Header");
                                break;
                            case HTML:
                                cell.setHtml("HTML Header");
                                break;
                            case WIDGET:
                                cell.setComponent(new Button("Button Header",
                                        new ClickListener() {

                                            @Override
                                            public void buttonClick(
                                                    ClickEvent event) {
                                                log("Button clicked!");
                                            }
                                        }));
                            default:
                                break;
                            }
                        }

                    }, c);

            defaultRows = new LinkedHashMap<String, GridStaticCellType>();
            defaultRows.put("Text Footer", GridStaticCellType.TEXT);
            defaultRows.put("Html Footer", GridStaticCellType.HTML);
            defaultRows.put("Widget Footer", GridStaticCellType.WIDGET);

            createMultiClickAction("Footer Type", getColumnProperty(c),
                    defaultRows, new Command<Grid, GridStaticCellType>() {

                        @Override
                        public void execute(Grid grid,
                                GridStaticCellType value, Object columnIndex) {
                            final Object propertyId = getColumnProperty((Integer) columnIndex);
                            final FooterCell cell = grid.getFooterRow(0)
                                    .getCell(propertyId);
                            switch (value) {
                            case TEXT:
                                cell.setText("Text Footer");
                                break;
                            case HTML:
                                cell.setHtml("HTML Footer");
                                break;
                            case WIDGET:
                                cell.setComponent(new Button("Button Footer",
                                        new ClickListener() {

                                            @Override
                                            public void buttonClick(
                                                    ClickEvent event) {
                                                log("Button clicked!");
                                            }
                                        }));
                            default:
                                break;
                            }
                        }

                    }, c);
        }
        createBooleanAction("All columns hidable", "Columns", false,
                new Command<Grid, Boolean>() {

                    @Override
                    public void execute(Grid c, Boolean value, Object data) {
                        for (Column col : grid.getColumns()) {
                            col.setHidable(value);
                        }

                    }
                });
    }

    private static String getColumnProperty(int c) {
        return "Column " + c;
    }

    protected void createPropertyActions() {
        createCategory("Properties", null);

        createBooleanAction("Prepend property", "Properties", false,
                new Command<Grid, Boolean>() {
                    private final Object propertyId = new Object();

                    @Override
                    public void execute(Grid c, Boolean enable, Object data) {
                        if (enable.booleanValue()) {
                            ds.addContainerProperty(propertyId, String.class,
                                    "property value");
                            grid.getColumn(propertyId).setHeaderCaption(
                                    "new property");
                            grid.setColumnOrder(propertyId);
                        } else {
                            ds.removeContainerProperty(propertyId);
                        }
                    }
                }, null);
    }

    protected void createRowActions() {
        createCategory("Body rows", null);

        class NewRowCommand implements Command<Grid, String> {
            private final int index;

            public NewRowCommand() {
                this(0);
            }

            public NewRowCommand(int index) {
                this.index = index;
            }

            @Override
            public void execute(Grid c, String value, Object data) {
                Item item = ds.addItemAt(index, new Object());
                for (int i = 0; i < COLUMNS; i++) {
                    Class<?> type = ds.getType(getColumnProperty(i));
                    if (String.class.isAssignableFrom(type)) {
                        Property<String> itemProperty = getProperty(item, i);
                        itemProperty.setValue("newcell: " + i);
                    } else if (Integer.class.isAssignableFrom(type)) {
                        Property<Integer> itemProperty = getProperty(item, i);
                        itemProperty.setValue(Integer.valueOf(i));
                    } else {
                        // let the default value be taken implicitly.
                    }
                }
            }

            private <T extends Object> Property<T> getProperty(Item item, int i) {
                @SuppressWarnings("unchecked")
                Property<T> itemProperty = item
                        .getItemProperty(getColumnProperty(i));
                return itemProperty;
            }
        }
        final NewRowCommand newRowCommand = new NewRowCommand();

        createClickAction("Add 18 rows", "Body rows",
                new Command<Grid, String>() {
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        for (int i = 0; i < 18; i++) {
                            newRowCommand.execute(c, value, data);
                        }
                    }
                }, null);

        createClickAction("Add first row", "Body rows", newRowCommand, null);

        createClickAction("Add third row", "Body rows", new NewRowCommand(2),
                null);

        createClickAction("Remove first row", "Body rows",
                new Command<Grid, String>() {
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        Object firstItemId = ds.getIdByIndex(0);
                        ds.removeItem(firstItemId);
                    }
                }, null);

        createClickAction("Remove 18 first rows", "Body rows",
                new Command<Grid, String>() {
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        for (int i = 0; i < 18; i++) {
                            Object firstItemId = ds.getIdByIndex(0);
                            ds.removeItem(firstItemId);
                        }
                    }
                }, null);

        createClickAction("Modify first row (getItemProperty)", "Body rows",
                new Command<Grid, String>() {
                    @SuppressWarnings("unchecked")
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        Object firstItemId = ds.getIdByIndex(0);
                        Item item = ds.getItem(firstItemId);
                        for (int i = 0; i < COLUMNS; i++) {
                            Property<?> property = item
                                    .getItemProperty(getColumnProperty(i));
                            if (property.getType().equals(String.class)) {
                                ((Property<String>) property)
                                        .setValue("modified: " + i);
                            }
                        }
                    }
                }, null);

        createClickAction("Modify first row (getContainerProperty)",
                "Body rows", new Command<Grid, String>() {
                    @SuppressWarnings("unchecked")
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        Object firstItemId = ds.getIdByIndex(0);
                        for (Object containerPropertyId : ds
                                .getContainerPropertyIds()) {
                            Property<?> property = ds.getContainerProperty(
                                    firstItemId, containerPropertyId);
                            if (property.getType().equals(String.class)) {
                                ((Property<String>) property)
                                        .setValue("modified: "
                                                + containerPropertyId);
                            }
                        }
                    }
                }, null);

        createBooleanAction("Select first row", "Body rows", false,
                new Command<Grid, Boolean>() {
                    @Override
                    public void execute(Grid grid, Boolean select, Object data) {
                        final Object firstItemId = grid
                                .getContainerDataSource().firstItemId();
                        if (select.booleanValue()) {
                            grid.select(firstItemId);
                        } else {
                            grid.deselect(firstItemId);
                        }
                    }
                });

        createClickAction("Remove all rows", "Body rows",
                new Command<Grid, String>() {
                    @SuppressWarnings("unchecked")
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        ds.removeAllItems();
                    }
                }, null);
    }

    protected void createEditorActions() {
        createBooleanAction("Enabled", "Editor", false,
                new Command<Grid, Boolean>() {
                    @Override
                    public void execute(Grid c, Boolean value, Object data) {
                        c.setEditorEnabled(value);
                    }
                });

        createClickAction("Edit item 5", "Editor", new Command<Grid, String>() {
            @Override
            public void execute(Grid c, String value, Object data) {
                c.editItem(5);
            }
        }, null);

        createClickAction("Edit item 100", "Editor",
                new Command<Grid, String>() {
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        c.editItem(100);
                    }
                }, null);
        createClickAction("Save", "Editor", new Command<Grid, String>() {
            @Override
            public void execute(Grid c, String value, Object data) {
                try {
                    c.saveEditor();
                } catch (CommitException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }, null);
        createClickAction("Cancel edit", "Editor", new Command<Grid, String>() {
            @Override
            public void execute(Grid c, String value, Object data) {
                c.cancelEditor();
            }
        }, null);

        createClickAction("Change save caption", "Editor",
                new Command<Grid, String>() {
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        c.setEditorSaveCaption("ǝʌɐS");
                    }
                }, null);

        createClickAction("Change cancel caption", "Editor",
                new Command<Grid, String>() {
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        c.setEditorCancelCaption("ʃǝɔuɐↃ");
                    }
                }, null);
    }

    @SuppressWarnings("boxing")
    protected void addHeightActions() {
        createCategory("Height by Rows", "Size");

        createBooleanAction("HeightMode Row", "Size", false,
                new Command<Grid, Boolean>() {
                    @Override
                    public void execute(Grid c, Boolean heightModeByRows,
                            Object data) {
                        c.setHeightMode(heightModeByRows ? HeightMode.ROW
                                : HeightMode.CSS);
                    }
                }, null);

        addActionForHeightByRows(1d / 3d);
        addActionForHeightByRows(2d / 3d);

        for (double i = 1; i < 5; i++) {
            addActionForHeightByRows(i);
            addActionForHeightByRows(i + 1d / 3d);
            addActionForHeightByRows(i + 2d / 3d);
        }

        Command<Grid, String> sizeCommand = new Command<Grid, String>() {
            @Override
            public void execute(Grid grid, String height, Object data) {
                grid.setHeight(height);
            }
        };

        createCategory("Height", "Size");
        // header 20px + scrollbar 16px = 36px baseline
        createClickAction("86px (no drag scroll select)", "Height",
                sizeCommand, "86px");
        createClickAction("96px (drag scroll select limit)", "Height",
                sizeCommand, "96px");
        createClickAction("106px (drag scroll select enabled)", "Height",
                sizeCommand, "106px");
    }

    private void addActionForHeightByRows(final Double i) {
        DecimalFormat df = new DecimalFormat("0.00");
        createClickAction(df.format(i) + " rows", "Height by Rows",
                new Command<Grid, String>() {
                    @Override
                    public void execute(Grid c, String value, Object data) {
                        c.setHeightByRows(i);
                    }
                }, null);
    }

    private void createDetailsActions() {
        Command<Grid, DetailsGenerator> swapDetailsGenerator = new Command<Grid, DetailsGenerator>() {
            @Override
            public void execute(Grid c, DetailsGenerator generator, Object data) {
                grid.setDetailsGenerator(generator);
            }
        };

        Command<Grid, Boolean> openOrCloseItemId = new Command<Grid, Boolean>() {
            @Override
            @SuppressWarnings("boxing")
            public void execute(Grid g, Boolean visible, Object itemId) {
                g.setDetailsVisible(itemId, visible);
            }
        };

        createCategory("Generators", "Details");
        createClickAction("NULL", "Generators", swapDetailsGenerator,
                DetailsGenerator.NULL);
        createClickAction("\"Watching\"", "Generators", swapDetailsGenerator,
                watchingDetailsGenerator);
        createClickAction("Detailed", "Generators", swapDetailsGenerator,
                detailedDetailsGenerator);
        createClickAction("Hierarchical", "Generators", swapDetailsGenerator,
                hierarchicalDetailsGenerator);

        createClickAction("- Change Component", "Generators",
                new Command<Grid, Void>() {
                    @Override
                    public void execute(Grid c, Void value, Object data) {
                        Label label = (Label) detailsPanel.getContent();
                        if (label.getValue().equals("One")) {
                            detailsPanel.setContent(new Label("Two"));
                        } else {
                            detailsPanel.setContent(new Label("One"));
                        }
                    }
                }, null);

        createClickAction("Toggle firstItemId", "Details",
                new Command<Grid, Void>() {
                    @Override
                    public void execute(Grid g, Void value, Object data) {
                        Object firstItemId = g.getContainerDataSource()
                                .firstItemId();
                        boolean toggle = g.isDetailsVisible(firstItemId);
                        g.setDetailsVisible(firstItemId, !toggle);
                        g.setDetailsVisible(firstItemId, toggle);
                    }
                }, null);

        createBooleanAction("Open firstItemId", "Details", false,
                openOrCloseItemId, ds.firstItemId());

        createBooleanAction("Open 1", "Details", false, openOrCloseItemId,
                ds.getIdByIndex(1));

        createBooleanAction("Open 995", "Details", false, openOrCloseItemId,
                ds.getIdByIndex(995));
    }

    @Override
    protected Integer getTicketNumber() {
        return 12829;
    }

    @Override
    protected Class<Grid> getTestClass() {
        return Grid.class;
    }

}