123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605 |
- /*
- * 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.widgetset.client.v7.grid;
-
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Random;
- import java.util.logging.Logger;
-
- import com.google.gwt.core.client.Scheduler;
- import com.google.gwt.core.client.Scheduler.ScheduledCommand;
- import com.google.gwt.dom.client.Style.Unit;
- import com.google.gwt.event.dom.client.ClickHandler;
- import com.google.gwt.event.dom.client.ContextMenuEvent;
- import com.google.gwt.event.dom.client.ContextMenuHandler;
- import com.google.gwt.event.shared.HandlerRegistration;
- import com.google.gwt.user.client.Event;
- import com.google.gwt.user.client.Timer;
- import com.google.gwt.user.client.Window;
- import com.google.gwt.user.client.ui.Button;
- import com.google.gwt.user.client.ui.Composite;
- import com.google.gwt.user.client.ui.FlowPanel;
- import com.google.gwt.user.client.ui.HTML;
- import com.google.gwt.user.client.ui.Label;
- import com.google.gwt.user.client.ui.MenuItem;
- import com.google.gwt.user.client.ui.MenuItemSeparator;
- import com.google.gwt.user.client.ui.TextBox;
- import com.google.gwt.user.client.ui.Widget;
- import com.vaadin.client.data.DataSource;
- import com.vaadin.client.data.DataSource.RowHandle;
- import com.vaadin.client.ui.VLabel;
- import com.vaadin.tests.widgetset.client.v7.grid.GridBasicClientFeaturesWidget.Data;
- import com.vaadin.v7.client.renderers.DateRenderer;
- import com.vaadin.v7.client.renderers.HtmlRenderer;
- import com.vaadin.v7.client.renderers.NumberRenderer;
- import com.vaadin.v7.client.renderers.Renderer;
- import com.vaadin.v7.client.renderers.TextRenderer;
- import com.vaadin.v7.client.widget.grid.CellReference;
- import com.vaadin.v7.client.widget.grid.CellStyleGenerator;
- import com.vaadin.v7.client.widget.grid.DetailsGenerator;
- import com.vaadin.v7.client.widget.grid.EditorHandler;
- import com.vaadin.v7.client.widget.grid.EventCellReference;
- import com.vaadin.v7.client.widget.grid.RendererCellReference;
- import com.vaadin.v7.client.widget.grid.RowReference;
- import com.vaadin.v7.client.widget.grid.RowStyleGenerator;
- import com.vaadin.v7.client.widget.grid.datasources.ListDataSource;
- import com.vaadin.v7.client.widget.grid.datasources.ListSorter;
- import com.vaadin.v7.client.widget.grid.events.BodyKeyDownHandler;
- import com.vaadin.v7.client.widget.grid.events.BodyKeyPressHandler;
- import com.vaadin.v7.client.widget.grid.events.BodyKeyUpHandler;
- import com.vaadin.v7.client.widget.grid.events.ColumnReorderEvent;
- import com.vaadin.v7.client.widget.grid.events.ColumnReorderHandler;
- import com.vaadin.v7.client.widget.grid.events.ColumnVisibilityChangeEvent;
- import com.vaadin.v7.client.widget.grid.events.ColumnVisibilityChangeHandler;
- import com.vaadin.v7.client.widget.grid.events.FooterKeyDownHandler;
- import com.vaadin.v7.client.widget.grid.events.FooterKeyPressHandler;
- import com.vaadin.v7.client.widget.grid.events.FooterKeyUpHandler;
- import com.vaadin.v7.client.widget.grid.events.GridKeyDownEvent;
- import com.vaadin.v7.client.widget.grid.events.GridKeyPressEvent;
- import com.vaadin.v7.client.widget.grid.events.GridKeyUpEvent;
- import com.vaadin.v7.client.widget.grid.events.HeaderKeyDownHandler;
- import com.vaadin.v7.client.widget.grid.events.HeaderKeyPressHandler;
- import com.vaadin.v7.client.widget.grid.events.HeaderKeyUpHandler;
- import com.vaadin.v7.client.widget.grid.selection.SelectionModel;
- import com.vaadin.v7.client.widget.grid.selection.SelectionModel.None;
- import com.vaadin.v7.client.widgets.Grid;
- import com.vaadin.v7.client.widgets.Grid.Column;
- import com.vaadin.v7.client.widgets.Grid.FooterRow;
- import com.vaadin.v7.client.widgets.Grid.HeaderRow;
- import com.vaadin.v7.client.widgets.Grid.SelectionMode;
- import com.vaadin.v7.shared.ui.grid.ScrollDestination;
-
- /**
- * Grid basic client features test application.
- *
- * @since
- * @author Vaadin Ltd
- */
- public class GridBasicClientFeaturesWidget
- extends PureGWTTestApplication<Grid<List<Data>>> {
- public static final String ROW_STYLE_GENERATOR_NONE = "None";
- public static final String ROW_STYLE_GENERATOR_ROW_INDEX = "Row numbers";
- public static final String ROW_STYLE_GENERATOR_EVERY_THIRD = "Every third";
-
- public static final String CELL_STYLE_GENERATOR_NONE = "None";
- public static final String CELL_STYLE_GENERATOR_SIMPLE = "Simple";
- public static final String CELL_STYLE_GENERATOR_COL_INDEX = "Column index";
-
- public static enum Renderers {
- TEXT_RENDERER, HTML_RENDERER, NUMBER_RENDERER, DATE_RENDERER;
- }
-
- private class TestEditorHandler implements EditorHandler<List<Data>> {
-
- private Map<Grid.Column<?, ?>, TextBox> widgets = new HashMap<>();
-
- private Label log = new Label();
-
- {
- log.addStyleName("grid-editor-log");
- addSouth(log, 20);
- }
-
- @Override
- public void bind(EditorRequest<List<Data>> request) {
- List<Data> rowData = ds.getRow(request.getRowIndex());
-
- boolean hasSelectionColumn = !(grid
- .getSelectionModel() instanceof None);
- for (int i = 0; i < rowData.size(); i++) {
- int columnIndex = hasSelectionColumn ? i + 1 : i;
- getWidget(columnIndex).setText(rowData.get(i).value.toString());
- }
- request.success();
- }
-
- @Override
- public void cancel(EditorRequest<List<Data>> request) {
- log.setText("Row " + request.getRowIndex() + " edit cancelled");
- }
-
- @Override
- public void save(EditorRequest<List<Data>> request) {
- if (secondEditorError) {
- request.failure("Syntethic fail of editor in column 2. "
- + "This message is so long that it doesn't fit into its box",
- Collections.<Column<?, List<Data>>> singleton(
- grid.getColumn(2)));
- return;
- }
- try {
- log.setText("Row " + request.getRowIndex() + " edit committed");
- List<Data> rowData = ds.getRow(request.getRowIndex());
-
- int i = 0;
- for (; i < COLUMNS - MANUALLY_FORMATTED_COLUMNS; i++) {
- rowData.get(i).value = getWidget(i).getText();
- }
-
- rowData.get(i).value = Integer
- .valueOf(getWidget(i++).getText());
- rowData.get(i).value = new Date(getWidget(i++).getText());
- rowData.get(i).value = getWidget(i++).getText();
- rowData.get(i).value = Integer
- .valueOf(getWidget(i++).getText());
- rowData.get(i).value = Integer
- .valueOf(getWidget(i++).getText());
-
- // notify data source of changes
- ds.asList().set(request.getRowIndex(), rowData);
- request.success();
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).warning(e.toString());
- request.failure(null, null);
- }
- }
-
- @Override
- public TextBox getWidget(Grid.Column<?, List<Data>> column) {
- if (grid.getColumns().indexOf(column) == 0
- && !(grid.getSelectionModel() instanceof None)) {
- return null;
- }
-
- TextBox w = widgets.get(column);
- if (w == null) {
- w = new TextBox();
- w.getElement().getStyle().setMargin(0, Unit.PX);
- widgets.put(column, w);
- }
- return w;
- }
-
- private TextBox getWidget(int i) {
- return getWidget(grid.getColumn(i));
- }
- }
-
- private static final int MANUALLY_FORMATTED_COLUMNS = 5;
- public static final int COLUMNS = 12;
- public static final int ROWS = 1000;
-
- private final Grid<List<Data>> grid;
- private List<List<Data>> data;
- private final ListDataSource<List<Data>> ds;
- private final ListSorter<List<Data>> sorter;
-
- private boolean secondEditorError = false;
-
- /**
- * Our basic data object
- */
- public static final class Data {
- Object value;
- }
-
- /**
- * @since
- * @return
- */
- private List<List<Data>> createData(int rowCount) {
- List<List<Data>> dataList = new ArrayList<>();
- Random rand = new Random();
- rand.setSeed(13334);
- long timestamp = 0;
- for (int row = 0; row < rowCount; row++) {
-
- List<Data> datarow = createDataRow(COLUMNS);
- dataList.add(datarow);
- Data d;
-
- int col = 0;
- for (; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) {
- d = datarow.get(col);
- d.value = "(" + row + ", " + col + ")";
- }
-
- d = datarow.get(col++);
- d.value = Integer.valueOf(row);
-
- d = datarow.get(col++);
- d.value = new Date(timestamp);
- timestamp += 91250000; // a bit over a day, just to get
- // variation
-
- d = datarow.get(col++);
- d.value = "<b>" + row + "</b>";
-
- d = datarow.get(col++);
- d.value = Integer.valueOf(rand.nextInt());
-
- d = datarow.get(col++);
- d.value = Integer.valueOf(rand.nextInt(5));
- }
-
- return dataList;
- }
-
- /**
- * Convenience method for creating a list of Data objects to be used as a
- * Row in the data source
- *
- * @param cols
- * number of columns (items) to include in the row
- * @return
- */
- private List<Data> createDataRow(int cols) {
- List<Data> list = new ArrayList<>(cols);
- for (int i = 0; i < cols; ++i) {
- list.add(new Data());
- }
- return list;
- }
-
- @SuppressWarnings("unchecked")
- public GridBasicClientFeaturesWidget() {
- super(new Grid<List<Data>>());
-
- // Initialize data source
- data = createData(ROWS);
-
- ds = new ListDataSource<>(data);
- grid = getTestedWidget();
- grid.getElement().setId("testComponent");
- grid.setDataSource(ds);
- grid.addSelectAllHandler(ds.getSelectAllHandler());
- grid.setSelectionMode(SelectionMode.NONE);
- grid.setEditorHandler(new TestEditorHandler());
-
- sorter = new ListSorter<>(grid);
-
- // Create a bunch of grid columns
-
- // Data source layout:
- // text (String) * (COLUMNS - MANUALLY_FORMATTED_COLUMNS + 1) |
- // rownumber (Integer) | some date (Date) | row number as HTML (String)
- // | random value (Integer)
-
- int col = 0;
-
- // Text times COLUMNS - MANUALLY_FORMATTED_COLUMNS
- for (col = 0; col < COLUMNS - MANUALLY_FORMATTED_COLUMNS; ++col) {
-
- final int c = col;
-
- Grid.Column<String, List<Data>> column = new Grid.Column<String, List<Data>>(
- createRenderer(Renderers.TEXT_RENDERER)) {
- @Override
- public String getValue(List<Data> row) {
- return (String) row.get(c).value;
- }
- };
-
- column.setWidth(50 + c * 25);
- column.setHeaderCaption("Header (0," + c + ")");
-
- grid.addColumn(column);
- }
-
- // Integer row number
- {
- final int c = col++;
- Grid.Column<Integer, List<Data>> column = new Grid.Column<Integer, List<Data>>(
- createRenderer(Renderers.NUMBER_RENDERER)) {
- @Override
- public Integer getValue(List<Data> row) {
- return (Integer) row.get(c).value;
- }
- };
- grid.addColumn(column);
- column.setHeaderCaption("Header (0," + c + ")");
- }
-
- // Some date
- {
- final int c = col++;
- Grid.Column<Date, List<Data>> column = new Grid.Column<Date, List<Data>>(
- createRenderer(Renderers.DATE_RENDERER)) {
- @Override
- public Date getValue(List<Data> row) {
- return (Date) row.get(c).value;
- }
- };
- grid.addColumn(column);
- column.setHeaderCaption("Header (0," + c + ")");
- }
-
- // Row number as a HTML string
- {
- final int c = col++;
- Grid.Column<String, List<Data>> column = new Grid.Column<String, List<Data>>(
- createRenderer(Renderers.HTML_RENDERER)) {
- @Override
- public String getValue(List<Data> row) {
- return (String) row.get(c).value;
- }
- };
- grid.addColumn(column);
- column.setHeaderCaption("Header (0," + c + ")");
- }
-
- // Random integer value
- {
- final int c = col++;
- Grid.Column<Integer, List<Data>> column = new Grid.Column<Integer, List<Data>>(
- createRenderer(Renderers.NUMBER_RENDERER)) {
- @Override
- public Integer getValue(List<Data> row) {
- return (Integer) row.get(c).value;
- }
- };
- grid.addColumn(column);
- column.setHeaderCaption("Header (0," + c + ")");
- }
-
- // Random integer value between 0 and 5
- {
- final int c = col++;
- Grid.Column<Integer, List<Data>> column = new Grid.Column<Integer, List<Data>>(
- createRenderer(Renderers.NUMBER_RENDERER)) {
- @Override
- public Integer getValue(List<Data> row) {
- return (Integer) row.get(c).value;
- }
- };
- grid.addColumn(column);
- column.setHeaderCaption("Header (0," + c + ")");
- }
-
- grid.getColumn(3).setEditable(false);
-
- HeaderRow row = grid.getDefaultHeaderRow();
- for (int i = 0; i < col; ++i) {
- String caption = "Header (0," + i + ")";
- Grid.Column<?, ?> column = grid.getColumn(i);
- // Lets use some different cell types
- if (i % 3 == 0) {
- // No-op
- } else if (i % 2 == 0) {
- row.getCell(column).setHtml("<b>" + caption + "</b>");
- } else {
- row.getCell(column).setWidget(new HTML(caption));
- }
- }
- ++headerCounter;
-
- //
- // Populate the menu
- //
-
- createStateMenu();
- createColumnsMenu();
- createHeaderMenu();
- createFooterMenu();
- createEditorMenu();
- createInternalsMenu();
- createDataSourceMenu();
- createDetailsMenu();
- createSidebarMenu();
-
- grid.getElement().getStyle().setZIndex(0);
-
- //
- // Composite wrapping for grid.
- //
- boolean isComposite = Window.Location.getParameter("composite") != null;
- if (isComposite) {
- addNorth(new Composite() {
- {
- initWidget(grid);
- }
- }, 400);
- } else {
- addNorth(grid, 400);
- }
-
- createKeyHandlers();
- }
-
- private void createInternalsMenu() {
- String[] listenersPath = { "Component", "Internals", "Listeners" };
- final Label label = new Label();
- addSouth(label, 20);
-
- addMenuCommand("Add scroll listener", new ScheduledCommand() {
- private HandlerRegistration scrollHandler = null;
-
- @Override
- public void execute() {
- if (scrollHandler != null) {
- return;
- }
- scrollHandler = grid.addScrollHandler(event -> {
- final Grid<?> grid = (Grid<?>) event.getSource();
- label.setText("scrollTop: " + grid.getScrollTop()
- + ", scrollLeft: " + grid.getScrollLeft());
- });
- }
- }, listenersPath);
- addMenuCommand("Add ColumnReorder listener", new ScheduledCommand() {
- private HandlerRegistration columnReorderHandler = null;
-
- @Override
- public void execute() {
- if (columnReorderHandler != null) {
- return;
- }
- final Label columnOrderLabel = new Label();
- columnOrderLabel.getElement().setId("columnreorder");
- addLineEnd(columnOrderLabel, 300);
- columnReorderHandler = grid.addColumnReorderHandler(
- new ColumnReorderHandler<List<Data>>() {
-
- private int eventIndex = 0;
-
- @Override
- public void onColumnReorder(
- ColumnReorderEvent<List<Data>> event) {
- columnOrderLabel.getElement().setAttribute(
- "columns", "" + (++eventIndex));
- }
- });
- }
- }, listenersPath);
- addMenuCommand("Add Column Visibility Change listener",
- new ScheduledCommand() {
- private HandlerRegistration columnVisibilityHandler = null;
-
- @Override
- public void execute() {
- if (columnVisibilityHandler != null) {
- return;
- }
- final Label columnOrderLabel = new Label();
- columnOrderLabel.getElement().setId("columnvisibility");
- addLineEnd(columnOrderLabel, 250);
- ColumnVisibilityChangeHandler handler = new ColumnVisibilityChangeHandler<List<Data>>() {
-
- private int eventIndex = 0;
-
- @Override
- public void onVisibilityChange(
- ColumnVisibilityChangeEvent<List<Data>> event) {
- columnOrderLabel.getElement().setAttribute(
- "counter", "" + (++eventIndex));
- columnOrderLabel.getElement().setAttribute(
- "useroriginated", (Boolean.toString(
- event.isUserOriginated())));
- columnOrderLabel.getElement().setAttribute(
- "ishidden",
- (Boolean.toString(event.isHidden())));
- columnOrderLabel.getElement().setAttribute(
- "columnindex", "" + grid.getColumns()
- .indexOf(event.getColumn()));
- }
- };
-
- columnVisibilityHandler = grid
- .addColumnVisibilityChangeHandler(handler);
- }
- }, listenersPath);
- addMenuCommand("Add context menu listener", new ScheduledCommand() {
-
- HandlerRegistration handler = null;
- ContextMenuHandler contextMenuHandler = event -> {
- event.preventDefault();
- final String location;
- EventCellReference<?> cellRef = grid.getEventCell();
- if (cellRef.isHeader()) {
- location = "header";
- } else if (cellRef.isBody()) {
- location = "body";
- } else if (cellRef.isFooter()) {
- location = "footer";
- } else {
- location = "somewhere";
- }
-
- getLogger().info(
- "Prevented opening a context menu in grid " + location);
- };
-
- @Override
- public void execute() {
- if (handler != null) {
- grid.unsinkEvents(Event.ONCONTEXTMENU);
- handler.removeHandler();
- } else {
- grid.sinkEvents(Event.ONCONTEXTMENU);
- handler = grid.addDomHandler(contextMenuHandler,
- ContextMenuEvent.getType());
- }
- }
-
- }, listenersPath);
- }
-
- private void createStateMenu() {
- String[] selectionModePath = { "Component", "State", "Selection mode" };
- String[] primaryStyleNamePath = { "Component", "State",
- "Primary Stylename" };
- String[] rowStyleGeneratorNamePath = { "Component", "State",
- "Row style generator" };
- String[] cellStyleGeneratorNamePath = { "Component", "State",
- "Cell style generator" };
-
- addMenuCommand("multi", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSelectionMode(SelectionMode.MULTI);
- }
- }, selectionModePath);
-
- addMenuCommand("single", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- }
- }, selectionModePath);
-
- addMenuCommand("single (no deselect)", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- ((SelectionModel.Single<?>) grid.getSelectionModel())
- .setDeselectAllowed(false);
- }
- }, selectionModePath);
-
- addMenuCommand("none", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSelectionMode(SelectionMode.NONE);
- }
- }, selectionModePath);
-
- addMenuCommand("v-grid", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setStylePrimaryName("v-grid");
-
- }
- }, primaryStyleNamePath);
-
- addMenuCommand("v-escalator", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setStylePrimaryName("v-escalator");
-
- }
- }, primaryStyleNamePath);
-
- addMenuCommand("v-custom-style", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setStylePrimaryName("v-custom-style");
-
- }
- }, primaryStyleNamePath);
-
- addMenuCommand("Edit and refresh Row 0", new ScheduledCommand() {
- @Override
- public void execute() {
- DataSource<List<Data>> ds = grid.getDataSource();
- RowHandle<List<Data>> rowHandle = ds.getHandle(ds.getRow(0));
- rowHandle.getRow().get(0).value = "Foo";
- rowHandle.updateRow();
- }
- }, "Component", "State");
-
- addMenuCommand("Delayed edit of Row 0", new ScheduledCommand() {
- @Override
- public void execute() {
- DataSource<List<Data>> ds = grid.getDataSource();
- final RowHandle<List<Data>> rowHandle = ds
- .getHandle(ds.getRow(0));
-
- new Timer() {
- @Override
- public void run() {
- rowHandle.getRow().get(0).value = "Bar";
- rowHandle.updateRow();
- }
-
- }.schedule(5000);
- }
- }, "Component", "State");
-
- addMenuCommand(ROW_STYLE_GENERATOR_NONE, new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setRowStyleGenerator(null);
- }
- }, rowStyleGeneratorNamePath);
-
- addMenuCommand(ROW_STYLE_GENERATOR_EVERY_THIRD, new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setRowStyleGenerator(new RowStyleGenerator<List<Data>>() {
-
- @Override
- public String getStyle(
- RowReference<List<Data>> rowReference) {
- if (rowReference.getRowIndex() % 3 == 0) {
- return "third";
- } else {
- // First manual col is integer
- Integer value = (Integer) rowReference.getRow().get(
- COLUMNS - MANUALLY_FORMATTED_COLUMNS).value;
- return value.toString();
- }
- }
- });
-
- }
- }, rowStyleGeneratorNamePath);
-
- addMenuCommand(ROW_STYLE_GENERATOR_ROW_INDEX, new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setRowStyleGenerator(new RowStyleGenerator<List<Data>>() {
-
- @Override
- public String getStyle(
- RowReference<List<Data>> rowReference) {
- return Integer.toString(rowReference.getRowIndex());
- }
- });
-
- }
- }, rowStyleGeneratorNamePath);
-
- addMenuCommand(CELL_STYLE_GENERATOR_NONE, new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setCellStyleGenerator(null);
- }
- }, cellStyleGeneratorNamePath);
-
- addMenuCommand(CELL_STYLE_GENERATOR_SIMPLE, new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setCellStyleGenerator(
- new CellStyleGenerator<List<Data>>() {
-
- @Override
- public String getStyle(
- CellReference<List<Data>> cellReference) {
- Grid.Column<?, List<Data>> column = cellReference
- .getColumn();
- if (column == grid.getColumn(2)) {
- return "two";
- } else if (column == grid.getColumn(
- COLUMNS - MANUALLY_FORMATTED_COLUMNS)) {
- // First manual col is integer
- Integer value = (Integer) column
- .getValue(cellReference.getRow());
- return value.toString();
-
- } else {
- return null;
- }
- }
- });
- }
- }, cellStyleGeneratorNamePath);
- addMenuCommand(CELL_STYLE_GENERATOR_COL_INDEX, new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setCellStyleGenerator(
- new CellStyleGenerator<List<Data>>() {
-
- @Override
- public String getStyle(
- CellReference<List<Data>> cellReference) {
- return cellReference.getRowIndex() + "_"
- + grid.getColumns().indexOf(
- cellReference.getColumn());
- }
- });
- }
- }, cellStyleGeneratorNamePath);
-
- for (int i = -1; i <= COLUMNS; i++) {
- final int index = i;
- // Including dummy "columns" prefix because TB fails to select item
- // if it's too narrow
- addMenuCommand(Integer.toString(index) + " columns",
- new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setFrozenColumnCount(index);
- }
- }, "Component", "State", "Frozen column count");
- }
-
- addMenuCommand("Enabled", new ScheduledCommand() {
-
- @Override
- public void execute() {
- grid.setEnabled(!grid.isEnabled());
- }
- }, "Component", "State");
- addMenuCommand("Reverse grid columns", new ScheduledCommand() {
-
- @Override
- public void execute() {
- List<Column> columns = new ArrayList<>(grid.getColumns());
- Collections.reverse(columns);
- grid.setColumnOrder(
- columns.toArray(new Column[columns.size()]));
- }
- }, "Component", "State");
- addMenuCommand("Column Reordering", new ScheduledCommand() {
-
- @Override
- public void execute() {
- grid.setColumnReorderingAllowed(
- !grid.isColumnReorderingAllowed());
- }
- }, "Component", "State");
- addMenuCommand("250px", new ScheduledCommand() {
-
- @Override
- public void execute() {
- grid.setWidth("250px");
- }
- }, "Component", "State", "Width");
- addMenuCommand("500px", new ScheduledCommand() {
-
- @Override
- public void execute() {
- grid.setWidth("500px");
- }
- }, "Component", "State", "Width");
- addMenuCommand("750px", new ScheduledCommand() {
-
- @Override
- public void execute() {
- grid.setWidth("750px");
- }
- }, "Component", "State", "Width");
- addMenuCommand("1000px", new ScheduledCommand() {
-
- @Override
- public void execute() {
- grid.setWidth("1000px");
- }
- }, "Component", "State", "Width");
-
- createScrollToRowMenu();
- }
-
- private void createScrollToRowMenu() {
- String[] menupath = { "Component", "State", "Scroll to...", null };
-
- for (int i = 0; i < ROWS; i += 100) {
- menupath[3] = "Row " + i + "...";
- for (final ScrollDestination scrollDestination : ScrollDestination
- .values()) {
- final int row = i;
- addMenuCommand("Destination " + scrollDestination,
- new ScheduledCommand() {
- @Override
- public void execute() {
- grid.scrollToRow(row, scrollDestination);
- }
- }, menupath);
- }
- }
-
- int i = ROWS - 1;
- menupath[3] = "Row " + i + "...";
- for (final ScrollDestination scrollDestination : ScrollDestination
- .values()) {
- final int row = i;
- addMenuCommand("Destination " + scrollDestination,
- new ScheduledCommand() {
- @Override
- public void execute() {
- grid.scrollToRow(row, scrollDestination);
- }
- }, menupath);
- }
-
- }
-
- private void createColumnsMenu() {
-
- for (int i = 0; i < COLUMNS; i++) {
- final int index = i;
- final Grid.Column<?, List<Data>> column = grid.getColumn(index);
- addMenuCommand("Sortable", new ScheduledCommand() {
- @Override
- public void execute() {
- column.setSortable(!column.isSortable());
- }
- }, "Component", "Columns", "Column " + i);
- addMenuCommand("Hidden", new ScheduledCommand() {
- @Override
- public void execute() {
- column.setHidden(!column.isHidden());
- }
- }, "Component", "Columns", "Column " + i);
- addMenuCommand("Hidable", new ScheduledCommand() {
- @Override
- public void execute() {
- column.setHidable(!column.isHidable());
- }
- }, "Component", "Columns", "Column " + i);
- addMenuCommand("auto", new ScheduledCommand() {
- @Override
- public void execute() {
- column.setWidth(-1);
- }
- }, "Component", "Columns", "Column " + i, "Width");
- addMenuCommand("50px", new ScheduledCommand() {
- @Override
- public void execute() {
- column.setWidth(50);
- }
- }, "Component", "Columns", "Column " + i, "Width");
- addMenuCommand("200px", new ScheduledCommand() {
- @Override
- public void execute() {
- column.setWidth(200);
- }
- }, "Component", "Columns", "Column " + i, "Width");
-
- // Header types
- addMenuCommand("Text Header", new ScheduledCommand() {
- @Override
- public void execute() {
- column.setHeaderCaption("Text Header");
- }
- }, "Component", "Columns", "Column " + i, "Header Type");
- addMenuCommand("HTML Header", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getHeaderRow(0).getCell(column)
- .setHtml("<b>HTML Header</b>");
- }
- }, "Component", "Columns", "Column " + i, "Header Type");
- addMenuCommand("Widget Header", new ScheduledCommand() {
- @Override
- public void execute() {
- final Button button = new Button("Button Header");
- button.addClickHandler(event -> button.setText("Clicked"));
- grid.getHeaderRow(0).getCell(column).setWidget(button);
- }
- }, "Component", "Columns", "Column " + i, "Header Type");
-
- // Footer types
- addMenuCommand("Text Footer", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getFooterRow(0).getCell(column).setText("Text Footer");
- }
- }, "Component", "Columns", "Column " + i, "Footer Type");
- addMenuCommand("HTML Footer", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getFooterRow(0).getCell(column)
- .setHtml("<b>HTML Footer</b>");
- }
- }, "Component", "Columns", "Column " + i, "Footer Type");
- addMenuCommand("Widget Footer", new ScheduledCommand() {
- @Override
- public void execute() {
- final Button button = new Button("Button Footer");
- button.addClickHandler(event -> button.setText("Clicked"));
- grid.getFooterRow(0).getCell(column).setWidget(button);
- }
- }, "Component", "Columns", "Column " + i, "Footer Type");
-
- // Renderer throwing exceptions
- addMenuCommand("Broken renderer", new ScheduledCommand() {
- @Override
- public void execute() {
- final Renderer<Object> originalRenderer = (Renderer<Object>) column
- .getRenderer();
-
- column.setRenderer(new Renderer<Object>() {
- @Override
- public void render(RendererCellReference cell,
- Object data) {
- if (cell.getRowIndex() == cell.getColumnIndex()) {
- throw new RuntimeException("I'm broken");
- }
- originalRenderer.render(cell, data);
- }
- });
- }
- }, "Component", "Columns", "Column " + i);
- addMenuCommand("Move column left", new ScheduledCommand() {
-
- @SuppressWarnings("unchecked")
- @Override
- public void execute() {
- List<Column<?, List<Data>>> cols = grid.getColumns();
- List<Column> reordered = new ArrayList<>(cols);
- final int index = cols.indexOf(column);
- if (index == 0) {
- Column<?, List<Data>> col = reordered.remove(0);
- reordered.add(col);
- } else {
- Column<?, List<Data>> col = reordered.remove(index);
- reordered.add(index - 1, col);
- }
- grid.setColumnOrder(
- reordered.toArray(new Column[reordered.size()]));
- }
- }, "Component", "Columns", "Column " + i);
- }
- }
-
- private int headerCounter = 0;
- private int footerCounter = 0;
-
- private void setHeaderTexts(HeaderRow row) {
- for (int i = 0; i < COLUMNS; ++i) {
- String caption = "Header (" + headerCounter + "," + i + ")";
-
- // Lets use some different cell types
- if (i % 3 == 0) {
- row.getCell(grid.getColumn(i)).setText(caption);
- } else if (i % 2 == 0) {
- row.getCell(grid.getColumn(i))
- .setHtml("<b>" + caption + "</b>");
- } else {
- row.getCell(grid.getColumn(i)).setWidget(new HTML(caption));
- }
- }
- headerCounter++;
- }
-
- private void setFooterTexts(FooterRow row) {
- for (int i = 0; i < COLUMNS; ++i) {
- String caption = "Footer (" + footerCounter + "," + i + ")";
-
- // Lets use some different cell types
- if (i % 3 == 0) {
- row.getCell(grid.getColumn(i)).setText(caption);
- } else if (i % 2 == 0) {
- row.getCell(grid.getColumn(i))
- .setHtml("<b>" + caption + "</b>");
- } else {
- row.getCell(grid.getColumn(i)).setWidget(new HTML(caption));
- }
- }
- footerCounter++;
- }
-
- private void createHeaderMenu() {
- final String[] menuPath = { "Component", "Header" };
-
- addMenuCommand("Visible", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setHeaderVisible(!grid.isHeaderVisible());
- }
- }, menuPath);
-
- addMenuCommand("Top", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setDefaultHeaderRow(grid.getHeaderRow(0));
- }
- }, "Component", "Header", "Default row");
- addMenuCommand("Bottom", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setDefaultHeaderRow(
- grid.getHeaderRow(grid.getHeaderRowCount() - 1));
- }
- }, "Component", "Header", "Default row");
- addMenuCommand("Unset", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setDefaultHeaderRow(null);
- }
- }, "Component", "Header", "Default row");
-
- addMenuCommand("Prepend row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureHeaderRow(grid.prependHeaderRow());
- }
- }, menuPath);
- addMenuCommand("Append row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureHeaderRow(grid.appendHeaderRow());
- }
- }, menuPath);
- addMenuCommand("Remove top row", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.removeHeaderRow(0);
- }
- }, menuPath);
- addMenuCommand("Remove bottom row", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.removeHeaderRow(grid.getHeaderRowCount() - 1);
- }
- }, menuPath);
-
- }
-
- private void configureHeaderRow(final HeaderRow row) {
- setHeaderTexts(row);
- String rowTitle = "Row " + grid.getHeaderRowCount();
- final String[] menuPath = { "Component", "Header", rowTitle };
-
- addMenuCommand("Join column cells 0, 1", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(row.getCell(grid.getColumn(0)),
- row.getCell(grid.getColumn(1)))
- .setText("Join column cells 0, 1");
-
- }
- }, menuPath);
-
- addMenuCommand("Join columns 1, 2", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumn(1), grid.getColumn(2))
- .setText("Join columns 1, 2");
- ;
-
- }
- }, menuPath);
-
- addMenuCommand("Join columns 3, 4, 5", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumn(3), grid.getColumn(4),
- grid.getColumn(5)).setText("Join columns 3, 4, 5");
-
- }
- }, menuPath);
-
- addMenuCommand("Join all columns", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumns()
- .toArray(new Grid.Column[grid.getColumnCount()]))
- .setText("Join all columns");
- ;
-
- }
- }, menuPath);
- }
-
- private void createFooterMenu() {
- final String[] menuPath = { "Component", "Footer" };
-
- addMenuCommand("Visible", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setFooterVisible(!grid.isFooterVisible());
- }
- }, menuPath);
-
- addMenuCommand("Prepend row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureFooterRow(grid.prependFooterRow());
- }
- }, menuPath);
- addMenuCommand("Append row", new ScheduledCommand() {
- @Override
- public void execute() {
- configureFooterRow(grid.appendFooterRow());
- }
- }, menuPath);
- addMenuCommand("Remove top row", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.removeFooterRow(0);
- }
- }, menuPath);
- addMenuCommand("Remove bottom row", new ScheduledCommand() {
- @Override
- public void execute() {
- assert grid.getFooterRowCount() > 0;
- grid.removeFooterRow(grid.getFooterRowCount() - 1);
- }
- }, menuPath);
- }
-
- private void createEditorMenu() {
- addMenuCommand("Enabled", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setEditorEnabled(!grid.isEditorEnabled());
- }
- }, "Component", "Editor");
-
- addMenuCommand("Edit row 5", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.editRow(5);
- }
- }, "Component", "Editor");
-
- addMenuCommand("Edit row 100", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.editRow(100);
- }
- }, "Component", "Editor");
-
- addMenuCommand("Save", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.saveEditor();
- }
- }, "Component", "Editor");
-
- addMenuCommand("Cancel edit", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.cancelEditor();
- }
- }, "Component", "Editor");
-
- addMenuCommand("Change Save Caption", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setEditorSaveCaption("ǝʌɐS");
- }
- }, "Component", "Editor");
-
- addMenuCommand("Change Cancel Caption", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setEditorCancelCaption("ʃǝɔuɐↃ");
- }
- }, "Component", "Editor");
-
- addMenuCommand("Toggle second editor error", new ScheduledCommand() {
- @Override
- public void execute() {
- secondEditorError = !secondEditorError;
- }
- }, "Component", "Editor");
- }
-
- private void configureFooterRow(final FooterRow row) {
- setFooterTexts(row);
- String rowTitle = "Row " + grid.getFooterRowCount();
- final String[] menuPath = { "Component", "Footer", rowTitle };
-
- addMenuCommand("Join column cells 0, 1", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(row.getCell(grid.getColumn(0)),
- row.getCell(grid.getColumn(1)))
- .setText("Join column cells 0, 1");
-
- }
- }, menuPath);
-
- addMenuCommand("Join columns 1, 2", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumn(1), grid.getColumn(2))
- .setText("Join columns 1, 2");
- ;
-
- }
- }, menuPath);
-
- addMenuCommand("Join all columns", new ScheduledCommand() {
-
- @Override
- public void execute() {
- row.join(grid.getColumns()
- .toArray(new Grid.Column[grid.getColumnCount()]))
- .setText("Join all columns");
- ;
-
- }
- }, menuPath);
- }
-
- private void createDataSourceMenu() {
- final String[] menuPath = { "Component", "DataSource" };
-
- addMenuCommand("Reset with 100 rows of Data", new ScheduledCommand() {
- @Override
- public void execute() {
- ds.asList().clear();
- data = createData(100);
- ds.asList().addAll(data);
- }
- }, menuPath);
-
- addMenuCommand("Reset with " + ROWS + " rows of Data",
- new ScheduledCommand() {
- @Override
- public void execute() {
- ds.asList().clear();
- data = createData(ROWS);
- ds.asList().addAll(data);
- }
- }, menuPath);
- }
-
- /**
- * Creates a renderer for a {@link Renderers}
- */
- @SuppressWarnings("rawtypes")
- private final Renderer createRenderer(Renderers renderer) {
- switch (renderer) {
- case TEXT_RENDERER:
- return new TextRenderer();
-
- case HTML_RENDERER:
- return new HtmlRenderer() {
-
- @Override
- public void render(RendererCellReference cell,
- String htmlString) {
- super.render(cell, "<b>" + htmlString + "</b>");
- }
- };
-
- case NUMBER_RENDERER:
- return new NumberRenderer();
-
- case DATE_RENDERER:
- return new DateRenderer();
-
- default:
- return new TextRenderer();
- }
- }
-
- /**
- * Creates a collection of handlers for all the grid key events
- */
- private void createKeyHandlers() {
- final List<VLabel> labels = new ArrayList<>();
- for (int i = 0; i < 9; ++i) {
- VLabel tmp = new VLabel();
- addNorth(tmp, 20);
- labels.add(tmp);
- }
-
- // Key Down Events
- grid.addBodyKeyDownHandler(new BodyKeyDownHandler() {
- private final VLabel label = labels.get(0);
-
- @Override
- public void onKeyDown(GridKeyDownEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- grid.addHeaderKeyDownHandler(new HeaderKeyDownHandler() {
- private final VLabel label = labels.get(1);
-
- @Override
- public void onKeyDown(GridKeyDownEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- grid.addFooterKeyDownHandler(new FooterKeyDownHandler() {
- private final VLabel label = labels.get(2);
-
- @Override
- public void onKeyDown(GridKeyDownEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- // Key Up Events
- grid.addBodyKeyUpHandler(new BodyKeyUpHandler() {
- private final VLabel label = labels.get(3);
-
- @Override
- public void onKeyUp(GridKeyUpEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- grid.addHeaderKeyUpHandler(new HeaderKeyUpHandler() {
- private final VLabel label = labels.get(4);
-
- @Override
- public void onKeyUp(GridKeyUpEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- grid.addFooterKeyUpHandler(new FooterKeyUpHandler() {
- private final VLabel label = labels.get(5);
-
- @Override
- public void onKeyUp(GridKeyUpEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- // Key Press Events
- grid.addBodyKeyPressHandler(new BodyKeyPressHandler() {
- private final VLabel label = labels.get(6);
-
- @Override
- public void onKeyPress(GridKeyPressEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- grid.addHeaderKeyPressHandler(new HeaderKeyPressHandler() {
- private final VLabel label = labels.get(7);
-
- @Override
- public void onKeyPress(GridKeyPressEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- grid.addFooterKeyPressHandler(new FooterKeyPressHandler() {
- private final VLabel label = labels.get(8);
-
- @Override
- public void onKeyPress(GridKeyPressEvent event) {
- CellReference<?> focused = event.getFocusedCell();
- updateLabel(label, event.toDebugString(), focused.getRowIndex(),
- focused.getColumnIndex());
- }
- });
-
- }
-
- private void updateLabel(VLabel label, String output, int object,
- int column) {
- String coords = "(" + object + ", " + column + ")";
- label.setText(coords + " " + output);
- }
-
- private void createDetailsMenu() {
- String[] menupath = { "Component", "Row details" };
- addMenuCommand("Set generator", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setDetailsGenerator(new DetailsGenerator() {
- @Override
- public Widget getDetails(int rowIndex) {
- FlowPanel panel = new FlowPanel();
-
- final Label label = new Label("Row: " + rowIndex + ".");
- Button button = new Button("Button",
- (ClickHandler) event -> label
- .setText("clicked"));
-
- panel.add(label);
- panel.add(button);
- return panel;
- }
- });
- }
- }, menupath);
-
- addMenuCommand("Set faulty generator", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setDetailsGenerator(new DetailsGenerator() {
- @Override
- public Widget getDetails(int rowIndex) {
- throw new RuntimeException("This is by design.");
- }
- });
- }
- }, menupath);
-
- addMenuCommand("Set empty generator", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setDetailsGenerator(new DetailsGenerator() {
- /*
- * While this is functionally equivalent to the NULL
- * generator, it's good to be explicit, since the behavior
- * isn't strictly tied between them. NULL generator might be
- * changed to render something different by default, and an
- * empty generator might behave differently also in the
- * future.
- */
-
- @Override
- public Widget getDetails(int rowIndex) {
- return null;
- }
- });
- }
- }, menupath);
-
- String[] togglemenupath = { menupath[0], menupath[1],
- "Toggle details for..." };
- for (int i : new int[] { 0, 1, 100, 200, 300, 400, 500, 600, 700, 800,
- 900, 999 }) {
- final int rowIndex = i;
- addMenuCommand("Row " + rowIndex, new ScheduledCommand() {
- boolean visible = false;
-
- @Override
- public void execute() {
- visible = !visible;
- grid.setDetailsVisible(rowIndex, visible);
- }
- }, togglemenupath);
- }
-
- }
-
- private static Logger getLogger() {
- return Logger.getLogger(GridBasicClientFeaturesWidget.class.getName());
- }
-
- private void createSidebarMenu() {
- String[] menupath = { "Component", "Sidebar" };
-
- final List<MenuItem> customMenuItems = new ArrayList<>();
- final List<MenuItemSeparator> separators = new ArrayList<>();
-
- addMenuCommand("Add item to end", new ScheduledCommand() {
- @Override
- public void execute() {
- MenuItem item = createSidebarMenuItem(customMenuItems.size());
- customMenuItems.add(item);
- grid.getSidebarMenu().addItem(item);
- }
- }, menupath);
-
- addMenuCommand("Add item before index 1", new ScheduledCommand() {
- @Override
- public void execute() {
- MenuItem item = createSidebarMenuItem(customMenuItems.size());
- customMenuItems.add(item);
- grid.getSidebarMenu().insertItem(item, 1);
- }
- }, menupath);
-
- addMenuCommand("Remove last added item", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getSidebarMenu().removeItem(
- customMenuItems.remove(customMenuItems.size() - 1));
- }
- }, menupath);
-
- addMenuCommand("Add separator to end", new ScheduledCommand() {
- @Override
- public void execute() {
- MenuItemSeparator separator = new MenuItemSeparator();
- separators.add(separator);
- grid.getSidebarMenu().addSeparator(separator);
- }
- }, menupath);
-
- addMenuCommand("Add separator before index 1", new ScheduledCommand() {
- @Override
- public void execute() {
- MenuItemSeparator separator = new MenuItemSeparator();
- separators.add(separator);
- grid.getSidebarMenu().insertSeparator(separator, 1);
- }
- }, menupath);
-
- addMenuCommand("Remove last added separator", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.getSidebarMenu().removeSeparator(
- separators.remove(separators.size() - 1));
- }
- }, menupath);
-
- addMenuCommand("Toggle sidebar visibility", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSidebarOpen(!grid.isSidebarOpen());
- }
- }, menupath);
-
- addMenuCommand("Open sidebar and disable grid", new ScheduledCommand() {
- @Override
- public void execute() {
- grid.setSidebarOpen(true);
-
- Scheduler.get()
- .scheduleFixedDelay(new Scheduler.RepeatingCommand() {
- @Override
- public boolean execute() {
- if (grid.isSidebarOpen()) {
- grid.setEnabled(false);
-
- return false;
- }
-
- return true;
- }
- }, 250);
- }
- }, menupath);
- }
-
- private MenuItem createSidebarMenuItem(final int index) {
- final MenuItem menuItem = new MenuItem("Custom menu item " + index,
- new ScheduledCommand() {
- @Override
- public void execute() {
- if (index % 2 == 0) {
- grid.setSidebarOpen(false);
- }
- getLogger().info("Menu item " + index + " selected");
- }
- });
- return menuItem;
- }
- }
|