From 00806654f5015e18c41ce1a8002f58d63a7d951c Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 3 Aug 2012 13:54:23 +0000 Subject: Updated test to catch correct exception (#9147) The test now fails before the query can be executed when the query string is generated. svn changeset:24061/svn branch:6.8 --- .../com/vaadin/data/util/sqlcontainer/query/TableQueryTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/query/TableQueryTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/query/TableQueryTest.java index 657f06ae5e..e135894013 100644 --- a/tests/server-side/com/vaadin/data/util/sqlcontainer/query/TableQueryTest.java +++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/query/TableQueryTest.java @@ -18,15 +18,13 @@ import com.vaadin.data.Container.Filter; import com.vaadin.data.util.filter.Compare.Equal; import com.vaadin.data.util.filter.Like; import com.vaadin.data.util.sqlcontainer.AllTests; +import com.vaadin.data.util.sqlcontainer.AllTests.DB; import com.vaadin.data.util.sqlcontainer.DataGenerator; import com.vaadin.data.util.sqlcontainer.OptimisticLockException; import com.vaadin.data.util.sqlcontainer.RowItem; import com.vaadin.data.util.sqlcontainer.SQLContainer; -import com.vaadin.data.util.sqlcontainer.AllTests.DB; import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool; import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; -import com.vaadin.data.util.sqlcontainer.query.OrderBy; -import com.vaadin.data.util.sqlcontainer.query.TableQuery; import com.vaadin.data.util.sqlcontainer.query.generator.DefaultSQLGenerator; public class TableQueryTest { @@ -281,7 +279,9 @@ public class TableQueryTest { AllTests.sqlGen); try { tQuery.containsRowWithKey(new Object[] { null }); - } catch (SQLException e) { + org.junit.Assert + .fail("null should throw an IllegalArgumentException from StatementHelper"); + } catch (IllegalArgumentException e) { // We should now be able to reserve two connections connectionPool.reserveConnection(); connectionPool.reserveConnection(); -- cgit v1.2.3 From 27fc8ddc0087a3ac4367e4e50883bd859fa90dd4 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 6 Aug 2012 05:46:29 +0000 Subject: Force horizontal scrolling with wide columns but no rows (#9187) svn changeset:24065/svn branch:6.8 --- .../terminal/gwt/client/ui/VScrollTable.java | 29 +++++++- .../table/HorizontalScrollWithNoRows.html | 86 ++++++++++++++++++++++ 2 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/table/HorizontalScrollWithNoRows.html (limited to 'tests') diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index e54493ca61..43e07376f4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -6091,16 +6091,39 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, // Hey IE, are you really sure about this? availW = scrollBody.getAvailableWidth(); int visibleCellCount = tHead.getVisibleCellCount(); - availW -= scrollBody.getCellExtraWidth() * visibleCellCount; + int totalExtraWidth = scrollBody.getCellExtraWidth() + * visibleCellCount; if (willHaveScrollbars()) { - availW -= Util.getNativeScrollbarSize(); + totalExtraWidth += Util.getNativeScrollbarSize(); } - + availW -= totalExtraWidth; + int forceScrollBodyWidth = -1; + int extraSpace = availW - usedMinimumWidth; if (extraSpace < 0) { + if (getTotalRows() == 0) { + /* + * Too wide header combined with no rows in the table. + * + * No horizontal scrollbars would be displayed because + * there's no rows that grows too wide causing the + * scrollBody container div to overflow. Must explicitely + * force a width to a scrollbar. (see #9187) + */ + forceScrollBodyWidth = usedMinimumWidth + totalExtraWidth; + } extraSpace = 0; } + if (forceScrollBodyWidth > 0) { + scrollBody.container.getStyle().setWidth(forceScrollBodyWidth, + Unit.PX); + } else { + // Clear width that might have been set to force horizontal + // scrolling if there are no rows + scrollBody.container.getStyle().clearWidth(); + } + int totalUndefinedNaturalWidths = usedMinimumWidth - totalExplicitColumnsWidths; diff --git a/tests/testbench/com/vaadin/tests/components/table/HorizontalScrollWithNoRows.html b/tests/testbench/com/vaadin/tests/components/table/HorizontalScrollWithNoRows.html new file mode 100644 index 0000000000..98629252d9 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/table/HorizontalScrollWithNoRows.html @@ -0,0 +1,86 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.table.Tables?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item023,8
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item533,5
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item150,8
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item054,10
mouseClickvaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item128,9
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item029,5
dragvaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]0,7
dropvaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]150,7
screenCapture1-wide-header
dragvaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]0,7
dropvaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]-152,7
screenCapture2-narrow-header
+ + -- cgit v1.2.3 From 049bb369b9215c15cb4de528c6877a61d41e493c Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 6 Aug 2012 10:48:02 +0000 Subject: Use separate screenshots because of IE9 inconsistency revealed by (#9207) svn changeset:24079/svn branch:6.8 --- tests/testbench/com/vaadin/tests/components/table/EmptyTable.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/testbench/com/vaadin/tests/components/table/EmptyTable.html b/tests/testbench/com/vaadin/tests/components/table/EmptyTable.html index 58f26cf607..7196771f56 100644 --- a/tests/testbench/com/vaadin/tests/components/table/EmptyTable.html +++ b/tests/testbench/com/vaadin/tests/components/table/EmptyTable.html @@ -65,7 +65,7 @@ screenCapture - empty-table + empty-table-after-reload -- cgit v1.2.3 From 763f77fc2f3b3c3c1ce2fa91ae2a8097b11f6b6b Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Mon, 6 Aug 2012 14:48:02 +0000 Subject: Fix and test for #9136 (Tree throws wrong ItemClickEvent in IE9) svn changeset:24087/svn branch:6.8 --- src/com/vaadin/terminal/gwt/client/ui/VTree.java | 14 +++- .../tree/TreeItemClickAndValueChange.html | 82 ++++++++++++++++++++++ 2 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html (limited to 'tests') diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index 1d5ec206aa..2d318522ea 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -753,6 +753,10 @@ public class VTree extends FocusElementPanel implements Paintable, if (BrowserInfo.get().isWebkit() && !treeHasFocus) { /* * Safari may need to wait for focus. See FocusImplSafari. + * + * Note that this if/else must exactly match the one in + * fireClick() to ensure that the above click/selection event + * logic works correctly (#9136) */ // VConsole.log("Deferring click handling to let webkit gain focus..."); Scheduler.get().scheduleDeferred(command); @@ -930,13 +934,17 @@ public class VTree extends FocusElementPanel implements Paintable, details.toString(), sendClickEventNow); } }; - if (treeHasFocus) { - command.execute(); - } else { + if (BrowserInfo.get().isWebkit() && !treeHasFocus) { /* * Webkits need a deferring due to FocusImplSafari uses timeout + * + * Note that this if/else must exactly match the one in + * handleClickSelection() to ensure that the above + * click/selection event logic works correctly (#9136) */ Scheduler.get().scheduleDeferred(command); + } else { + command.execute(); } } diff --git a/tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html b/tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html new file mode 100644 index 0000000000..9593c6f6e5 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html @@ -0,0 +1,82 @@ + + + + + + +TreeItemClickAndValueChange + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TreeItemClickAndValueChange
open/run/Trees?restartApplication
mouseClickvaadin=runTrees::PID_Smenu#item019,8
mouseClickvaadin=runTrees::Root/VOverlay[0]/VMenuBar[0]#item323,7
mouseClickvaadin=runTrees::Root/VOverlay[1]/VMenuBar[0]#item038,6
mouseClickvaadin=runTrees::PID_Smenu#item052,12
mouseClickvaadin=runTrees::Root/VOverlay[0]/VMenuBar[0]#item353,12
mouseClickvaadin=runTrees::Root/VOverlay[1]/VMenuBar[0]#item450,4
mouseClickvaadin=runTrees::PID_StestComponent#n[0]22,9
mouseClickvaadin=runTrees::PID_StestComponent#n[1]20,6
assertTextvaadin=runTrees::PID_SLog_row_05. ValueChangeEvent, new value: '[Item 2]'
assertTextvaadin=runTrees::PID_SLog_row_14. left click on source: [Item 1], client: [54,218];, relative: [-1,-1], itemId: Item 2, propertyId: null
assertTextvaadin=runTrees::PID_SLog_row_23. ValueChangeEvent, new value: '[Item 1]'
assertTextvaadin=runTrees::PID_SLog_row_32. left click on source: [], client: [56,202];, relative: [-1,-1], itemId: Item 1, propertyId: null
+ + -- cgit v1.2.3 From 27b9747a67c7276a8d501049d41177ae6946c28a Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Mon, 6 Aug 2012 15:18:01 +0000 Subject: Use a glob pattern in assertText to allow for slightly different click coordinates between browsers svn changeset:24089/svn branch:6.8 --- .../com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html b/tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html index 9593c6f6e5..bf83a1acdb 100644 --- a/tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html +++ b/tests/testbench/com/vaadin/tests/components/tree/TreeItemClickAndValueChange.html @@ -64,7 +64,7 @@ assertText vaadin=runTrees::PID_SLog_row_1 - 4. left click on source: [Item 1], client: [54,218];, relative: [-1,-1], itemId: Item 2, propertyId: null + 4. left click on source: [Item 1], client: [*];, relative: [-1,-1], itemId: Item 2, propertyId: null assertText @@ -74,7 +74,7 @@ assertText vaadin=runTrees::PID_SLog_row_3 - 2. left click on source: [], client: [56,202];, relative: [-1,-1], itemId: Item 1, propertyId: null + 2. left click on source: [], client: [*];, relative: [-1,-1], itemId: Item 1, propertyId: null -- cgit v1.2.3 From 6ead5944ab0a1e4d48b3f502281ac24d43e5ed89 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 8 Aug 2012 12:26:55 +0000 Subject: Allow removing Window while iterating child window set (#9251) svn changeset:24115/svn branch:6.8 --- src/com/vaadin/ui/Window.java | 3 ++- .../server/component/window/AddRemoveSubWindow.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index 32415433ad..fce9a30c82 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -10,6 +10,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -1549,7 +1550,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler, * @return Set of child windows. */ public Set getChildWindows() { - return Collections.unmodifiableSet(subwindows); + return Collections.unmodifiableSet(new HashSet(subwindows)); } /** diff --git a/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java b/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java index 50de91e2af..74859fd8b7 100644 --- a/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java +++ b/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java @@ -5,6 +5,8 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.Set; + import org.junit.Test; import com.vaadin.Application; @@ -80,4 +82,19 @@ public class AddRemoveSubWindow { assertTrue("Window was not removed correctly", removed); assertNull(subWindow.getParent()); } + + @Test + public void testChildWindowsIteratorModification() { + Window mainWindow = new Window(); + mainWindow.addWindow(new Window()); + mainWindow.addWindow(new Window()); + + Set childWindows = mainWindow.getChildWindows(); + for (Window window : childWindows) { + mainWindow.removeWindow(window); + } + + assertEquals(2, childWindows.size()); + assertEquals(0, mainWindow.getChildWindows().size()); + } } -- cgit v1.2.3 From d5137280033543017834e4beb4c5b5f987120142 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 8 Aug 2012 14:55:50 +0000 Subject: Removed extra backslash svn changeset:24122/svn branch:6.8 --- .../tests/components/notification/CloseErrorNotificationWithEscape.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/testbench/com/vaadin/tests/components/notification/CloseErrorNotificationWithEscape.html b/tests/testbench/com/vaadin/tests/components/notification/CloseErrorNotificationWithEscape.html index 288fd65c66..1ab75e1176 100644 --- a/tests/testbench/com/vaadin/tests/components/notification/CloseErrorNotificationWithEscape.html +++ b/tests/testbench/com/vaadin/tests/components/notification/CloseErrorNotificationWithEscape.html @@ -34,7 +34,7 @@ keyDown vaadin=runcomvaadintestscomponentsnotificationNotifications::Root/VNotification[0]/HTML[0]/domChild[0] - \\27 + \27 -- cgit v1.2.3 From e03ac3fe1c5934cf24ed0aea58226baf43efb159 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 8 Aug 2012 14:56:05 +0000 Subject: Fixed TextArea maxlength so it is always enforced (#9199) Uses native maxlength attribute for browsers which support it. svn changeset:24123/svn branch:6.8 --- .../vaadin/terminal/gwt/client/BrowserInfo.java | 78 +++++++++++++++---- .../vaadin/terminal/gwt/client/ui/VTextArea.java | 91 ++++++++++++++++++---- .../vaadin/terminal/gwt/client/ui/VTextField.java | 32 +++++--- .../components/textarea/TextAreaMaxLength.html | 53 +++++++++++++ 4 files changed, 210 insertions(+), 44 deletions(-) create mode 100755 tests/testbench/com/vaadin/tests/components/textarea/TextAreaMaxLength.html (limited to 'tests') diff --git a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java index 4b9f3eacab..6a94611a60 100644 --- a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java +++ b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java @@ -128,7 +128,7 @@ public class BrowserInfo { if (browserDetails.isFirefox()) { browserIdentifier = BROWSER_FIREFOX; majorVersionClass = browserIdentifier - + browserDetails.getBrowserMajorVersion(); + + getBrowserMajorVersion(); minorVersionClass = majorVersionClass + browserDetails.getBrowserMinorVersion(); browserEngineClass = ENGINE_GECKO; @@ -140,21 +140,21 @@ public class BrowserInfo { } else if (browserDetails.isSafari()) { browserIdentifier = BROWSER_SAFARI; majorVersionClass = browserIdentifier - + browserDetails.getBrowserMajorVersion(); + + getBrowserMajorVersion(); minorVersionClass = majorVersionClass + browserDetails.getBrowserMinorVersion(); browserEngineClass = ENGINE_WEBKIT; } else if (browserDetails.isIE()) { browserIdentifier = BROWSER_IE; majorVersionClass = browserIdentifier - + browserDetails.getBrowserMajorVersion(); + + getBrowserMajorVersion(); minorVersionClass = majorVersionClass + browserDetails.getBrowserMinorVersion(); browserEngineClass = ENGINE_TRIDENT; } else if (browserDetails.isOpera()) { browserIdentifier = BROWSER_OPERA; majorVersionClass = browserIdentifier - + browserDetails.getBrowserMajorVersion(); + + getBrowserMajorVersion(); minorVersionClass = majorVersionClass + browserDetails.getBrowserMinorVersion(); browserEngineClass = ENGINE_PRESTO; @@ -211,23 +211,23 @@ public class BrowserInfo { } public boolean isSafari4() { - return isSafari() && browserDetails.getBrowserMajorVersion() == 4; + return isSafari() && getBrowserMajorVersion() == 4; } public boolean isIE6() { - return isIE() && browserDetails.getBrowserMajorVersion() == 6; + return isIE() && getBrowserMajorVersion() == 6; } public boolean isIE7() { - return isIE() && browserDetails.getBrowserMajorVersion() == 7; + return isIE() && getBrowserMajorVersion() == 7; } public boolean isIE8() { - return isIE() && browserDetails.getBrowserMajorVersion() == 8; + return isIE() && getBrowserMajorVersion() == 8; } public boolean isIE9() { - return isIE() && browserDetails.getBrowserMajorVersion() == 9; + return isIE() && getBrowserMajorVersion() == 9; } public boolean isChrome() { @@ -255,8 +255,7 @@ public class BrowserInfo { } public boolean isFF4() { - return browserDetails.isFirefox() - && browserDetails.getBrowserMajorVersion() == 4; + return browserDetails.isFirefox() && getBrowserMajorVersion() == 4; } /** @@ -292,7 +291,7 @@ public class BrowserInfo { return -1; } - return browserDetails.getBrowserMajorVersion(); + return getBrowserMajorVersion(); } public float getOperaVersion() { @@ -300,7 +299,7 @@ public class BrowserInfo { return -1; } - return browserDetails.getBrowserMajorVersion(); + return getBrowserMajorVersion(); } public boolean isOpera() { @@ -308,13 +307,11 @@ public class BrowserInfo { } public boolean isOpera10() { - return browserDetails.isOpera() - && browserDetails.getBrowserMajorVersion() == 10; + return browserDetails.isOpera() && getBrowserMajorVersion() == 10; } public boolean isOpera11() { - return browserDetails.isOpera() - && browserDetails.getBrowserMajorVersion() == 11; + return browserDetails.isOpera() && getBrowserMajorVersion() == 11; } public native static String getBrowserString() @@ -475,4 +472,51 @@ public class BrowserInfo { private int getOperatingSystemMajorVersion() { return browserDetails.getOperatingSystemMajorVersion(); } + + /** + * Returns the browser major version e.g., 3 for Firefox 3.5, 4 for Chrome + * 4, 8 for Internet Explorer 8. + *

+ * Note that Internet Explorer 8 and newer will return the document mode so + * IE8 rendering as IE7 will return 7. + *

+ * + * @return The major version of the browser. + */ + public int getBrowserMajorVersion() { + return browserDetails.getBrowserMajorVersion(); + } + + /** + * Returns the browser minor version e.g., 5 for Firefox 3.5. + * + * @see #getBrowserMajorVersion() + * + * @return The minor version of the browser, or -1 if not known/parsed. + */ + public int getBrowserMinorVersion() { + return browserDetails.getBrowserMinorVersion(); + } + + /** + * Checks if the browser version is newer or equal to the given major+minor + * version. + * + * @param majorVersion + * The major version to check for + * @param minorVersion + * The minor version to check for + * @return true if the browser version is newer or equal to the given + * version + */ + public boolean isBrowserVersionNewerOrEqual(int majorVersion, + int minorVersion) { + if (getBrowserMajorVersion() == majorVersion) { + // Same major + return (getBrowserMinorVersion() >= minorVersion); + } + + // Older or newer major + return (getBrowserMajorVersion() > majorVersion); + } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java b/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java index 0ed5887442..4ab27646ed 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java @@ -5,12 +5,17 @@ package com.vaadin.terminal.gwt.client.ui; import com.google.gwt.core.client.Scheduler; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.event.dom.client.KeyDownEvent; +import com.google.gwt.event.dom.client.KeyUpEvent; +import com.google.gwt.event.dom.client.KeyUpHandler; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.vaadin.terminal.gwt.client.ApplicationConnection; +import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.UIDL; /** @@ -24,10 +29,17 @@ import com.vaadin.terminal.gwt.client.UIDL; */ public class VTextArea extends VTextField { public static final String CLASSNAME = "v-textarea"; + private MaxLengthHandler maxLengthHandler = new MaxLengthHandler(); + private boolean browserSupportsMaxLengthAttribute = browserSupportsMaxLengthAttribute(); public VTextArea() { super(DOM.createTextArea()); setStyleName(CLASSNAME); + if (!browserSupportsMaxLengthAttribute) { + addKeyUpHandler(maxLengthHandler); + addChangeHandler(maxLengthHandler); + sinkEvents(Event.ONPASTE); + } } @Override @@ -39,8 +51,69 @@ public class VTextArea extends VTextField { setRows(uidl.getIntAttribute("rows")); } - if (getMaxLength() >= 0) { - sinkEvents(Event.ONKEYUP); + } + + private class MaxLengthHandler implements KeyUpHandler, ChangeHandler { + + public void onKeyUp(KeyUpEvent event) { + enforceMaxLength(); + } + + public void onPaste(Event event) { + enforceMaxLength(); + } + + private void enforceMaxLength() { + if (getMaxLength() >= 0) { + Scheduler.get().scheduleDeferred(new Command() { + public void execute() { + if (getText().length() > getMaxLength()) { + setText(getText().substring(0, getMaxLength())); + } + } + }); + } + } + + public void onChange(ChangeEvent event) { + // Opera does not support paste events so this enforces max length + // for Opera. + enforceMaxLength(); + } + + } + + protected boolean browserSupportsMaxLengthAttribute() { + BrowserInfo info = BrowserInfo.get(); + if (info.isFirefox() && info.isBrowserVersionNewerOrEqual(4, 0)) { + return true; + } + if (info.isSafari() && info.isBrowserVersionNewerOrEqual(5, 0)) { + return true; + } + if (info.isIE() && info.isBrowserVersionNewerOrEqual(10, 0)) { + return true; + } + if (info.isAndroid() && info.isBrowserVersionNewerOrEqual(2, 3)) { + return true; + } + return false; + } + + @Override + protected void updateMaxLength(int maxLength) { + if (browserSupportsMaxLengthAttribute) { + super.updateMaxLength(maxLength); + } else { + // Handled automatically by MaxLengthHandler + } + } + + @Override + public void onBrowserEvent(Event event) { + super.onBrowserEvent(event); + if (event.getTypeInt() == Event.ONPASTE) { + maxLengthHandler.onPaste(event); } } @@ -56,20 +129,6 @@ public class VTextArea extends VTextField { } catch (e) {} }-*/; - @Override - public void onBrowserEvent(Event event) { - if (getMaxLength() >= 0 && event.getTypeInt() == Event.ONKEYUP) { - Scheduler.get().scheduleDeferred(new Command() { - public void execute() { - if (getText().length() > getMaxLength()) { - setText(getText().substring(0, getMaxLength())); - } - } - }); - } - super.onBrowserEvent(event); - } - @Override public int getCursorPos() { // This is needed so that TextBoxImplIE6 is used to return the correct diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java index b05b9ba830..b24e304b82 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextField.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextField.java @@ -385,20 +385,30 @@ public class VTextField extends TextBoxBase implements Paintable, Field, } private void setMaxLength(int newMaxLength) { - if (newMaxLength >= 0) { + if (newMaxLength >= 0 && newMaxLength != maxLength) { maxLength = newMaxLength; - if (getElement().getTagName().toLowerCase().equals("textarea")) { - // NOP no maxlength property for textarea - } else { - getElement().setPropertyInt("maxLength", maxLength); - } + updateMaxLength(maxLength); } else if (maxLength != -1) { - if (getElement().getTagName().toLowerCase().equals("textarea")) { - // NOP no maxlength property for textarea - } else { - getElement().removeAttribute("maxLength"); - } maxLength = -1; + updateMaxLength(maxLength); + } + + } + + /** + * This method is reponsible for updating the DOM or otherwise ensuring that + * the given max length is enforced. Called when the max length for the + * field has changed. + * + * @param maxLength + * The new max length + */ + protected void updateMaxLength(int maxLength) { + if (maxLength >= 0) { + getElement().setPropertyInt("maxLength", maxLength); + } else { + getElement().removeAttribute("maxLength"); + } } diff --git a/tests/testbench/com/vaadin/tests/components/textarea/TextAreaMaxLength.html b/tests/testbench/com/vaadin/tests/components/textarea/TextAreaMaxLength.html new file mode 100755 index 0000000000..5fe43b7b7a --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/textarea/TextAreaMaxLength.html @@ -0,0 +1,53 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.textarea.TextAreaTest?debug&restartApplication
mouseClickvaadin=runcomvaadintestscomponentstextareaTextAreaTest::PID_Smenu#item020,9
mouseClickvaadin=runcomvaadintestscomponentstextareaTextAreaTest::Root/VOverlay[0]/VMenuBar[0]#item543,8
mouseClickvaadin=runcomvaadintestscomponentstextareaTextAreaTest::Root/VOverlay[1]/VMenuBar[0]#item270,13
mouseClickvaadin=runcomvaadintestscomponentstextareaTextAreaTest::Root/VOverlay[2]/VMenuBar[0]#item540,9
enterCharactervaadin=runcomvaadintestscomponentstextareaTextAreaTest::PID_StestComponent0123456789
assertValuevaadin=runcomvaadintestscomponentstextareaTextAreaTest::PID_StestComponent01234
+ + -- cgit v1.2.3 From 42c26abe83d933eb980995044317cc7fb41b8424 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 8 Aug 2012 14:56:13 +0000 Subject: Test for ensuring that overlays can be transparent (not in IE < 9) svn changeset:24124/svn branch:6.8 --- .../notification/SemiTransparentNotification.java | 34 ++++++++++++++++++++++ .../notification/SemitransparentNotification.html | 27 +++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 tests/testbench/com/vaadin/tests/components/notification/SemiTransparentNotification.java create mode 100755 tests/testbench/com/vaadin/tests/components/notification/SemitransparentNotification.html (limited to 'tests') diff --git a/tests/testbench/com/vaadin/tests/components/notification/SemiTransparentNotification.java b/tests/testbench/com/vaadin/tests/components/notification/SemiTransparentNotification.java new file mode 100755 index 0000000000..d252b89aa3 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/notification/SemiTransparentNotification.java @@ -0,0 +1,34 @@ +package com.vaadin.tests.components.notification; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.LoremIpsum; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window.Notification; + +public class SemiTransparentNotification extends TestBase { + + @Override + protected void setup() { + Label l = new Label(LoremIpsum.get(10000)); + getLayout().setSizeFull(); + addComponent(l); + getMainWindow() + .showNotification( + new Notification( + "                                                     This should be a
SEMI-TRANSPARENT
notification", + Notification.TYPE_WARNING_MESSAGE)); + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/notification/SemitransparentNotification.html b/tests/testbench/com/vaadin/tests/components/notification/SemitransparentNotification.html new file mode 100755 index 0000000000..f125b98ee1 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/notification/SemitransparentNotification.html @@ -0,0 +1,27 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.notification.SemiTransparentNotification
screenCapturesemitransparent-warning
+ + -- cgit v1.2.3 From 15b7d21c5ed5d6f79b9eb091948392586bdb9e70 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 9 Aug 2012 09:50:54 +0000 Subject: Renamed screenshots to have sensible names svn changeset:24130/svn branch:6.8 --- .../datefield/PopupDateFieldExtendedRange.html | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/testbench/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.html b/tests/testbench/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.html index 64fe8e2952..2783ed2aa3 100644 --- a/tests/testbench/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.html +++ b/tests/testbench/com/vaadin/tests/components/datefield/PopupDateFieldExtendedRange.html @@ -24,7 +24,7 @@ screenCapture - + popup1-01-2011 mouseClick @@ -34,7 +34,7 @@ screenCapture - + popup1-12-2010 mouseClick @@ -44,7 +44,7 @@ screenCapture - + popup1-12-2009 mouseClick @@ -64,7 +64,7 @@ screenCapture - + popup2-02-2010 pressSpecialKey @@ -79,7 +79,7 @@ screenCapture - + popup2-03-2010 pressSpecialKey @@ -94,7 +94,7 @@ screenCapture - + popup2-02-2010-again mouseClick @@ -114,7 +114,7 @@ screenCapture - + popup3-01-2010 pressSpecialKey @@ -124,14 +124,13 @@ screenCapture - + popup3-01-2009 mouseClick vaadin=runcomvaadintestscomponentsdatefieldPopupDateFieldExtendedRange::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VPopupCalendar[0]#popupButton 10,8 - -- cgit v1.2.3 From c8f35e5aef1619512aee438c155b417fa7bb48ba Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 10 Aug 2012 14:09:57 +0000 Subject: Disabled shim iframe for all but IE8+ (#9284, #6219) The shim iframe causes crashes in IE6 and does not really help in Opera/Safari/Firefox. svn changeset:24146/svn branch:6.8 --- WebContent/statictestfiles/applet.html | 5 +++ .../tests/components/embedded/TestApplet.class | Bin 0 -> 583 bytes .../vaadin/terminal/gwt/client/ui/VOverlay.java | 22 +++++++++-- .../tests/components/embedded/EmbeddedApplet.html | 36 ++++++++++++++++++ .../tests/components/embedded/EmbeddedApplet.java | 42 +++++++++++++++++++++ .../tests/components/embedded/TestApplet.java | 11 ++++++ 6 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 WebContent/statictestfiles/applet.html create mode 100644 WebContent/statictestfiles/com/vaadin/tests/components/embedded/TestApplet.class create mode 100644 tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.html create mode 100644 tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.java create mode 100644 tests/testbench/com/vaadin/tests/components/embedded/TestApplet.java (limited to 'tests') diff --git a/WebContent/statictestfiles/applet.html b/WebContent/statictestfiles/applet.html new file mode 100644 index 0000000000..05e1785e10 --- /dev/null +++ b/WebContent/statictestfiles/applet.html @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/WebContent/statictestfiles/com/vaadin/tests/components/embedded/TestApplet.class b/WebContent/statictestfiles/com/vaadin/tests/components/embedded/TestApplet.class new file mode 100644 index 0000000000..7650e1f870 Binary files /dev/null and b/WebContent/statictestfiles/com/vaadin/tests/components/embedded/TestApplet.class differ diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java index 60829f1cc8..92f2d6540b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java @@ -244,7 +244,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { } private IFrameElement getShimElement() { - if (shimElement == null) { + if (shimElement == null && useShimIframe()) { shimElement = Document.get().createIFrameElement(); // Insert shim iframe before the main overlay element. It does not @@ -463,8 +463,10 @@ public class VOverlay extends PopupPanel implements CloseHandler { DOM.setStyleAttribute(shadow, "display", progress < 0.9 ? "none" : ""); } - updatePositionAndSize((Element) Element.as(getShimElement()), - positionAndSize); + if (useShimIframe()) { + updatePositionAndSize((Element) Element.as(getShimElement()), + positionAndSize); + } // Opera fix, part 2 (ticket #2704) if (BrowserInfo.get().isOpera() && isShadowEnabled()) { @@ -488,13 +490,25 @@ public class VOverlay extends PopupPanel implements CloseHandler { RootPanel.get().getElement().insertBefore(shadow, getElement()); sinkShadowEvents(); } - if (!isShimAttached()) { + if (useShimIframe() && !isShimAttached()) { RootPanel.get().getElement() .insertBefore(shimElement, getElement()); } } + /** + * Returns true if we should add a shim iframe below the overlay to deal + * with zindex issues with PDFs and applets. Can be overriden to disable + * shim iframes if they are not needed. + * + * @return true if a shim iframe should be added, false otherwise + */ + protected boolean useShimIframe() { + BrowserInfo info = BrowserInfo.get(); + return info.isIE() && info.isBrowserVersionNewerOrEqual(8, 0); + } + private void updatePositionAndSize(Element e, PositionAndSize positionAndSize) { e.getStyle().setLeft(positionAndSize.getLeft(), Unit.PX); diff --git a/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.html b/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.html new file mode 100644 index 0000000000..d8fb0593d1 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.html @@ -0,0 +1,36 @@ + + + + + + +EmbeddedClickListenerRelativeCoordinates + + + + + + + + + + + + + + + + + + + + + + + + + + +
EmbeddedClickListenerRelativeCoordinates
open/run/com.vaadin.tests.components.embedded.EmbeddedApplet?restartApplication
screenCapturewith-applet
clickvaadin=runcomvaadintestscomponentsembeddedEmbeddedApplet::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturewithout-applet
+ + diff --git a/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.java b/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.java new file mode 100644 index 0000000000..7460e15af0 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/embedded/EmbeddedApplet.java @@ -0,0 +1,42 @@ +package com.vaadin.tests.components.embedded; + +import com.vaadin.terminal.ExternalResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Embedded; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; + +public class EmbeddedApplet extends TestBase { + + @Override + protected String getDescription() { + return "The sub window should be shown on top of the embedded applet"; + } + + @Override + protected Integer getTicketNumber() { + return 8399; + } + + @Override + public void setup() { + final Embedded applet = new Embedded(); + applet.setType(Embedded.TYPE_BROWSER); + applet.setWidth("400px"); + applet.setHeight("300px"); + applet.setSource(new ExternalResource("/statictestfiles/applet.html")); + addComponent(applet); + + addComponent(new Button("Remove applet", new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + removeComponent(applet); + } + })); + + Window window = new Window("Testwindow"); + window.addComponent(new Label("I am inside the window")); + applet.getWindow().addWindow(window); + } +} diff --git a/tests/testbench/com/vaadin/tests/components/embedded/TestApplet.java b/tests/testbench/com/vaadin/tests/components/embedded/TestApplet.java new file mode 100644 index 0000000000..3cf7cf888b --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/embedded/TestApplet.java @@ -0,0 +1,11 @@ +package com.vaadin.tests.components.embedded; + +import java.applet.Applet; +import java.awt.Graphics; + +public class TestApplet extends Applet { + @Override + public void paint(Graphics g) { + g.drawString("Hello, I am an applet! Look at me!", 10, 20); + } +} -- cgit v1.2.3 From 131c3db7abb86c7518e5826f74bdd31b729de94e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 13 Aug 2012 10:10:19 +0000 Subject: Correctly measure indent when adding to an empty TreeTable (#9264) svn changeset:24155/svn branch:6.8 --- .../terminal/gwt/client/ui/VScrollTable.java | 6 +- .../vaadin/terminal/gwt/client/ui/VTreeTable.java | 31 ++++++++-- .../treetable/AddItemToEmptyTreeTable.html | 72 ++++++++++++++++++++++ 3 files changed, 103 insertions(+), 6 deletions(-) create mode 100755 tests/testbench/com/vaadin/tests/components/treetable/AddItemToEmptyTreeTable.html (limited to 'tests') diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 43e07376f4..fa2a7c4849 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -4334,8 +4334,10 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, row.addStyleName("v-selected"); } tBodyElement.appendChild(row.getElement()); - adopt(row); + // Add to renderedRows before adopt so iterator() will return also + // this row if called in an attach handler (#9264) renderedRows.add(row); + adopt(row); } private void insertRowAt(VScrollTableRow row, int index) { @@ -6098,7 +6100,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, } availW -= totalExtraWidth; int forceScrollBodyWidth = -1; - + int extraSpace = availW - usedMinimumWidth; if (extraSpace < 0) { if (getTotalRows() == 0) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java b/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java index 4b1448cdfb..ee6a082adc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTreeTable.java @@ -252,8 +252,7 @@ public class VTreeTable extends VScrollTable { if (isTreeCellAdded) { return false; } - return curColIndex == colIndexOfHierarchy - + (showRowHeaders ? 1 : 0); + return curColIndex == getHierarchyColumnIndex(); } @Override @@ -291,6 +290,23 @@ public class VTreeTable extends VScrollTable { super.onAttach(); if (getIndentWidth() < 0) { detectIndent(this); + // If we detect indent here then the size of the hierarchy + // column is still wrong as it has been set when the indent + // was not known. + int w = getCellWidthFromDom(getHierarchyColumnIndex()); + if (w >= 0) { + setColWidth(getHierarchyColumnIndex(), w); + } + } + } + + private int getCellWidthFromDom(int cellIndex) { + final Element cell = DOM.getChild(getElement(), cellIndex); + String w = cell.getStyle().getProperty("width"); + if (w == null || "".equals(w) || !w.endsWith("px")) { + return -1; + } else { + return Integer.parseInt(w.substring(0, w.length() - 2)); } } @@ -329,14 +345,21 @@ public class VTreeTable extends VScrollTable { @Override protected void setCellWidth(int cellIx, int width) { - if (cellIx == colIndexOfHierarchy + (showRowHeaders ? 1 : 0)) { + if (cellIx == getHierarchyColumnIndex()) { // take indentation padding into account if this is the // hierarchy column - width = Math.max(width - getIndent(), 0); + int indent = getIndent(); + if (indent != -1) { + width = Math.max(width - getIndent(), 0); + } } super.setCellWidth(cellIx, width); } + private int getHierarchyColumnIndex() { + return colIndexOfHierarchy + (showRowHeaders ? 1 : 0); + } + private int getIndent() { return (depth + 1) * getIndentWidth(); } diff --git a/tests/testbench/com/vaadin/tests/components/treetable/AddItemToEmptyTreeTable.html b/tests/testbench/com/vaadin/tests/components/treetable/AddItemToEmptyTreeTable.html new file mode 100755 index 0000000000..15dc0e074d --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/treetable/AddItemToEmptyTreeTable.html @@ -0,0 +1,72 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.treetable.TreeTableTest?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_Smenu#item038,10
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[0]/VMenuBar[0]#item552,6
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[1]/VMenuBar[0]#item168,8
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[2]/VMenuBar[0]#item012,4
open/run/com.vaadin.tests.components.treetable.TreeTableTest
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_Smenu#item033,7
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[0]/VMenuBar[0]#item552,9
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[1]/VMenuBar[0]#item139,5
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[2]/VMenuBar[0]#item123,3
screenCaptureitem-added-to-empty-treetable
+ + -- cgit v1.2.3 From 946ce4708d935bfc0b1cd74d121136633799979c Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Wed, 15 Aug 2012 08:59:24 +0000 Subject: TestBench test for #8193 now that #8827 is fixed svn changeset:24175/svn branch:6.8 --- .../popupview/PopupViewClickShortcut.html | 152 +++++++++++++++++++++ .../popupview/PopupViewClickShortcut.java | 17 ++- 2 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.html (limited to 'tests') diff --git a/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.html b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.html new file mode 100644 index 0000000000..c52bfa634d --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.html @@ -0,0 +1,152 @@ + + + + + + +PopupViewClickShortcut + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PopupViewClickShortcut
open/run/com.vaadin.tests.components.popupview.PopupViewClickShortcut?restartApplication=
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::ctrl alt M
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[5]/domChild[0]/domChild[0]added 5
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::PID_SLog_row_01. Submitted from Main window
mouseClickvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VPopupView[0]57,6
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::ctrl alt P
mouseClickvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VPopupView[0]/VPopupView$CustomPopup[0]/VCaptionWrapper[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]159,142
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VPopupView[0]/VPopupView$CustomPopup[0]/VCaptionWrapper[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]ctrl alt P
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VPopupView[0]/VPopupView$CustomPopup[0]/VCaptionWrapper[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[0]/domChild[0]added 6
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::PID_SLog_row_12. Submitted from Popup
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::PID_SLog_row_03. Submitted from Popup
mouseClickvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]83,151
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]ctrl alt S
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[5]/domChild[0]/domChild[0]added 5
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::PID_SLog_row_04. Submitted from Subwindow
mouseClickvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VPopupView[0]76,4
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]/domChild[0]ctrl alt U
mouseClickvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VPopupView[0]/VPopupView$CustomPopup[0]/VCaptionWrapper[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[5]/domChild[0]/domChild[0]132,11
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VPopupView[0]/VPopupView$CustomPopup[0]/VCaptionWrapper[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]ctrl alt U
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VWindow[0]/FocusableScrollPanel[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VPopupView[0]/VPopupView$CustomPopup[0]/VCaptionWrapper[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[0]/domChild[0]added 6
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::PID_SLog_row_15. Submitted from Subwindow popup
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::PID_SLog_row_06. Submitted from Subwindow popup
mouseClickvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::/VVerticalLayout[0]/domChild[0]/domChild[1]279,482
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::ctrl alt P
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::ctrl alt U
pressSpecialKeyvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::ctrl alt S
assertTextvaadin=runcomvaadintestscomponentspopupviewPopupViewClickShortcut::PID_SLog_row_06. Submitted from Subwindow popup
+ + diff --git a/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java index c8d4ee9858..baca96d3c3 100644 --- a/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java +++ b/tests/testbench/com/vaadin/tests/components/popupview/PopupViewClickShortcut.java @@ -46,16 +46,15 @@ public class PopupViewClickShortcut extends TestBase { l.setWidth(null); Button b = new Button("Submit " + caption + " (Ctrl+Alt+" - + String.valueOf(Character.toChars(keyCode)) + ")", - new Button.ClickListener() { - private int i = 5; + + (char) keyCode + ")", new Button.ClickListener() { + private int i = 5; - public void buttonClick(ClickEvent event) { - log.log("Submitted from " - + event.getButton().getParent().getCaption()); - t.addItem(new String[] { "added " + i++ }, i); - } - }); + public void buttonClick(ClickEvent event) { + log.log("Submitted from " + + event.getButton().getParent().getCaption()); + t.addItem(new String[] { "added " + i++ }, i); + } + }); b.setClickShortcut(keyCode, ModifierKey.CTRL, ModifierKey.ALT); l.addComponent(t); -- cgit v1.2.3 From d2110e364b0aa87fd25f1f48d865dd455c5d0d7a Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Fri, 17 Aug 2012 15:13:16 +0000 Subject: #9145 Reviewed and committed Petri's patch with minor cleanup and clarifications svn changeset:24196/svn branch:6.8 --- .../data/util/sqlcontainer/ColumnProperty.java | 101 ++++++++++++++++ .../data/util/sqlcontainer/SQLContainer.java | 38 ++++-- .../query/generator/DefaultSQLGenerator.java | 18 ++- .../data/util/sqlcontainer/ColumnPropertyTest.java | 131 +++++++++++++++++---- 4 files changed, 247 insertions(+), 41 deletions(-) (limited to 'tests') diff --git a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java index 85ff60d5d9..81c0568f15 100644 --- a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java +++ b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java @@ -36,6 +36,7 @@ final public class ColumnProperty implements Property { private boolean modified; private boolean versionColumn; + private boolean primaryKey = false; /** * Prevent instantiation without required parameters. @@ -44,9 +45,50 @@ final public class ColumnProperty implements Property { private ColumnProperty() { } + /** + * Deprecated constructor for ColumnProperty. If this is used the primary + * keys are not identified correctly in some cases for some databases (i.e. + * Oracle). See http://dev.vaadin.com/ticket/9145. + * + * @param propertyId + * @param readOnly + * @param allowReadOnlyChange + * @param nullable + * @param value + * @param type + * + * @deprecated + */ + @Deprecated public ColumnProperty(String propertyId, boolean readOnly, boolean allowReadOnlyChange, boolean nullable, Object value, Class type) { + this(propertyId, readOnly, allowReadOnlyChange, nullable, false, value, + type); + } + + /** + * Creates a new ColumnProperty instance. + * + * @param propertyId + * The ID of this property. + * @param readOnly + * Whether this property is read-only. + * @param allowReadOnlyChange + * Whether the read-only status of this property can be changed. + * @param nullable + * Whether this property accepts null values. + * @param primaryKey + * Whether this property corresponds to a database primary key. + * @param value + * The value of this property. + * @param type + * The type of this property. + */ + public ColumnProperty(String propertyId, boolean readOnly, + boolean allowReadOnlyChange, boolean nullable, boolean primaryKey, + Object value, Class type) { + if (propertyId == null) { throw new IllegalArgumentException("Properties must be named."); } @@ -60,8 +102,15 @@ final public class ColumnProperty implements Property { this.allowReadOnlyChange = allowReadOnlyChange; this.nullable = nullable; this.readOnly = readOnly; + this.primaryKey = primaryKey; } + /** + * Returns the current value for this property. To get the previous value + * (if one exists) for a modified property use {@link #getOldValue()}. + * + * @return + */ public Object getValue() { if (isModified()) { return changedValue; @@ -69,6 +118,17 @@ final public class ColumnProperty implements Property { return value; } + /** + * Returns the original non-modified value of this property if it has been + * modified. + * + * @return The original value if isModified() is true, + * getValue() otherwise. + */ + public Object getOldValue() { + return value; + } + public void setValue(Object newValue) throws ReadOnlyException, ConversionException { if (newValue == null && !nullable) { @@ -154,6 +214,17 @@ final public class ColumnProperty implements Property { return readOnly; } + /** + * Returns whether the read-only status of this property can be changed + * using {@link #setReadOnly(boolean)}. + *

+ * Used to prevent setting to read/write mode a property that is not allowed + * to be written by the underlying database. Also used for values like + * VERSION and AUTO_INCREMENT fields that might be set to read-only by the + * container but the database still allows writes. + * + * @return true if the read-only status can be changed, false otherwise. + */ public boolean isReadOnlyChangeAllowed() { return allowReadOnlyChange; } @@ -164,6 +235,10 @@ final public class ColumnProperty implements Property { } } + public boolean isPrimaryKey() { + return primaryKey; + } + public String getPropertyId() { return propertyId; } @@ -204,6 +279,32 @@ final public class ColumnProperty implements Property { return nullable; } + /** + * Return whether the value of this property should be persisted to the + * database. + * + * @return true if the value should be written to the database, false + * otherwise. + */ + public boolean isPersistent() { + if (isVersionColumn()) { + return false; + } else if (isReadOnlyChangeAllowed() && !isReadOnly()) { + return true; + } else { + return false; + } + } + + /** + * Returns whether or not this property is used as a row identifier. + * + * @return true if the property is a row identifier, false otherwise. + */ + public boolean isRowIdentifier() { + return isPrimaryKey() || isVersionColumn(); + } + /** * An exception that signals that a null value was passed to * the setValue method, but the value of this property can not diff --git a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index 32afc337a8..71b260fa21 100644 --- a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -56,7 +56,9 @@ public class SQLContainer implements Container, Container.Filterable, private final List propertyIds = new ArrayList(); private final Map> propertyTypes = new HashMap>(); private final Map propertyReadOnly = new HashMap(); + private final Map propertyPersistable = new HashMap(); private final Map propertyNullable = new HashMap(); + private final Map propertyPrimaryKey = new HashMap(); /** Filters (WHERE) and sorters (ORDER BY) */ private final List filters = new ArrayList(); @@ -136,11 +138,14 @@ public class SQLContainer implements Container, Container.Filterable, List itemProperties = new ArrayList(); for (String propertyId : propertyIds) { /* Default settings for new item properties. */ - itemProperties - .add(new ColumnProperty(propertyId, propertyReadOnly - .get(propertyId), - !propertyReadOnly.get(propertyId), propertyNullable - .get(propertyId), null, getType(propertyId))); + ColumnProperty cp = new ColumnProperty(propertyId, + propertyReadOnly.get(propertyId), + propertyPersistable.get(propertyId), + propertyNullable.get(propertyId), + propertyPrimaryKey.get(propertyId), null, + getType(propertyId)); + + itemProperties.add(cp); } RowItem newRowItem = new RowItem(this, itemId, itemProperties); @@ -1085,14 +1090,22 @@ public class SQLContainer implements Container, Container.Filterable, */ boolean readOnly = rsmd.isAutoIncrement(i) || rsmd.isReadOnly(i); - if (delegate instanceof TableQuery - && rsmd.getColumnLabel(i).equals( - ((TableQuery) delegate).getVersionColumn())) { - readOnly = true; + + boolean persistable = !rsmd.isReadOnly(i); + + if (delegate instanceof TableQuery) { + if (rsmd.getColumnLabel(i).equals( + ((TableQuery) delegate).getVersionColumn())) { + readOnly = true; + } } + propertyReadOnly.put(colName, readOnly); + propertyPersistable.put(colName, persistable); propertyNullable.put(colName, rsmd.isNullable(i) == ResultSetMetaData.columnNullable); + propertyPrimaryKey.put(colName, delegate.getPrimaryKeyColumns() + .contains(rsmd.getColumnLabel(i))); propertyTypes.put(colName, type); } rs.getStatement().close(); @@ -1192,10 +1205,13 @@ public class SQLContainer implements Container, Container.Filterable, * column. */ if (propertiesToAdd.contains(colName)) { + cp = new ColumnProperty(colName, propertyReadOnly.get(colName), - !propertyReadOnly.get(colName), - propertyNullable.get(colName), value, type); + propertyPersistable.get(colName), + propertyNullable.get(colName), + propertyPrimaryKey.get(colName), value, + type); itemProperties.add(cp); propertiesToAdd.remove(colName); } diff --git a/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java b/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java index d1700fc0d2..130a72605f 100644 --- a/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java +++ b/src/com/vaadin/data/util/sqlcontainer/query/generator/DefaultSQLGenerator.java @@ -311,10 +311,8 @@ public class DefaultSQLGenerator implements SQLGenerator { && cp.getPropertyId().equalsIgnoreCase("rownum")) { continue; } - Object value = cp.getValue() == null ? null : cp.getValue(); - /* Only include properties whose read-only status can be altered */ - if (cp.isReadOnlyChangeAllowed() && !cp.isVersionColumn()) { - columnToValueMap.put(cp.getPropertyId(), value); + if (cp.isPersistent()) { + columnToValueMap.put(cp.getPropertyId(), cp.getValue()); } } return columnToValueMap; @@ -329,8 +327,16 @@ public class DefaultSQLGenerator implements SQLGenerator { && cp.getPropertyId().equalsIgnoreCase("rownum")) { continue; } - Object value = cp.getValue() == null ? null : cp.getValue(); - if (!cp.isReadOnlyChangeAllowed() || cp.isVersionColumn()) { + + if (cp.isRowIdentifier()) { + Object value; + if (cp.isPrimaryKey()) { + // If the value of a primary key has changed, its old value + // should be used to identify the row (#9145) + value = cp.getOldValue(); + } else { + value = cp.getValue(); + } rowIdentifiers.put(cp.getPropertyId(), value); } } diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/ColumnPropertyTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/ColumnPropertyTest.java index b9621d518a..09f620cc2a 100644 --- a/tests/server-side/com/vaadin/data/util/sqlcontainer/ColumnPropertyTest.java +++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/ColumnPropertyTest.java @@ -4,46 +4,48 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; import java.util.Arrays; -import com.vaadin.data.Property.ReadOnlyException; -import com.vaadin.data.util.sqlcontainer.ColumnProperty.NotNullableException; -import com.vaadin.data.util.sqlcontainer.query.QueryDelegate; - import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Test; +import com.vaadin.data.Property.ReadOnlyException; +import com.vaadin.data.util.sqlcontainer.ColumnProperty.NotNullableException; +import com.vaadin.data.util.sqlcontainer.query.QueryDelegate; + public class ColumnPropertyTest { @Test public void constructor_legalParameters_shouldSucceed() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); Assert.assertNotNull(cp); } @Test(expected = IllegalArgumentException.class) public void constructor_missingPropertyId_shouldFail() { - new ColumnProperty(null, false, true, true, "Ville", String.class); + new ColumnProperty(null, false, true, true, false, "Ville", + String.class); } @Test(expected = IllegalArgumentException.class) public void constructor_missingType_shouldFail() { - new ColumnProperty("NAME", false, true, true, "Ville", null); + new ColumnProperty("NAME", false, true, true, false, "Ville", null); } @Test public void getValue_defaultValue_returnsVille() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); Assert.assertEquals("Ville", cp.getValue()); } @Test public void setValue_readWriteNullable_returnsKalle() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); SQLContainer container = EasyMock.createMock(SQLContainer.class); RowItem owner = new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); @@ -57,7 +59,7 @@ public class ColumnPropertyTest { @Test(expected = ReadOnlyException.class) public void setValue_readOnlyNullable_shouldFail() { ColumnProperty cp = new ColumnProperty("NAME", true, true, true, - "Ville", String.class); + false, "Ville", String.class); SQLContainer container = EasyMock.createMock(SQLContainer.class); new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); EasyMock.replay(container); @@ -68,7 +70,7 @@ public class ColumnPropertyTest { @Test public void setValue_readWriteNullable_nullShouldWork() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); SQLContainer container = EasyMock.createMock(SQLContainer.class); RowItem owner = new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); @@ -82,7 +84,7 @@ public class ColumnPropertyTest { @Test(expected = NotNullableException.class) public void setValue_readWriteNotNullable_nullShouldFail() { ColumnProperty cp = new ColumnProperty("NAME", false, true, false, - "Ville", String.class); + false, "Ville", String.class); SQLContainer container = EasyMock.createMock(SQLContainer.class); RowItem owner = new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); @@ -96,28 +98,28 @@ public class ColumnPropertyTest { @Test public void getType_normal_returnsStringClass() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); Assert.assertSame(String.class, cp.getType()); } @Test public void isReadOnly_readWriteNullable_returnsTrue() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); Assert.assertFalse(cp.isReadOnly()); } @Test public void isReadOnly_readOnlyNullable_returnsTrue() { ColumnProperty cp = new ColumnProperty("NAME", true, true, true, - "Ville", String.class); + false, "Ville", String.class); Assert.assertTrue(cp.isReadOnly()); } @Test public void setReadOnly_readOnlyChangeAllowed_shouldSucceed() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); cp.setReadOnly(true); Assert.assertTrue(cp.isReadOnly()); } @@ -125,7 +127,7 @@ public class ColumnPropertyTest { @Test public void setReadOnly_readOnlyChangeDisallowed_shouldFail() { ColumnProperty cp = new ColumnProperty("NAME", false, false, true, - "Ville", String.class); + false, "Ville", String.class); cp.setReadOnly(true); Assert.assertFalse(cp.isReadOnly()); } @@ -133,14 +135,14 @@ public class ColumnPropertyTest { @Test public void getPropertyId_normal_returnsNAME() { ColumnProperty cp = new ColumnProperty("NAME", false, false, true, - "Ville", String.class); + false, "Ville", String.class); Assert.assertEquals("NAME", cp.getPropertyId()); } @Test public void isModified_valueModified_returnsTrue() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); SQLContainer container = EasyMock.createMock(SQLContainer.class); RowItem owner = new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); @@ -155,14 +157,14 @@ public class ColumnPropertyTest { @Test public void isModified_valueNotModified_returnsFalse() { ColumnProperty cp = new ColumnProperty("NAME", false, false, true, - "Ville", String.class); + false, "Ville", String.class); Assert.assertFalse(cp.isModified()); } @Test public void setValue_nullOnNullable_shouldWork() { ColumnProperty cp = new ColumnProperty("NAME", false, true, true, - "asdf", String.class); + false, "asdf", String.class); SQLContainer container = EasyMock.createMock(SQLContainer.class); new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); cp.setValue(null); @@ -171,8 +173,8 @@ public class ColumnPropertyTest { @Test public void setValue_resetTonullOnNullable_shouldWork() { - ColumnProperty cp = new ColumnProperty("NAME", false, true, true, null, - String.class); + ColumnProperty cp = new ColumnProperty("NAME", false, true, true, false, + null, String.class); SQLContainer container = EasyMock.createMock(SQLContainer.class); new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); cp.setValue("asdf"); @@ -202,7 +204,7 @@ public class ColumnPropertyTest { } ColumnProperty property = new ColumnProperty("NAME", false, true, true, - "Ville", String.class); + false, "Ville", String.class); Statement statement = EasyMock.createNiceMock(Statement.class); EasyMock.replay(statement); @@ -229,4 +231,85 @@ public class ColumnPropertyTest { Assert.assertEquals("Kalle", container.value); Assert.assertTrue(container.modified); } + + @Test + public void versionColumnsShouldNotBeInValueMap_shouldReturnFalse() { + ColumnProperty property = new ColumnProperty("NAME", false, true, true, + false, "Ville", String.class); + property.setVersionColumn(true); + + Assert.assertFalse(property.isPersistent()); + } + + @Test + public void neverWritableColumnsShouldNotBeInValueMap_shouldReturnFalse() { + ColumnProperty property = new ColumnProperty("NAME", true, false, true, + false, "Ville", String.class); + + Assert.assertFalse(property.isPersistent()); + } + + @Test + public void writableColumnsShouldBeInValueMap_shouldReturnTrue() { + ColumnProperty property = new ColumnProperty("NAME", false, true, true, + false, "Ville", String.class); + + Assert.assertTrue(property.isPersistent()); + } + + @Test + public void writableButReadOnlyColumnsShouldNotBeInValueMap_shouldReturnFalse() { + ColumnProperty property = new ColumnProperty("NAME", true, true, true, + false, "Ville", String.class); + + Assert.assertFalse(property.isPersistent()); + } + + @Test + public void primKeysShouldBeRowIdentifiers_shouldReturnTrue() { + ColumnProperty property = new ColumnProperty("NAME", false, true, true, + true, "Ville", String.class); + + Assert.assertTrue(property.isRowIdentifier()); + } + + @Test + public void versionColumnsShouldBeRowIdentifiers_shouldReturnTrue() { + ColumnProperty property = new ColumnProperty("NAME", false, true, true, + false, "Ville", String.class); + property.setVersionColumn(true); + + Assert.assertTrue(property.isRowIdentifier()); + } + + @Test + public void nonPrimKeyOrVersionColumnsShouldBeNotRowIdentifiers_shouldReturnFalse() { + ColumnProperty property = new ColumnProperty("NAME", false, true, true, + false, "Ville", String.class); + + Assert.assertFalse(property.isRowIdentifier()); + } + + @Test + public void getOldValueShouldReturnPreviousValue_shouldReturnVille() { + ColumnProperty property = new ColumnProperty("NAME", false, true, true, + false, "Ville", String.class); + + // Here we really don't care about the container management, but in + // order to set the value for a column the owner (RowItem) must be set + // and to create the owner we must have a container... + ArrayList properties = new ArrayList(); + properties.add(property); + + SQLContainer container = EasyMock.createNiceMock(SQLContainer.class); + RowItem rowItem = new RowItem(container, new RowId(new Object[] { 1 }), + Arrays.asList(property)); + + property.setValue("Kalle"); + // Just check that the new value was actually set... + Assert.assertEquals("Kalle", property.getValue()); + // Assert that old value is the original value... + Assert.assertEquals("Ville", property.getOldValue()); + } + } -- cgit v1.2.3