From 36a201f22f66989bf7a78ce8afce1ee64aaa0a22 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 6 Mar 2013 14:55:15 +0200 Subject: Fixed focus and tab index handling for UI (#11129) Change-Id: I80377792ade11946337e2900a7ea84209ae1d060 --- .../client/ui/AbstractComponentConnector.java | 13 ++- client/src/com/vaadin/client/ui/FocusUtil.java | 94 ++++++++++++++++++++++ client/src/com/vaadin/client/ui/VUI.java | 25 +++++- .../src/com/vaadin/client/ui/ui/UIConnector.java | 8 +- server/src/com/vaadin/ui/UI.java | 17 +++- shared/src/com/vaadin/shared/ui/ui/UIState.java | 6 +- .../com/vaadin/tests/components/ui/UITabIndex.html | 57 +++++++++++++ .../com/vaadin/tests/components/ui/UITabIndex.java | 51 ++++++++++++ 8 files changed, 258 insertions(+), 13 deletions(-) create mode 100644 client/src/com/vaadin/client/ui/FocusUtil.java create mode 100644 uitest/src/com/vaadin/tests/components/ui/UITabIndex.html create mode 100644 uitest/src/com/vaadin/tests/components/ui/UITabIndex.java diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index 694db6f02c..74cb85c297 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -137,10 +137,15 @@ public abstract class AbstractComponentConnector extends AbstractConnector * implementation). */ Profiler.enter("AbstractComponentConnector.onStateChanged update tab index"); - if (getState() instanceof TabIndexState - && getWidget() instanceof Focusable) { - ((Focusable) getWidget()) - .setTabIndex(((TabIndexState) getState()).tabIndex); + if (getState() instanceof TabIndexState) { + if (getWidget() instanceof Focusable) { + ((Focusable) getWidget()) + .setTabIndex(((TabIndexState) getState()).tabIndex); + } else { + VConsole.error("Tab index received for " + + Util.getSimpleName(getWidget()) + + " which does not implement Focusable"); + } } Profiler.leave("AbstractComponentConnector.onStateChanged update tab index"); diff --git a/client/src/com/vaadin/client/ui/FocusUtil.java b/client/src/com/vaadin/client/ui/FocusUtil.java new file mode 100644 index 0000000000..7c0fea5f6d --- /dev/null +++ b/client/src/com/vaadin/client/ui/FocusUtil.java @@ -0,0 +1,94 @@ +/* + * 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.client.ui; + +import com.google.gwt.user.client.ui.Focusable; +import com.google.gwt.user.client.ui.Widget; + +/** + * A helper class used to make it easier for {@link Widget}s to implement + * {@link Focusable}. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.3 + * + */ +public class FocusUtil { + + /** + * Sets the access key property + * + * @param focusable + * The widget for which we want to set the access key. + * @param key + * The access key to set + */ + public static void setAccessKey(Widget focusable, char key) { + assert (focusable != null && focusable.getElement() != null) : "Can't setAccessKey for a widget without an element"; + focusable.getElement().setPropertyString("accessKey", "" + key); + } + + /** + * Explicitly focus/unfocus the given widget. Only one widget can have focus + * at a time, and the widget that does will receive all keyboard events. + * + * @param focusable + * the widget to focus/unfocus + * @param focused + * whether this widget should take focus or release it + */ + public static void setFocus(Widget focusable, boolean focus) { + assert (focusable != null && focusable.getElement() != null) : "Can't setFocus for a widget without an element"; + + if (focus) { + focusable.getElement().focus(); + } else { + focusable.getElement().blur(); + } + } + + /** + * Sets the widget's position in the tab index. If more than one widget has + * the same tab index, each such widget will receive focus in an arbitrary + * order. Setting the tab index to -1 will cause the widget to + * be removed from the tab order. + * + * @param focusable + * The widget + * @param tabIndex + * the widget's tab index + */ + public static void setTabIndex(Widget focusable, int tabIndex) { + assert (focusable != null && focusable.getElement() != null) : "Can't setTabIndex for a widget without an element"; + + focusable.getElement().setTabIndex(tabIndex); + } + + /** + * Gets the widget's position in the tab index. + * + * @param focusable + * The widget + * + * @return the widget's tab index + */ + public static int getTabIndex(Widget focusable) { + assert (focusable != null && focusable.getElement() != null) : "Can't getTabIndex for a widget without an element"; + + return focusable.getElement().getTabIndex(); + } +} diff --git a/client/src/com/vaadin/client/ui/VUI.java b/client/src/com/vaadin/client/ui/VUI.java index b627d4a2a9..b07593896f 100644 --- a/client/src/com/vaadin/client/ui/VUI.java +++ b/client/src/com/vaadin/client/ui/VUI.java @@ -53,7 +53,8 @@ import com.vaadin.shared.ui.ui.UIConstants; */ public class VUI extends SimplePanel implements ResizeHandler, Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable, - HasResizeHandlers, HasScrollHandlers { + com.google.gwt.user.client.ui.Focusable, HasResizeHandlers, + HasScrollHandlers { private static int MONITOR_PARENT_TIMER_INTERVAL = 1000; @@ -437,7 +438,7 @@ public class VUI extends SimplePanel implements ResizeHandler, @Override public void focus() { - getElement().focus(); + setFocus(true); } /** @@ -462,4 +463,24 @@ public class VUI extends SimplePanel implements ResizeHandler, return addHandler(scrollHandler, ScrollEvent.getType()); } + @Override + public int getTabIndex() { + return FocusUtil.getTabIndex(this); + } + + @Override + public void setAccessKey(char key) { + FocusUtil.setAccessKey(this, key); + } + + @Override + public void setFocus(boolean focused) { + FocusUtil.setFocus(this, focused); + } + + @Override + public void setTabIndex(int index) { + FocusUtil.setTabIndex(this, index); + } + } diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 0fb7439587..ac441fc625 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -329,10 +329,6 @@ public class UIConnector extends AbstractSingleComponentContainerConnector DOM.sinkEvents(getWidget().getElement(), Event.ONKEYDOWN | Event.ONSCROLL); - // iview is focused when created so element needs tabIndex - // 1 due 0 is at the end of natural tabbing order - DOM.setElementProperty(getWidget().getElement(), "tabIndex", "1"); - RootPanel root = RootPanel.get(rootPanelId); // Remove the v-app-loading or any splash screen added inside the div by @@ -347,6 +343,10 @@ public class UIConnector extends AbstractSingleComponentContainerConnector root.add(getWidget()); + // Set default tab index before focus call. State change handler + // will update this later if needed. + getWidget().setTabIndex(1); + if (applicationConnection.getConfiguration().isStandalone()) { // set focus to iview element by default to listen possible keyboard // shortcuts. For embedded applications this is unacceptable as we diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index d12c8d89c9..796d1f08ea 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -78,7 +78,7 @@ import com.vaadin.util.CurrentInstance; * @since 7.0 */ public abstract class UI extends AbstractSingleComponentContainer implements - Action.Container, Action.Notifier, LegacyComponent { + Action.Container, Action.Notifier, LegacyComponent, Focusable { /** * The application to which this UI belongs @@ -183,6 +183,11 @@ public abstract class UI extends AbstractSingleComponentContainer implements return (UIState) super.getState(); } + @Override + protected UIState getState(boolean markAsDirty) { + return (UIState) super.getState(markAsDirty); + } + @Override public Class getStateType() { // This is a workaround for a problem with creating the correct state @@ -1039,4 +1044,14 @@ public abstract class UI extends AbstractSingleComponentContainer implements } super.setContent(content); } + + @Override + public void setTabIndex(int tabIndex) { + getState().tabIndex = tabIndex; + } + + @Override + public int getTabIndex() { + return getState(false).tabIndex; + } } diff --git a/shared/src/com/vaadin/shared/ui/ui/UIState.java b/shared/src/com/vaadin/shared/ui/ui/UIState.java index aa862ae31a..9abaf47f4b 100644 --- a/shared/src/com/vaadin/shared/ui/ui/UIState.java +++ b/shared/src/com/vaadin/shared/ui/ui/UIState.java @@ -15,10 +15,12 @@ */ package com.vaadin.shared.ui.ui; -import com.vaadin.shared.AbstractComponentState; +import com.vaadin.shared.ui.TabIndexState; -public class UIState extends AbstractComponentState { +public class UIState extends TabIndexState { { primaryStyleName = "v-ui"; + // Default is 1 for legacy reasons + tabIndex = 1; } } \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/ui/UITabIndex.html b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.html new file mode 100644 index 0000000000..fa083f1489 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.html @@ -0,0 +1,57 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.ui.UITabIndex?restartApplication
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex1
clickvaadin=runcomvaadintestscomponentsuiUITabIndex::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex-1
clickvaadin=runcomvaadintestscomponentsuiUITabIndex::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex0
clickvaadin=runcomvaadintestscomponentsuiUITabIndex::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]
assertAttributevaadin=runcomvaadintestscomponentsuiUITabIndex::@tabIndex1
+ + diff --git a/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java new file mode 100644 index 0000000000..083eaf3f7d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UITabIndex.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.components.ui; + +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.Button.ClickListener; + +public class UITabIndex extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Button b; + + b = new Button("Set tabIndex to -1"); + b.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setTabIndex(-1); + } + }); + addComponent(b); + b = new Button("Set tabIndex to 0"); + b.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setTabIndex(0); + } + }); + addComponent(b); + b = new Button("Set tabIndex to 1"); + b.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setTabIndex(1); + } + }); + addComponent(b); + } + + @Override + protected String getTestDescription() { + return "Tests tab index handling for UI"; + } + + @Override + protected Integer getTicketNumber() { + return 11129; + } + +} -- cgit v1.2.3 From 9748ed6932022abfc044913eb706d11c0a2dfec5 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 15:52:21 +0200 Subject: Fixed IE8 sub window focus issue after editing a RichTextArea #10776 Tests were merged to 7.0 in a previous commit. svn changeset:25458/svn branch:6.8 Change-Id: Ib4233f4d96311c76c104f1041f132377d357916d --- client/src/com/vaadin/client/ui/VWindow.java | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index bd9493c761..fd2a701334 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -22,6 +22,9 @@ import java.util.Comparator; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.Position; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; import com.google.gwt.event.dom.client.FocusEvent; @@ -35,6 +38,7 @@ import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; @@ -423,6 +427,36 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, // Remove window from windowOrder to avoid references being left // hanging. windowOrder.remove(this); + + /* + * If the window has a RichTextArea and the RTA is focused at the time + * of hiding in IE8 only the window will have some problems returning + * the focus to the correct place. Curiously the focus will be returned + * correctly if clicking on the "close" button in the window header but + * closing the window from a button for example in the window will fail. + * Symptom described in #10776 + * + * The problematic part is that for the focus to be returned correctly + * an input element needs to be focused in the root panel. Focusing some + * other element apparently won't work. + */ + if (BrowserInfo.get().isIE8()) { + fixIE8FocusCaptureIssue(); + } + } + + private void fixIE8FocusCaptureIssue() { + Element e = DOM.createInputText(); + Style elemStyle = e.getStyle(); + elemStyle.setPosition(Position.ABSOLUTE); + elemStyle.setLeft(-10, Unit.PX); + elemStyle.setWidth(0, Unit.PX); + elemStyle.setHeight(0, Unit.PX); + + Element rootPanel = RootPanel.getBodyElement(); + rootPanel.appendChild(e); + e.focus(); + rootPanel.removeChild(e); } /** For internal use only. May be removed or replaced in the future. */ -- cgit v1.2.3 From 21fd2028470f43825a25d9c245346827263ea875 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 12 Mar 2013 16:12:16 +0200 Subject: Unpack all static files for integration tests (#11314) Change-Id: Icef8bf0b4ec7fc752ca41cbdf38a98112e44a245 --- uitest/integration_base_files/base.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/uitest/integration_base_files/base.xml b/uitest/integration_base_files/base.xml index f9c2ff3d6b..5196aecfa9 100644 --- a/uitest/integration_base_files/base.xml +++ b/uitest/integration_base_files/base.xml @@ -28,6 +28,20 @@ + + + + + + + + + + + + + + -- cgit v1.2.3 From e47bd1e31237d24b72c0e0b7a114bff50dffc8ac Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 12 Mar 2013 16:32:31 +0200 Subject: Updated GateIn3 script to work correctly (#11314) Change-Id: Ic8a86bc2dd6f0b791047ebb4c4bc81d4a9e7b9eb --- .../integration-test-GateIn-3.1.0-portlet2.html | 99 ++++++++++------------ 1 file changed, 43 insertions(+), 56 deletions(-) diff --git a/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html b/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html index 4bc3e6a2cf..9ae3865815 100644 --- a/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html +++ b/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html @@ -32,24 +32,49 @@ 93,13 - expectDialog - //div[2]/div[2]/div[1]/div[1]/div[2] - 73,18 + mouseClickAndWait + link=Portlet + 33,11 - assertConfirmation - This action will automatically create categories and import all the gadgets and portlets on it. - + mouseClickAndWait + link=Vaadin Portlet 2.0 Test + 59,9 - waitForElementPresent - link=demo - + mouseClickAndWait + link=Click here to add into categories + 48,3 + + + mouseClickAndWait + name=category_Gadgets + 10,16 + + + mouseClickAndWait + link=Save + 4,6 mouseClickAndWait - link=Home - 65,18 + link=Vaadin Liferay Theme + 64,13 + + + mouseClickAndWait + link=Click here to add into categories + 96,9 + + + mouseClickAndWait + name=category_Gadgets + 7,12 + + + mouseClickAndWait + link=Save + 4,6 mouseClick @@ -86,24 +111,15 @@ //div[@id='UIPageCreationWizard']/div/div[3]/div/div/div/div[2]/div/table/tbody/tr/td/div[2]/div/div/div 21,13 + waitForElementPresent - //div[@id='UIPageEditor']/div[1]/div/div/div/div[2] - - - - mouseClick - //div[@onclick="javascript:ajaxGet('/portal/private/classic/home?portal:componentId=UIApplicationList&portal:action=SelectCategory&objectId=demo&ajaxRequest=true')"] - 51,11 - - - pause - 300 + //div[@id='Gadgets/JSR286TestPortlet']/div/div/div/div drag - //div[@id='demo/JSR286TestPortlet']/div/div/div[1]/div[2] + //div[@id='Gadgets/JSR286TestPortlet']/div/div/div/div @@ -111,50 +127,21 @@ //div[2]/div/div/div[1]/div/div[2]/div/div/div/div 113,9 + mouseClickAndWait //a[@onclick='eXo.core.DOMUtil.disableOnClick(this);'] 13,5 - mouseClickAndWait - //div[@id='UIPage']/div/div/div[2]/div/div/div/div/div/div/div[2]/div[5]/div/a - 10,10 - - - closeNotification - //body/div[2] - 0,0 - - - pause - 500 - - - - screenCapture - - Edit_mode - - - mouseClickAndWait - //div[@id='UIPage']/div/div/div[2]/div/div/div/div/div/div/div[2]/div[5]/div/a - 15,8 - - - closeNotification - //body/div[2] - 0,0 - - - pause - 500 + waitForElementPresent + //div[2]/div/div[2]/img screenCapture - done + view -- cgit v1.2.3 From 6b49a6dce955537ea093db85ebc50d070690820b Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 16:22:36 +0200 Subject: Eliminate connection/statement/result set leaks in TableQuery (#10582) Includes some refactoring to extract common parts of FreeformQuery and TableQuery to AbstractTransactionalQuery. svn changeset:25541/svn branch:6.8 Added missing Serializable for AbstractTransactionalQuery (#10582). svn changeset:25559/svn branch:6.8 Conflicts: server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java Change-Id: I3d055e0f071739ac4536fddb0f49b8d6b8e6d07b --- .../query/AbstractTransactionalQuery.java | 185 ++++++++++++++++++ .../util/sqlcontainer/query/FreeformQuery.java | 130 ++----------- .../data/util/sqlcontainer/query/TableQuery.java | 207 +++++++++------------ 3 files changed, 292 insertions(+), 230 deletions(-) create mode 100644 server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java new file mode 100644 index 0000000000..3264118732 --- /dev/null +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/AbstractTransactionalQuery.java @@ -0,0 +1,185 @@ +/* + * 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.data.util.sqlcontainer.query; + +import java.io.Serializable; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; + +/** + * Common base class for database query classes that handle connections and + * transactions. + * + * @author Vaadin Ltd + * @since 6.8.9 + */ +abstract class AbstractTransactionalQuery implements Serializable { + + private JDBCConnectionPool connectionPool; + private transient Connection activeConnection; + + AbstractTransactionalQuery() { + } + + AbstractTransactionalQuery(JDBCConnectionPool connectionPool) { + this.connectionPool = connectionPool; + } + + /** + * Reserves a connection with auto-commit off if no transaction is in + * progress. + * + * @throws IllegalStateException + * if a transaction is already open + * @throws SQLException + * if a connection could not be obtained or configured + */ + public void beginTransaction() throws UnsupportedOperationException, + SQLException { + if (isInTransaction()) { + throw new IllegalStateException("A transaction is already active!"); + } + activeConnection = connectionPool.reserveConnection(); + activeConnection.setAutoCommit(false); + } + + /** + * Commits (if not in auto-commit mode) and releases the active connection. + * + * @throws SQLException + * if not in a transaction managed by this query + */ + public void commit() throws UnsupportedOperationException, SQLException { + if (!isInTransaction()) { + throw new SQLException("No active transaction"); + } + if (!activeConnection.getAutoCommit()) { + activeConnection.commit(); + } + connectionPool.releaseConnection(activeConnection); + activeConnection = null; + } + + /** + * Rolls back and releases the active connection. + * + * @throws SQLException + * if not in a transaction managed by this query + */ + public void rollback() throws UnsupportedOperationException, SQLException { + if (!isInTransaction()) { + throw new SQLException("No active transaction"); + } + activeConnection.rollback(); + connectionPool.releaseConnection(activeConnection); + activeConnection = null; + } + + /** + * Check that a transaction is active. + * + * @throws SQLException + * if no active transaction + */ + protected void ensureTransaction() throws SQLException { + if (!isInTransaction()) { + throw new SQLException("No active transaction!"); + } + } + + /** + * Closes a statement and a resultset, then releases the connection if it is + * not part of an active transaction. A failure in closing one of the + * parameters does not prevent closing the rest. + * + * If the statement is a {@link PreparedStatement}, its parameters are + * cleared prior to closing the statement. + * + * Although JDBC specification does state that closing a statement closes + * its result set and closing a connection closes statements and result + * sets, this method does try to close the result set and statement + * explicitly whenever not null. This can guard against bugs in certain JDBC + * drivers and reduce leaks in case e.g. closing the result set succeeds but + * closing the statement or connection fails. + * + * @param conn + * the connection to release + * @param statement + * the statement to close, may be null to skip closing + * @param rs + * the result set to close, may be null to skip closing + * @throws SQLException + * if closing the result set or the statement fails + */ + protected void releaseConnection(Connection conn, Statement statement, + ResultSet rs) throws SQLException { + try { + try { + if (null != rs) { + rs.close(); + } + } finally { + if (null != statement) { + if (statement instanceof PreparedStatement) { + try { + ((PreparedStatement) statement).clearParameters(); + } catch (Exception e) { + // will be closed below anyway + } + } + statement.close(); + } + } + } finally { + releaseConnection(conn); + } + } + + /** + * Returns the currently active connection, reserves and returns a new + * connection if no active connection. + * + * @return previously active or newly reserved connection + * @throws SQLException + */ + protected Connection getConnection() throws SQLException { + if (activeConnection != null) { + return activeConnection; + } + return connectionPool.reserveConnection(); + } + + protected boolean isInTransaction() { + return activeConnection != null; + } + + /** + * Releases the connection if it is not part of an active transaction. + * + * @param conn + * the connection to release + */ + private void releaseConnection(Connection conn) { + if (conn != activeConnection && conn != null) { + connectionPool.releaseConnection(conn); + } + } +} diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java index 299183f5e6..6895e02147 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/FreeformQuery.java @@ -34,13 +34,12 @@ import com.vaadin.data.util.sqlcontainer.query.generator.StatementHelper; import com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder; @SuppressWarnings("serial") -public class FreeformQuery implements QueryDelegate { +public class FreeformQuery extends AbstractTransactionalQuery implements + QueryDelegate { FreeformQueryDelegate delegate = null; private String queryString; private List primaryKeyColumns; - private JDBCConnectionPool connectionPool; - private transient Connection activeConnection = null; /** * Prevent no-parameters instantiation of FreeformQuery @@ -67,6 +66,7 @@ public class FreeformQuery implements QueryDelegate { @Deprecated public FreeformQuery(String queryString, List primaryKeyColumns, JDBCConnectionPool connectionPool) { + super(connectionPool); if (primaryKeyColumns == null) { primaryKeyColumns = new ArrayList(); } @@ -83,7 +83,6 @@ public class FreeformQuery implements QueryDelegate { this.queryString = queryString; this.primaryKeyColumns = Collections .unmodifiableList(primaryKeyColumns); - this.connectionPool = connectionPool; } /** @@ -189,13 +188,6 @@ public class FreeformQuery implements QueryDelegate { return count; } - private Connection getConnection() throws SQLException { - if (activeConnection != null) { - return activeConnection; - } - return connectionPool.reserveConnection(); - } - /** * Fetches the results for the query. This implementation always fetches the * entire record set, ignoring the offset and page length parameters. In @@ -210,9 +202,7 @@ public class FreeformQuery implements QueryDelegate { @Override @SuppressWarnings({ "deprecation", "finally" }) public ResultSet getResults(int offset, int pagelength) throws SQLException { - if (activeConnection == null) { - throw new SQLException("No active transaction!"); - } + ensureTransaction(); String query = queryString; if (delegate != null) { /* First try using prepared statement */ @@ -220,8 +210,8 @@ public class FreeformQuery implements QueryDelegate { try { StatementHelper sh = ((FreeformStatementDelegate) delegate) .getQueryStatement(offset, pagelength); - PreparedStatement pstmt = activeConnection - .prepareStatement(sh.getQueryString()); + PreparedStatement pstmt = getConnection().prepareStatement( + sh.getQueryString()); sh.setParameterValuesToStatement(pstmt); return pstmt.executeQuery(); } catch (UnsupportedOperationException e) { @@ -234,7 +224,7 @@ public class FreeformQuery implements QueryDelegate { // This is fine, we'll just use the default queryString. } } - Statement statement = activeConnection.createStatement(); + Statement statement = getConnection().createStatement(); ResultSet rs; try { rs = statement.executeQuery(query); @@ -322,14 +312,14 @@ public class FreeformQuery implements QueryDelegate { */ @Override public int storeRow(RowItem row) throws SQLException { - if (activeConnection == null) { + if (!isInTransaction()) { throw new IllegalStateException("No transaction is active!"); } else if (primaryKeyColumns.isEmpty()) { throw new UnsupportedOperationException( "Cannot store items fetched with a read-only freeform query!"); } if (delegate != null) { - return delegate.storeRow(activeConnection, row); + return delegate.storeRow(getConnection(), row); } else { throw new UnsupportedOperationException( "FreeFormQueryDelegate not set!"); @@ -345,68 +335,36 @@ public class FreeformQuery implements QueryDelegate { */ @Override public boolean removeRow(RowItem row) throws SQLException { - if (activeConnection == null) { + if (!isInTransaction()) { throw new IllegalStateException("No transaction is active!"); } else if (primaryKeyColumns.isEmpty()) { throw new UnsupportedOperationException( "Cannot remove items fetched with a read-only freeform query!"); } if (delegate != null) { - return delegate.removeRow(activeConnection, row); + return delegate.removeRow(getConnection(), row); } else { throw new UnsupportedOperationException( "FreeFormQueryDelegate not set!"); } } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.data.util.sqlcontainer.query.QueryDelegate#beginTransaction() - */ @Override public synchronized void beginTransaction() throws UnsupportedOperationException, SQLException { - if (activeConnection != null) { - throw new IllegalStateException("A transaction is already active!"); - } - activeConnection = connectionPool.reserveConnection(); - activeConnection.setAutoCommit(false); + super.beginTransaction(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.data.util.sqlcontainer.query.QueryDelegate#commit() - */ @Override public synchronized void commit() throws UnsupportedOperationException, SQLException { - if (activeConnection == null) { - throw new SQLException("No active transaction"); - } - if (!activeConnection.getAutoCommit()) { - activeConnection.commit(); - } - connectionPool.releaseConnection(activeConnection); - activeConnection = null; + super.commit(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.data.util.sqlcontainer.query.QueryDelegate#rollback() - */ @Override public synchronized void rollback() throws UnsupportedOperationException, SQLException { - if (activeConnection == null) { - throw new SQLException("No active transaction"); - } - activeConnection.rollback(); - connectionPool.releaseConnection(activeConnection); - activeConnection = null; + super.rollback(); } /* @@ -492,66 +450,6 @@ public class FreeformQuery implements QueryDelegate { return contains; } - /** - * Releases the connection if it is not part of an active transaction. - * - * @param conn - * the connection to release - */ - private void releaseConnection(Connection conn) { - if (conn != activeConnection) { - connectionPool.releaseConnection(conn); - } - } - - /** - * Closes a statement and a resultset, then releases the connection if it is - * not part of an active transaction. A failure in closing one of the - * parameters does not prevent closing the rest. - * - * If the statement is a {@link PreparedStatement}, its parameters are - * cleared prior to closing the statement. - * - * Although JDBC specification does state that closing a statement closes - * its result set and closing a connection closes statements and result - * sets, this method does try to close the result set and statement - * explicitly whenever not null. This can guard against bugs in certain JDBC - * drivers and reduce leaks in case e.g. closing the result set succeeds but - * closing the statement or connection fails. - * - * @param conn - * the connection to release - * @param statement - * the statement to close, may be null to skip closing - * @param rs - * the result set to close, may be null to skip closing - * @throws SQLException - * if closing the result set or the statement fails - */ - private void releaseConnection(Connection conn, Statement statement, - ResultSet rs) throws SQLException { - try { - try { - if (null != rs) { - rs.close(); - } - } finally { - if (null != statement) { - if (statement instanceof PreparedStatement) { - try { - ((PreparedStatement) statement).clearParameters(); - } catch (Exception e) { - // will be closed below anyway - } - } - statement.close(); - } - } - } finally { - releaseConnection(conn); - } - } - private String modifyWhereClause(Object... keys) { // Build the where rules for the provided keys StringBuffer where = new StringBuffer(); diff --git a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java index 63e4b3362c..caed5526e3 100644 --- a/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java +++ b/server/src/com/vaadin/data/util/sqlcontainer/query/TableQuery.java @@ -47,8 +47,8 @@ import com.vaadin.data.util.sqlcontainer.query.generator.SQLGenerator; import com.vaadin.data.util.sqlcontainer.query.generator.StatementHelper; @SuppressWarnings("serial") -public class TableQuery implements QueryDelegate, - QueryDelegate.RowIdChangeNotifier { +public class TableQuery extends AbstractTransactionalQuery implements + QueryDelegate, QueryDelegate.RowIdChangeNotifier { /** Table name, primary key column name(s) and version column name */ private String tableName; @@ -62,18 +62,13 @@ public class TableQuery implements QueryDelegate, /** SQLGenerator instance to use for generating queries */ private SQLGenerator sqlGenerator; - /** Fields related to Connection and Transaction handling */ - private JDBCConnectionPool connectionPool; - private transient Connection activeConnection; - private boolean transactionOpen; - /** Row ID change listeners */ private LinkedList rowIdChangeListeners; /** Row ID change events, stored until commit() is called */ private final List bufferedEvents = new ArrayList(); /** Set to true to output generated SQL Queries to System.out */ - private boolean debug = false; + private final boolean debug = false; /** Prevent no-parameters instantiation of TableQuery */ @SuppressWarnings("unused") @@ -93,6 +88,7 @@ public class TableQuery implements QueryDelegate, */ public TableQuery(String tableName, JDBCConnectionPool connectionPool, SQLGenerator sqlGenerator) { + super(connectionPool); if (tableName == null || tableName.trim().length() < 1 || connectionPool == null || sqlGenerator == null) { throw new IllegalArgumentException( @@ -100,7 +96,6 @@ public class TableQuery implements QueryDelegate, } this.tableName = tableName; this.sqlGenerator = sqlGenerator; - this.connectionPool = connectionPool; fetchMetaData(); } @@ -129,17 +124,27 @@ public class TableQuery implements QueryDelegate, StatementHelper sh = sqlGenerator.generateSelectQuery(tableName, filters, null, 0, 0, "COUNT(*)"); boolean shouldCloseTransaction = false; - if (!transactionOpen) { + if (!isInTransaction()) { shouldCloseTransaction = true; beginTransaction(); } - ResultSet r = executeQuery(sh); - r.next(); - int count = r.getInt(1); - r.getStatement().close(); - r.close(); - if (shouldCloseTransaction) { - commit(); + ResultSet r = null; + int count = -1; + try { + r = executeQuery(sh); + r.next(); + count = r.getInt(1); + } finally { + try { + if (r != null) { + releaseConnection(r.getStatement().getConnection(), + r.getStatement(), r); + } + } finally { + if (shouldCloseTransaction) { + commit(); + } + } } return count; } @@ -240,28 +245,30 @@ public class TableQuery implements QueryDelegate, setVersionColumnFlagInProperty(row); /* Generate query */ StatementHelper sh = sqlGenerator.generateInsertQuery(tableName, row); - PreparedStatement pstmt = activeConnection.prepareStatement( - sh.getQueryString(), primaryKeyColumns.toArray(new String[0])); - sh.setParameterValuesToStatement(pstmt); - getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); - int result = pstmt.executeUpdate(); - if (result > 0) { - /* - * If affected rows exist, we'll get the new RowId, commit the - * transaction and return the new RowId. - */ - ResultSet generatedKeys = pstmt.getGeneratedKeys(); - RowId newId = getNewRowId(row, generatedKeys); - generatedKeys.close(); - pstmt.clearParameters(); - pstmt.close(); + Connection connection = null; + PreparedStatement pstmt = null; + ResultSet generatedKeys = null; + connection = getConnection(); + try { + pstmt = connection.prepareStatement(sh.getQueryString(), + primaryKeyColumns.toArray(new String[0])); + sh.setParameterValuesToStatement(pstmt); + getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); + int result = pstmt.executeUpdate(); + RowId newId = null; + if (result > 0) { + /* + * If affected rows exist, we'll get the new RowId, commit the + * transaction and return the new RowId. + */ + generatedKeys = pstmt.getGeneratedKeys(); + newId = getNewRowId(row, generatedKeys); + } + // transaction has to be closed in any case commit(); return newId; - } else { - pstmt.clearParameters(); - pstmt.close(); - /* On failure return null */ - return null; + } finally { + releaseConnection(connection, pstmt, generatedKeys); } } @@ -307,14 +314,8 @@ public class TableQuery implements QueryDelegate, @Override public void beginTransaction() throws UnsupportedOperationException, SQLException { - if (transactionOpen && activeConnection != null) { - throw new IllegalStateException(); - } - getLogger().log(Level.FINE, "DB -> begin transaction"); - activeConnection = connectionPool.reserveConnection(); - activeConnection.setAutoCommit(false); - transactionOpen = true; + super.beginTransaction(); } /* @@ -324,14 +325,8 @@ public class TableQuery implements QueryDelegate, */ @Override public void commit() throws UnsupportedOperationException, SQLException { - if (transactionOpen && activeConnection != null) { - getLogger().log(Level.FINE, "DB -> commit"); - activeConnection.commit(); - connectionPool.releaseConnection(activeConnection); - } else { - throw new SQLException("No active transaction"); - } - transactionOpen = false; + getLogger().log(Level.FINE, "DB -> commit"); + super.commit(); /* Handle firing row ID change events */ RowIdChangeEvent[] unFiredEvents = bufferedEvents @@ -353,14 +348,8 @@ public class TableQuery implements QueryDelegate, */ @Override public void rollback() throws UnsupportedOperationException, SQLException { - if (transactionOpen && activeConnection != null) { - getLogger().log(Level.FINE, "DB -> rollback"); - activeConnection.rollback(); - connectionPool.releaseConnection(activeConnection); - } else { - throw new SQLException("No active transaction"); - } - transactionOpen = false; + getLogger().log(Level.FINE, "DB -> rollback"); + super.rollback(); } /* @@ -402,16 +391,18 @@ public class TableQuery implements QueryDelegate, * @throws SQLException */ private ResultSet executeQuery(StatementHelper sh) throws SQLException { - Connection c = null; - if (transactionOpen && activeConnection != null) { - c = activeConnection; - } else { - throw new SQLException("No active transaction!"); + ensureTransaction(); + Connection connection = getConnection(); + PreparedStatement pstmt = null; + try { + pstmt = connection.prepareStatement(sh.getQueryString()); + sh.setParameterValuesToStatement(pstmt); + getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); + return pstmt.executeQuery(); + } catch (SQLException e) { + releaseConnection(null, pstmt, null); + throw e; } - PreparedStatement pstmt = c.prepareStatement(sh.getQueryString()); - sh.setParameterValuesToStatement(pstmt); - getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); - return pstmt.executeQuery(); } /** @@ -426,27 +417,17 @@ public class TableQuery implements QueryDelegate, * @throws SQLException */ private int executeUpdate(StatementHelper sh) throws SQLException { - Connection c = null; PreparedStatement pstmt = null; + Connection connection = null; try { - if (transactionOpen && activeConnection != null) { - c = activeConnection; - } else { - c = connectionPool.reserveConnection(); - } - pstmt = c.prepareStatement(sh.getQueryString()); + connection = getConnection(); + pstmt = connection.prepareStatement(sh.getQueryString()); sh.setParameterValuesToStatement(pstmt); getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); int retval = pstmt.executeUpdate(); return retval; } finally { - if (pstmt != null) { - pstmt.clearParameters(); - pstmt.close(); - } - if (!transactionOpen) { - connectionPool.releaseConnection(c); - } + releaseConnection(connection, pstmt, null); } } @@ -467,16 +448,12 @@ public class TableQuery implements QueryDelegate, */ private int executeUpdateReturnKeys(StatementHelper sh, RowItem row) throws SQLException { - Connection c = null; PreparedStatement pstmt = null; ResultSet genKeys = null; + Connection connection = null; try { - if (transactionOpen && activeConnection != null) { - c = activeConnection; - } else { - c = connectionPool.reserveConnection(); - } - pstmt = c.prepareStatement(sh.getQueryString(), + connection = getConnection(); + pstmt = connection.prepareStatement(sh.getQueryString(), primaryKeyColumns.toArray(new String[0])); sh.setParameterValuesToStatement(pstmt); getLogger().log(Level.FINE, "DB -> {0}", sh.getQueryString()); @@ -486,16 +463,7 @@ public class TableQuery implements QueryDelegate, bufferedEvents.add(new RowIdChangeEvent(row.getId(), newId)); return result; } finally { - if (genKeys != null) { - genKeys.close(); - } - if (pstmt != null) { - pstmt.clearParameters(); - pstmt.close(); - } - if (!transactionOpen) { - connectionPool.releaseConnection(c); - } + releaseConnection(connection, pstmt, genKeys); } } @@ -505,13 +473,15 @@ public class TableQuery implements QueryDelegate, * Also tries to get the escape string to be used in search strings. */ private void fetchMetaData() { - Connection c = null; + Connection connection = null; + ResultSet rs = null; + ResultSet tables = null; try { - c = connectionPool.reserveConnection(); - DatabaseMetaData dbmd = c.getMetaData(); + connection = getConnection(); + DatabaseMetaData dbmd = connection.getMetaData(); if (dbmd != null) { tableName = SQLUtil.escapeSQL(tableName); - ResultSet tables = dbmd.getTables(null, null, tableName, null); + tables = dbmd.getTables(null, null, tableName, null); if (!tables.next()) { tables = dbmd.getTables(null, null, tableName.toUpperCase(), null); @@ -525,7 +495,7 @@ public class TableQuery implements QueryDelegate, } } tables.close(); - ResultSet rs = dbmd.getPrimaryKeys(null, null, tableName); + rs = dbmd.getPrimaryKeys(null, null, tableName); List names = new ArrayList(); while (rs.next()) { names.add(rs.getString("COLUMN_NAME")); @@ -554,7 +524,15 @@ public class TableQuery implements QueryDelegate, } catch (SQLException e) { throw new RuntimeException(e); } finally { - connectionPool.releaseConnection(c); + try { + releaseConnection(connection, null, rs); + } catch (SQLException ignore) { + } finally { + try { + tables.close(); + } catch (SQLException ignore) { + } + } } } @@ -648,7 +626,7 @@ public class TableQuery implements QueryDelegate, filtersAndKeys, orderBys, 0, 0, "*"); boolean shouldCloseTransaction = false; - if (!transactionOpen) { + if (!isInTransaction()) { shouldCloseTransaction = true; beginTransaction(); } @@ -658,14 +636,15 @@ public class TableQuery implements QueryDelegate, boolean contains = rs.next(); return contains; } finally { - if (rs != null) { - if (rs.getStatement() != null) { - rs.getStatement().close(); + try { + if (rs != null) { + releaseConnection(rs.getStatement().getConnection(), + rs.getStatement(), rs); + } + } finally { + if (shouldCloseTransaction) { + commit(); } - rs.close(); - } - if (shouldCloseTransaction) { - commit(); } } } -- cgit v1.2.3 From 0d75be99df6075f86ceb48ef4e430411cf47a854 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 18:44:16 +0200 Subject: Ensure nonwrapping textarea has white-space: pre; style (#10536) Change-Id: Iaac6b58d204082374827cb7b6caef5f5f81e3dbc --- client/src/com/vaadin/client/ui/VTextArea.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 6e93a076d9..139cd87ca4 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -18,6 +18,7 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Style.Overflow; +import com.google.gwt.dom.client.Style.WhiteSpace; import com.google.gwt.dom.client.TextAreaElement; import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ChangeHandler; @@ -154,9 +155,11 @@ public class VTextArea extends VTextField { if (wordwrap) { getElement().removeAttribute("wrap"); getElement().getStyle().clearOverflow(); + getElement().getStyle().clearWhiteSpace(); } else { getElement().setAttribute("wrap", "off"); getElement().getStyle().setOverflow(Overflow.AUTO); + getElement().getStyle().setWhiteSpace(WhiteSpace.PRE); } if (BrowserInfo.get().isOpera()) { // Opera fails to dynamically update the wrap attribute so we detach -- cgit v1.2.3 From 371259c75868469b4c16a16bef29299f4664cc26 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 09:11:19 +0200 Subject: Fixed header to make checkstyles happy (#11129) Change-Id: I4f1da57d318407da6a47a7095dbe4a08a6acc0f7 --- client/src/com/vaadin/client/ui/FocusUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/com/vaadin/client/ui/FocusUtil.java b/client/src/com/vaadin/client/ui/FocusUtil.java index 7c0fea5f6d..8de3f767bd 100644 --- a/client/src/com/vaadin/client/ui/FocusUtil.java +++ b/client/src/com/vaadin/client/ui/FocusUtil.java @@ -1,12 +1,12 @@ /* * 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 -- cgit v1.2.3 From 531c7873e79dd89be9189b49500ecbc72b7e5c90 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 13 Mar 2013 10:12:32 +0200 Subject: Updated supported browser versions in release notes (#10887) Based on svn changeset:25626/svn branch:6.8 Change-Id: I76333c1af0eab1d727a03dcd82ae6b9b7187e58a --- WebContent/release-notes.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WebContent/release-notes.html b/WebContent/release-notes.html index 39b6652532..0f49e819b0 100644 --- a/WebContent/release-notes.html +++ b/WebContent/release-notes.html @@ -658,12 +658,12 @@

    -
  • Mozilla Firefox 18
  • +
  • Mozilla Firefox 18-19
  • Mozilla Firefox 17 ESR
  • Internet Explorer 8-10
  • Safari 6
  • Opera 12
  • -
  • Google Chrome 23
  • +
  • Google Chrome 23-25

-- cgit v1.2.3 From 6b83d70033b95ea573b2f20b3fadfcd3c21f7621 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 10:35:03 +0200 Subject: Fixed Tree keyboard navigation in Opera 12 (#11183) Change-Id: I6bbd486caef0056703d1b9ebc1ba5537aca75cfd --- client/src/com/vaadin/client/ui/VTree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/com/vaadin/client/ui/VTree.java b/client/src/com/vaadin/client/ui/VTree.java index 809ed9c82d..624dce4f13 100644 --- a/client/src/com/vaadin/client/ui/VTree.java +++ b/client/src/com/vaadin/client/ui/VTree.java @@ -189,7 +189,7 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, * handler, other browsers handle it correctly when using a key down * handler */ - if (BrowserInfo.get().isGecko() || BrowserInfo.get().isOpera()) { + if (BrowserInfo.get().isGecko()) { addKeyPressHandler(this); } else { addKeyDownHandler(this); -- cgit v1.2.3 From 499e13878e3cb3711b21c21406166cee72ba98bf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 10:35:41 +0200 Subject: Test using Opera 12 (#8976) Change-Id: I6e72f8ecb0fbd52b6774956ed2c904a060dc1424 --- uitest/test.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uitest/test.xml b/uitest/test.xml index 8f65841744..ee4927fc7b 100644 --- a/uitest/test.xml +++ b/uitest/test.xml @@ -8,7 +8,7 @@ - + -- cgit v1.2.3 From 5cba827316eed64508ffb254edb95f303f44eab9 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 11:14:24 +0200 Subject: Fixed client-server value sync problem in CheckBox (#11028) Change-Id: I1bac8e8a746bcc97b3ce929e76cf3476ad793bf6 --- server/src/com/vaadin/ui/CheckBox.java | 17 +++++ .../tests/components/AbstractTestUIWithLog.java | 36 ++++++++++ .../checkbox/CheckBoxRevertValueChange.html | 82 ++++++++++++++++++++++ .../checkbox/CheckBoxRevertValueChange.java | 65 +++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html create mode 100644 uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 0ace0a4f26..ac33f5e410 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import org.json.JSONException; + import com.vaadin.data.Property; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; @@ -37,6 +39,21 @@ public class CheckBox extends AbstractField { return; } + /* + * Client side updates the state before sending the event so we need + * to make sure the cached state is updated to match the client. If + * we do not do this, a reverting setValue() call in a listener will + * not cause the new state to be sent to the client. + * + * See #11028, #10030. + */ + try { + getUI().getConnectorTracker().getDiffState(CheckBox.this) + .put("checked", checked); + } catch (JSONException e) { + throw new RuntimeException(e); + } + final Boolean oldValue = getValue(); final Boolean newValue = checked; diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java b/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java new file mode 100644 index 0000000000..cace7c3404 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUIWithLog.java @@ -0,0 +1,36 @@ +/* + * 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.components; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.VerticalLayout; + +public abstract class AbstractTestUIWithLog extends AbstractTestUI { + + protected Log log = new Log(5); + + @Override + public void init(VaadinRequest request) { + super.init(request); + ((VerticalLayout) getContent()).addComponent(log, 0); + } + + protected void log(String message) { + log.log(message); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html new file mode 100644 index 0000000000..ea5849f99f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.html @@ -0,0 +1,82 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.checkbox.CheckBoxRevertValueChange?restartApplication
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]10,5
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_01. I said no checking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]off
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[1]93,10
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_02. I said no checking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[0]/VCheckBox[0]/domChild[0]off
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]5,8
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_03. I said no unchecking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]on
mouseClickvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[1]78,12
assertTextvaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::PID_SLog_row_04. I said no unchecking!
assertValuevaadin=runcomvaadintestscomponentscheckboxCheckBoxRevertValueChange::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]on
+ + diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java new file mode 100644 index 0000000000..5b086fb935 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckBoxRevertValueChange.java @@ -0,0 +1,65 @@ +/* + * 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.components.checkbox; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.data.Property; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.CheckBox; + +@PreserveOnRefresh +public class CheckBoxRevertValueChange extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final CheckBox alwaysUnchecked = new CheckBox("You may not check me"); + alwaysUnchecked + .addValueChangeListener(new Property.ValueChangeListener() { + public void valueChange(Property.ValueChangeEvent event) { + if (alwaysUnchecked.getValue()) { + log("I said no checking!"); + alwaysUnchecked.setValue(false); + } + } + }); + final CheckBox alwaysChecked = new CheckBox("You may not uncheck me"); + alwaysChecked.setValue(true); + alwaysChecked + .addValueChangeListener(new Property.ValueChangeListener() { + public void valueChange(Property.ValueChangeEvent event) { + if (!alwaysChecked.getValue()) { + log("I said no unchecking!"); + alwaysChecked.setValue(true); + } + } + }); + + addComponent(alwaysUnchecked); + addComponent(alwaysChecked); + } + + @Override + protected String getTestDescription() { + return "Ensure checking of a checkbox can be reverted on the server side without making the client go out of sync"; + } + + @Override + protected Integer getTicketNumber() { + return 11028; + } + +} -- cgit v1.2.3 From 749fd7085ec2db6af0b4f401378b2694be3626c7 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 13 Mar 2013 13:50:44 +0200 Subject: Added missing state update on the client side (#11028) Change-Id: I547f6e6426208d788b92ea8f429d4bb0aa9fdf24 --- client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java index 014ea849a2..772419e730 100644 --- a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java +++ b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java @@ -143,11 +143,13 @@ public class CheckBoxConnector extends AbstractFieldConnector implements return; } + getState().checked = getWidget().getValue(); + // Add mouse details MouseEventDetails details = MouseEventDetailsBuilder .buildMouseEventDetails(event.getNativeEvent(), getWidget() .getElement()); - getRpcProxy(CheckBoxServerRpc.class).setChecked(getWidget().getValue(), + getRpcProxy(CheckBoxServerRpc.class).setChecked(getState().checked, details); } -- cgit v1.2.3 From d2d4279e9946f9b193c0b706ecad9e01a5bf77c3 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 13 Mar 2013 09:50:41 +0200 Subject: Fixed setting column width back to undefined by setting it to -1. #7922 svn changeset:25591/svn branch:6.8 Conflicts: server/src/com/vaadin/ui/Table.java Reverted change included by mistake in changeset [25591] for #7922 svn changeset:25606/svn branch:6.8 Change-Id: I6765a52ab213c131cca053227ee72b0007552f7f --- client/src/com/vaadin/client/ui/VScrollTable.java | 24 +++++-- server/src/com/vaadin/ui/Table.java | 71 ++++++++++++------ .../table/TableColumnWidthsAndExpandRatios.html | 83 ++++++++++++++++++++++ .../table/TableColumnWidthsAndExpandRatios.java | 57 +++++++++++++++ 4 files changed, 208 insertions(+), 27 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html create mode 100644 uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 6f9fd6da88..4d61fba429 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -3056,7 +3056,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets, .hasNext(); columnIndex++) { if (it.next() == this) { break; - } + } } } final int cw = scrollBody.getColWidth(columnIndex); @@ -3266,10 +3266,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, } if (col.hasAttribute("width")) { - final String widthStr = col.getStringAttribute("width"); // Make sure to accomodate for the sort indicator if // necessary. - int width = Integer.parseInt(widthStr); + int width = col.getIntAttribute("width"); int widthWithoutAddedIndent = width; // get min width with indent, no padding @@ -3301,12 +3300,25 @@ public class VScrollTable extends FlowPanel implements HasWidgets, // save min width without indent c.setWidth(widthWithoutAddedIndent, true); } + } else if (col.hasAttribute("er")) { + c.setExpandRatio(col.getFloatAttribute("er")); + } else if (recalcWidths) { c.setUndefinedWidth(); + + } else { + boolean hadExpandRatio = c.getExpandRatio() > 0; + boolean hadDefinedWidth = c.isDefinedWidth(); + if (hadExpandRatio || hadDefinedWidth) { + // Someone has removed a expand width or the defined + // width on the server side (setting it to -1), make the + // column undefined again and measure columns again. + c.setUndefinedWidth(); + c.setExpandRatio(0); + refreshContentWidths = true; + } } - if (col.hasAttribute("er")) { - c.setExpandRatio(col.getFloatAttribute("er")); - } + if (col.hasAttribute("collapsed")) { // ensure header is properly removed from parent (case when // collapsing happens via servers side api) diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 641c0ff1f6..3d7cb42050 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -396,10 +396,14 @@ public class Table extends AbstractSelect implements Action.Container, private HashMap columnAlignments = new HashMap(); /** - * Holds column widths in pixels (Integer) or expand ratios (Float) for - * visible columns (by propertyId). + * Holds column widths in pixels for visible columns (by propertyId). */ - private final HashMap columnWidths = new HashMap(); + private final HashMap columnWidths = new HashMap(); + + /** + * Holds column expand rations for visible columns (by propertyId). + */ + private final HashMap columnExpandRatios = new HashMap(); /** * Holds column generators @@ -886,10 +890,14 @@ public class Table extends AbstractSelect implements Action.Container, // id to store the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } + + // Setting column width should remove any expand ratios as well + columnExpandRatios.remove(propertyId); + if (width < 0) { columnWidths.remove(propertyId); } else { - columnWidths.put(propertyId, Integer.valueOf(width)); + columnWidths.put(propertyId, width); } markAsDirty(); } @@ -930,21 +938,39 @@ public class Table extends AbstractSelect implements Action.Container, * the expandRatio used to divide excess space for this column */ public void setColumnExpandRatio(Object propertyId, float expandRatio) { + if (propertyId == null) { + // Since propertyId is null, this is the row header. Use the magic + // id to store the width of the row header. + propertyId = ROW_HEADER_FAKE_PROPERTY_ID; + } + + // Setting the column expand ratio should remove and defined column + // width + columnWidths.remove(propertyId); + if (expandRatio < 0) { - columnWidths.remove(propertyId); + columnExpandRatios.remove(propertyId); } else { - columnWidths.put(propertyId, new Float(expandRatio)); + columnExpandRatios.put(propertyId, expandRatio); } + + requestRepaint(); } + /** + * Gets the column expand ratio for a columnd. See + * {@link #setColumnExpandRatio(Object, float)} + * + * @param propertyId + * columns property id + * @return the expandRatio used to divide excess space for this column + */ public float getColumnExpandRatio(Object propertyId) { - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Float)) { + final Float width = columnExpandRatios.get(propertyId); + if (width == null) { return -1; } - final Float value = (Float) width; - return value.floatValue(); - + return width.floatValue(); } /** @@ -959,12 +985,11 @@ public class Table extends AbstractSelect implements Action.Container, // id to retrieve the width of the row header. propertyId = ROW_HEADER_FAKE_PROPERTY_ID; } - final Object width = columnWidths.get(propertyId); - if (width == null || !(width instanceof Integer)) { + final Integer width = columnWidths.get(propertyId); + if (width == null) { return -1; } - final Integer value = (Integer) width; - return value.intValue(); + return width.intValue(); } /** @@ -3434,6 +3459,7 @@ public class Table extends AbstractSelect implements Action.Container, target.startTag("column"); target.addAttribute("cid", ROW_HEADER_COLUMN_KEY); paintColumnWidth(target, ROW_HEADER_FAKE_PROPERTY_ID); + paintColumnExpandRatio(target, ROW_HEADER_FAKE_PROPERTY_ID); target.endTag("column"); } final Collection sortables = getSortableContainerPropertyIds(); @@ -3461,6 +3487,7 @@ public class Table extends AbstractSelect implements Action.Container, .toString()); } paintColumnWidth(target, colId); + paintColumnExpandRatio(target, colId); target.endTag("column"); } } @@ -3706,12 +3733,14 @@ public class Table extends AbstractSelect implements Action.Container, private void paintColumnWidth(PaintTarget target, final Object columnId) throws PaintException { if (columnWidths.containsKey(columnId)) { - if (getColumnWidth(columnId) > -1) { - target.addAttribute("width", - String.valueOf(getColumnWidth(columnId))); - } else { - target.addAttribute("er", getColumnExpandRatio(columnId)); - } + target.addAttribute("width", getColumnWidth(columnId)); + } + } + + private void paintColumnExpandRatio(PaintTarget target, + final Object columnId) throws PaintException { + if (columnExpandRatios.containsKey(columnId)) { + target.addAttribute("er", getColumnExpandRatio(columnId)); } } diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html new file mode 100644 index 0000000000..75d98ce2e6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.html @@ -0,0 +1,83 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.table.TableColumnWidthsAndExpandRatios?restartApplication
screenCaptureinitial-all-columns-undefined
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[1]/domChild[0]-300,0
dragAndDropvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]-300,0
screenCapturecolumns-defined-width
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[0]/VNativeButton[0]114,4
screenCapturecolumn1-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[1]/VNativeButton[0]98,13
screenCapturecolumn2-undefined
mouseClickvaadin=runcomvaadintestscomponentstableTableColumnWidthsAndExpandRatios::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VHorizontalLayout[0]/ChildComponentContainer[2]/VNativeButton[0]40,10
screenCapturecolumns-undefined-width
+ + diff --git a/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java new file mode 100644 index 0000000000..747c99468f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TableColumnWidthsAndExpandRatios.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.Table; + +public class TableColumnWidthsAndExpandRatios extends TestBase { + + @Override + protected void setup() { + getLayout().setSizeFull(); + + final Table table = new Table(); + table.setSizeFull(); + + table.addContainerProperty("column1", String.class, "Humpty"); + table.addContainerProperty("column2", String.class, "Dumpty"); + table.addContainerProperty("column3", String.class, "Doe"); + + for (int row = 0; row < 100; row++) { + table.addItem(); + } + + HorizontalLayout buttons = new HorizontalLayout(); + for (Object col : table.getContainerPropertyIds()) { + buttons.addComponent(createResetButton(col, table)); + } + + addComponent(table); + addComponent(buttons); + } + + private NativeButton createResetButton(final Object property, + final Table table) { + return new NativeButton("Reset " + property + " width", + new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + table.setColumnWidth(property, -1); + } + }); + } + + @Override + protected String getDescription() { + return "Changing column width to -1 should remove any previous size measurements"; + } + + @Override + protected Integer getTicketNumber() { + return 7922; + } + +} -- cgit v1.2.3 From a9d93e91ad4c70272c0714f4b92032800100a6af Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Thu, 14 Mar 2013 15:18:06 +0200 Subject: Ignored test case where Tree memory leak is checked since it cannot be fixed before 7.1 (no-merge) #11053 Change-Id: I723b7fc01184da19f448de4c43d3dee715c01242 --- .../tests/server/component/tree/TreeTest.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java index c1d7653c01..634e6a86f3 100644 --- a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java @@ -1,24 +1,31 @@ package com.vaadin.tests.server.component.tree; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.lang.reflect.Field; import java.util.HashSet; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; import com.vaadin.data.Container; import com.vaadin.data.util.HierarchicalContainer; import com.vaadin.data.util.IndexedContainer; import com.vaadin.ui.Tree; -public class TreeTest extends TestCase { +public class TreeTest { private Tree tree; private Tree tree2; private Tree tree3; private Tree tree4; - @Override - protected void setUp() { + @Before + public void setUp() { tree = new Tree(); tree.addItem("parent"); tree.addItem("child"); @@ -44,6 +51,7 @@ public class TreeTest extends TestCase { tree4.setParent("child", "parent"); } + @Test public void testRemoveChildren() { assertTrue(tree.hasChildren("parent")); tree.removeItem("child"); @@ -62,6 +70,7 @@ public class TreeTest extends TestCase { assertFalse(tree4.hasChildren("parent")); } + @Test public void testContainerTypeIsHierarchical() { assertTrue(HierarchicalContainer.class.isAssignableFrom(tree .getContainerDataSource().getClass())); @@ -75,6 +84,11 @@ public class TreeTest extends TestCase { .getContainerDataSource().getClass())); } + @Ignore("This test tests that item ids which are removed are also " + + "removed from the expand list to prevent a memory leak. " + + "Fixing the memory leak cannot be done without changing some API (see #11053) " + + "so ignoring this test for the 7.0.x series.") + @Test public void testRemoveExpandedItems() throws Exception { tree.expandItem("parent"); tree.expandItem("child"); @@ -113,6 +127,7 @@ public class TreeTest extends TestCase { assertNull(expandedItemId); } + @Test public void testRemoveExpandedItemsOnContainerChange() throws Exception { tree.expandItem("parent"); tree.expandItem("child"); -- cgit v1.2.3 From 781fc2a5e8e213b4d135de13c9b1c2a185eec025 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 14 Mar 2013 16:30:31 +0200 Subject: Deprecated TestBase to avoid new tests which are LegacyApplications Change-Id: Ic4bc242b6d2707e7a856256ca7eeddc4efd9eb83 --- uitest/src/com/vaadin/tests/components/TestBase.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/uitest/src/com/vaadin/tests/components/TestBase.java b/uitest/src/com/vaadin/tests/components/TestBase.java index d267d80669..15f39f6e5d 100644 --- a/uitest/src/com/vaadin/tests/components/TestBase.java +++ b/uitest/src/com/vaadin/tests/components/TestBase.java @@ -6,6 +6,12 @@ import com.vaadin.ui.Label; import com.vaadin.ui.LegacyWindow; import com.vaadin.ui.VerticalLayout; +/** + * + * @deprecated Use {@link AbstractTestUI} or {@link AbstractTestUIWithLog} + * instead. TestBase is a LegacyApplication + */ +@Deprecated public abstract class TestBase extends AbstractTestCase { @Override -- cgit v1.2.3 From 12228618971e94fee1264a2e5018a1d24be64137 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 14 Mar 2013 16:31:41 +0200 Subject: Deprecated AbstractComponentContainer.getComponentIterator (#11328) Change-Id: I24298165f0b078d42415cfce65118eed5587623c --- server/src/com/vaadin/ui/AbstractComponentContainer.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/src/com/vaadin/ui/AbstractComponentContainer.java b/server/src/com/vaadin/ui/AbstractComponentContainer.java index ca83286311..4aacad680f 100644 --- a/server/src/com/vaadin/ui/AbstractComponentContainer.java +++ b/server/src/com/vaadin/ui/AbstractComponentContainer.java @@ -339,6 +339,12 @@ public abstract class AbstractComponentContainer extends AbstractComponent true); } + /** + * {@inheritDoc} + * + * @deprecated As of 7.0, use {@link #iterator()} instead. + */ + @Deprecated @Override public Iterator getComponentIterator() { return iterator(); -- cgit v1.2.3 From 468438fc0ff41c299e2e015f569f96fbd5e09411 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 14 Mar 2013 16:31:06 +0200 Subject: Reattach when wrapping in webkit for correct text flow (#10536) Change-Id: I431b6a3c61a9308ad4189e5d79a5e70de8f1f560 --- client/src/com/vaadin/client/ui/VTextArea.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 139cd87ca4..4a5de23828 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -161,9 +161,12 @@ public class VTextArea extends VTextField { getElement().getStyle().setOverflow(Overflow.AUTO); getElement().getStyle().setWhiteSpace(WhiteSpace.PRE); } - if (BrowserInfo.get().isOpera()) { + if (BrowserInfo.get().isOpera() + || (BrowserInfo.get().isWebkit() && wordwrap)) { // Opera fails to dynamically update the wrap attribute so we detach // and reattach the whole TextArea. + // Webkit fails to properly reflow the text when enabling wrapping, + // same workaround Util.detachAttach(getElement()); } this.wordwrap = wordwrap; -- cgit v1.2.3 From f7b9f9f9afe8b09571d05f1790c9fe0c68a363a9 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Thu, 14 Mar 2013 14:21:53 +0200 Subject: Audio/Video fixes, for #11160 but it was much more broken. Also quite a few browser differences. Ticket: 11160 Change-Id: I1ee228e593eab75d96c285bfa26af9939e058d47 --- .../com/vaadin/client/ui/MediaBaseConnector.java | 25 ++++-- client/src/com/vaadin/client/ui/VMediaBase.java | 26 ++++++- .../com/vaadin/client/ui/audio/AudioConnector.java | 48 ++++++++---- .../vaadin/tests/components/media/AudioTest.html | 66 ++++++++++++++++ .../vaadin/tests/components/media/AudioTest.java | 86 +++++++++++++++++++++ .../src/com/vaadin/tests/components/media/bip.mp3 | Bin 0 -> 13837 bytes .../src/com/vaadin/tests/components/media/bip.ogg | Bin 0 -> 15137 bytes .../tests/components/media/toyphone_dialling.mp3 | Bin 0 -> 80083 bytes .../tests/components/media/toyphone_dialling.ogg | Bin 0 -> 77861 bytes 9 files changed, 225 insertions(+), 26 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/media/AudioTest.html create mode 100644 uitest/src/com/vaadin/tests/components/media/AudioTest.java create mode 100644 uitest/src/com/vaadin/tests/components/media/bip.mp3 create mode 100644 uitest/src/com/vaadin/tests/components/media/bip.ogg create mode 100644 uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 create mode 100644 uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg diff --git a/client/src/com/vaadin/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/client/ui/MediaBaseConnector.java index 6824caff78..8614977be1 100644 --- a/client/src/com/vaadin/client/ui/MediaBaseConnector.java +++ b/client/src/com/vaadin/client/ui/MediaBaseConnector.java @@ -46,15 +46,26 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { } @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); + public void onStateChanged(StateChangeEvent event) { + super.onStateChanged(event); - for (int i = 0; i < getState().sources.size(); i++) { - URLReference source = getState().sources.get(i); - String sourceType = getState().sourceTypes.get(i); - getWidget().addSource(source.getURL(), sourceType); + final VMediaBase widget = getWidget(); + final AbstractMediaState state = getState(); + + setAltText(state.altText); // must do before loading sources + widget.setAutoplay(state.autoplay); + widget.setMuted(state.muted); + widget.setControls(state.showControls); + + if (event.hasPropertyChanged("sources")) { + widget.removeAllSources(); + for (int i = 0; i < state.sources.size(); i++) { + URLReference source = state.sources.get(i); + String sourceType = state.sourceTypes.get(i); + widget.addSource(source.getURL(), sourceType); + } + widget.load(); } - setAltText(getState().altText); } @Override diff --git a/client/src/com/vaadin/client/ui/VMediaBase.java b/client/src/com/vaadin/client/ui/VMediaBase.java index 8d40775c8d..b77e8bb161 100644 --- a/client/src/com/vaadin/client/ui/VMediaBase.java +++ b/client/src/com/vaadin/client/ui/VMediaBase.java @@ -18,12 +18,16 @@ package com.vaadin.client.ui; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.MediaElement; +import com.google.gwt.dom.client.NodeList; +import com.google.gwt.dom.client.SourceElement; +import com.google.gwt.dom.client.Text; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; public abstract class VMediaBase extends Widget { private MediaElement media; + private Text altText; /** * Sets the MediaElement that is to receive all commands and properties. @@ -44,7 +48,12 @@ public abstract class VMediaBase extends Widget { } public void setAltText(String alt) { - media.appendChild(Document.get().createTextNode(alt)); + if (altText == null) { + altText = Document.get().createTextNode(alt); + media.appendChild(altText); + } else { + altText.setNodeValue(alt); + } } public void setControls(boolean shouldShowControls) { @@ -59,8 +68,21 @@ public abstract class VMediaBase extends Widget { media.setMuted(mediaMuted); } + public void removeAllSources() { + NodeList l = media + .getElementsByTagName(SourceElement.TAG); + for (int i = l.getLength() - 1; i >= 0; i--) { + media.removeChild(l.getItem(i)); + } + + } + + public void load() { + media.load(); + } + public void addSource(String sourceUrl, String sourceType) { - Element src = Document.get().createElement("source").cast(); + Element src = Document.get().createElement(SourceElement.TAG).cast(); src.setAttribute("src", sourceUrl); src.setAttribute("type", sourceType); media.appendChild(src); diff --git a/client/src/com/vaadin/client/ui/audio/AudioConnector.java b/client/src/com/vaadin/client/ui/audio/AudioConnector.java index c7d20ef585..5a90cab09d 100644 --- a/client/src/com/vaadin/client/ui/audio/AudioConnector.java +++ b/client/src/com/vaadin/client/ui/audio/AudioConnector.java @@ -29,23 +29,6 @@ import com.vaadin.ui.Audio; @Connect(Audio.class) public class AudioConnector extends MediaBaseConnector { - @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); - - Style style = getWidget().getElement().getStyle(); - - // Make sure that the controls are not clipped if visible. - if (getState().showControls - && (style.getHeight() == null || "".equals(style.getHeight()))) { - if (BrowserInfo.get().isChrome()) { - style.setHeight(32, Unit.PX); - } else { - style.setHeight(25, Unit.PX); - } - } - } - @Override protected Widget createWidget() { return GWT.create(VAudio.class); @@ -55,4 +38,35 @@ public class AudioConnector extends MediaBaseConnector { protected String getDefaultAltHtml() { return "Your browser does not support the audio element."; } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + // Opera (12.14) has a bug where an audio element w/o controls is shown + // as 150x300px, which is not usually desired. However, in order to show + // the error/alt message, we only do this in the exact situation. + if (BrowserInfo.get().isOpera() + && stateChangeEvent.hasPropertyChanged("showControls")) { + Style style = getWidget().getElement().getStyle(); + if (!getState().showControls) { + if (isUndefinedHeight() && isUndefinedWidth() + && getWidget().getOffsetHeight() == 150 + && getWidget().getOffsetWidth() == 300) { + // only if no size set and 150x300 + style.setWidth(0, Unit.PX); + style.setHeight(0, Unit.PX); + } + } else { + // clear sizes if it's supposed to be undefined + if (isUndefinedHeight()) { + style.clearHeight(); + } + if (isUndefinedWidth()) { + style.clearWidth(); + } + } + } + } + } diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.html b/uitest/src/com/vaadin/tests/components/media/AudioTest.html new file mode 100644 index 0000000000..8425cad38a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.html @@ -0,0 +1,66 @@ + + + + + + +AudioTest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AudioTest
open/run/AudioTest?restartApplication
pause3000
screenCaptureshortAtEndUnmuted
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VCheckBox[0]/domChild[0]11,7
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VCheckBox[0]/domChild[0]6,7
clickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]
pause5000
screenCapturelongerAtEndMuted
mouseClickvaadin=runAudioTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]69,9
screenCapturecontrolsHidden
+ + diff --git a/uitest/src/com/vaadin/tests/components/media/AudioTest.java b/uitest/src/com/vaadin/tests/components/media/AudioTest.java new file mode 100644 index 0000000000..28d1a7716f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/media/AudioTest.java @@ -0,0 +1,86 @@ +/* + * 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.components.media; + +import com.vaadin.data.util.MethodProperty; +import com.vaadin.server.ClassResource; +import com.vaadin.server.Resource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Audio; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CheckBox; + +public class AudioTest extends TestBase { + + @Override + protected void setup() { + + // Public domain sounds from pdsounds.org 27.2.2013 + + final Resource[] s1 = { new ClassResource(getClass(), "bip.mp3"), + new ClassResource(getClass(), "bip.ogg") }; + final Resource[] s2 = { + new ClassResource(getClass(), "toyphone_dialling.mp3"), + new ClassResource(getClass(), "toyphone_dialling.ogg") }; + + final Audio audio = new Audio(); + + audio.setSources(s1); + audio.setShowControls(true); + audio.setHtmlContentAllowed(true); + audio.setAltText("Can't play media"); + audio.setAutoplay(true); + + addComponent(audio); + + CheckBox checkBox = new CheckBox("Show controls", + new MethodProperty(audio, "showControls")); + addComponent(checkBox); + checkBox = new CheckBox("HtmlContentAllowed", + new MethodProperty(audio, "htmlContentAllowed")); + addComponent(checkBox); + checkBox = new CheckBox("muted", new MethodProperty(audio, + "muted")); + addComponent(checkBox); + checkBox = new CheckBox("autoplay", new MethodProperty(audio, + "autoplay")); + addComponent(checkBox); + + Button b = new Button("Change", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + audio.setSources(s2); + } + }); + addComponent(b); + getLayout().setHeight("400px"); + getLayout().setExpandRatio(b, 1.0f); + } + + @Override + protected String getDescription() { + return "Should autoplay, manipulating checkboxes should do appropriate thing, button changes file."; + } + + @Override + protected Integer getTicketNumber() { + return 11160; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/media/bip.mp3 b/uitest/src/com/vaadin/tests/components/media/bip.mp3 new file mode 100644 index 0000000000..2c7e790cf7 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/bip.mp3 differ diff --git a/uitest/src/com/vaadin/tests/components/media/bip.ogg b/uitest/src/com/vaadin/tests/components/media/bip.ogg new file mode 100644 index 0000000000..4e5014d92f Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/bip.ogg differ diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 new file mode 100644 index 0000000000..1788026856 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.mp3 differ diff --git a/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg new file mode 100644 index 0000000000..a042da5795 Binary files /dev/null and b/uitest/src/com/vaadin/tests/components/media/toyphone_dialling.ogg differ -- cgit v1.2.3 From 0dbe5989a8c503bbe878bce20c9fe3ad1725f45e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 15 Mar 2013 14:56:09 +0200 Subject: Made test more reliable Change-Id: Ibd93d834abaa1ec2ba322ab4ca9f53944cfe9519 --- .../integration-test-GateIn-3.1.0-portlet2.html | 73 +++++++++++++++++----- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html b/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html index 9ae3865815..5d2d4c3445 100644 --- a/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html +++ b/uitest/integration-testscripts/GateIn-3/integration-test-GateIn-3.1.0-portlet2.html @@ -16,11 +16,6 @@ /portal/public/classic/ - - setSpeed - 100 - 100 - mouseClickAndWait link=Administrator @@ -32,50 +27,95 @@ 93,13 - mouseClickAndWait + mouseClick link=Portlet 33,11 - mouseClickAndWait + waitForElementPresent link=Vaadin Portlet 2.0 Test 59,9 - mouseClickAndWait + mouseClick + link=Vaadin Portlet 2.0 Test + 59,9 + + + waitForElementPresent + link=Click here to add into categories + + + + mouseClick link=Click here to add into categories 48,3 - mouseClickAndWait + waitForElementPresent + name=category_Gadgets + + + + mouseClick name=category_Gadgets 10,16 - mouseClickAndWait + waitForElementPresent + link=Save + + + + mouseClick link=Save 4,6 - mouseClickAndWait + waitForElementPresent + link=Vaadin Liferay Theme + + + + mouseClick link=Vaadin Liferay Theme 64,13 - mouseClickAndWait + waitForElementPresent + link=Click here to add into categories + + + + mouseClick link=Click here to add into categories 96,9 - mouseClickAndWait + waitForElementPresent name=category_Gadgets 7,12 - mouseClickAndWait + mouseClick + name=category_Gadgets + 7,12 + + + waitForElementPresent link=Save 4,6 + + mouseClick + link=Save + 4,6 + + + waitForElementPresent + link=Add New Page + 55,11 + mouseClick link=Add New Page @@ -127,6 +167,11 @@ //div[2]/div/div/div[1]/div/div[2]/div/div/div/div 113,9 + + waitForTextPresent + Vaadin Portlet 2.0 Test + + mouseClickAndWait -- cgit v1.2.3 From 7cea6411274603a10f997216ca6f52194342888d Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sat, 16 Mar 2013 02:15:39 +0200 Subject: Updated test to test interactions and to be more stable Change-Id: If608cef429f6a18864d99780e9ee945adcc06b57 --- .../Liferay-6/integration-test-liferay-6.0.5.html | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/uitest/integration-testscripts/Liferay-6/integration-test-liferay-6.0.5.html b/uitest/integration-testscripts/Liferay-6/integration-test-liferay-6.0.5.html index 88cac6cd74..037ce23865 100644 --- a/uitest/integration-testscripts/Liferay-6/integration-test-liferay-6.0.5.html +++ b/uitest/integration-testscripts/Liferay-6/integration-test-liferay-6.0.5.html @@ -36,8 +36,6 @@ //input[@value='Sign In'] 43,18 - - mouseClickAndWait //input[@type='submit'] @@ -144,19 +142,34 @@ 10,10 - pause - 5000 + waitForTextPresent + Normal Label - waitForVaadin + screenCapture + + theme + + + mouseClick + //td[3]/div/div/div + 22,7 + + + assertTextPresent + Normal TextField + + + assertTextPresent + Normal TextArea - screenCapture + assertTextNotPresent + Normal Label - theme -- cgit v1.2.3 From d816697f2d87c6c3a8ae68003d0d2e3c142b3c5f Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 19 Mar 2013 00:44:39 +0200 Subject: Do not run TestRunner as a test Change-Id: I4a32bb614b7c175e1a6ced0078143978b2155194 --- common.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.xml b/common.xml index 8569a91075..5b464e5047 100644 --- a/common.xml +++ b/common.xml @@ -315,7 +315,7 @@ - + -- cgit v1.2.3 From 17f64543bcc74f74017a3d1c13e5db83c7a4ec41 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 19 Mar 2013 20:27:22 +0200 Subject: Disabled TabIndex warning for now (#11325) Change-Id: I89311c7e4bdab3a70aa335c203ef57badab7bec8 --- .../src/com/vaadin/client/ui/AbstractComponentConnector.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index 74cb85c297..ecd6abae08 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -142,9 +142,13 @@ public abstract class AbstractComponentConnector extends AbstractConnector ((Focusable) getWidget()) .setTabIndex(((TabIndexState) getState()).tabIndex); } else { - VConsole.error("Tab index received for " - + Util.getSimpleName(getWidget()) - + " which does not implement Focusable"); + /* + * TODO Enable this error when all widgets have been fixed to + * properly support tabIndex, i.e. implement Focusable + */ + // VConsole.error("Tab index received for " + // + Util.getSimpleName(getWidget()) + // + " which does not implement Focusable"); } } Profiler.leave("AbstractComponentConnector.onStateChanged update tab index"); -- cgit v1.2.3 From 5ea677d377c96c60fbc546eb2381bb88f2d4b478 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 12 Mar 2013 18:34:18 +0200 Subject: Make TextArea.setCursorPosition work in all browsers (#8769) svn changeset:25579/svn branch:6.8 Conflicts: client/src/com/vaadin/client/ui/VTextField.java Change-Id: I3b53be8df4ce0564f34d8aa9bc1ce1c34648eadd --- client/src/com/vaadin/client/ui/VTextArea.java | 114 ++++++++++++++ client/src/com/vaadin/client/ui/VTextField.java | 4 + .../tests/components/textarea/ScrollCursor.html | 169 +++++++++++++++++++++ .../tests/components/textarea/ScrollCursor.java | 89 +++++++++++ 4 files changed, 376 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html create mode 100644 uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java diff --git a/client/src/com/vaadin/client/ui/VTextArea.java b/client/src/com/vaadin/client/ui/VTextArea.java index 4a5de23828..45e0532451 100644 --- a/client/src/com/vaadin/client/ui/VTextArea.java +++ b/client/src/com/vaadin/client/ui/VTextArea.java @@ -63,6 +63,120 @@ public class VTextArea extends VTextField { getTextAreaElement().setRows(rows); } + @Override + public void setSelectionRange(int pos, int length) { + super.setSelectionRange(pos, length); + final String value = getValue(); + /* + * Align position to index inside string value + */ + int index = pos; + if (index < 0) { + index = 0; + } + if (index > value.length()) { + index = value.length(); + } + // Get pixels count required to scroll textarea vertically + int scrollTop = getScrollTop(value, index); + int scrollLeft = -1; + /* + * Check if textarea has wrap attribute set to "off". In the latter case + * horizontal scroll is also required. + */ + if (!isWordwrap()) { + // Get pixels count required to scroll textarea horizontally + scrollLeft = getScrollLeft(value, index); + } + // Set back original text if previous methods calls changed it + if (!isWordwrap() || index < value.length()) { + setValue(value, false); + } + /* + * Call original method to set cursor position. In most browsers it + * doesn't lead to scrolling. + */ + super.setSelectionRange(pos, length); + /* + * Align vertical scroll to middle of textarea view (height) if + * scrolling is reqiured at all. + */ + if (scrollTop > 0) { + scrollTop += getElement().getClientHeight() / 2; + } + /* + * Align horizontal scroll to middle of textarea view (widht) if + * scrolling is reqiured at all. + */ + if (scrollLeft > 0) { + scrollLeft += getElement().getClientWidth() / 2; + } + /* + * Scroll if computed scrollTop is greater than scroll after cursor + * setting + */ + if (getElement().getScrollTop() < scrollTop) { + getElement().setScrollTop(scrollTop); + } + /* + * Scroll if computed scrollLeft is greater than scroll after cursor + * setting + */ + if (getElement().getScrollLeft() < scrollLeft) { + getElement().setScrollLeft(scrollLeft); + } + } + + /* + * Get horizontal scroll value required to get position visible. Method is + * called only when text wrapping is off. There is need to scroll + * horizontally in case words are wrapped. + */ + private int getScrollLeft(String value, int index) { + String beginning = value.substring(0, index); + // Compute beginning of the current line + int begin = beginning.lastIndexOf('\n'); + String line = value.substring(begin + 1); + index = index - begin - 1; + if (index < line.length()) { + index++; + } + line = line.substring(0, index); + /* + * Now line contains current line up to index position + */ + setValue(line.trim(), false); // Set this line to the textarea. + /* + * Scroll textarea up to the end of the line (maximum possible + * horizontal scrolling value). Now the end line becomes visible. + */ + getElement().setScrollLeft(getElement().getScrollWidth()); + // Return resulting horizontal scrolling value. + return getElement().getScrollLeft(); + } + + /* + * Get vertical scroll value required to get position visible + */ + private int getScrollTop(String value, int index) { + /* + * Trim text after position and set this trimmed text if index is not + * very end. + */ + if (index < value.length()) { + String beginning = value.substring(0, index); + setValue(beginning, false); + } + /* + * Now textarea contains trimmed text and could be scrolled up to the + * top. Scroll it to maximum possible value to get end of the text + * visible. + */ + getElement().setScrollTop(getElement().getScrollHeight()); + // Return resulting vertical scrolling value. + return getElement().getScrollTop(); + } + private class MaxLengthHandler implements KeyUpHandler, ChangeHandler { @Override diff --git a/client/src/com/vaadin/client/ui/VTextField.java b/client/src/com/vaadin/client/ui/VTextField.java index 0fbed0dd90..da9445c811 100644 --- a/client/src/com/vaadin/client/ui/VTextField.java +++ b/client/src/com/vaadin/client/ui/VTextField.java @@ -446,4 +446,8 @@ public class VTextField extends TextBoxBase implements Field, ChangeHandler, this.inputPrompt = inputPrompt; } + protected boolean isWordwrap() { + String wrap = getElement().getAttribute("wrap"); + return !"off".equals(wrap); + } } diff --git a/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html new file mode 100644 index 0000000000..9eaa1ceada --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.html @@ -0,0 +1,169 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.textarea.ScrollCursor?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/domChild[0]/domChild[0]191,94
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-middle
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[5]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-end
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewrap-end-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-start
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-middle
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[5]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturenowrap-end
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstextareaScrollCursor::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]
screenCapturenowrap-end-start
+ + diff --git a/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java new file mode 100644 index 0000000000..c95731d94f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java @@ -0,0 +1,89 @@ +package com.vaadin.tests.components.textarea; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.TextArea; + +/** + * @author denis + * + */ +public class ScrollCursor extends TestBase { + + private TextArea textArea; + private int position; + + @Override + protected void setup() { + textArea = new TextArea(); + textArea.setValue("saddddddddddd fdgdfgfdgfd\n" + + "aasddddddddddd\n" + "dsaffffffdsf\n" + "sdf\n" + + "dsfsdfsdfsdfsd\n\n" + "ffffffffffffffffffff\n" + + "sdfdsfdsfsdfsdfsd xxxxxxxxxxxxxxxx\n" + "sdgfsd\n" + + "dsf\n" + "ds\n" + "fds\n" + "fds\nfs"); + addComponent(textArea); + Button button = new Button("Scroll"); + button.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + textArea.setCursorPosition(getPosition()); + } + }); + Button wrap = new Button("Set wrap"); + wrap.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + textArea.setWordwrap(false); + } + }); + + Button toBegin = new Button("To begin"); + toBegin.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = 3; + } + }); + + Button toMiddle = new Button("To middle"); + toMiddle.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = 130; + } + }); + + Button toEnd = new Button("To end"); + toEnd.addListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + position = textArea.getValue().toString().length(); + } + }); + + addComponent(button); + addComponent(wrap); + addComponent(toBegin); + addComponent(toMiddle); + addComponent(toEnd); + } + + @Override + protected String getDescription() { + return "Tests scrolling for TextArea with different word wrapping settings. " + + "Sets cursor position at the beginning, middle and the end " + + "of text and checks textarea is scrolled."; + } + + @Override + protected Integer getTicketNumber() { + return 8769; + } + + private int getPosition() { + return position; + } + +} -- cgit v1.2.3 From e4c9eda51082a443822b66864df2fe14be7dc6d7 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 18 Mar 2013 21:34:27 +0200 Subject: Enable a Vaadin applications to be re-initialized if if has been re-added to the same page (#8350) Change-Id: I30dbc14f00108fa699694ecd1d37679d8a0dff4b --- WebContent/VAADIN/vaadinBootstrap.js | 34 +++++++++++++++++++--- .../com/vaadin/client/ApplicationConnection.java | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/WebContent/VAADIN/vaadinBootstrap.js b/WebContent/VAADIN/vaadinBootstrap.js index 9e012ae987..81adfcccc6 100644 --- a/WebContent/VAADIN/vaadinBootstrap.js +++ b/WebContent/VAADIN/vaadinBootstrap.js @@ -55,19 +55,45 @@ pendingApps: [] }; }; - + + var isInitializedInDom = function(appId) { + var appDiv = document.getElementById(appId); + if (!appDiv) { + return false; + } + for ( var i = 0; i < appDiv.childElementCount; i++) { + var className = appDiv.childNodes[i].className; + // If the app div contains a child with the class + // "v-app-loading" we have only received the HTML + // but not yet started the widget set + // (UIConnector removes the v-app-loading div). + if (className && className.contains("v-app-loading")) { + return false; + } + } + return true; + }; + window.vaadin = window.vaadin || { initApplication: function(appId, config) { + var testbenchId = appId.replace(/-\d+$/, ''); + if (apps[appId]) { - throw "Application " + appId + " already initialized"; + if (window.vaadin && window.vaadin.clients && window.vaadin.clients[testbenchId] && window.vaadin.clients[testbenchId].initializing) { + throw "Application " + appId + " is already being initialized"; + } + if (isInitializedInDom(appId)) { + throw "Application " + appId + " already initialized"; + } } + log("init application", appId, config); - var testbenchId = appId.replace(/-\d+$/, ''); window.vaadin.clients[testbenchId] = { isActive: function() { return true; - } + }, + initializing: true }; var getConfig = function(name) { diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 62827feffb..4ddbd7c39b 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -510,6 +510,7 @@ public class ApplicationConnection { client.getPathForElement = $entry(function(element) { return componentLocator.@com.vaadin.client.ComponentLocator::getPathForElement(Lcom/google/gwt/user/client/Element;)(element); }); + client.initializing = false; $wnd.vaadin.clients[TTAppId] = client; }-*/; -- cgit v1.2.3