From a058f557aae3a4b754620fc22454503737026a69 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 9 Mar 2015 13:35:32 +0200 Subject: Disallow RunLocally annotation in framework tests. Fix NPE for screenshots. Change-Id: I72793d85dfaba41aefa5370331c1ae81348607e9 --- uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java | 3 +-- .../com/vaadin/tests/tb3/PrivateTB3Configuration.java | 17 ++++++++++++++++- uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index a95def5983..2d032ecd9e 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -142,7 +142,6 @@ public abstract class AbstractTB3Test extends ParallelTest { } catch (UnsupportedOperationException e) { // Opera does not support this... } - } /** @@ -244,7 +243,7 @@ public abstract class AbstractTB3Test extends ParallelTest { private void openTestURL(Class uiClass, Set parameters) { String url = getTestURL(uiClass); - if(isDebug()) { + if (isDebug()) { parameters.add("debug"); } diff --git a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java index d0134a4feb..dce725b7c0 100644 --- a/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java +++ b/uitest/src/com/vaadin/tests/tb3/PrivateTB3Configuration.java @@ -25,9 +25,11 @@ import java.net.SocketException; import java.util.Enumeration; import java.util.Properties; +import org.junit.Assert; import org.openqa.selenium.remote.DesiredCapabilities; import com.vaadin.testbench.annotations.BrowserFactory; +import com.vaadin.testbench.annotations.RunLocally; import com.vaadin.testbench.annotations.RunOnHub; import com.vaadin.testbench.parallel.Browser; @@ -45,8 +47,9 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { * */ public static final String SCREENSHOT_DIRECTORY = "com.vaadin.testbench.screenshot.directory"; - private static final String RUN_LOCALLY_PROPERTY = "com.vaadin.testbench.runLocally"; private static final String HOSTNAME_PROPERTY = "com.vaadin.testbench.deployment.hostname"; + private static final String RUN_LOCALLY_PROPERTY = "com.vaadin.testbench.runLocally"; + private static final String ALLOW_RUN_LOCALLY_PROPERTY = "com.vaadin.testbench.allowRunLocally"; private static final String PORT_PROPERTY = "com.vaadin.testbench.deployment.port"; private static final String DEPLOYMENT_PROPERTY = "com.vaadin.testbench.deployment.url"; private static final String HUB_URL = "com.vaadin.testbench.hub.url"; @@ -77,6 +80,18 @@ public abstract class PrivateTB3Configuration extends ScreenshotTB3Test { } } + @Override + public void setup() throws Exception { + String allowRunLocally = getProperty(ALLOW_RUN_LOCALLY_PROPERTY); + if ((allowRunLocally == null || !allowRunLocally.equals("" + true)) + && getClass().getAnnotation(RunLocally.class) != null) { + Assert.fail("@RunLocally annotation is not allowed by default in framework tests. " + + "See file uitest/eclipse-run-selected-test.properties for more information."); + } + + super.setup(); + } + private static DesiredCapabilities getRunLocallyCapabilities() { Browser localBrowser; try { diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java index f401e0613b..e059dea78d 100644 --- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java @@ -340,7 +340,7 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test { */ @After public void checkCompareFailures() throws IOException { - if (!screenshotFailures.isEmpty()) { + if (screenshotFailures != null && !screenshotFailures.isEmpty()) { throw new IOException( "The following screenshots did not match the reference: " + screenshotFailures.toString()); -- cgit v1.2.3 From 6e494b16ab428d4d6f946b513d3fe004798149e2 Mon Sep 17 00:00:00 2001 From: Alexey Fansky Date: Wed, 1 Apr 2015 15:08:58 -0700 Subject: Displaying tooltip on touch devices underneath the field (#17150) Change-Id: I7381a6212b824f9dafc5fe7359b0e791f15c57b2 --- client/src/com/vaadin/client/BrowserInfo.java | 3 +- client/src/com/vaadin/client/VTooltip.java | 127 +++++++++++++++++---- client/src/com/vaadin/client/ui/VFormLayout.java | 6 +- shared/src/com/vaadin/shared/VBrowserDetails.java | 11 ++ .../tests/components/TouchDevicesTooltip.java | 66 +++++++++++ 5 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/TouchDevicesTooltip.java (limited to 'uitest/src') diff --git a/client/src/com/vaadin/client/BrowserInfo.java b/client/src/com/vaadin/client/BrowserInfo.java index 3bc75a9a9b..01968a17a6 100644 --- a/client/src/com/vaadin/client/BrowserInfo.java +++ b/client/src/com/vaadin/client/BrowserInfo.java @@ -88,7 +88,8 @@ public class BrowserInfo { } else if (browserDetails.isIE()) { touchDevice = detectIETouchDevice(); } else { - touchDevice = detectTouchDevice(); + //PhantomJS pretends to be a touch device which breaks some UI tests + touchDevice = !browserDetails.isPhantomJS() && detectTouchDevice(); } } diff --git a/client/src/com/vaadin/client/VTooltip.java b/client/src/com/vaadin/client/VTooltip.java index 453563370c..b9392e3941 100644 --- a/client/src/com/vaadin/client/VTooltip.java +++ b/client/src/com/vaadin/client/VTooltip.java @@ -20,17 +20,7 @@ import com.google.gwt.aria.client.RelevantValue; import com.google.gwt.aria.client.Roles; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Display; -import com.google.gwt.event.dom.client.BlurEvent; -import com.google.gwt.event.dom.client.BlurHandler; -import com.google.gwt.event.dom.client.DomEvent; -import com.google.gwt.event.dom.client.FocusEvent; -import com.google.gwt.event.dom.client.FocusHandler; -import com.google.gwt.event.dom.client.KeyDownEvent; -import com.google.gwt.event.dom.client.KeyDownHandler; -import com.google.gwt.event.dom.client.MouseDownEvent; -import com.google.gwt.event.dom.client.MouseDownHandler; -import com.google.gwt.event.dom.client.MouseMoveEvent; -import com.google.gwt.event.dom.client.MouseMoveHandler; +import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; @@ -69,6 +59,11 @@ public class VTooltip extends VOverlay { private int quickOpenTimeout; private int closeTimeout; + /** + * Current element hovered + */ + private com.google.gwt.dom.client.Element currentElement = null; + /** * Used to show tooltips; usually used via the singleton in * {@link ApplicationConnection}. NOTE that #setOwner(Widget)} should be @@ -179,8 +174,20 @@ public class VTooltip extends VOverlay { offsetWidth = getOffsetWidth(); offsetHeight = getOffsetHeight(); } - int x = getFinalX(offsetWidth); - int y = getFinalY(offsetHeight); + + int x = 0; + int y = 0; + if(BrowserInfo.get().isTouchDevice()) { + setMaxWidth(Window.getClientWidth()); + offsetWidth = getOffsetWidth(); + offsetHeight = getOffsetHeight(); + + x = getFinalTouchX(offsetWidth); + y = getFinalTouchY(offsetHeight); + } else { + x = getFinalX(offsetWidth); + y = getFinalY(offsetHeight); + } setPopupPosition(x, y); sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT); @@ -221,6 +228,40 @@ public class VTooltip extends VOverlay { return x; } + /** + * Return the final X-coordinate of the tooltip based on cursor + * position, size of the tooltip, size of the page and necessary + * margins. + * + * @param offsetWidth + * @return The final X-coordinate + */ + private int getFinalTouchX(int offsetWidth) { + int x = 0; + int widthNeeded = 10 + offsetWidth; + int roomLeft = currentElement != null ? + currentElement.getAbsoluteLeft() : EVENT_XY_POSITION_OUTSIDE; + int viewPortWidth = Window.getClientWidth(); + int roomRight = viewPortWidth - roomLeft; + if (roomRight > widthNeeded) { + x = roomLeft; + } else { + x = roomLeft - offsetWidth; + } + if (x + offsetWidth - Window.getScrollLeft() > viewPortWidth) { + x = viewPortWidth - offsetWidth + Window.getScrollLeft(); + } + + if (roomLeft != EVENT_XY_POSITION_OUTSIDE) { + // Do not allow x to be zero, for otherwise the tooltip + // does not close when the mouse is moved (see + // isTooltipOpen()). #15129 + int minX = Window.getScrollLeft(); + x = Math.max(x, minX); + } + return x; + } + /** * Return the final Y-coordinate of the tooltip based on cursor * position, size of the tooltip, size of the page and necessary @@ -232,7 +273,7 @@ public class VTooltip extends VOverlay { */ private int getFinalY(int offsetHeight) { int y = 0; - int heightNeeded = 10 + MARGIN + offsetHeight; + int heightNeeded = 10 + offsetHeight; int roomAbove = tooltipEventMouseY; int roomBelow = Window.getClientHeight() - roomAbove; @@ -263,12 +304,58 @@ public class VTooltip extends VOverlay { } return y; } + + /** + * Return the final Y-coordinate of the tooltip based on cursor + * position, size of the tooltip, size of the page and necessary + * margins. + * + * @param offsetHeight + * @return The final y-coordinate + * + */ + private int getFinalTouchY(int offsetHeight) { + int y = 0; + int heightNeeded = 10 + offsetHeight; + int roomAbove = currentElement != null ? + currentElement.getAbsoluteTop() + currentElement.getOffsetHeight() + : EVENT_XY_POSITION_OUTSIDE; + int roomBelow = Window.getClientHeight() - roomAbove; + + if (roomBelow > heightNeeded) { + y = roomAbove; + } else { + y = roomAbove - offsetHeight - + (currentElement != null ? currentElement.getOffsetHeight() : 0); + } + + if (y + offsetHeight - Window.getScrollTop() > Window + .getClientHeight()) { + y = roomAbove - 5 - offsetHeight + + Window.getScrollTop(); + if (y - Window.getScrollTop() < 0) { + // tooltip does not fit on top of the mouse either, + // put it at the top of the screen + y = Window.getScrollTop(); + } + } + + if (roomAbove != EVENT_XY_POSITION_OUTSIDE) { + // Do not allow y to be zero, for otherwise the tooltip + // does not close when the mouse is moved (see + // isTooltipOpen()). #15129 + int minY = Window.getScrollTop(); + y = Math.max(y, minY); + } + return y; + } }); } else { hide(); } } + /** * For assistive tooltips to work correctly we must have the tooltip visible * and attached to the DOM well in advance. For this reason both isShowing @@ -390,11 +477,6 @@ public class VTooltip extends VOverlay { private class TooltipEventHandler implements MouseMoveHandler, KeyDownHandler, FocusHandler, BlurHandler, MouseDownHandler { - /** - * Current element hovered - */ - private com.google.gwt.dom.client.Element currentElement = null; - /** * Marker for handling of tooltip through focus */ @@ -455,7 +537,7 @@ public class VTooltip extends VOverlay { @Override public void onMouseDown(MouseDownEvent event) { - handleHideEvent(); + handleHideEvent(); } @Override @@ -524,6 +606,11 @@ public class VTooltip extends VOverlay { updatePosition(event, isFocused); // Schedule timer for showing the tooltip according to if it // was recently closed or not. + + if (BrowserInfo.get().isIOS()) { + element.focus(); + } + int timeout = justClosed ? getQuickOpenDelay() : getOpenDelay(); if (timeout == 0) { showTooltip(); diff --git a/client/src/com/vaadin/client/ui/VFormLayout.java b/client/src/com/vaadin/client/ui/VFormLayout.java index a2ea77d31c..3781305e52 100644 --- a/client/src/com/vaadin/client/ui/VFormLayout.java +++ b/client/src/com/vaadin/client/ui/VFormLayout.java @@ -361,7 +361,11 @@ public class VFormLayout extends SimplePanel { public ErrorFlag(ComponentConnector owner) { setStyleName(CLASSNAME); - sinkEvents(VTooltip.TOOLTIP_EVENTS); + + if(!BrowserInfo.get().isTouchDevice()) { + sinkEvents(VTooltip.TOOLTIP_EVENTS); + } + this.owner = owner; } diff --git a/shared/src/com/vaadin/shared/VBrowserDetails.java b/shared/src/com/vaadin/shared/VBrowserDetails.java index 6e45d33e16..561b6c76d0 100644 --- a/shared/src/com/vaadin/shared/VBrowserDetails.java +++ b/shared/src/com/vaadin/shared/VBrowserDetails.java @@ -41,6 +41,7 @@ public class VBrowserDetails implements Serializable { private boolean isFirefox = false; private boolean isOpera = false; private boolean isIE = false; + private boolean isPhantomJS = false; private boolean isWindowsPhone; private boolean isIPad; @@ -86,6 +87,7 @@ public class VBrowserDetails implements Serializable { isSafari = !isChrome && !isIE && userAgent.indexOf("safari") != -1; isFirefox = userAgent.indexOf(" firefox/") != -1; + isPhantomJS = userAgent.indexOf("phantomjs/") != -1; // chromeframe isChromeFrameCapable = userAgent.indexOf("chromeframe") != -1; @@ -370,6 +372,15 @@ public class VBrowserDetails implements Serializable { return isIE; } + /** + * Tests if the browser is PhantomJS. + * + * @return true if it is PhantomJS, false otherwise + */ + public boolean isPhantomJS() { + return isPhantomJS; + } + /** * Returns the version of the browser engine. For WebKit this is an integer * e.g., 532.0. For gecko it is a float e.g., 1.8 or 1.9. diff --git a/uitest/src/com/vaadin/tests/components/TouchDevicesTooltip.java b/uitest/src/com/vaadin/tests/components/TouchDevicesTooltip.java new file mode 100644 index 0000000000..ac4b48711e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/TouchDevicesTooltip.java @@ -0,0 +1,66 @@ +package com.vaadin.tests.components; + +import com.vaadin.annotations.Viewport; +import com.vaadin.data.util.converter.StringToIntegerConverter; +import com.vaadin.data.validator.IntegerRangeValidator; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +@Viewport(value = "width=device-width,height=device-height") +public class TouchDevicesTooltip extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Label errorLabel = new Label("No error"); + addComponent(errorLabel); + + for (int i = 0; i < 50; i++) { + createTextField(i); + } + } + + private void createTextField(int n) { + TextField textField = new TextField("Value" + n); + textField.setConverter(new StringToIntegerConverter()); + textField.addValidator(new IntegerRangeValidator(getErrorMessage(n), 0, 100)); + textField.setImmediate(true); + textField.setValue("-5"); + addComponent(textField); + } + + private String getErrorMessage(int n) { + if(n % 2 == 0) { + return "incorrect value" + n; + } else { + return "super long long long long long long long long long long long error message " + n; + } + } + + public static class Bean { + @NotNull + @Min(0) + private Integer value; + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + } + + @Override + protected Integer getTicketNumber() { + return 17150; + } + + @Override + public String getDescription() { + return "Unable to dismiss a tooltip on touch devices"; + } +} \ No newline at end of file -- cgit v1.2.3 From d175f53e44bb835139fd10097fed4cb8eee58870 Mon Sep 17 00:00:00 2001 From: Ilya Ermakov Date: Thu, 12 Mar 2015 20:19:36 +0300 Subject: Set value selected by mouse when pressing Enter in ComboBox (#16981) With this patch pressing Enter in ComboBox sets value selected by mouse. Selection by keyboard is not given higher priority. Change-Id: I2e5f610923a40f67be2c1504a004af0d431a67a3 --- client/src/com/vaadin/client/ui/VFilterSelect.java | 50 ++-------- .../combobox/ComboBoxMouseSelectEnter.java | 66 +++++++++++++ .../combobox/ComboBoxMouseSelectEnterTest.java | 105 +++++++++++++++++++++ 3 files changed, 177 insertions(+), 44 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnter.java create mode 100644 uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnterTest.java (limited to 'uitest/src') diff --git a/client/src/com/vaadin/client/ui/VFilterSelect.java b/client/src/com/vaadin/client/ui/VFilterSelect.java index c99ed49c91..d99779b7ec 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -454,7 +454,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, // Set the text. setText(suggestion.getReplacementString()); - menu.updateKeyboardSelectedItem(); } /* @@ -739,13 +738,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, public class SuggestionMenu extends MenuBar implements SubPartAware, LoadHandler { - /** - * Tracks the item that is currently selected using the keyboard. This - * is need only because mouseover changes the selection and we do not - * want to use that selection when pressing enter to select the item. - */ - private MenuItem keyboardSelectedItem; - private VLazyExecutor delayedImageLoadExecutioner = new VLazyExecutor( 100, new ScheduledCommand() { @@ -807,9 +799,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, if (enableDebug) { debug("VFS.SM: setSuggestions(" + suggestions + ")"); } - // Reset keyboard selection when contents is updated to avoid - // reusing old, invalid data - setKeyboardSelectedItem(null); clearItems(); final Iterator it = suggestions.iterator(); @@ -984,14 +973,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, } - private MenuItem getKeyboardSelectedItem() { - return keyboardSelectedItem; - } - - public void setKeyboardSelectedItem(MenuItem menuItem) { - keyboardSelectedItem = menuItem; - } - /** * @deprecated use {@link SuggestionPopup#selectFirstItem()} instead. */ @@ -1013,13 +994,6 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, selectItem(lastItem); } - /* - * Sets the keyboard item as the current selected one. - */ - void updateKeyboardSelectedItem() { - setKeyboardSelectedItem(getSelectedItem()); - } - /* * Gets the height of one menu item. */ @@ -1787,25 +1761,13 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, break; case KeyCodes.KEY_TAB: case KeyCodes.KEY_ENTER: - if (suggestionPopup.menu.getKeyboardSelectedItem() == null) { - /* - * Nothing selected using up/down. Happens e.g. when entering a - * text (causes popup to open) and then pressing enter. - */ - if (!allowNewItem) { - onSuggestionSelected(currentSuggestions - .get(suggestionPopup.menu.getSelectedIndex())); - } else { - // Handle addition of new items. - suggestionPopup.menu.doSelectedItemAction(); - } + + if (!allowNewItem) { + onSuggestionSelected(currentSuggestions + .get(suggestionPopup.menu.getSelectedIndex())); } else { - /* - * Get the suggestion that was navigated to using up/down. - */ - currentSuggestion = ((FilterSelectSuggestion) suggestionPopup.menu - .getKeyboardSelectedItem().getCommand()); - onSuggestionSelected(currentSuggestion); + // Handle addition of new items. + suggestionPopup.menu.doSelectedItemAction(); } event.stopPropagation(); diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnter.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnter.java new file mode 100644 index 0000000000..5af4749349 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnter.java @@ -0,0 +1,66 @@ +/* + * 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.combobox; + +import com.vaadin.data.Property; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Label; + +public class ComboBoxMouseSelectEnter extends AbstractTestUI { + protected ComboBox comboBox; + + @Override + protected void setup(VaadinRequest request) { + comboBox = new ComboBox(); + final Label label = new Label(); + label.setId("value"); + + comboBox.setTextInputAllowed(true); + comboBox.setNullSelectionAllowed(true); + comboBox.setNullSelectionItemId(null); + + for (int i = 0; i < 10; i++) { + comboBox.addItem("a" + i); + } + + comboBox.addValueChangeListener(new Property.ValueChangeListener() { + @Override + public void valueChange(Property.ValueChangeEvent event) { + Object value = event.getProperty().getValue(); + if (value != null) { + label.setValue(value.toString()); + } else { + label.setValue("null"); + } + } + }); + + addComponents(comboBox); + addComponent(label); + } + + @Override + protected String getTestDescription() { + return "Pressing Enter should set value highlighted from mouse position after using arrow keys"; + } + + @Override + protected Integer getTicketNumber() { + return 16981; + } +} diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnterTest.java b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnterTest.java new file mode 100644 index 0000000000..d3ba37682d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboBoxMouseSelectEnterTest.java @@ -0,0 +1,105 @@ +/* + * 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.combobox; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.parallel.BrowserUtil; +import com.vaadin.tests.tb3.MultiBrowserTest; +import com.vaadin.tests.tb3.newelements.ComboBoxElement; + +public class ComboBoxMouseSelectEnterTest extends MultiBrowserTest { + + private ComboBoxElement comboBoxElement; + + @Override + public void setup() throws Exception { + + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-filterselect")); + comboBoxElement = $(ComboBoxElement.class).first(); + } + + @Test + public void enterSetsValueSelectedByMouseOver() { + comboBoxElement.openPopup(); + comboBoxElement.sendKeys(Keys.DOWN, Keys.DOWN); + String selectedItemText = findElement( + By.className("gwt-MenuItem-selected")).getText(); + assertThat("Item selected by arrows should be a1", selectedItemText, + is("a1")); + new Actions(driver).moveToElement(getWebElementForItem("a5")).build() + .perform(); + comboBoxElement.sendKeys(getReturn()); + assertThat("Item selected by mouse should be a5", + comboBoxElement.getText(), is("a5")); + checkLabelValue("a5"); + } + + private WebElement getWebElementForItem(String wantedText) { + WebElement wantedItem = null; + List items = findElements(By.className("gwt-MenuItem")); + for (WebElement item : items) { + if (item.getText().equals(wantedText)) { + wantedItem = item; + break; + } + } + return wantedItem; + } + + private Keys getReturn() { + if (BrowserUtil.isPhantomJS(getDesiredCapabilities())) { + return Keys.ENTER; + } else { + return Keys.RETURN; + } + } + + private void checkLabelValue(final String expectedValue) { + + waitUntil(new ExpectedCondition() { + private String actualValue; + + @Override + public Boolean apply(WebDriver input) { + actualValue = $(LabelElement.class).id("value").getText(); + return actualValue.equals(expectedValue); + } + + @Override + public String toString() { + // Timed out after 10 seconds waiting for ... + return String.format("Label value to match '%s' (was: '%s')", + expectedValue, actualValue); + } + }); + } + +} \ No newline at end of file -- cgit v1.2.3 From 37be37449713b3e07fc2e284695d94ea116e43e7 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Thu, 12 Mar 2015 14:19:14 +0200 Subject: Grid layout slots should be slot size not slot content size (#17039) Change-Id: I73a26b0d2f07bb624df6037e4e77f7137fd21791 --- client/src/com/vaadin/client/ui/VGridLayout.java | 4 + client/src/com/vaadin/client/ui/VSlider.java | 16 ++- .../com/vaadin/client/ui/layout/VLayoutSlot.java | 37 +++---- .../gridlayout/GridLayoutCellSizesUI.java | 53 ++++++++++ .../gridlayout/GridLayoutCellSizesUITest.java | 111 +++++++++++++++++++++ 5 files changed, 201 insertions(+), 20 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java create mode 100644 uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java (limited to 'uitest/src') diff --git a/client/src/com/vaadin/client/ui/VGridLayout.java b/client/src/com/vaadin/client/ui/VGridLayout.java index 90ae944322..d1e055eb5d 100644 --- a/client/src/com/vaadin/client/ui/VGridLayout.java +++ b/client/src/com/vaadin/client/ui/VGridLayout.java @@ -889,6 +889,10 @@ public class VGridLayout extends ComplexPanel { cell.slot.setCaption(null); cell.slot.getWrapperElement().removeFromParent(); cell.slot = null; + Style style = w.getElement().getStyle(); + style.clearTop(); + style.clearLeft(); + style.clearPosition(); if (cells.length < cell.col && cells.length != 0 && cells[0].length < cell.row diff --git a/client/src/com/vaadin/client/ui/VSlider.java b/client/src/com/vaadin/client/ui/VSlider.java index f5769ddf74..651880502c 100644 --- a/client/src/com/vaadin/client/ui/VSlider.java +++ b/client/src/com/vaadin/client/ui/VSlider.java @@ -201,7 +201,7 @@ public class VSlider extends SimpleFocusablePanel implements Field, * applied to call code for parentElement only in case it exists. */ if (getElement().hasParentElement()) { - final Element p = getElement().getParentElement(); + final Element p = getElement(); if (p.getPropertyInt(domProperty) > MIN_SIZE) { if (isVertical()) { setHeight(); @@ -216,8 +216,10 @@ public class VSlider extends SimpleFocusablePanel implements Field, @Override public void execute() { - final Element p = getElement().getParentElement(); - if (p.getPropertyInt(domProperty) > (MIN_SIZE + 5)) { + final Element p = getElement(); + if (p.getPropertyInt(domProperty) > (MIN_SIZE + 5) + || propertyNotNullOrEmpty(styleAttribute, + p)) { if (isVertical()) { setHeight(); } else { @@ -227,6 +229,14 @@ public class VSlider extends SimpleFocusablePanel implements Field, setValue(value, false); } } + + // Style has non empty property + private boolean propertyNotNullOrEmpty( + final String styleAttribute, final Element p) { + return p.getStyle().getProperty(styleAttribute) != null + && !p.getStyle().getProperty(styleAttribute) + .isEmpty(); + } }); } } diff --git a/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java b/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java index 50020e51fe..5d463712df 100644 --- a/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java +++ b/client/src/com/vaadin/client/ui/layout/VLayoutSlot.java @@ -69,6 +69,11 @@ public abstract class VLayoutSlot { public void setAlignment(AlignmentInfo alignment) { this.alignment = alignment; + // if alignment is something other than topLeft then we need to align + // the component inside this slot + if (alignment != null && (!alignment.isLeft() || !alignment.isTop())) { + widget.getElement().getStyle().setPosition(Position.ABSOLUTE); + } } public void positionHorizontally(double currentLocation, @@ -109,11 +114,7 @@ public abstract class VLayoutSlot { style.clearMarginRight(); } - if (isRelativeWidth()) { - style.setPropertyPx("width", (int) availableWidth); - } else { - style.clearProperty("width"); - } + style.setPropertyPx("width", (int) availableWidth); double allocatedContentWidth = 0; if (isRelativeWidth()) { @@ -124,6 +125,8 @@ public abstract class VLayoutSlot { reportActualRelativeWidth(Math.round((float) allocatedContentWidth)); } + style.setLeft(Math.round(currentLocation), Unit.PX); + double padding = 0; AlignmentInfo alignment = getAlignment(); if (!alignment.isLeft()) { double usedWidth; @@ -133,25 +136,26 @@ public abstract class VLayoutSlot { usedWidth = getWidgetWidth(); } if (alignment.isHorizontalCenter()) { - currentLocation += (allocatedSpace - usedWidth) / 2d; + padding = (allocatedSpace - usedWidth) / 2d; if (captionAboveCompnent) { captionStyle.setLeft( Math.round(usedWidth - captionWidth) / 2, Unit.PX); } } else { - currentLocation += (allocatedSpace - usedWidth); + padding = (allocatedSpace - usedWidth); if (captionAboveCompnent) { captionStyle.setLeft(Math.round(usedWidth - captionWidth), Unit.PX); } } + widget.getElement().getStyle() + .setLeft(Math.round(padding), Unit.PX); } else { if (captionAboveCompnent) { captionStyle.setLeft(0, Unit.PX); } } - style.setLeft(Math.round(currentLocation), Unit.PX); } private double parsePercent(String size) { @@ -184,11 +188,7 @@ public abstract class VLayoutSlot { style.clearMarginBottom(); } - if (isRelativeHeight()) { - style.setHeight(contentHeight, Unit.PX); - } else { - style.clearHeight(); - } + style.setHeight(contentHeight, Unit.PX); double allocatedContentHeight = 0; if (isRelativeHeight()) { @@ -199,6 +199,8 @@ public abstract class VLayoutSlot { .round((float) allocatedContentHeight)); } + style.setTop(currentLocation, Unit.PX); + double padding = 0; AlignmentInfo alignment = getAlignment(); if (!alignment.isTop()) { double usedHeight; @@ -208,13 +210,14 @@ public abstract class VLayoutSlot { usedHeight = getUsedHeight(); } if (alignment.isVerticalCenter()) { - currentLocation += (allocatedSpace - usedHeight) / 2d; + padding = (allocatedSpace - usedHeight) / 2d; } else { - currentLocation += (allocatedSpace - usedHeight); + padding = (allocatedSpace - usedHeight); } - } + padding += captionHeight; - style.setTop(currentLocation, Unit.PX); + widget.getElement().getStyle().setTop(padding, Unit.PX); + } } protected void reportActualRelativeHeight(int allocatedHeight) { diff --git a/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java new file mode 100644 index 0000000000..d2ca7700ad --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUI.java @@ -0,0 +1,53 @@ +package com.vaadin.tests.components.gridlayout; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.InlineDateField; +import com.vaadin.ui.Label; + +@SuppressWarnings("serial") +public class GridLayoutCellSizesUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + + // Create a 4 by 4 grid layout + final GridLayout grid = new GridLayout(4, 4); + + // Fill out the first row using the cursor + grid.addComponent(new Button("R/C 1")); + for (int i = 0; i < 3; i++) { + grid.addComponent(new Button("Col " + (grid.getCursorX() + 1))); + } + + // Fill out the first column using coordinates + for (int i = 1; i < 4; i++) { + grid.addComponent(new Button("Row " + i), 0, i); + } + + // Add some components of various shapes. + grid.addComponent(new Button("3x1 button"), 1, 1, 3, 1); + grid.addComponent(new Label("1x2 cell"), 1, 2, 1, 3); + final InlineDateField date = new InlineDateField("A 2x2 date field"); + date.setResolution(Resolution.DAY); + grid.addComponent(date, 2, 2, 3, 3); + + grid.setMargin(true); + grid.setSizeUndefined(); + + addComponent(grid); + } + + @Override + protected Integer getTicketNumber() { + return 17039; + } + + @Override + protected String getTestDescription() { + return "Grid cells should be full size when adding borders around the cells"; + } +} \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java new file mode 100644 index 0000000000..8c753b1f5c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/gridlayout/GridLayoutCellSizesUITest.java @@ -0,0 +1,111 @@ +/* + * 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.gridlayout; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.GridLayoutElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridLayoutCellSizesUITest extends MultiBrowserTest { + + private List slots4x4; + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + slots4x4 = getSlots(); + } + + @Test + public void equalsHeightSlotsShouldHaveTheSameHeight() { + // items in positions 0,1,2,3,4,5 should have the same height + int firstSlotHeight = getSlotHeight(0); + for (int i = 1; i < 6; i++) { + Assert.assertEquals("Cell height didn't match for cell: " + i, + firstSlotHeight, getSlotHeight(i)); + } + } + + @Test + public void expandedAndLargeSizeSlotsShouldNotEqualFirstSlot() { + int firstSlotHeight = getSlotHeight(0); + + assertNotMatchesSmallHeight(firstSlotHeight, 6, "Row 2"); + assertNotMatchesSmallHeight(firstSlotHeight, 7, "1x2 cell"); + assertNotMatchesSmallHeight(firstSlotHeight, 8, "A 2x2 date field"); + assertNotMatchesSmallHeight(firstSlotHeight, 9, "Row 3"); + } + + @Test + public void expandedRowsShouldHaveCorrectHeight() { + // Slots expanding over 2 rows should have the same height. + Assert.assertEquals("1x2 and 2x2 cell heights didn't match", + getSlotHeight(7), getSlotHeight(8)); + + // Slots on same row as the 1x2 label should have the same combined + // height. + Assert.assertEquals( + "1x2 and combined row two and row three cell heights didn't match", + getSlotHeight(7), getSlotHeight(6) + getSlotHeight(9)); + } + + @Test + public void expandedRowsShouldHaveCorrectWidth() { + // Col 2 slot should be the dame width as 1x2 cell slot + Assert.assertEquals( + "Col 2 slot was not the same width as slot for 1x2 cell", + getSlotWidth(1), getSlotWidth(7)); + + // Row one col 3 & 4 should be as wide as the 2x2 date field + Assert.assertEquals( + "2x2 date field width didn't match col 3 & col 4 combined width", + getSlotWidth(8), getSlotWidth(2) + getSlotWidth(3)); + + // 3x1 button should be as wide as 1x2cell + 2x2 data field + Assert.assertEquals( + "3x1 slot width wasn't the same as the combined slot widths of 1x2 cell and 2x2 date field", + getSlotWidth(5), getSlotWidth(7) + getSlotWidth(8)); + + } + + private void assertNotMatchesSmallHeight(int firstSlotHeight, int i, + String id) { + Assert.assertNotEquals("Big slot '" + id + + "' matched small slots in height", firstSlotHeight, + getSlotHeight(i)); + } + + private int getSlotHeight(int slot) { + return slots4x4.get(slot).getSize().height; + } + + private int getSlotWidth(int slot) { + return slots4x4.get(slot).getSize().width; + } + + private List getSlots() { + GridLayoutElement layout = $(GridLayoutElement.class).first(); + + return layout.findElements(By.className("v-gridlayout-slot")); + } +} -- cgit v1.2.3 From 4217d7bbc8552e822367fac9d7d3cc9ee48821dd Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Fri, 13 Mar 2015 10:52:35 +0200 Subject: Don't use !important for ColorPicker width in Valo (#17140). Change-Id: I47feff9c78a39e30233f388b938c7e4e53b52051 --- .../themes/base/colorpicker/colorpicker.scss | 3 + .../themes/valo/components/_colorpicker.scss | 2 +- .../colorpicker/AbstractColorPickerConnector.java | 16 +++++ server/src/com/vaadin/ui/ColorPicker.java | 12 ---- .../colorpicker/DefaultCaptionWidth.java | 72 ++++++++++++++++++++++ .../colorpicker/DefaultCaptionWidthTest.java | 67 ++++++++++++++++++++ .../tests/themes/valo/ValoDefaultCaptionWidth.java | 29 +++++++++ .../themes/valo/ValoDefaultCaptionWidthTest.java | 56 +++++++++++++++++ 8 files changed, 244 insertions(+), 13 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java create mode 100644 uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidthTest.java create mode 100644 uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidth.java create mode 100644 uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidthTest.java (limited to 'uitest/src') diff --git a/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss b/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss index b2558d8df3..70705dcee3 100644 --- a/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss +++ b/WebContent/VAADIN/themes/base/colorpicker/colorpicker.scss @@ -18,6 +18,9 @@ margin: 1px auto; } +.#{$name}.v-default-caption-width { + width: 100px; +} /***************** COLOR HISTORY COMPONENT *****************************/ .#{$name}-history { diff --git a/WebContent/VAADIN/themes/valo/components/_colorpicker.scss b/WebContent/VAADIN/themes/valo/components/_colorpicker.scss index b859904e59..18f92500dc 100644 --- a/WebContent/VAADIN/themes/valo/components/_colorpicker.scss +++ b/WebContent/VAADIN/themes/valo/components/_colorpicker.scss @@ -198,7 +198,7 @@ } .#{$primary-stylename} { - width: auto !important; + width: auto; } .#{$primary-stylename}-button-color { diff --git a/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java b/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java index ac168d1f9a..cba2a667ca 100644 --- a/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java +++ b/client/src/com/vaadin/client/ui/colorpicker/AbstractColorPickerConnector.java @@ -30,6 +30,8 @@ import com.vaadin.shared.ui.colorpicker.ColorPickerState; public abstract class AbstractColorPickerConnector extends AbstractComponentConnector implements ClickHandler { + private static final String DEFAULT_WIDTH_STYLE = "v-default-caption-width"; + @Override public ColorPickerState getState() { return (ColorPickerState) super.getState(); @@ -59,6 +61,7 @@ public abstract class AbstractColorPickerConnector extends || stateChangeEvent.hasPropertyChanged("showDefaultCaption")) { setCaption(getCaption()); + refreshDefaultCaptionStyle(); } } @@ -83,6 +86,19 @@ public abstract class AbstractColorPickerConnector extends return getState().caption; } + /** + * Add/remove default caption style. + */ + protected void refreshDefaultCaptionStyle() { + if (getState().showDefaultCaption + && (getState().caption == null || getState().caption.isEmpty()) + && getState().width.isEmpty()) { + getWidget().addStyleName(DEFAULT_WIDTH_STYLE); + } else { + getWidget().removeStyleName(DEFAULT_WIDTH_STYLE); + } + } + /** * Set caption of the color picker widget. * diff --git a/server/src/com/vaadin/ui/ColorPicker.java b/server/src/com/vaadin/ui/ColorPicker.java index f65b67db72..9e46c4e718 100644 --- a/server/src/com/vaadin/ui/ColorPicker.java +++ b/server/src/com/vaadin/ui/ColorPicker.java @@ -64,16 +64,4 @@ public class ColorPicker extends AbstractColorPicker { addStyleName(STYLENAME_DEFAULT); } - @Override - public void beforeClientResponse(boolean initial) { - super.beforeClientResponse(initial); - - if (isDefaultCaptionEnabled() - && ((getState().caption == null || "" - .equals(getState().caption))) - && "".equals(getState().width)) { - getState().width = "100px"; - } - } - } diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java new file mode 100644 index 0000000000..d3dd0aeccc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidth.java @@ -0,0 +1,72 @@ +/* + * 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.colorpicker; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.ColorPicker; + +/** + * Test for color picker with default caption. + * + * @author Vaadin Ltd + */ +public class DefaultCaptionWidth extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final ColorPicker colorPicker = new ColorPicker(); + addComponent(colorPicker); + colorPicker.setDefaultCaptionEnabled(true); + + Button setWidth = new Button("Set explicit width", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + colorPicker.setCaption(null); + colorPicker.setWidth("150px"); + } + }); + setWidth.addStyleName("set-width"); + addComponent(setWidth); + + Button setCaption = new Button("Set explicit caption", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + colorPicker.setCaption("caption"); + colorPicker.setWidthUndefined(); + } + }); + setCaption.addStyleName("set-caption"); + addComponent(setCaption); + + } + + @Override + protected String getTestDescription() { + return "Color picker with default caption enabled should get appropriate style"; + } + + @Override + protected Integer getTicketNumber() { + return 17140; + } +} diff --git a/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidthTest.java b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidthTest.java new file mode 100644 index 0000000000..78b7120b4e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/colorpicker/DefaultCaptionWidthTest.java @@ -0,0 +1,67 @@ +/* + * 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.colorpicker; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ColorPickerElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for default caption behavior in color picker. + * + * @author Vaadin Ltd + */ +public class DefaultCaptionWidthTest extends MultiBrowserTest { + + @Before + public void setUp() { + openTestURL(); + } + + @Test + public void setDefaultCaption_sizeAndCaptionAreNotSet_pickerGetsStyle() { + checkStylePresence(true); + } + + @Test + public void setDefaultCaption_explicitSizeIsSet_pickerNoCaptionStyle() { + findElement(By.className("set-width")).click(); + checkStylePresence(false); + } + + @Test + public void setDefaultCaption_explicitCaptionIsSet_pickerNoCaptionStyle() { + findElement(By.className("set-caption")).click(); + checkStylePresence(false); + } + + protected void checkStylePresence(boolean expectedStyle) { + String clazz = $(ColorPickerElement.class).first() + .getAttribute("class"); + if (expectedStyle) { + Assert.assertTrue("Default caption style is not found", + clazz.contains("v-default-caption-width")); + } else { + Assert.assertFalse("Found unexpected default caption style", + clazz.contains("v-default-caption-width")); + } + } + +} diff --git a/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidth.java b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidth.java new file mode 100644 index 0000000000..6ef585cc12 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidth.java @@ -0,0 +1,29 @@ +/* + * 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.themes.valo; + +import com.vaadin.annotations.Theme; +import com.vaadin.tests.components.colorpicker.DefaultCaptionWidth; + +/** + * Test for color picker with default caption. + * + * @author Vaadin Ltd + */ +@Theme("valo") +public class ValoDefaultCaptionWidth extends DefaultCaptionWidth { + +} diff --git a/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidthTest.java b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidthTest.java new file mode 100644 index 0000000000..7651b641de --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/valo/ValoDefaultCaptionWidthTest.java @@ -0,0 +1,56 @@ +/* + * 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.themes.valo; + +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +import com.vaadin.testbench.elements.ColorPickerElement; +import com.vaadin.tests.components.colorpicker.DefaultCaptionWidthTest; + +/** + * Test for default caption behavior in color picker using Valo theme. + * + * @author Vaadin Ltd + */ +public class ValoDefaultCaptionWidthTest extends DefaultCaptionWidthTest { + + @Override + @Test + public void setDefaultCaption_sizeAndCaptionAreNotSet_pickerGetsStyle() { + super.setDefaultCaption_sizeAndCaptionAreNotSet_pickerGetsStyle(); + int width = $(ColorPickerElement.class).first().getSize().getWidth(); + // Make sure that implicit width is less than one that will be + // explicitly set by the test + assertThat("Width of color picker is overriden by " + + "default caption feature", width, is(lessThan(148))); + } + + @Override + @Test + public void setDefaultCaption_explicitSizeIsSet_pickerNoCaptionStyle() { + super.setDefaultCaption_explicitSizeIsSet_pickerNoCaptionStyle(); + int width = $(ColorPickerElement.class).first().getSize().getWidth(); + // Width should be 150px but let's just check that it's not which is + // used when default caption is used and at least >= 150-1 + assertThat("Width of color picker is overriden by " + + "default caption feature", width, is(greaterThan(149))); + } +} -- cgit v1.2.3 From 817906332a8ba99e8a711067c10282b8cd9a6415 Mon Sep 17 00:00:00 2001 From: Alexey Fansky Date: Thu, 9 Apr 2015 11:09:15 -0700 Subject: Adding a temporary style to VNotification on Chrome >=41 (#17252) Change-Id: I41c05e8f8487d351035804e0681947956d861479 --- client/src/com/vaadin/client/ui/VNotification.java | 9 +++++- .../notification/ChromeBottomNotification.java | 33 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/notification/ChromeBottomNotification.java (limited to 'uitest/src') diff --git a/client/src/com/vaadin/client/ui/VNotification.java b/client/src/com/vaadin/client/ui/VNotification.java index d7639b0022..eee0f459a6 100644 --- a/client/src/com/vaadin/client/ui/VNotification.java +++ b/client/src/com/vaadin/client/ui/VNotification.java @@ -257,12 +257,19 @@ public class VNotification extends VOverlay { /** * Android 4 fails to render notifications correctly without a little * nudge (#8551) + * Chrome 41 now requires this too (#17252) */ - if (BrowserInfo.get().isAndroid()) { + if (BrowserInfo.get().isAndroid() + || isChrome41OrHigher()) { WidgetUtil.setStyleTemporarily(getElement(), "display", "none"); } } + private boolean isChrome41OrHigher() { + return BrowserInfo.get().isChrome() + && BrowserInfo.get().getBrowserMajorVersion() >= 41; + } + protected void hideAfterDelay() { if (delay == null) { delay = new Timer() { diff --git a/uitest/src/com/vaadin/tests/components/notification/ChromeBottomNotification.java b/uitest/src/com/vaadin/tests/components/notification/ChromeBottomNotification.java new file mode 100644 index 0000000000..0fdc8df360 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/notification/ChromeBottomNotification.java @@ -0,0 +1,33 @@ +package com.vaadin.tests.components.notification; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.Position; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Notification; + +public class ChromeBottomNotification extends AbstractTestUI { + @Override + protected void setup(VaadinRequest request) { + addButton("Show notification", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + Notification notification = new Notification( + "Hello world", + Notification.Type.ERROR_MESSAGE); + notification.setPosition(Position.BOTTOM_CENTER); + notification.show(getPage()); + } + }); + } + + @Override + protected Integer getTicketNumber() { + return 17252; + } + + @Override + public String getDescription() { + return "Bottom notification on Chrome goes up to top"; + } +} -- cgit v1.2.3 From 31b3cd924e163363366e588e7e5def151a61b77d Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Fri, 20 Mar 2015 08:07:51 +0200 Subject: Grid header should render "the same" after changes to header (#17131) Change-Id: I2a16ffbd59bf4863eb6a7bea8d4b590a693af637 --- client/src/com/vaadin/client/widgets/Grid.java | 82 +++++++-- .../components/grid/GridHeaderFormatChange.java | 183 +++++++++++++++++++++ .../grid/GridHeaderFormatChangeTest.java | 156 ++++++++++++++++++ 3 files changed, 403 insertions(+), 18 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChange.java create mode 100644 uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java (limited to 'uitest/src') diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 4b27e17e37..3aaac14f10 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -2178,14 +2178,33 @@ public class Grid extends ResizeComposite implements public final class SelectionColumn extends Column { private boolean initDone = false; + private boolean selected = false; SelectionColumn(final Renderer selectColumnRenderer) { super(selectColumnRenderer); } void initDone() { + addSelectAllToDefaultHeader(); + + setWidth(-1); + + setEditable(false); + + initDone = true; + } + + protected void addSelectAllToDefaultHeader() { if (getSelectionModel() instanceof SelectionModel.Multi && header.getDefaultRow() != null) { + // If selection cell already contains a widget do not + // create a new CheckBox + HeaderCell selectionCell = header.getDefaultRow().getCell(this); + if (selectionCell.getType() + .equals(GridStaticCellType.WIDGET) + && selectionCell.getWidget() instanceof CheckBox) { + return; + } /* * TODO: Currently the select all check box is shown when multi * selection is in use. This might result in malfunctions if no @@ -2202,19 +2221,18 @@ public class Grid extends ResizeComposite implements public void onValueChange(ValueChangeEvent event) { if (event.getValue()) { fireEvent(new SelectAllEvent(model)); + selected = true; } else { model.deselectAll(); + selected = false; } } }); - header.getDefaultRow().getCell(this).setWidget(checkBox); - } + checkBox.setValue(selected); - setWidth(-1); - - setEditable(false); + selectionCell.setWidget(checkBox); - initDone = true; + } } @Override @@ -3685,27 +3703,34 @@ public class Grid extends ResizeComposite implements final StaticSection.StaticCell metadata = staticRow .getCell(columns.get(cell.getColumn())); + boolean updateCellData = true; // Decorate default row with sorting indicators if (staticRow instanceof HeaderRow) { addSortingIndicatorsToHeaderRow((HeaderRow) staticRow, cell); + + if (isHeaderSelectionColumn(row, cell)) { + updateCellData = false; + } } // Assign colspan to cell before rendering cell.setColSpan(metadata.getColspan()); TableCellElement element = cell.getElement(); - switch (metadata.getType()) { - case TEXT: - element.setInnerText(metadata.getText()); - break; - case HTML: - element.setInnerHTML(metadata.getHtml()); - break; - case WIDGET: - preDetach(row, Arrays.asList(cell)); - element.setInnerHTML(""); - postAttach(row, Arrays.asList(cell)); - break; + if (updateCellData) { + switch (metadata.getType()) { + case TEXT: + element.setInnerText(metadata.getText()); + break; + case HTML: + element.setInnerHTML(metadata.getHtml()); + break; + case WIDGET: + preDetach(row, Arrays.asList(cell)); + element.setInnerHTML(""); + postAttach(row, Arrays.asList(cell)); + break; + } } setCustomStyleName(element, metadata.getStyleName()); @@ -3765,6 +3790,27 @@ public class Grid extends ResizeComposite implements @Override public void preAttach(Row row, Iterable cellsToAttach) { + // Add select all checkbox if needed on rebuild. + for (FlyweightCell cell : cellsToAttach) { + if (isHeaderSelectionColumn(row, cell)) { + selectionColumn.addSelectAllToDefaultHeader(); + } + } + } + + /** + * Check if selectionColumn in the default header row + */ + private boolean isHeaderSelectionColumn(Row row, FlyweightCell cell) { + return selectionColumn != null && isDefaultHeaderRow(row) + && getColumn(cell.getColumn()).equals(selectionColumn); + } + + /** + * Row is the default header row. + */ + private boolean isDefaultHeaderRow(Row row) { + return section.getRow(row.getRow()).equals(header.getDefaultRow()); } @Override diff --git a/uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChange.java b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChange.java new file mode 100644 index 0000000000..fbd6a42a38 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChange.java @@ -0,0 +1,183 @@ +/* + * 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; + +import java.io.Serializable; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.HeaderRow; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.Grid.SelectionModel; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridHeaderFormatChange extends AbstractTestUI { + + private static final long serialVersionUID = -2787771187365766027L; + + private HeaderRow row; + + public class Person implements Serializable { + private static final long serialVersionUID = -7995927620756317000L; + + String firstName; + String lastName; + String streetAddress; + Integer zipCode; + String city; + + public Person(String firstName, String lastName, String streetAddress, + Integer zipCode, String city) { + this.firstName = firstName; + this.lastName = lastName; + this.streetAddress = streetAddress; + this.zipCode = zipCode; + this.city = city; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getStreetAddress() { + return streetAddress; + } + + public void setStreetAddress(String streetAddress) { + this.streetAddress = streetAddress; + } + + public Integer getZipCode() { + return zipCode; + } + + public void setZipCode(Integer zipCode) { + this.zipCode = zipCode; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + } + + @Override + protected void setup(VaadinRequest request) { + BeanItemContainer datasource = new BeanItemContainer( + Person.class); + final Grid grid; + + datasource.addItem(new Person("Rudolph", "Reindeer", "Ruukinkatu 2-4", + 20540, "Turku")); + + grid = new Grid(datasource); + grid.setWidth("600px"); + grid.getColumn("zipCode").setRenderer(new NumberRenderer()); + grid.setColumnOrder("firstName", "lastName", "streetAddress", + "zipCode", "city"); + grid.setSelectionMode(SelectionMode.SINGLE); + addComponent(grid); + + Button showHide = new Button("Hide firstName", + new Button.ClickListener() { + private static final long serialVersionUID = 8107530972693788705L; + + @Override + public void buttonClick(ClickEvent event) { + if (grid.getColumn("firstName") != null) { + grid.removeColumn("firstName"); + event.getButton().setCaption("Show firstName"); + } else { + grid.addColumn("firstName"); + grid.setColumnOrder("firstName", "lastName", + "streetAddress", "zipCode", "city"); + + event.getButton().setCaption("Hide firstName"); + } + } + }); + showHide.setId("show_hide"); + + Button selectionMode = new Button("Set multiselect", + new Button.ClickListener() { + private static final long serialVersionUID = 8107530972693788705L; + + @Override + public void buttonClick(ClickEvent event) { + if (grid.getSelectionModel() instanceof SelectionModel.Single) { + grid.setSelectionMode(SelectionMode.MULTI); + } else { + grid.setSelectionMode(SelectionMode.SINGLE); + } + } + }); + selectionMode.setId("selection_mode"); + + Button join = new Button("Add Join header column", + new Button.ClickListener() { + private static final long serialVersionUID = -5330801275551280623L; + + @Override + public void buttonClick(ClickEvent event) { + if (row == null) { + row = grid.prependHeaderRow(); + if (grid.getColumn("firstName") != null) { + row.join("firstName", "lastName").setText( + "Full Name"); + } + row.join("streetAddress", "zipCode", "city") + .setText("Address"); + } else { + grid.removeHeaderRow(row); + row = null; + } + } + }); + join.setId("join"); + addComponent(new HorizontalLayout(showHide, selectionMode, join)); + } + + @Override + protected String getTestDescription() { + return "Grid for testing header re-rendering."; + } + + @Override + protected Integer getTicketNumber() { + return 17131; + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java new file mode 100644 index 0000000000..0e2a3d6ac6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFormatChangeTest.java @@ -0,0 +1,156 @@ +/* + * 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; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridHeaderFormatChangeTest extends MultiBrowserTest { + + @Test + public void testHeaderRetainsSelectAllForColumnRemoval() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Assert that we do not have the select all checkbox + Assert.assertTrue( + "Found input in header even though none should exist.", grid + .getHeader().findElements(By.tagName("input")) + .isEmpty()); + + // Set grid into multiselection mode + toggleSelectionMode(); + + // Assert that we now have a select all checkbox in the header + Assert.assertFalse("Expected one input field in header", grid + .getHeader().findElements(By.tagName("input")).isEmpty()); + + // Hide the firstName column from the grid. + toggleFirstName(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse("Header was missing checkbox after hiding column", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // Show the firstName column. + toggleFirstName(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse( + "Header was missing checkbox after bringing back column", grid + .getHeader().findElements(By.tagName("input")) + .isEmpty()); + } + + @Test + public void testHeaderRetainsSelectAllForJoinColumnAdd() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Assert that we do not have the select all checkbox + Assert.assertTrue( + "Found input in header even though none should exist.", grid + .getHeader().findElements(By.tagName("input")) + .isEmpty()); + + // Set grid into multiselection mode + toggleSelectionMode(); + + // Assert that we now have a select all checkbox in the header + Assert.assertFalse("Expected one input field in header", grid + .getHeader().findElements(By.tagName("input")).isEmpty()); + + // Add Join columns header + toggleJoin(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse("Header was missing checkbox after hiding column", + grid.getHeader().findElements(By.tagName("input")).isEmpty()); + + // remove Join Columns header + toggleJoin(); + + // Assert that we still have the select all checkbox in the header. + Assert.assertFalse( + "Header was missing checkbox after bringing back column", grid + .getHeader().findElements(By.tagName("input")) + .isEmpty()); + } + + @Test + public void selectAllShouldKeepState() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Assert that we do not have the select all checkbox + Assert.assertTrue( + "Found input in header even though none should exist.", grid + .getHeader().findElements(By.tagName("input")) + .isEmpty()); + + // Set grid into multiselection mode + toggleSelectionMode(); + + // Assert that we now have a select all checkbox in the header + Assert.assertFalse("Should not be selected after adding", grid + .getHeader().findElement(By.tagName("input")).isSelected()); + + grid.getHeader().findElement(By.tagName("input")).click(); + + // Assert that checkbox is checked + assertSelectAllChecked( + "Not selected even though we just clicked selection", grid); + + // Hide the firstName column from the grid. + toggleFirstName(); + + // Assert that checkbox is still checked + assertSelectAllChecked("Selection disappeared after removing column", + grid); + + // Show the firstName column. + toggleFirstName(); + + // Assert that checkbox is still checked + assertSelectAllChecked("Selection disappeared after adding column", + grid); + + } + + private void assertSelectAllChecked(String message, GridElement grid) { + Assert.assertTrue(message, + grid.getHeader().findElement(By.tagName("input")).isSelected()); + } + + private void toggleSelectionMode() { + $(ButtonElement.class).id("selection_mode").click(); + } + + private void toggleFirstName() { + $(ButtonElement.class).id("show_hide").click(); + } + + private void toggleJoin() { + $(ButtonElement.class).id("join").click(); + } +} -- cgit v1.2.3 From 38e35c5db6621b20929d924707be149e22032997 Mon Sep 17 00:00:00 2001 From: Ilya Ermakov Date: Thu, 26 Feb 2015 20:54:29 +0300 Subject: Prevent opening Table context menu on short tapping on iOS (#15297) With this patch handling touchstart in Table body is prevented if it is handled in Table row. This is the smallest patch that solves the problem, refactoring remains an open problem. Change-Id: Iea54210ee81a3fdf17e45c6c98026af9080abddf --- client/src/com/vaadin/client/ui/VScrollTable.java | 3 +- .../components/table/TableContextMenuTouch.java | 106 +++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableContextMenuTouch.java (limited to 'uitest/src') diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 13561dcd0f..6a8ce67678 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -5947,6 +5947,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } contextTouchTimeout .schedule(TOUCH_CONTEXT_MENU_TIMEOUT); + event.stopPropagation(); } break; case Event.ONTOUCHMOVE: @@ -5987,10 +5988,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (touchStart != null) { if (!BrowserInfo.get().isAndroid()) { event.preventDefault(); - event.stopPropagation(); WidgetUtil.simulateClickFromTouchEvent( touchStart, this); } + event.stopPropagation(); touchStart = null; } isDragging = false; diff --git a/uitest/src/com/vaadin/tests/components/table/TableContextMenuTouch.java b/uitest/src/com/vaadin/tests/components/table/TableContextMenuTouch.java new file mode 100644 index 0000000000..1d909d101e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableContextMenuTouch.java @@ -0,0 +1,106 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.event.Action; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; + +/* + * Differs from TableContextMenu by number of items, their numbering and + * immediate/selectable/multiselect toggling + */ +public class TableContextMenuTouch extends AbstractTestUI { + + private static final Action ACTION_MYACTION = new Action("Action!!"); + + @Override + protected void setup(VaadinRequest req) { + + HorizontalLayout hlay = new HorizontalLayout(); + addComponent(hlay); + hlay.setSpacing(true); + + final Table table = new Table(); + + table.addActionHandler(new Action.Handler() { + @Override + public void handleAction(Action action, Object sender, Object target) { + Notification.show("Done that :-)"); + } + + @Override + public Action[] getActions(Object target, Object sender) { + return new Action[] { ACTION_MYACTION }; + } + }); + + table.addContainerProperty("Foo", String.class, "BAR1"); + table.addContainerProperty("Bar", String.class, "FOO2"); + + table.setHeight("200px"); + + for (int i = 0; i < 30; i++) { + Object key = table.addItem(); + table.getItem(key).getItemProperty("Foo") + .setValue(new Integer(i).toString()); + } + + hlay.addComponent(table); + + VerticalLayout vlay = new VerticalLayout(); + hlay.addComponent(vlay); + + final CheckBox immediateCheckBox = new CheckBox("Immediate"); + vlay.addComponent(immediateCheckBox); + immediateCheckBox.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + table.setImmediate(immediateCheckBox.getValue()); + } + }); + immediateCheckBox.setValue(true); + table.setImmediate(immediateCheckBox.getValue()); + + final CheckBox selectableCheckBox = new CheckBox("Selectable"); + final CheckBox multiselectCheckBox = new CheckBox("Multiselect"); + vlay.addComponent(selectableCheckBox); + selectableCheckBox.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + table.setSelectable(selectableCheckBox.getValue()); + multiselectCheckBox.setEnabled(selectableCheckBox.getValue()); + } + }); + selectableCheckBox.setValue(true); + multiselectCheckBox.setEnabled(selectableCheckBox.getValue()); + table.setSelectable(selectableCheckBox.getValue()); + + vlay.addComponent(multiselectCheckBox); + multiselectCheckBox.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + table.setMultiSelect(multiselectCheckBox.getValue()); + } + }); + multiselectCheckBox.setValue(true); + table.setMultiSelect(multiselectCheckBox.getValue()); + + } + + @Override + protected String getTestDescription() { + return "Context menu in Table on touch devices should not open on selection tapping"; + } + + @Override + protected Integer getTicketNumber() { + return 15297; + } + +} \ No newline at end of file -- cgit v1.2.3