*/
package com.vaadin.tests.components.grid.basicfeatures;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
protected static final String COLUMNS = "Columns";
protected static final String ADD_ONE_COLUMN_TO_BEGINNING = "Add one column to beginning";
protected static final String ADD_ONE_ROW_TO_BEGINNING = "Add one row to beginning";
+ protected static final String REMOVE_ONE_COLUMN_FROM_BEGINNING = "Remove one column from beginning";
+ protected static final String REMOVE_ONE_ROW_FROM_BEGINNING = "Remove one row from beginning";
protected static final String HEADER_ROWS = "Header Rows";
protected static final String BODY_ROWS = "Body Rows";
}
protected void assertLogContains(String substring) {
+ assertTrue("log should've contained, but didn't: " + substring,
+ getLogText().contains(substring));
+ }
+
+ protected void assertLogDoesNotContain(String substring) {
+ assertFalse("log shouldn't have contained, but did: " + substring,
+ getLogText().contains(substring));
+ }
+
+ private String getLogText() {
WebElement log = getDriver().findElement(By.cssSelector("#log"));
- assertTrue("log did not contain: " + substring,
- log.getText().contains(substring));
+ return log.getText();
+ }
+
+ protected void assertLogContainsInOrder(String... substrings) {
+ String log = getLogText();
+ int cursor = 0;
+ for (String substring : substrings) {
+ String remainingLog = log.substring(cursor, log.length());
+ int substringIndex = remainingLog.indexOf(substring);
+ if (substringIndex == -1) {
+ fail("substring \"" + substring
+ + "\" was not found in order from log.");
+ }
+
+ cursor += substringIndex + substring.length();
+ }
}
protected void scrollVerticallyTo(int px) {
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid.basicfeatures;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.UI;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class EscalatorUpdaterUi extends UI {
+
+ public class EscalatorUpdaterTestComponent extends AbstractComponent {
+ // empty
+ }
+
+ @Override
+ protected void init(VaadinRequest request) {
+ setContent(new EscalatorUpdaterTestComponent());
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid.basicfeatures;
+
+import org.junit.Test;
+
+public class EscalatorUpdaterUiTest extends EscalatorBasicClientFeaturesTest {
+ @Override
+ protected Class<?> getUIClass() {
+ return EscalatorUpdaterUi.class;
+ }
+
+ @Test
+ public void testHeaderPaintOrderRowColRowCol() {
+ boolean addColumnFirst = false;
+ boolean removeColumnFirst = false;
+ testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testHeaderPaintOrderRowColColRow() {
+ boolean addColumnFirst = false;
+ boolean removeColumnFirst = true;
+ testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testHeaderPaintOrderColRowColRow() {
+ boolean addColumnFirst = true;
+ boolean removeColumnFirst = true;
+ testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testHeaderPaintOrderColRowRowCol() {
+ boolean addColumnFirst = true;
+ boolean removeColumnFirst = false;
+ testPaintOrder(HEADER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testBodyPaintOrderRowColRowCol() {
+ boolean addColumnFirst = false;
+ boolean removeColumnFirst = false;
+ testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testBodyPaintOrderRowColColRow() {
+ boolean addColumnFirst = false;
+ boolean removeColumnFirst = true;
+ testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testBodyPaintOrderColRowColRow() {
+ boolean addColumnFirst = true;
+ boolean removeColumnFirst = true;
+ testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testBodyPaintOrderColRowRowCol() {
+ boolean addColumnFirst = true;
+ boolean removeColumnFirst = false;
+ testPaintOrder(BODY_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testFooterPaintOrderRowColRowCol() {
+ boolean addColumnFirst = false;
+ boolean removeColumnFirst = false;
+ testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testFooterPaintOrderRowColColRow() {
+ boolean addColumnFirst = false;
+ boolean removeColumnFirst = true;
+ testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testFooterPaintOrderColRowColRow() {
+ boolean addColumnFirst = true;
+ boolean removeColumnFirst = true;
+ testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ @Test
+ public void testFooterPaintOrderColRowRowCol() {
+ boolean addColumnFirst = true;
+ boolean removeColumnFirst = false;
+ testPaintOrder(FOOTER_ROWS, addColumnFirst, removeColumnFirst);
+ }
+
+ private void testPaintOrder(String tableSection, boolean addColumnFirst,
+ boolean removeColumnFirst) {
+ openTestURL();
+
+ if (addColumnFirst) {
+ selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+ ADD_ONE_COLUMN_TO_BEGINNING);
+ selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+ ADD_ONE_ROW_TO_BEGINNING);
+ } else {
+ selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+ ADD_ONE_ROW_TO_BEGINNING);
+ selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+ ADD_ONE_COLUMN_TO_BEGINNING);
+ }
+
+ assertLogContainsInOrder("preAttach: elementIsAttached == false",
+ "postAttach: elementIsAttached == true",
+ "update: elementIsAttached == true");
+ assertLogDoesNotContain("preDetach");
+ assertLogDoesNotContain("postDetach");
+
+ if (removeColumnFirst) {
+ selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+ REMOVE_ONE_COLUMN_FROM_BEGINNING);
+ selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+ REMOVE_ONE_ROW_FROM_BEGINNING);
+ } else {
+ selectMenuPath(COLUMNS_AND_ROWS, tableSection,
+ REMOVE_ONE_ROW_FROM_BEGINNING);
+ selectMenuPath(COLUMNS_AND_ROWS, COLUMNS,
+ REMOVE_ONE_COLUMN_FROM_BEGINNING);
+ }
+
+ assertLogContainsInOrder("preDetach: elementIsAttached == true",
+ "postDetach: elementIsAttached == false");
+ }
+
+}
import com.google.gwt.core.client.Duration;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.dom.client.TableCellElement;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.vaadin.client.ui.grid.Escalator;
}
}
+ public static class UpdaterLifetimeWidget extends
+ EscalatorBasicClientFeaturesWidget {
+
+ private final EscalatorUpdater debugUpdater = new EscalatorUpdater() {
+ @Override
+ public void preAttach(Row row, Iterable<FlyweightCell> cellsToAttach) {
+ log("preAttach", cellsToAttach);
+ }
+
+ @Override
+ public void postAttach(Row row,
+ Iterable<FlyweightCell> attachedCells) {
+ log("postAttach", attachedCells);
+ }
+
+ @Override
+ public void update(Row row, Iterable<FlyweightCell> cellsToUpdate) {
+ log("update", cellsToUpdate);
+ }
+
+ @Override
+ public void preDetach(Row row, Iterable<FlyweightCell> cellsToDetach) {
+ log("preDetach", cellsToDetach);
+ }
+
+ @Override
+ public void postDetach(Row row,
+ Iterable<FlyweightCell> detachedCells) {
+ log("postDetach", detachedCells);
+ }
+
+ private void log(String methodName, Iterable<FlyweightCell> cells) {
+ if (!cells.iterator().hasNext()) {
+ return;
+ }
+
+ TableCellElement cellElement = cells.iterator().next()
+ .getElement();
+ boolean isAttached = cellElement.getParentElement() != null
+ && cellElement.getParentElement().getParentElement() != null;
+ logWidget.log(methodName + ": elementIsAttached == "
+ + isAttached);
+ }
+ };
+
+ public UpdaterLifetimeWidget() {
+ super();
+ escalator.getHeader().setEscalatorUpdater(debugUpdater);
+ escalator.getBody().setEscalatorUpdater(debugUpdater);
+ escalator.getFooter().setEscalatorUpdater(debugUpdater);
+ }
+ }
+
private static final String COLUMNS_AND_ROWS_MENU = "Columns and Rows";
private static final String GENERAL_MENU = "General";
private static final String FEATURES_MENU = "Features";
}
private Colspan colspan = Colspan.NONE;
- private final LogWidget logWidget = new LogWidget();
+ protected final LogWidget logWidget = new LogWidget();
public EscalatorBasicClientFeaturesWidget() {
super(new EscalatorProxy());
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.widgetset.client.grid;
+
+import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.tests.components.grid.basicfeatures.EscalatorUpdaterUi.EscalatorUpdaterTestComponent;
+
+@Connect(EscalatorUpdaterTestComponent.class)
+public class EscalatorUpdaterTestConnector extends AbstractComponentConnector {
+
+ @Override
+ public EscalatorBasicClientFeaturesWidget.UpdaterLifetimeWidget getWidget() {
+ return (EscalatorBasicClientFeaturesWidget.UpdaterLifetimeWidget) super
+ .getWidget();
+ }
+}