1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630 |
- /*
- * Copyright 2000-2016 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.HashMap;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
- import java.util.Random;
-
- import com.vaadin.data.sort.Sort;
- import com.vaadin.data.sort.SortOrder;
- 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.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.Label;
- import com.vaadin.ui.Notification;
- import com.vaadin.ui.Panel;
- import com.vaadin.v7.data.Container.Filter;
- import com.vaadin.v7.data.Item;
- import com.vaadin.v7.data.Property;
- import com.vaadin.v7.data.Property.ValueChangeEvent;
- import com.vaadin.v7.data.Property.ValueChangeListener;
- import com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException;
- import com.vaadin.v7.data.util.IndexedContainer;
- import com.vaadin.v7.event.ItemClickEvent;
- import com.vaadin.v7.event.ItemClickEvent.ItemClickListener;
- import com.vaadin.v7.shared.ui.grid.GridStaticCellType;
- import com.vaadin.v7.shared.ui.grid.HeightMode;
- import com.vaadin.v7.ui.Field;
- import com.vaadin.v7.ui.Grid;
- import com.vaadin.v7.ui.Grid.CellDescriptionGenerator;
- import com.vaadin.v7.ui.Grid.CellReference;
- import com.vaadin.v7.ui.Grid.CellStyleGenerator;
- import com.vaadin.v7.ui.Grid.Column;
- import com.vaadin.v7.ui.Grid.ColumnReorderEvent;
- import com.vaadin.v7.ui.Grid.ColumnReorderListener;
- import com.vaadin.v7.ui.Grid.ColumnResizeEvent;
- import com.vaadin.v7.ui.Grid.ColumnResizeListener;
- import com.vaadin.v7.ui.Grid.ColumnVisibilityChangeEvent;
- import com.vaadin.v7.ui.Grid.ColumnVisibilityChangeListener;
- import com.vaadin.v7.ui.Grid.DetailsGenerator;
- import com.vaadin.v7.ui.Grid.FooterCell;
- import com.vaadin.v7.ui.Grid.HeaderCell;
- import com.vaadin.v7.ui.Grid.HeaderRow;
- import com.vaadin.v7.ui.Grid.MultiSelectionModel;
- import com.vaadin.v7.ui.Grid.RowDescriptionGenerator;
- import com.vaadin.v7.ui.Grid.RowReference;
- import com.vaadin.v7.ui.Grid.RowStyleGenerator;
- import com.vaadin.v7.ui.Grid.SelectionMode;
- import com.vaadin.v7.ui.Grid.SelectionModel;
- import com.vaadin.v7.ui.renderers.DateRenderer;
- import com.vaadin.v7.ui.renderers.HtmlRenderer;
- import com.vaadin.v7.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 RowDescriptionGenerator rowDescriptionGenerator = new RowDescriptionGenerator() {
-
- @Override
- public String getDescription(RowReference row) {
- return "Row tooltip for row " + row.getItemId();
- }
- };
-
- private CellDescriptionGenerator cellDescriptionGenerator = new CellDescriptionGenerator() {
-
- @Override
- public String getDescription(CellReference cell) {
- if ("Column 0".equals(cell.getPropertyId())) {
- return "Cell tooltip for row " + cell.getItemId()
- + ", column 0";
- } else {
- return null;
- }
- }
- };
-
- private ItemClickListener editorOpeningItemClickListener = new ItemClickListener() {
-
- @Override
- public void itemClick(ItemClickEvent event) {
- grid.editItem(event.getItemId());
- }
- };
-
- private ValueChangeListener reactiveValueChanger = new ValueChangeListener() {
- @Override
- @SuppressWarnings("unchecked")
- public void valueChange(ValueChangeEvent event) {
- Object id = grid.getEditedItemId();
- grid.getContainerDataSource().getContainerProperty(id, "Column 2")
- .setValue("Modified");
- }
- };
-
- 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 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 Map<Object, Panel> detailsMap = new HashMap<Object, Panel>();
-
- private final DetailsGenerator persistingDetailsGenerator = new DetailsGenerator() {
-
- @Override
- public Component getDetails(RowReference rowReference) {
- Object itemId = rowReference.getItemId();
- if (!detailsMap.containsKey(itemId)) {
-
- Panel panel = new Panel();
- panel.setContent(new Label("One"));
- detailsMap.put(itemId, panel);
- }
- return detailsMap.get(itemId);
- }
- };
-
- @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("SortEvent: isUserOriginated? " + event.isUserOriginated());
- }
- });
-
- grid.addColumnResizeListener(new ColumnResizeListener() {
- @Override
- public void columnResize(ColumnResizeEvent event) {
- log("ColumnResizeEvent: 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() {
- createBooleanAction("Column 1 starts with \"(23\"", "Filter", false,
- new Command<Grid, Boolean>() {
- Filter filter = new Filter() {
- @Override
- public boolean passesFilter(Object itemId, Item item) {
- return item.getItemProperty("Column 1").getValue()
- .toString().startsWith("(23");
- }
-
- @Override
- public boolean appliesToProperty(Object propertyId) {
- return propertyId.equals("Column 1");
- }
- };
-
- @Override
- public void execute(Grid grid, Boolean value, Object data) {
- if (value) {
- ds.addContainerFilter(filter);
- } else {
- ds.removeContainerFilter(filter);
- }
- }
- });
-
- createBooleanAction("Impassable filter", "Filter", false,
- new Command<Grid, Boolean>() {
- Filter filter = new Filter() {
- @Override
- public boolean passesFilter(Object itemId, Item item) {
- return false;
- }
-
- @Override
- public boolean appliesToProperty(Object propertyId) {
- return true;
- }
- };
-
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- if (value) {
- ds.addContainerFilter(filter);
- } else {
- ds.removeContainerFilter(filter);
- }
- }
- });
- }
-
- 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);
- }
- });
-
- createBooleanAction("Row description generator", "State", false,
- new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- c.setRowDescriptionGenerator(
- value ? rowDescriptionGenerator : null);
- }
- });
-
- createBooleanAction("Cell description generator", "State", false,
- new Command<Grid, Boolean>() {
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- c.setCellDescriptionGenerator(
- value ? cellDescriptionGenerator : null);
- }
- });
-
- 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("EditorOpeningItemClickListener", "State", false,
- new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- if (!value) {
- c.removeItemClickListener(
- editorOpeningItemClickListener);
- } else {
- c.addItemClickListener(
- editorOpeningItemClickListener);
- }
- }
-
- });
- createBooleanAction("ReactiveValueChanger", "State", false,
- new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- Field<?> targetField = grid.getEditorFieldGroup()
- .getField("Column 0");
- if (targetField != null) {
- if (!value) {
- targetField.removeValueChangeListener(
- reactiveValueChanger);
- } else {
- targetField.addValueChangeListener(
- reactiveValueChanger);
- }
- }
- }
-
- });
- 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);
- }
- });
-
- createClickAction("Select all", "State", new Command<Grid, String>() {
- @Override
- public void execute(Grid c, String value, Object data) {
- SelectionModel selectionModel = c.getSelectionModel();
- if (selectionModel instanceof SelectionModel.Multi) {
- ((SelectionModel.Multi) selectionModel).selectAll();
- }
- }
- }, null);
-
- createClickAction("Select none", "State", new Command<Grid, String>() {
- @Override
- public void execute(Grid c, String value, Object data) {
- SelectionModel selectionModel = c.getSelectionModel();
- if (selectionModel instanceof SelectionModel.Multi) {
- ((SelectionModel.Multi) selectionModel).deselectAll();
- }
- }
- }, null);
- }
-
- 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("Resizable", 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.setResizable(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);
-
- createClickAction("Change header 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).setHeaderCaption(
- columnProperty + " header " + 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);
- }
-
- createClickAction("All columns auto width", "Columns",
- new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- for (Column col : grid.getColumns()) {
- col.setWidthUndefined();
- }
-
- }
- }, null);
-
- 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);
- }
-
- }
- });
- createBooleanAction("All columns resizable", "Columns", false,
- new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- for (Column col : grid.getColumns()) {
- col.setResizable(value);
- }
-
- }
- });
-
- createClickAction("All columns expanding, Col 0 has max width of 30px",
- "Columns", new Command<Grid, Boolean>() {
-
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- for (Column col : grid.getColumns()) {
- col.setWidthUndefined();
- }
- grid.getColumns().get(0).setMaximumWidth(30);
- }
- }, null);
- }
-
- 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);
-
- createClickAction("Remove selected rows", "Body rows",
- new Command<Grid, String>() {
- @Override
- public void execute(Grid c, String value, Object data) {
- // Usually you'd deselect all the rows before removing
- // them. It is done this way to test for #19152
- for (Object itemId : c.getSelectedRows()) {
- ds.removeItem(itemId);
- }
- c.select(null);
- }
- }, 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);
- }
- });
-
- createBooleanAction("Buffered mode", "Editor", true,
- new Command<Grid, Boolean>() {
- @Override
- public void execute(Grid c, Boolean value, Object data) {
- c.setEditorBuffered(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("Persisting", "Generators", swapDetailsGenerator,
- persistingDetailsGenerator);
-
- createClickAction("- Change Component", "Generators",
- new Command<Grid, Void>() {
- @Override
- public void execute(Grid c, Void value, Object data) {
- for (Object id : detailsMap.keySet()) {
- Panel panel = detailsMap.get(id);
- Label label = (Label) panel.getContent();
- if (label.getValue().equals("One")) {
- panel.setContent(new Label("Two"));
- } else {
- panel.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;
- }
-
- }
|