From dca728c134756f5a4e9296ab7ac95198675a69db Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 13 May 2013 14:46:58 +0300 Subject: Warn if using old widgetset (#11836) Change-Id: Id7332da3468572f4df55aa7b3fed39ef811fe09d --- .../vaadin/tests/components/AbstractTestUI.java | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index a044b52f18..45809e3270 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -1,10 +1,16 @@ package com.vaadin.tests.components; +import java.io.File; + +import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinServlet; import com.vaadin.server.WebBrowser; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.ui.Component; import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; +import com.vaadin.ui.Notification.Type; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; @@ -27,9 +33,67 @@ public abstract class AbstractTestUI extends UI { rootLayout.addComponent(layout); ((VerticalLayout) getContent()).setExpandRatio(layout, 1); + warnIfWidgetsetMaybeNotCompiled(); + setup(request); } + protected void warnIfWidgetsetMaybeNotCompiled() { + // Ignore if using debug mode + if (getPage().getLocation().getQuery().matches(".*[&?]gwt\\.codesvr.*")) { + return; + } + + // Find out the widgetset of this UI based on @Widgetset annotation + Class currentType = getClass(); + String usedWidgetset = VaadinServlet.DEFAULT_WIDGETSET; + while (currentType != Object.class) { + Widgetset annotation = currentType.getAnnotation(Widgetset.class); + if (annotation != null) { + usedWidgetset = annotation.value(); + break; + } else { + currentType = currentType.getSuperclass(); + } + } + + // Assuming the same folder structure as in git repo + // Assuming project root is the working dir of this process + File widgetsetsFolder = new File("WebContent/VAADIN/widgetsets"); + if (!widgetsetsFolder.isDirectory()) { + return; + } + + // Find the most newly compiled widgetset + long newestWidgetsetTimestamp = -1; + String newestWidgetsetName = null; + File[] children = widgetsetsFolder.listFiles(); + for (File child : children) { + if (!child.isDirectory() || child.getName().equals("WEB-INF")) { + continue; + } + long lastModified = child.lastModified(); + if (lastModified > newestWidgetsetTimestamp) { + newestWidgetsetTimestamp = lastModified; + newestWidgetsetName = child.getName(); + } + } + + // Compare to currently used widgetset, with a 30 minute grace period + File currentWidgetsetFolder = new File(widgetsetsFolder, usedWidgetset); + long currentWidgetsetTimestamp = currentWidgetsetFolder.lastModified(); + int halfHour = 30 * 60 * 1000; + if (currentWidgetsetTimestamp + halfHour < newestWidgetsetTimestamp) { + Notification + .show("The currently used widgetset (" + + usedWidgetset + + ") was compiled long before the most recently compiled one (" + + newestWidgetsetName + + "). Are you sure you have compiled the right widgetset?", + Type.WARNING_MESSAGE); + } + } + private VerticalLayout layout; protected VerticalLayout getLayout() { -- cgit v1.2.3 From 936439dfe4be81637e63f539e281e190c1155460 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 13 May 2013 13:19:10 +0300 Subject: Verify that tests are run with the expected JRE version (#11835) Change-Id: I77b48cc646776a452204e2c93954fdd1eea7e4de --- uitest/src/com/vaadin/tests/VerifyJreVersion.html | 26 +++++++++++++ uitest/src/com/vaadin/tests/VerifyJreVersion.java | 45 +++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/VerifyJreVersion.html create mode 100644 uitest/src/com/vaadin/tests/VerifyJreVersion.java (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/VerifyJreVersion.html b/uitest/src/com/vaadin/tests/VerifyJreVersion.html new file mode 100644 index 0000000000..abf53883c1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/VerifyJreVersion.html @@ -0,0 +1,26 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.VerifyJreVersion?restartApplication
assertTextvaadin=runcomvaadintestsVerifyJreVersion::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]Using Java 1.6.0_32 by Sun Microsystems Inc.
+ + diff --git a/uitest/src/com/vaadin/tests/VerifyJreVersion.java b/uitest/src/com/vaadin/tests/VerifyJreVersion.java new file mode 100644 index 0000000000..fe3e4bd870 --- /dev/null +++ b/uitest/src/com/vaadin/tests/VerifyJreVersion.java @@ -0,0 +1,45 @@ +/* + * 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; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; + +public class VerifyJreVersion extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + String jreVersion = "Using Java " + System.getProperty("java.version") + + " by " + System.getProperty("java.vendor"); + addComponent(new Label(jreVersion)); + } + + @Override + protected String getTestDescription() { + return "Test used to detect when the JRE used to run these tests have changed."; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(11835); + } + +} -- cgit v1.2.3 From b8c6a15da87ff6d2a83e7c0d79dd45ee120fe6a2 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Fri, 10 May 2013 16:25:55 +0300 Subject: Clear items in ComboBox only if changed (#10924) Selection is now sent only as a key, removed redundant attribute on the item. Change-Id: I882d4ae17a1dc91f7a55a0b4a94e47c078ffc022 --- client/src/com/vaadin/client/ui/VFilterSelect.java | 21 +++ .../client/ui/combobox/ComboBoxConnector.java | 147 +++++++++++++-------- server/src/com/vaadin/ui/ComboBox.java | 4 +- .../tests/components/combobox/ComboPushTiming.java | 110 +++++++++++++++ 4 files changed, 222 insertions(+), 60 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/combobox/ComboPushTiming.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 11f89ee232..a3156221b9 100644 --- a/client/src/com/vaadin/client/ui/VFilterSelect.java +++ b/client/src/com/vaadin/client/ui/VFilterSelect.java @@ -168,6 +168,27 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, public void execute() { onSuggestionSelected(this); } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof FilterSelectSuggestion)) { + return false; + } + FilterSelectSuggestion other = (FilterSelectSuggestion) obj; + if ((key == null && other.key != null) + || (key != null && !key.equals(other.key))) { + return false; + } + if ((caption == null && other.caption != null) + || (caption != null && !caption.equals(other.caption))) { + return false; + } + if ((iconUri == null && other.iconUri != null) + || (iconUri != null && !iconUri.equals(other.iconUri))) { + return false; + } + return true; + } } /** diff --git a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java index 7c82db1b00..345bdc0cbb 100644 --- a/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -15,7 +15,9 @@ */ package com.vaadin.client.ui.combobox; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.Paintable; @@ -98,24 +100,6 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().allowNewItem = uidl.hasAttribute("allownewitem"); getWidget().lastNewItemString = null; - getWidget().currentSuggestions.clear(); - if (!getWidget().waitingForFilteringResponse) { - /* - * Clear the current suggestions as the server response always - * includes the new ones. Exception is when filtering, then we need - * to retain the value if the user does not select any of the - * options matching the filter. - */ - getWidget().currentSuggestion = null; - /* - * Also ensure no old items in menu. Unless cleared the old values - * may cause odd effects on blur events. Suggestions in menu might - * not necessary exist in select at all anymore. - */ - getWidget().suggestionPopup.menu.clearItems(); - - } - final UIDL options = uidl.getChildUIDL(0); if (uidl.hasAttribute("totalMatches")) { getWidget().totalMatches = uidl.getIntAttribute("totalMatches"); @@ -123,54 +107,52 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().totalMatches = 0; } + List newSuggestions = new ArrayList(); + for (final Iterator i = options.getChildIterator(); i.hasNext();) { final UIDL optionUidl = (UIDL) i.next(); final FilterSelectSuggestion suggestion = getWidget().new FilterSelectSuggestion( optionUidl); - getWidget().currentSuggestions.add(suggestion); - if (optionUidl.hasAttribute("selected")) { - if (!getWidget().waitingForFilteringResponse - || getWidget().popupOpenerClicked) { - String newSelectedOptionKey = suggestion.getOptionKey(); - if (!newSelectedOptionKey - .equals(getWidget().selectedOptionKey) - || suggestion.getReplacementString().equals( - getWidget().tb.getText())) { - // Update text field if we've got a new selection - // Also update if we've got the same text to retain old - // text selection behavior - getWidget().setPromptingOff( - suggestion.getReplacementString()); - getWidget().selectedOptionKey = newSelectedOptionKey; - } - } - getWidget().currentSuggestion = suggestion; - getWidget().setSelectedItemIcon(suggestion.getIconUri()); + newSuggestions.add(suggestion); + } + + // only close the popup if the suggestions list has actually changed + boolean suggestionsChanged = !getWidget().initDone + || !newSuggestions.equals(getWidget().currentSuggestions); + + if (suggestionsChanged) { + getWidget().currentSuggestions.clear(); + + if (!getWidget().waitingForFilteringResponse) { + /* + * Clear the current suggestions as the server response always + * includes the new ones. Exception is when filtering, then we + * need to retain the value if the user does not select any of + * the options matching the filter. + */ + getWidget().currentSuggestion = null; + /* + * Also ensure no old items in menu. Unless cleared the old + * values may cause odd effects on blur events. Suggestions in + * menu might not necessary exist in select at all anymore. + */ + getWidget().suggestionPopup.menu.clearItems(); + + } + + for (FilterSelectSuggestion suggestion : newSuggestions) { + getWidget().currentSuggestions.add(suggestion); } } - if ((!getWidget().waitingForFilteringResponse || getWidget().popupOpenerClicked) - && uidl.hasVariable("selected") - && uidl.getStringArrayVariable("selected").length == 0) { - // select nulled - if (!getWidget().waitingForFilteringResponse - || !getWidget().popupOpenerClicked) { - if (!getWidget().focused) { - /* - * client.updateComponent overwrites all styles so we must - * ALWAYS set the prompting style at this point, even though - * we think it has been set already... - */ - getWidget().prompting = false; - getWidget().setPromptingOn(); - } else { - // we have focus in field, prompting can't be set on, - // instead just clear the input - getWidget().tb.setValue(""); - } + // handle selection (null or a single value) + if (uidl.hasVariable("selected")) { + String[] selectedKeys = uidl.getStringArrayVariable("selected"); + if (selectedKeys.length > 0) { + performSelection(selectedKeys[0]); + } else { + resetSelection(); } - getWidget().setSelectedItemIcon(null); - getWidget().selectedOptionKey = null; } if (getWidget().waitingForFilteringResponse @@ -229,6 +211,55 @@ public class ComboBoxConnector extends AbstractFieldConnector implements getWidget().initDone = true; } + private void performSelection(String selectedKey) { + // some item selected + for (FilterSelectSuggestion suggestion : getWidget().currentSuggestions) { + String suggestionKey = suggestion.getOptionKey(); + if (suggestionKey.equals(selectedKey)) { + if (!getWidget().waitingForFilteringResponse + || getWidget().popupOpenerClicked) { + if (!suggestionKey.equals(getWidget().selectedOptionKey) + || suggestion.getReplacementString().equals( + getWidget().tb.getText())) { + // Update text field if we've got a new + // selection + // Also update if we've got the same text to + // retain old text selection behavior + getWidget().setPromptingOff( + suggestion.getReplacementString()); + getWidget().selectedOptionKey = suggestionKey; + } + } + getWidget().currentSuggestion = suggestion; + getWidget().setSelectedItemIcon(suggestion.getIconUri()); + // only a single item can be selected + break; + } + } + } + + private void resetSelection() { + if (!getWidget().waitingForFilteringResponse + || getWidget().popupOpenerClicked) { + // select nulled + if (!getWidget().focused) { + /* + * client.updateComponent overwrites all styles so we must + * ALWAYS set the prompting style at this point, even though we + * think it has been set already... + */ + getWidget().prompting = false; + getWidget().setPromptingOn(); + } else { + // we have focus in field, prompting can't be set on, instead + // just clear the input + getWidget().tb.setValue(""); + } + getWidget().setSelectedItemIcon(null); + getWidget().selectedOptionKey = null; + } + } + @Override public VFilterSelect getWidget() { return (VFilterSelect) super.getWidget(); diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java index 0f42749acd..88e895df82 100644 --- a/server/src/com/vaadin/ui/ComboBox.java +++ b/server/src/com/vaadin/ui/ComboBox.java @@ -262,8 +262,8 @@ public class ComboBox extends AbstractSelect implements target.addAttribute("nullselection", true); } target.addAttribute("key", key); - if (isSelected(id) && keyIndex < selectedKeys.length) { - target.addAttribute("selected", true); + if (keyIndex < selectedKeys.length && isSelected(id)) { + // at most one item can be selected at a time selectedKeys[keyIndex++] = key; } target.endTag("so"); diff --git a/uitest/src/com/vaadin/tests/components/combobox/ComboPushTiming.java b/uitest/src/com/vaadin/tests/components/combobox/ComboPushTiming.java new file mode 100644 index 0000000000..fe2cffdc4c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/combobox/ComboPushTiming.java @@ -0,0 +1,110 @@ +package com.vaadin.tests.components.combobox; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.event.FieldEvents; +import com.vaadin.event.FieldEvents.BlurEvent; +import com.vaadin.event.FieldEvents.FocusEvent; +import com.vaadin.server.VaadinSession; +import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Label; +import com.vaadin.ui.ProgressIndicator; +import com.vaadin.ui.TextField; + +public class ComboPushTiming extends TestBase { + + private int counter = 0; + private final MyExecutor executor = new MyExecutor(); + + @Override + protected void setup() { + + List list = new ArrayList(); + for (int i = 0; i < 100; i++) { + list.add("Item " + i); + } + + final ComboBox cb = new ComboBox("Combobox", list); + cb.setImmediate(true); + cb.setInputPrompt("Enter text"); + cb.setDescription("Some Combobox"); + addComponent(cb); + + final ObjectProperty log = new ObjectProperty(""); + + cb.addListener(new FieldEvents.FocusListener() { + @Override + public void focus(FocusEvent event) { + log.setValue(log.getValue().toString() + "
" + counter + + ": Focus event!"); + counter++; + changeValue(cb); + } + }); + + cb.addListener(new FieldEvents.BlurListener() { + @Override + public void blur(BlurEvent event) { + log.setValue(log.getValue().toString() + "
" + counter + + ": Blur event!"); + counter++; + } + }); + + TextField field = new TextField("Some textfield"); + field.setImmediate(true); + addComponent(field); + + Label output = new Label(log); + output.setCaption("Events:"); + + output.setContentMode(ContentMode.HTML); + addComponent(output); + + ProgressIndicator progressIndicator = new ProgressIndicator(); + addComponent(progressIndicator); + progressIndicator.setPollingInterval(3000); + } + + private void changeValue(final ComboBox cb) { + executor.execute(new Runnable() { + public void run() { + VaadinSession.getCurrent().lock(); + try { + cb.setEnabled(true); + cb.setValue("B"); + cb.setEnabled(true); + + // If this isn't sent by push or poll in the background, the + // problem will go away + } finally { + VaadinSession.getCurrent().unlock(); + } + } + }); + } + + class MyExecutor extends ThreadPoolExecutor { + public MyExecutor() { + super(5, 20, 20, TimeUnit.SECONDS, new SynchronousQueue()); + } + } + + @Override + protected String getDescription() { + return "When an update is received while the popup is open, the suggestion popup blurs away"; + } + + @Override + protected Integer getTicketNumber() { + return 10924; + } + +} -- cgit v1.2.3 From 42545ac81ae49cb9a3af2a8b3b06ba9525886b22 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 14 May 2013 16:13:43 +0300 Subject: Fix NPE if there's no query in the URI (#11836) Change-Id: I8960e5917ffb0988e705599d1fe5e8aacf2654ef --- uitest/src/com/vaadin/tests/components/AbstractTestUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java index 45809e3270..ec6cf0c57d 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestUI.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUI.java @@ -40,7 +40,8 @@ public abstract class AbstractTestUI extends UI { protected void warnIfWidgetsetMaybeNotCompiled() { // Ignore if using debug mode - if (getPage().getLocation().getQuery().matches(".*[&?]gwt\\.codesvr.*")) { + String query = getPage().getLocation().getQuery(); + if (query != null && query.matches(".*[&?]gwt\\.codesvr.*")) { return; } -- cgit v1.2.3