diff options
author | Leif Åstrand <leif@vaadin.com> | 2014-03-18 15:40:01 +0200 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2014-03-18 15:40:50 +0200 |
commit | 4420f52578e245045677f88852f1ba3f405e88a3 (patch) | |
tree | 5f5c3f6c03326afe580f26eb395963f5c1e50804 /uitest/src/com/vaadin/tests/widgetset/client | |
parent | 5d0b53bad905a2f77e4e75a3e307a69824c9b87d (diff) | |
parent | 796063f898ef34bbbe457164976ae96c802c1bc7 (diff) | |
download | vaadin-framework-4420f52578e245045677f88852f1ba3f405e88a3.tar.gz vaadin-framework-4420f52578e245045677f88852f1ba3f405e88a3.zip |
Merge branch 'master' into grid
Change-Id: Ia9d156009a3f1b4e61f12eb415040670a52d7876
Diffstat (limited to 'uitest/src/com/vaadin/tests/widgetset/client')
4 files changed, 435 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridClientRpc.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridClientRpc.java new file mode 100644 index 0000000000..ae2799d228 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridClientRpc.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2013 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.grid; + +import com.vaadin.shared.communication.ClientRpc; + +public interface TestGridClientRpc extends ClientRpc { + void insertRows(int offset, int amount); + + void removeRows(int offset, int amount); + + void insertColumns(int offset, int amount); + + void removeColumns(int offset, int amount); + + void scrollToRow(int index, String destination, int padding); + + void scrollToColumn(int index, String destination, int padding); + + void setFrozenColumns(int frozenColumns); + + void insertHeaders(int index, int amount); + + void removeHeaders(int index, int amount); + + void insertFooters(int index, int amount); + + void removeFooters(int index, int amount); + + void setColumnWidth(int index, int px); + + void calculateColumnWidths(); + + void randomRowHeight(); +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridConnector.java new file mode 100644 index 0000000000..e2d88c57f2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridConnector.java @@ -0,0 +1,138 @@ +/* + * Copyright 2000-2013 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.grid; + +import com.google.gwt.user.client.Random; +import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.grid.ScrollDestination; +import com.vaadin.tests.widgetset.server.grid.TestGrid; + +/** + * @since 7.2 + * @author Vaadin Ltd + */ +@Connect(TestGrid.class) +public class TestGridConnector extends AbstractComponentConnector { + @Override + protected void init() { + super.init(); + registerRpc(TestGridClientRpc.class, new TestGridClientRpc() { + @Override + public void insertRows(int offset, int amount) { + getWidget().insertRows(offset, amount); + } + + @Override + public void removeRows(int offset, int amount) { + getWidget().removeRows(offset, amount); + } + + @Override + public void removeColumns(int offset, int amount) { + getWidget().removeColumns(offset, amount); + } + + @Override + public void insertColumns(int offset, int amount) { + getWidget().insertColumns(offset, amount); + } + + @Override + public void scrollToRow(int index, String destination, int padding) { + getWidget().scrollToRow(index, getDestination(destination), + padding); + } + + @Override + public void scrollToColumn(int index, String destination, + int padding) { + getWidget().scrollToColumn(index, getDestination(destination), + padding); + } + + private ScrollDestination getDestination(String destination) { + final ScrollDestination d; + if (destination.equals("start")) { + d = ScrollDestination.START; + } else if (destination.equals("middle")) { + d = ScrollDestination.MIDDLE; + } else if (destination.equals("end")) { + d = ScrollDestination.END; + } else { + d = ScrollDestination.ANY; + } + return d; + } + + @Override + public void setFrozenColumns(int frozenColumns) { + getWidget().getColumnConfiguration().setFrozenColumnCount( + frozenColumns); + } + + @Override + public void insertHeaders(int index, int amount) { + getWidget().getHeader().insertRows(index, amount); + } + + @Override + public void removeHeaders(int index, int amount) { + getWidget().getHeader().removeRows(index, amount); + } + + @Override + public void insertFooters(int index, int amount) { + getWidget().getFooter().insertRows(index, amount); + } + + @Override + public void removeFooters(int index, int amount) { + getWidget().getFooter().removeRows(index, amount); + } + + @Override + public void setColumnWidth(int index, int px) { + getWidget().getColumnConfiguration().setColumnWidth(index, px); + } + + @Override + public void calculateColumnWidths() { + getWidget().calculateColumnWidths(); + } + + @Override + public void randomRowHeight() { + getWidget().getHeader().setDefaultRowHeight( + Random.nextInt(20) + 20); + getWidget().getBody().setDefaultRowHeight( + Random.nextInt(20) + 20); + getWidget().getFooter().setDefaultRowHeight( + Random.nextInt(20) + 20); + } + }); + } + + @Override + public VTestGrid getWidget() { + return (VTestGrid) super.getWidget(); + } + + @Override + public TestGridState getState() { + return (TestGridState) super.getState(); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridState.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridState.java new file mode 100644 index 0000000000..73d6ba311c --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/TestGridState.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2013 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.grid; + +import com.vaadin.shared.AbstractComponentState; + +/** + * @since 7.2 + * @author Vaadin Ltd + */ +public class TestGridState extends AbstractComponentState { + public static final String DEFAULT_HEIGHT = "400.0px"; + + /* TODO: this should be "100%" before setting final. */ + public static final String DEFAULT_WIDTH = "800.0px"; +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/VTestGrid.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/VTestGrid.java new file mode 100644 index 0000000000..28e650edc1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/VTestGrid.java @@ -0,0 +1,220 @@ +package com.vaadin.tests.widgetset.client.grid; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gwt.user.client.ui.Composite; +import com.vaadin.client.ui.grid.Cell; +import com.vaadin.client.ui.grid.ColumnConfiguration; +import com.vaadin.client.ui.grid.Escalator; +import com.vaadin.client.ui.grid.EscalatorUpdater; +import com.vaadin.client.ui.grid.Row; +import com.vaadin.client.ui.grid.RowContainer; +import com.vaadin.shared.ui.grid.ScrollDestination; + +public class VTestGrid extends Composite { + + private static class Data { + private int columnCounter = 0; + private int rowCounter = 0; + private final List<Integer> columns = new ArrayList<Integer>(); + private final List<Integer> rows = new ArrayList<Integer>(); + + @SuppressWarnings("boxing") + public void insertRows(final int offset, final int amount) { + final List<Integer> newRows = new ArrayList<Integer>(); + for (int i = 0; i < amount; i++) { + newRows.add(rowCounter++); + } + rows.addAll(offset, newRows); + } + + @SuppressWarnings("boxing") + public void insertColumns(final int offset, final int amount) { + final List<Integer> newColumns = new ArrayList<Integer>(); + for (int i = 0; i < amount; i++) { + newColumns.add(columnCounter++); + } + columns.addAll(offset, newColumns); + } + + public EscalatorUpdater createHeaderUpdater() { + return new EscalatorUpdater() { + @Override + public void updateCells(final Row row, + final Iterable<Cell> cellsToUpdate) { + for (final Cell cell : cellsToUpdate) { + if (cell.getColumn() % 3 == 0) { + cell.setColSpan(2); + } + + final Integer columnName = columns + .get(cell.getColumn()); + cell.getElement().setInnerText("Header " + columnName); + } + } + }; + } + + public EscalatorUpdater createFooterUpdater() { + return new EscalatorUpdater() { + @Override + public void updateCells(final Row row, + final Iterable<Cell> cellsToUpdate) { + for (final Cell cell : cellsToUpdate) { + if (cell.getColumn() % 3 == 1) { + cell.setColSpan(2); + } + + final Integer columnName = columns + .get(cell.getColumn()); + cell.getElement().setInnerText("Footer " + columnName); + } + } + }; + } + + public EscalatorUpdater createBodyUpdater() { + return new EscalatorUpdater() { + private int i = 0; + + public void renderCell(final Cell cell) { + final Integer columnName = columns.get(cell.getColumn()); + final Integer rowName = rows.get(cell.getRow()); + final String cellInfo = columnName + "," + rowName + " (" + + i + ")"; + + if (cell.getColumn() > 0) { + cell.getElement().setInnerText("Cell: " + cellInfo); + } else { + cell.getElement().setInnerText( + "Row " + cell.getRow() + ": " + cellInfo); + } + + if (cell.getColumn() % 3 == cell.getRow() % 3) { + cell.setColSpan(3); + } + + final double c = i * .1; + final int r = (int) ((Math.cos(c) + 1) * 128); + final int g = (int) ((Math.cos(c / Math.PI) + 1) * 128); + final int b = (int) ((Math.cos(c / (Math.PI * 2)) + 1) * 128); + cell.getElement() + .getStyle() + .setBackgroundColor( + "rgb(" + r + "," + g + "," + b + ")"); + if ((r * .8 + g * 1.3 + b * .9) / 3 < 127) { + cell.getElement().getStyle().setColor("white"); + } else { + cell.getElement().getStyle().clearColor(); + } + + i++; + } + + @Override + public void updateCells(final Row row, + final Iterable<Cell> cellsToUpdate) { + for (final Cell cell : cellsToUpdate) { + renderCell(cell); + } + } + }; + } + + public void removeRows(final int offset, final int amount) { + for (int i = 0; i < amount; i++) { + rows.remove(offset); + } + } + + public void removeColumns(final int offset, final int amount) { + for (int i = 0; i < amount; i++) { + columns.remove(offset); + } + } + } + + private final Escalator escalator = new Escalator(); + private final Data data = new Data(); + + public VTestGrid() { + initWidget(escalator); + final RowContainer header = escalator.getHeader(); + header.setEscalatorUpdater(data.createHeaderUpdater()); + header.insertRows(0, 1); + + final RowContainer footer = escalator.getFooter(); + footer.setEscalatorUpdater(data.createFooterUpdater()); + footer.insertRows(0, 1); + + escalator.getBody().setEscalatorUpdater(data.createBodyUpdater()); + + insertRows(0, 100); + insertColumns(0, 10); + + setWidth(TestGridState.DEFAULT_WIDTH); + setHeight(TestGridState.DEFAULT_HEIGHT); + + } + + public void insertRows(final int offset, final int number) { + data.insertRows(offset, number); + escalator.getBody().insertRows(offset, number); + } + + public void insertColumns(final int offset, final int number) { + data.insertColumns(offset, number); + escalator.getColumnConfiguration().insertColumns(offset, number); + } + + public ColumnConfiguration getColumnConfiguration() { + return escalator.getColumnConfiguration(); + } + + public void scrollToRow(final int index, + final ScrollDestination destination, final int padding) { + escalator.scrollToRow(index, destination, padding); + } + + public void scrollToColumn(final int index, + final ScrollDestination destination, final int padding) { + escalator.scrollToColumn(index, destination, padding); + } + + public void removeRows(final int offset, final int amount) { + data.removeRows(offset, amount); + escalator.getBody().removeRows(offset, amount); + } + + public void removeColumns(final int offset, final int amount) { + data.removeColumns(offset, amount); + escalator.getColumnConfiguration().removeColumns(offset, amount); + } + + @Override + public void setWidth(String width) { + escalator.setWidth(width); + } + + @Override + public void setHeight(String height) { + escalator.setHeight(height); + } + + public RowContainer getHeader() { + return escalator.getHeader(); + } + + public RowContainer getBody() { + return escalator.getBody(); + } + + public RowContainer getFooter() { + return escalator.getFooter(); + } + + public void calculateColumnWidths() { + escalator.calculateColumnWidths(); + } +} |