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(-) 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 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(-) 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 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 458f8bed858f72af8c15086220dd18dfe0abe804 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Mon, 6 Aug 2012 15:08:17 +0000 Subject: Moved #9136 fix into a helper method svn changeset:24088/svn branch:6.8 --- src/com/vaadin/terminal/gwt/client/ui/VTree.java | 37 ++++++++---------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java index 2d318522ea..c32e035e1c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java @@ -714,7 +714,7 @@ public class VTree extends FocusElementPanel implements Paintable, focus(); } - ScheduledCommand command = new ScheduledCommand() { + executeEventCommand(new ScheduledCommand() { public void execute() { if (multiSelectMode == MULTISELECT_MODE_SIMPLE @@ -748,21 +748,7 @@ 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); - } else { - command.execute(); - } + }); return true; } @@ -906,7 +892,8 @@ public class VTree extends FocusElementPanel implements Paintable, } } final MouseEventDetails details = new MouseEventDetails(evt); - ScheduledCommand command = new ScheduledCommand() { + + executeEventCommand(new ScheduledCommand() { public void execute() { // Determine if we should send the event immediately to the // server. We do not want to send the event if there is a @@ -933,15 +920,15 @@ public class VTree extends FocusElementPanel implements Paintable, client.updateVariable(paintableId, "clickEvent", details.toString(), sendClickEventNow); } - }; + }); + } + + /* + * Must wait for Safari to focus before sending click and value change + * events (see #6373, #6374) + */ + private void executeEventCommand(ScheduledCommand command) { 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(); -- 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(-) 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 acde6c0f95a86c2819f34616d8102ade90044c3a Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 7 Aug 2012 11:44:18 +0000 Subject: Refactoring based on review (#6219) svn changeset:24093/svn branch:6.8 --- .../vaadin/terminal/gwt/client/ui/VMenuBar.java | 2 +- .../terminal/gwt/client/ui/VNotification.java | 2 +- .../vaadin/terminal/gwt/client/ui/VOverlay.java | 64 ++++++++++++---------- .../vaadin/terminal/gwt/client/ui/VPopupView.java | 2 +- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java index d89cec9ad6..04374f357e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java @@ -793,7 +793,7 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, contentWidth + Util.getNativeScrollbarSize(), Unit.PX); } - popup.sizeOrPositionUpdated(); + popup.positionOrSizeUpdated(); } } return top; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java index e56a458147..ca4c99be01 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java @@ -154,7 +154,7 @@ public class VNotification extends VOverlay { super.show(); notifications.add(this); setPosition(position); - sizeOrPositionUpdated(); + positionOrSizeUpdated(); /** * Android 4 fails to render notifications correctly without a little * nudge (#8551) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java index f385aa0676..60829f1cc8 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java @@ -30,6 +30,14 @@ public class VOverlay extends PopupPanel implements CloseHandler { public static class PositionAndSize { private int left, top, width, height; + public PositionAndSize(int left, int top, int width, int height) { + super(); + setLeft(left); + setTop(top); + setWidth(width); + setHeight(height); + } + public int getLeft() { return left; } @@ -51,6 +59,10 @@ public class VOverlay extends PopupPanel implements CloseHandler { } public void setWidth(int width) { + if (width < 0) { + width = 0; + } + this.width = width; } @@ -59,6 +71,10 @@ public class VOverlay extends PopupPanel implements CloseHandler { } public void setHeight(int height) { + if (height < 0) { + height = 0; + } + this.height = height; } @@ -224,7 +240,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { style.setMarginLeft(-adjustByRelativeLeftBodyMargin(), Unit.PX); style.setMarginTop(-adjustByRelativeTopBodyMargin(), Unit.PX); super.setPopupPosition(left, top); - sizeOrPositionUpdated(isAnimationEnabled() ? 0 : 1); + positionOrSizeUpdated(isAnimationEnabled() ? 0 : 1); } private IFrameElement getShimElement() { @@ -316,7 +332,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { if (isAnimationEnabled()) { new ResizeAnimation().run(POPUP_PANEL_ANIMATION_DURATION); } else { - sizeOrPositionUpdated(1.0); + positionOrSizeUpdated(1.0); } Util.runIE7ZeroSizedBodyFix(); } @@ -348,13 +364,13 @@ public class VOverlay extends PopupPanel implements CloseHandler { @Override public void setWidth(String width) { super.setWidth(width); - sizeOrPositionUpdated(1.0); + positionOrSizeUpdated(1.0); } @Override public void setHeight(String height) { super.setHeight(height); - sizeOrPositionUpdated(1.0); + positionOrSizeUpdated(1.0); } /** @@ -378,15 +394,15 @@ public class VOverlay extends PopupPanel implements CloseHandler { * size of overlay without using normal 'setWidth(String)' and * 'setHeight(String)' methods (if not calling super.setWidth/Height). * - * @deprecated Call {@link #sizeOrPositionUpdated()} instead. + * @deprecated Call {@link #positionOrSizeUpdated()} instead. */ @Deprecated protected void updateShadowSizeAndPosition() { - sizeOrPositionUpdated(); + positionOrSizeUpdated(); } - protected void sizeOrPositionUpdated() { - sizeOrPositionUpdated(1.0); + protected void positionOrSizeUpdated() { + positionOrSizeUpdated(1.0); } /** @@ -399,7 +415,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { * A value between 0.0 and 1.0, indicating the progress of the * animation (0=start, 1=end). */ - private void sizeOrPositionUpdated(final double progress) { + private void positionOrSizeUpdated(final double progress) { // Don't do anything if overlay element is not attached if (!isAttached()) { return; @@ -424,18 +440,8 @@ public class VOverlay extends PopupPanel implements CloseHandler { getOffsetWidth(); } - PositionAndSize positionAndSize = new PositionAndSize(); - positionAndSize.left = getActualLeft(); - positionAndSize.top = getActualTop(); - positionAndSize.width = getOffsetWidth(); - positionAndSize.height = getOffsetHeight(); - - if (positionAndSize.width < 0) { - positionAndSize.width = 0; - } - if (positionAndSize.height < 0) { - positionAndSize.height = 0; - } + PositionAndSize positionAndSize = new PositionAndSize(getActualLeft(), + getActualTop(), getOffsetWidth(), getOffsetHeight()); // Animate the size positionAndSize.setAnimationFromCenterProgress(progress); @@ -452,12 +458,12 @@ public class VOverlay extends PopupPanel implements CloseHandler { // Update correct values if (isShadowEnabled()) { - updateSizeAndPosition(shadow, positionAndSize); + updatePositionAndSize(shadow, positionAndSize); DOM.setStyleAttribute(shadow, "zIndex", zIndex); DOM.setStyleAttribute(shadow, "display", progress < 0.9 ? "none" : ""); } - updateSizeAndPosition((Element) Element.as(getShimElement()), + updatePositionAndSize((Element) Element.as(getShimElement()), positionAndSize); // Opera fix, part 2 (ticket #2704) @@ -489,18 +495,18 @@ public class VOverlay extends PopupPanel implements CloseHandler { } - private void updateSizeAndPosition(Element e, + private void updatePositionAndSize(Element e, PositionAndSize positionAndSize) { - e.getStyle().setLeft(positionAndSize.left, Unit.PX); - e.getStyle().setTop(positionAndSize.top, Unit.PX); - e.getStyle().setWidth(positionAndSize.width, Unit.PX); - e.getStyle().setHeight(positionAndSize.height, Unit.PX); + e.getStyle().setLeft(positionAndSize.getLeft(), Unit.PX); + e.getStyle().setTop(positionAndSize.getTop(), Unit.PX); + e.getStyle().setWidth(positionAndSize.getWidth(), Unit.PX); + e.getStyle().setHeight(positionAndSize.getHeight(), Unit.PX); } protected class ResizeAnimation extends Animation { @Override protected void onUpdate(double progress) { - sizeOrPositionUpdated(progress); + positionOrSizeUpdated(progress); } } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java index 6a46d64c5a..280ca720fc 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupView.java @@ -477,7 +477,7 @@ public class VPopupView extends HTML implements Container, Iterable { } public boolean requestLayout(Set child) { - popup.sizeOrPositionUpdated(); + popup.positionOrSizeUpdated(); return true; } -- cgit v1.2.3 From 0cb6d53b234eafbf94a3d451d7ebddd8d2e14e53 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Tue, 7 Aug 2012 11:46:34 +0000 Subject: Enable native touch scrolling on iOS 6 (#8792) svn changeset:24094/svn branch:6.8 --- WebContent/VAADIN/themes/base/common/common.css | 4 ++++ src/com/vaadin/terminal/gwt/client/BrowserInfo.java | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/WebContent/VAADIN/themes/base/common/common.css b/WebContent/VAADIN/themes/base/common/common.css index 74ed21bd1a..6bc3fea9b0 100644 --- a/WebContent/VAADIN/themes/base/common/common.css +++ b/WebContent/VAADIN/themes/base/common/common.css @@ -233,4 +233,8 @@ div.v-app-loading { .v-scrollable { overflow: auto; +} +/* Enable kinetic scrolling on Mobile Safari */ +.v-ios.v-sa6 .v-scrollable { + -webkit-overflow-scrolling: touch; } \ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java index 4b9f3eacab..76c9552e6a 100644 --- a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java +++ b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java @@ -450,13 +450,15 @@ public class BrowserInfo { if (!isTouchDevice()) { return false; } + // Android 4+ has native scrolling if (isAndroid() && isWebkit() && getWebkitVersion() >= 534) { return false; } - // Cannot enable native touch scrolling on iOS 5 until #8792 is resolved - // if (isIOS() && isWebkit() && getWebkitVersion() >= 534) { - // return false; - // } + // iOS 5 has native scrolling but suffers from #8792; + // iOS 6 works fine. + if (isIOS() && isWebkit() && getWebkitVersion() >= 536) { + return false; + } return true; } -- cgit v1.2.3 From 80d8cb69ce6e5dfa4a6a356e91559c062664b360 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 7 Aug 2012 13:05:15 +0000 Subject: #9155 revert first fix for now - requires proper fix in Select together with this correction svn changeset:24095/svn branch:6.8 --- src/com/vaadin/data/util/sqlcontainer/SQLContainer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java index 156b51b94c..32afc337a8 100644 --- a/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java +++ b/src/com/vaadin/data/util/sqlcontainer/SQLContainer.java @@ -510,7 +510,9 @@ public class SQLContainer implements Container, Container.Filterable, */ public void removeContainerFilter(Filter filter) { filters.remove(filter); - refresh(); + // TODO this cannot be added before ComboBox is fixed + // (Select.requestRepaint() must not affect filter string) + // refresh(); } /** -- cgit v1.2.3 From 6ce151337819a3f694ceba19016748de47c132e9 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 7 Aug 2012 13:18:32 +0000 Subject: Updated supported browsers svn changeset:24096/svn branch:6.8 --- WebContent/release-notes.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WebContent/release-notes.html b/WebContent/release-notes.html index eeacbfac75..792c129aea 100644 --- a/WebContent/release-notes.html +++ b/WebContent/release-notes.html @@ -394,11 +394,11 @@

    -
  • Mozilla Firefox 3-12
  • +
  • Mozilla Firefox 3-14
  • Internet Explorer 6-9
  • Safari 4-5
  • -
  • Opera 10-11
  • -
  • Google Chrome 13-19
  • +
  • Opera 10-12
  • +
  • Google Chrome 13-21

-- cgit v1.2.3 From 22116474403982fbeb44112c385657cc9dee8d19 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 7 Aug 2012 13:18:47 +0000 Subject: Updated resolved ticket list for 6.8.2 svn changeset:24097/svn branch:6.8 --- WebContent/release-notes.html | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/WebContent/release-notes.html b/WebContent/release-notes.html index 792c129aea..f9aaf12b1b 100644 --- a/WebContent/release-notes.html +++ b/WebContent/release-notes.html @@ -81,21 +81,35 @@

    -
  • #6039: Extra scrollbars when resizing Table
  • -
  • #7387: TreeTable loses formatting when using addGeneratedColumn
  • -
  • #7766: component in Panel in DragAndDropWrapper fails to show tooltip
  • -
  • #7938: Window.center() keeps the window centered on implicit resize
  • -
  • #8386: ChameleonTheme.THEME_NAME is wrong typed
  • -
  • #8852: Sizing problem of Form in a subwindow when error indicator is shown
  • -
  • #8941: Malformed response header for Cache-Control max-age (problematic in MSIE)
  • -
  • #8949: Drag&Drop image with DragStartMode.WRAPPER is broken since 6.8.0
  • -
  • #8957: Table rendering broken in IE if paddings remove on cell-content and cell-wrapper
  • -
  • #9064: Could not select row in edit mode on a row with a boolean value
  • +
  • #8932: Custom build from 6.8
  • +
  • #8193: Enter ClickShortcut not working in a PopupView
  • +
  • #8584: Invalid behavior of multiselection for com.vaadin.ui.Table
  • +
  • #9136: Tree throws wrong ItemClickEvent in IE9 (when immediate is set to true)
  • +
  • #9139: TextArea in Internet Explorer
  • +
  • #9188: Error parsing maps with empty string as the last value
  • +
  • #7036: Enable scrollbars on a read-only RichTextArea
  • +
  • #8109: Iterating over Table multiselection causes multiple Vaadin SQLContainer full table scans
  • +
  • #8144: Can't use LoginForm inside an iframe
  • +
  • #9202: Test using Chrome 21
  • +
  • #6219: PDF viewer draws itself over floating Vaadin elements
  • +
  • #8230: TextField's input prompt is persisted if Alt is depressed while in focus (Chrome)
  • +
  • #8399: On IE 8 or Google Chrome 16, VOverlay components aren't display on top of Applet
  • +
  • #9148: Oracle TIMESTAMP not supported in SQLContainer
  • +
  • #9189: Variables sent to the DragAndDropManager are not logged in the debug console
  • +
  • #9128: Typo in vaadin book
  • +
  • #8736: com.vaadin.ui.Table component return null value on multiple selection
  • +
  • #9132: No entries in Table with a defined pageLength causes Table to shrink in height
  • +
  • #9147: SQLContainer Filters - Comparison against NULL value produces error
  • +
  • #9154: NumberFormatException in client-side component VSplitPanel
  • +
  • #9171: StreamVariable never cleaned up in CommunicationManager
  • +
  • #9187: No horizontal scroll bar on empty Table
  • +
  • #8838: Drag and Drop in Google Chrome causes ArrayIndexOutOfBoundsException in AbstractCommunicationManager#convertMap (1612)
  • +
  • #8917: input prompt text is leaking into the component's value

The full + href="http://dev.vaadin.com/query?status=closed&resolution=fixed&milestone=Vaadin+@version@&order=priority">full list of the closed issues can be found at dev.vaadin.com.

-- cgit v1.2.3 From b5d5e2029cc39bcdd3ff7cd870f5a84c853e4614 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Tue, 7 Aug 2012 13:27:30 +0000 Subject: Remove #8792 fix from 6.8.2, defer to 6.8.3 svn changeset:24098/svn branch:6.8 --- WebContent/VAADIN/themes/base/common/common.css | 4 ---- src/com/vaadin/terminal/gwt/client/BrowserInfo.java | 10 ++++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/WebContent/VAADIN/themes/base/common/common.css b/WebContent/VAADIN/themes/base/common/common.css index 6bc3fea9b0..74ed21bd1a 100644 --- a/WebContent/VAADIN/themes/base/common/common.css +++ b/WebContent/VAADIN/themes/base/common/common.css @@ -233,8 +233,4 @@ div.v-app-loading { .v-scrollable { overflow: auto; -} -/* Enable kinetic scrolling on Mobile Safari */ -.v-ios.v-sa6 .v-scrollable { - -webkit-overflow-scrolling: touch; } \ No newline at end of file diff --git a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java index 76c9552e6a..4b9f3eacab 100644 --- a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java +++ b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java @@ -450,15 +450,13 @@ public class BrowserInfo { if (!isTouchDevice()) { return false; } - // Android 4+ has native scrolling if (isAndroid() && isWebkit() && getWebkitVersion() >= 534) { return false; } - // iOS 5 has native scrolling but suffers from #8792; - // iOS 6 works fine. - if (isIOS() && isWebkit() && getWebkitVersion() >= 536) { - return false; - } + // Cannot enable native touch scrolling on iOS 5 until #8792 is resolved + // if (isIOS() && isWebkit() && getWebkitVersion() >= 534) { + // return false; + // } return true; } -- cgit v1.2.3 From f303f62b2e966fe8e4f2a220f03c8c6b777212ed Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 7 Aug 2012 15:54:17 +0000 Subject: Use latest 6.8 version for diff svn changeset:24100/svn branch:6.8 --- build/bin/package-diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/bin/package-diff.py b/build/bin/package-diff.py index f3b0d59562..f926ea46f4 100644 --- a/build/bin/package-diff.py +++ b/build/bin/package-diff.py @@ -7,7 +7,7 @@ from sets import Set # Configuration ################################################################################ downloadsite = "http://vaadin.com/download" -latestfile = "/release/6.7/LATEST" +latestfile = "/release/6.8/LATEST" JAPIZE = "japize" JAPICOMPAT = "japicompat" -- 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(-) 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 f0a48ad7bf6a99527a207b0f2825abf0da366bdd Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 8 Aug 2012 12:28:06 +0000 Subject: Change #9251 fix to preserve iteration order. svn changeset:24116/svn branch:6.8 --- src/com/vaadin/ui/Window.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/vaadin/ui/Window.java b/src/com/vaadin/ui/Window.java index fce9a30c82..55917c3ddd 100644 --- a/src/com/vaadin/ui/Window.java +++ b/src/com/vaadin/ui/Window.java @@ -10,7 +10,6 @@ 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; @@ -1550,7 +1549,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler, * @return Set of child windows. */ public Set getChildWindows() { - return Collections.unmodifiableSet(new HashSet(subwindows)); + return Collections + .unmodifiableSet(new LinkedHashSet(subwindows)); } /** -- 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(-) 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 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 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(-) 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 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 1e81c23ea378facf0d3ef9fd3fa24c4d813fce5e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sat, 11 Aug 2012 12:05:07 +0000 Subject: Include statictestfiles in test war svn changeset:24151/svn branch:6.8 --- build/build.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/build/build.xml b/build/build.xml index a6a75b8918..4f267c333d 100644 --- a/build/build.xml +++ b/build/build.xml @@ -414,6 +414,7 @@ + -- 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 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 856a68cbdb93d8ca8b6b45b604f606bfbb138b28 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 13 Aug 2012 10:11:42 +0000 Subject: Renames based on review (#9284) svn changeset:24156/svn branch:6.8 --- src/com/vaadin/terminal/gwt/client/ui/VOverlay.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java index 92f2d6540b..6efedda93c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VOverlay.java @@ -190,7 +190,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { return shadow != null; } - private void removeShim() { + private void removeShimElement() { if (shimElement != null) { shimElement.removeFromParent(); } @@ -209,7 +209,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { return isShadowEnabled() && shadow.getParentElement() != null; } - private boolean isShimAttached() { + private boolean isShimElementAttached() { return shimElement != null && shimElement.hasParentElement(); } @@ -244,7 +244,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { } private IFrameElement getShimElement() { - if (shimElement == null && useShimIframe()) { + if (shimElement == null && needsShimElement()) { shimElement = Document.get().createIFrameElement(); // Insert shim iframe before the main overlay element. It does not @@ -349,7 +349,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { // Always ensure shadow is removed when the overlay is removed. removeShadowIfPresent(); - removeShim(); + removeShimElement(); } @Override @@ -463,7 +463,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { DOM.setStyleAttribute(shadow, "display", progress < 0.9 ? "none" : ""); } - if (useShimIframe()) { + if (needsShimElement()) { updatePositionAndSize((Element) Element.as(getShimElement()), positionAndSize); } @@ -490,9 +490,9 @@ public class VOverlay extends PopupPanel implements CloseHandler { RootPanel.get().getElement().insertBefore(shadow, getElement()); sinkShadowEvents(); } - if (useShimIframe() && !isShimAttached()) { + if (needsShimElement() && !isShimElementAttached()) { RootPanel.get().getElement() - .insertBefore(shimElement, getElement()); + .insertBefore(getShimElement(), getElement()); } } @@ -504,7 +504,7 @@ public class VOverlay extends PopupPanel implements CloseHandler { * * @return true if a shim iframe should be added, false otherwise */ - protected boolean useShimIframe() { + protected boolean needsShimElement() { BrowserInfo info = BrowserInfo.get(); return info.isIE() && info.isBrowserVersionNewerOrEqual(8, 0); } -- cgit v1.2.3 From eb9eef97e527d366f25b9dffd4b992d0e9a0ca65 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 13 Aug 2012 10:11:49 +0000 Subject: Enforce max length when max length changes (#9199) svn changeset:24157/svn branch:6.8 --- .../vaadin/terminal/gwt/client/ui/VTextArea.java | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java b/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java index 4ab27646ed..a90a5679d9 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTextArea.java @@ -63,18 +63,6 @@ public class VTextArea extends VTextField { 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. @@ -83,6 +71,18 @@ public class VTextArea extends VTextField { } + protected void enforceMaxLength() { + if (getMaxLength() >= 0) { + Scheduler.get().scheduleDeferred(new Command() { + public void execute() { + if (getText().length() > getMaxLength()) { + setText(getText().substring(0, getMaxLength())); + } + } + }); + } + } + protected boolean browserSupportsMaxLengthAttribute() { BrowserInfo info = BrowserInfo.get(); if (info.isFirefox() && info.isBrowserVersionNewerOrEqual(4, 0)) { @@ -105,7 +105,9 @@ public class VTextArea extends VTextField { if (browserSupportsMaxLengthAttribute) { super.updateMaxLength(maxLength); } else { - // Handled automatically by MaxLengthHandler + // Events handled by MaxLengthHandler. This call enforces max length + // when the max length value has changed + enforceMaxLength(); } } -- 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 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 6af7d09617d77e34c7abecf02b12b538bf19550f Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Fri, 17 Aug 2012 08:20:48 +0000 Subject: Fix getResourceCacheTime() javadoc to specify that the return value is in seconds, not milliseconds svn changeset:24189/svn branch:6.8 --- src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index b7a6fd3479..9313e3bcad 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -370,10 +370,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements } /** - * Returns the amount of milliseconds the browser should cache a file. - * Default is 1 hour (3600 ms). + * Returns the number of seconds the browser should cache a file. Default is + * 1 hour (3600 s). * - * @return The amount of milliseconds files are cached in the browser + * @return The number of seconds files are cached in the browser */ public int getResourceCacheTime() { return resourceCacheTime; -- 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(-) 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 From 890356e6ab17661364a04d60ded9fe01628b0830 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 20 Aug 2012 08:53:33 +0300 Subject: Support @Delayable and change window size update to use it (#8421) --- .../gwt/widgetsetutils/RpcProxyGenerator.java | 7 +- .../terminal/gwt/client/ApplicationConnection.java | 90 ++++++++++++++-------- .../gwt/client/JavaScriptConnectorHelper.java | 5 +- .../src/com/vaadin/terminal/gwt/client/Util.java | 8 +- .../JavaScriptManagerConnector.java | 2 +- .../terminal/gwt/client/ui/root/RootConnector.java | 12 +++ .../vaadin/terminal/gwt/client/ui/root/VRoot.java | 20 +++-- server/src/com/vaadin/terminal/Page.java | 20 ++--- .../gwt/server/AbstractCommunicationManager.java | 1 + .../server/LegacyChangeVariablesInvocation.java | 50 ------------ server/src/com/vaadin/ui/Root.java | 13 ++-- server/src/com/vaadin/ui/Window.java | 19 ----- .../src/com/vaadin/shared/annotations/Delayed.java | 54 +++++++++++++ .../LegacyChangeVariablesInvocation.java | 57 ++++++++++++++ .../shared/communication/MethodInvocation.java | 14 ++++ .../com/vaadin/shared/ui/root/RootConstants.java | 4 - .../com/vaadin/shared/ui/root/RootServerRpc.java | 5 +- 17 files changed, 239 insertions(+), 142 deletions(-) delete mode 100644 server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java create mode 100644 shared/src/com/vaadin/shared/annotations/Delayed.java create mode 100644 shared/src/com/vaadin/shared/communication/LegacyChangeVariablesInvocation.java diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java index a54798e5d6..6d322c734e 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java @@ -29,6 +29,7 @@ import com.google.gwt.core.ext.typeinfo.JParameter; import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; +import com.vaadin.shared.annotations.Delayed; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.terminal.gwt.client.ApplicationConnection; @@ -129,6 +130,10 @@ public class RpcProxyGenerator extends Generator { writer.println(" {"); writer.indent(); + Delayed delayedAnnotation = m.getAnnotation(Delayed.class); + boolean delayed = delayedAnnotation != null; + boolean lastonly = delayed && delayedAnnotation.lastonly(); + writer.print("this.connector.getConnection().addMethodInvocationToQueue(new MethodInvocation(this.connector.getConnectorId(), \"" + requestedType.getQualifiedBinaryName() + "\", \""); writer.print(m.getName()); @@ -145,7 +150,7 @@ public class RpcProxyGenerator extends Generator { writer.print(p.getName()); } - writer.println("}), true);"); + writer.println("}), " + delayed + ", " + lastonly + ");"); writer.outdent(); writer.println("}"); diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index a8852fe9fa..664a73dc12 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -22,6 +22,7 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -54,9 +55,9 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.ComponentState; import com.vaadin.shared.Version; +import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.SharedState; -import com.vaadin.shared.communication.UidlValue; import com.vaadin.terminal.gwt.client.ApplicationConfiguration.ErrorMessage; import com.vaadin.terminal.gwt.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.terminal.gwt.client.ResourceLoader.ResourceLoadListener; @@ -132,7 +133,18 @@ public class ApplicationConnection { private final HashMap resourcesMap = new HashMap(); - private ArrayList pendingInvocations = new ArrayList(); + /** + * The pending method invocations that will be send to the server by + * {@link #sendPendingCommand}. The key is defined differently based on + * whether the method invocation is enqueued with lastonly. With lastonly + * enabled, the method signature ( {@link MethodInvocation#getLastonlyTag()} + * ) is used as the key to make enable removing a previously enqueued + * invocation. Without lastonly, an incremental id based on + * {@link #lastInvocationTag} is used to get unique values. + */ + private LinkedHashMap pendingInvocations = new LinkedHashMap(); + + private int lastInvocationTag = 0; private WidgetSet widgetSet; @@ -155,7 +167,7 @@ public class ApplicationConnection { private ApplicationConfiguration configuration; /** List of pending variable change bursts that must be submitted in order */ - private final ArrayList> pendingBursts = new ArrayList>(); + private final ArrayList> pendingBursts = new ArrayList>(); /** Timer for automatic refirect to SessionExpiredURL */ private Timer redirectTimer; @@ -886,12 +898,11 @@ public class ApplicationConnection { private void checkForPendingVariableBursts() { cleanVariableBurst(pendingInvocations); if (pendingBursts.size() > 0) { - for (Iterator> iterator = pendingBursts - .iterator(); iterator.hasNext();) { - cleanVariableBurst(iterator.next()); + for (LinkedHashMap pendingBurst : pendingBursts) { + cleanVariableBurst(pendingBurst); } - ArrayList nextBurst = pendingBursts.get(0); - pendingBursts.remove(0); + LinkedHashMap nextBurst = pendingBursts + .remove(0); buildAndSendVariableBurst(nextBurst, false); } } @@ -902,13 +913,15 @@ public class ApplicationConnection { * * @param variableBurst */ - private void cleanVariableBurst(ArrayList variableBurst) { - for (int i = 1; i < variableBurst.size(); i++) { - String id = variableBurst.get(i).getConnectorId(); + private void cleanVariableBurst( + LinkedHashMap variableBurst) { + Iterator iterator = variableBurst.values().iterator(); + while (iterator.hasNext()) { + String id = iterator.next().getConnectorId(); if (!getConnectorMap().hasConnector(id) && !getConnectorMap().isDragAndDropPaintable(id)) { // variable owner does not exist anymore - variableBurst.remove(i); + iterator.remove(); VConsole.log("Removed variable from removed component: " + id); } } @@ -1693,12 +1706,10 @@ public class ApplicationConnection { private void addVariableToQueue(String connectorId, String variableName, Object value, boolean immediate) { + boolean lastOnly = !immediate; // note that type is now deduced from value - // TODO could eliminate invocations of same shared variable setter - addMethodInvocationToQueue(new MethodInvocation(connectorId, - ApplicationConstants.UPDATE_VARIABLE_INTERFACE, - ApplicationConstants.UPDATE_VARIABLE_METHOD, new Object[] { - variableName, new UidlValue(value) }), immediate); + addMethodInvocationToQueue(new LegacyChangeVariablesInvocation( + connectorId, variableName, value), lastOnly, lastOnly); } /** @@ -1708,16 +1719,31 @@ public class ApplicationConnection { * * @param invocation * RPC method invocation - * @param immediate - * true to trigger sending within a short time window (possibly - * combining subsequent calls to a single request), false to let - * the framework delay sending of RPC calls and variable changes - * until the next immediate change + * @param delayed + * false to trigger sending within a short time + * window (possibly combining subsequent calls to a single + * request), true to let the framework delay sending + * of RPC calls and variable changes until the next non-delayed + * change + * @param lastonly + * true to remove all previously delayed invocations + * of the same method that were also enqueued with lastonly set + * to true. false to add invocation to + * the end of the queue without touching previously enqueued + * invocations. */ public void addMethodInvocationToQueue(MethodInvocation invocation, - boolean immediate) { - pendingInvocations.add(invocation); - if (immediate) { + boolean delayed, boolean lastonly) { + String tag; + if (lastonly) { + tag = invocation.getLastonlyTag(); + assert !tag.matches("\\d+") : "getLastonlyTag value must have at least one non-digit character"; + pendingInvocations.remove(tag); + } else { + tag = Integer.toString(lastInvocationTag++); + } + pendingInvocations.put(tag, invocation); + if (!delayed) { sendPendingVariableChanges(); } } @@ -1748,14 +1774,15 @@ public class ApplicationConnection { }; private boolean deferedSendPending = false; - @SuppressWarnings("unchecked") private void doSendPendingVariableChanges() { if (applicationRunning) { if (hasActiveRequest()) { // skip empty queues if there are pending bursts to be sent if (pendingInvocations.size() > 0 || pendingBursts.size() == 0) { pendingBursts.add(pendingInvocations); - pendingInvocations = new ArrayList(); + pendingInvocations = new LinkedHashMap(); + // Keep tag string short + lastInvocationTag = 0; } } else { buildAndSendVariableBurst(pendingInvocations, false); @@ -1776,17 +1803,18 @@ public class ApplicationConnection { * Should we use synchronous request? */ private void buildAndSendVariableBurst( - ArrayList pendingInvocations, boolean forceSync) { + LinkedHashMap pendingInvocations, + boolean forceSync) { final StringBuffer req = new StringBuffer(); while (!pendingInvocations.isEmpty()) { if (ApplicationConfiguration.isDebugMode()) { - Util.logVariableBurst(this, pendingInvocations); + Util.logVariableBurst(this, pendingInvocations.values()); } JSONArray reqJson = new JSONArray(); - for (MethodInvocation invocation : pendingInvocations) { + for (MethodInvocation invocation : pendingInvocations.values()) { JSONArray invocationJson = new JSONArray(); invocationJson.set(0, new JSONString(invocation.getConnectorId())); @@ -1810,6 +1838,8 @@ public class ApplicationConnection { req.append(escapeBurstContents(reqJson.toString())); pendingInvocations.clear(); + // Keep tag string short + lastInvocationTag = 0; // Append all the bursts to this synchronous request if (forceSync && !pendingBursts.isEmpty()) { pendingInvocations = pendingBursts.get(0); diff --git a/client/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java b/client/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java index 98c014b5ec..6494ae3480 100644 --- a/client/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java +++ b/client/src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java @@ -267,7 +267,7 @@ public class JavaScriptConnectorHelper { } connector.getConnection().addMethodInvocationToQueue( new MethodInvocation(connector.getConnectorId(), iface, method, - parameters), true); + parameters), false, false); } private String findWildcardInterface(String method) { @@ -298,7 +298,8 @@ public class JavaScriptConnectorHelper { connector.getConnectorId(), "com.vaadin.ui.JavaScript$JavaScriptCallbackRpc", "call", new Object[] { name, new JSONArray(arguments) }); - connector.getConnection().addMethodInvocationToQueue(invocation, true); + connector.getConnection().addMethodInvocationToQueue(invocation, false, + false); } public void setNativeState(JavaScriptObject state) { diff --git a/client/src/com/vaadin/terminal/gwt/client/Util.java b/client/src/com/vaadin/terminal/gwt/client/Util.java index 571258dbe3..96344f0792 100644 --- a/client/src/com/vaadin/terminal/gwt/client/Util.java +++ b/client/src/com/vaadin/terminal/gwt/client/Util.java @@ -874,13 +874,13 @@ public class Util { } static void logVariableBurst(ApplicationConnection c, - ArrayList loggedBurst) { + Collection loggedBurst) { try { VConsole.log("Variable burst to be sent to server:"); String curId = null; ArrayList invocations = new ArrayList(); - for (int i = 0; i < loggedBurst.size(); i++) { - String id = loggedBurst.get(i).getConnectorId(); + for (MethodInvocation methodInvocation : loggedBurst) { + String id = methodInvocation.getConnectorId(); if (curId == null) { curId = id; @@ -889,7 +889,7 @@ public class Util { invocations.clear(); curId = id; } - invocations.add(loggedBurst.get(i)); + invocations.add(methodInvocation); } if (!invocations.isEmpty()) { printConnectorInvocations(invocations, curId, c); diff --git a/client/src/com/vaadin/terminal/gwt/client/extensions/javascriptmanager/JavaScriptManagerConnector.java b/client/src/com/vaadin/terminal/gwt/client/extensions/javascriptmanager/JavaScriptManagerConnector.java index 5cc5911bb1..46578b0641 100644 --- a/client/src/com/vaadin/terminal/gwt/client/extensions/javascriptmanager/JavaScriptManagerConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/extensions/javascriptmanager/JavaScriptManagerConnector.java @@ -124,7 +124,7 @@ public class JavaScriptManagerConnector extends AbstractExtensionConnector { getConnection().addMethodInvocationToQueue( new MethodInvocation(getConnectorId(), "com.vaadin.ui.JavaScript$JavaScriptCallbackRpc", - "call", parameters), true); + "call", parameters), false, false); } @Override diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java index 0a0e0e5082..9b5c3cd767 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java @@ -23,6 +23,8 @@ import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Position; +import com.google.gwt.event.logical.shared.ResizeEvent; +import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestCallback; @@ -98,6 +100,16 @@ public class RootConnector extends AbstractComponentContainerConnector schedule(heartbeatInterval); } }.schedule(heartbeatInterval); + getWidget().addResizeHandler(new ResizeHandler() { + @Override + public void onResize(ResizeEvent event) { + rpc.resize(event.getHeight(), event.getWidth(), + Window.getClientWidth(), Window.getClientHeight()); + if (getState().isImmediate()) { + getConnection().sendPendingVariableChanges(); + } + } + }); } @Override diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java b/client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java index a473bf4846..162e7c55a8 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/root/VRoot.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; +import com.google.gwt.event.logical.shared.HasResizeHandlers; import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.event.logical.shared.ValueChangeEvent; @@ -50,7 +51,8 @@ import com.vaadin.terminal.gwt.client.ui.textfield.VTextField; * */ public class VRoot extends SimplePanel implements ResizeHandler, - Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable { + Window.ClosingHandler, ShortcutActionHandlerOwner, Focusable, + HasResizeHandlers { private static final String CLASSNAME = "v-view"; @@ -401,16 +403,7 @@ public class VRoot extends SimplePanel implements ResizeHandler, int viewHeight = parentElement.getClientHeight(); int viewWidth = parentElement.getClientWidth(); - connection.updateVariable(id, "height", viewHeight, false); - connection.updateVariable(id, "width", viewWidth, false); - - int windowWidth = Window.getClientWidth(); - int windowHeight = Window.getClientHeight(); - - connection.updateVariable(id, RootConstants.BROWSER_WIDTH_VAR, - windowWidth, false); - connection.updateVariable(id, RootConstants.BROWSER_HEIGHT_VAR, - windowHeight, immediate); + ResizeEvent.fire(this, viewWidth, viewHeight); } public native static void goTo(String url) @@ -458,4 +451,9 @@ public class VRoot extends SimplePanel implements ResizeHandler, touchScrollHandler.addElement(getElement()); } + @Override + public HandlerRegistration addResizeHandler(ResizeHandler resizeHandler) { + return addHandler(resizeHandler, ResizeEvent.getType()); + } + } diff --git a/server/src/com/vaadin/terminal/Page.java b/server/src/com/vaadin/terminal/Page.java index d5d474e2e3..933f9b39e6 100644 --- a/server/src/com/vaadin/terminal/Page.java +++ b/server/src/com/vaadin/terminal/Page.java @@ -376,23 +376,17 @@ public class Page implements Serializable { .getBrowser(); } - public void setBrowserWindowSize(Integer width, Integer height) { + public void setBrowserWindowSize(int width, int height) { boolean fireEvent = false; - if (width != null) { - int newWidth = width.intValue(); - if (newWidth != browserWindowWidth) { - browserWindowWidth = newWidth; - fireEvent = true; - } + if (width != browserWindowWidth) { + browserWindowWidth = width; + fireEvent = true; } - if (height != null) { - int newHeight = height.intValue(); - if (newHeight != browserWindowHeight) { - browserWindowHeight = newHeight; - fireEvent = true; - } + if (height != browserWindowHeight) { + browserWindowHeight = height; + fireEvent = true; } if (fireEvent) { diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 00e65382cd..96ae70f27c 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -69,6 +69,7 @@ import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Connector; import com.vaadin.shared.Version; +import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.SharedState; import com.vaadin.shared.communication.UidlValue; diff --git a/server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java b/server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java deleted file mode 100644 index fc3fbd6c00..0000000000 --- a/server/src/com/vaadin/terminal/gwt/server/LegacyChangeVariablesInvocation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2011 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.terminal.gwt.server; - -import java.util.HashMap; -import java.util.Map; - -import com.vaadin.shared.ApplicationConstants; -import com.vaadin.shared.communication.MethodInvocation; - -public class LegacyChangeVariablesInvocation extends MethodInvocation { - private Map variableChanges = new HashMap(); - - public LegacyChangeVariablesInvocation(String connectorId, - String variableName, Object value) { - super(connectorId, ApplicationConstants.UPDATE_VARIABLE_INTERFACE, - ApplicationConstants.UPDATE_VARIABLE_METHOD); - setVariableChange(variableName, value); - } - - public static boolean isLegacyVariableChange(String interfaceName, - String methodName) { - return ApplicationConstants.UPDATE_VARIABLE_METHOD - .equals(interfaceName) - && ApplicationConstants.UPDATE_VARIABLE_METHOD - .equals(methodName); - } - - public void setVariableChange(String name, Object value) { - variableChanges.put(name, value); - } - - public Map getVariableChanges() { - return variableChanges; - } - -} diff --git a/server/src/com/vaadin/ui/Root.java b/server/src/com/vaadin/ui/Root.java index 685296c55a..b37005a16e 100644 --- a/server/src/com/vaadin/ui/Root.java +++ b/server/src/com/vaadin/ui/Root.java @@ -434,6 +434,13 @@ public abstract class Root extends AbstractComponentContainer implements public void click(MouseEventDetails mouseDetails) { fireEvent(new ClickEvent(Root.this, mouseDetails)); } + + @Override + public void resize(int viewWidth, int viewHeight, int windowWidth, + int windowHeight) { + // TODO We're not doing anything with the view dimensions + getPage().setBrowserWindowSize(windowWidth, windowHeight); + } }; /** @@ -582,12 +589,6 @@ public abstract class Root extends AbstractComponentContainer implements .get(RootConstants.FRAGMENT_VARIABLE); getPage().setFragment(fragment, true); } - - if (variables.containsKey("height") || variables.containsKey("width")) { - getPage().setBrowserWindowSize((Integer) variables.get("width"), - (Integer) variables.get("height")); - } - } /* diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index 13ef7e5784..d1d2c25d8b 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -32,7 +32,6 @@ import com.vaadin.event.ShortcutAction.KeyCode; import com.vaadin.event.ShortcutAction.ModifierKey; import com.vaadin.event.ShortcutListener; import com.vaadin.shared.MouseEventDetails; -import com.vaadin.shared.ui.root.RootConstants; import com.vaadin.shared.ui.window.WindowServerRpc; import com.vaadin.shared.ui.window.WindowState; import com.vaadin.terminal.PaintException; @@ -76,10 +75,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, } }; - private int browserWindowWidth = -1; - - private int browserWindowHeight = -1; - /** * Creates a new unnamed window with a default layout. */ @@ -170,20 +165,6 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, .get("width") != getWidth())) { sizeHasChanged = true; } - Integer browserHeightVar = (Integer) variables - .get(RootConstants.BROWSER_HEIGHT_VAR); - if (browserHeightVar != null - && browserHeightVar.intValue() != browserWindowHeight) { - browserWindowHeight = browserHeightVar.intValue(); - sizeHasChanged = true; - } - Integer browserWidthVar = (Integer) variables - .get(RootConstants.BROWSER_WIDTH_VAR); - if (browserWidthVar != null - && browserWidthVar.intValue() != browserWindowWidth) { - browserWindowWidth = browserWidthVar.intValue(); - sizeHasChanged = true; - } super.changeVariables(source, variables); diff --git a/shared/src/com/vaadin/shared/annotations/Delayed.java b/shared/src/com/vaadin/shared/annotations/Delayed.java new file mode 100644 index 0000000000..706ffc1c53 --- /dev/null +++ b/shared/src/com/vaadin/shared/annotations/Delayed.java @@ -0,0 +1,54 @@ +/* + * Copyright 2011 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.shared.annotations; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +import com.vaadin.shared.communication.ServerRpc; + +/** + * Invoking a method in a {@link ServerRpc} interface marked with this + * annotation will only add the invocation to a queue of outgoing RPC + * invocations, but it will not cause the queue to be purged and sent to the + * server. The queue will instead be sent when any RPC method not marked as @Delayed + * has been invoked. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +@Target(ElementType.METHOD) +@Documented +public @interface Delayed { + /** + * By setting lastonly to true, any previous invocations of the + * same method will be removed from the queue when a new invocation is + * added. This can be used in cases where only the last value is of + * interest. + *

+ * The default value is false which means that invoking the + * method multiple times will cause multiple invocations to be enqueued and + * eventually sent to the server. + * + * @return true if only the last invocation of the annotated + * method should be sent to the server, false if all + * enqueued invocations should be sent. + */ + public boolean lastonly() default false; +} diff --git a/shared/src/com/vaadin/shared/communication/LegacyChangeVariablesInvocation.java b/shared/src/com/vaadin/shared/communication/LegacyChangeVariablesInvocation.java new file mode 100644 index 0000000000..2ffc56dd71 --- /dev/null +++ b/shared/src/com/vaadin/shared/communication/LegacyChangeVariablesInvocation.java @@ -0,0 +1,57 @@ +/* + * Copyright 2011 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.shared.communication; + +import java.util.HashMap; +import java.util.Map; + +import com.vaadin.shared.ApplicationConstants; + +public class LegacyChangeVariablesInvocation extends MethodInvocation { + private Map variableChanges = new HashMap(); + + public LegacyChangeVariablesInvocation(String connectorId, + String variableName, Object value) { + super(connectorId, ApplicationConstants.UPDATE_VARIABLE_INTERFACE, + ApplicationConstants.UPDATE_VARIABLE_METHOD, new Object[] { + variableName, new UidlValue(value) }); + setVariableChange(variableName, value); + } + + public static boolean isLegacyVariableChange(String interfaceName, + String methodName) { + return ApplicationConstants.UPDATE_VARIABLE_METHOD + .equals(interfaceName) + && ApplicationConstants.UPDATE_VARIABLE_METHOD + .equals(methodName); + } + + public void setVariableChange(String name, Object value) { + variableChanges.put(name, value); + } + + public Map getVariableChanges() { + return variableChanges; + } + + @Override + public String getLastonlyTag() { + assert variableChanges.size() == 1; + return super.getLastonlyTag() + + variableChanges.keySet().iterator().next(); + } + +} diff --git a/shared/src/com/vaadin/shared/communication/MethodInvocation.java b/shared/src/com/vaadin/shared/communication/MethodInvocation.java index 720ce09fcb..c4da937c27 100644 --- a/shared/src/com/vaadin/shared/communication/MethodInvocation.java +++ b/shared/src/com/vaadin/shared/communication/MethodInvocation.java @@ -71,4 +71,18 @@ public class MethodInvocation implements Serializable { + Arrays.toString(parameters) + ")"; } + /** + * Gets a String tag that is used to uniquely identify previous method + * invocations that should be purged from the queue if + * {@literal @}Delay(lastonly = true) is used. + *

+ * The returned string should contain at least one non-number char to ensure + * it doesn't collide with the keys used for invocations without lastonly. + * + * @return a string identifying this method invocation + */ + public String getLastonlyTag() { + return connectorId + "-" + getInterfaceName() + "-" + getMethodName(); + } + } \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/root/RootConstants.java b/shared/src/com/vaadin/shared/ui/root/RootConstants.java index bc4f6017f6..34c17ac71f 100644 --- a/shared/src/com/vaadin/shared/ui/root/RootConstants.java +++ b/shared/src/com/vaadin/shared/ui/root/RootConstants.java @@ -21,11 +21,7 @@ public class RootConstants { */ @Deprecated public static final String RESIZE_LAZY = "rL"; - @Deprecated - public static final String BROWSER_HEIGHT_VAR = "browserHeight"; - @Deprecated - public static final String BROWSER_WIDTH_VAR = "browserWidth"; @Deprecated public static final String NOTIFICATION_HTML_CONTENT_NOT_ALLOWED = "useplain"; diff --git a/shared/src/com/vaadin/shared/ui/root/RootServerRpc.java b/shared/src/com/vaadin/shared/ui/root/RootServerRpc.java index f074a8d3cc..df2031f7d5 100644 --- a/shared/src/com/vaadin/shared/ui/root/RootServerRpc.java +++ b/shared/src/com/vaadin/shared/ui/root/RootServerRpc.java @@ -15,9 +15,12 @@ */ package com.vaadin.shared.ui.root; +import com.vaadin.shared.annotations.Delayed; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.ui.ClickRpc; public interface RootServerRpc extends ClickRpc, ServerRpc { - + @Delayed(lastonly = true) + public void resize(int viewWidth, int viewHeight, int windowWidth, + int windowHeight); } \ No newline at end of file -- cgit v1.2.3 From a80335107906f1c41c1f42d2462dd838e8ea5b6c Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Wed, 15 Aug 2012 16:12:50 +0300 Subject: Introduce ClientConnector.beforeClientResponse(boolean initial) #9228 Remove Component.updateState() to use the new method instead. --- .../vaadin/terminal/AbstractClientConnector.java | 5 +++ .../gwt/server/AbstractCommunicationManager.java | 11 ++++-- .../terminal/gwt/server/ClientConnector.java | 20 ++++++++++ .../terminal/gwt/server/DragAndDropService.java | 5 +++ server/src/com/vaadin/ui/AbsoluteLayout.java | 4 +- server/src/com/vaadin/ui/AbstractComponent.java | 8 +--- server/src/com/vaadin/ui/AbstractField.java | 4 +- server/src/com/vaadin/ui/AbstractTextField.java | 4 +- server/src/com/vaadin/ui/Component.java | 12 ------ server/src/com/vaadin/ui/ConnectorTracker.java | 45 ++++++++++++++++++++++ server/src/com/vaadin/ui/CssLayout.java | 4 +- 11 files changed, 93 insertions(+), 29 deletions(-) diff --git a/server/src/com/vaadin/terminal/AbstractClientConnector.java b/server/src/com/vaadin/terminal/AbstractClientConnector.java index 0eb38a3d13..bc1cd2af1a 100644 --- a/server/src/com/vaadin/terminal/AbstractClientConnector.java +++ b/server/src/com/vaadin/terminal/AbstractClientConnector.java @@ -518,4 +518,9 @@ public abstract class AbstractClientConnector implements ClientConnector { return getParent().isConnectorEnabled(); } } + + @Override + public void beforeClientResponse(boolean initial) { + // Do nothing by default + } } diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 96ae70f27c..ffee517550 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -819,6 +819,7 @@ public abstract class AbstractCommunicationManager implements Serializable { if (repaintAll) { getClientCache(root).clear(); rootConnectorTracker.markAllConnectorsDirty(); + rootConnectorTracker.markAllClientSidesUninitialized(); // Reset sent locales locales = null; @@ -833,9 +834,9 @@ public abstract class AbstractCommunicationManager implements Serializable { "Found " + dirtyVisibleConnectors.size() + " dirty connectors to paint"); for (ClientConnector connector : dirtyVisibleConnectors) { - if (connector instanceof Component) { - ((Component) connector).updateState(); - } + boolean initialized = rootConnectorTracker + .isClientSideInitialized(connector); + connector.beforeClientResponse(!initialized); } rootConnectorTracker.markAllConnectorsClean(); @@ -1251,6 +1252,10 @@ public abstract class AbstractCommunicationManager implements Serializable { dragAndDropService.printJSONResponse(outWriter); } + for (ClientConnector connector : dirtyVisibleConnectors) { + rootConnectorTracker.markClientSideInitialized(connector); + } + writePerformanceData(outWriter); } diff --git a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java index eef4e240ec..c9fe2563f9 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java +++ b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java @@ -157,4 +157,24 @@ public interface ClientConnector extends Connector, RpcTarget { * attached to any Root */ public Root getRoot(); + + /** + * Called before the shared state and RPC invocations are sent to the + * client. Gives the connector an opportunity to set computed/dynamic state + * values or to invoke last minute RPC methods depending on other component + * features. + *

+ * This method must not alter the component hierarchy in any way. Calling + * requestRepaint() from this method will have no effect. + *

+ * + * @param initial + * true if the client-side connector will be created + * and initialized after this method has been invoked. + * false if there is already an initialized + * client-side connector. + * + * @since 7.0 + */ + public void beforeClientResponse(boolean initial); } diff --git a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java index bb96c6e53e..56d5ed1393 100644 --- a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java +++ b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java @@ -322,4 +322,9 @@ public class DragAndDropService implements VariableOwner, ClientConnector { public Root getRoot() { return null; } + + @Override + public void beforeClientResponse(boolean initial) { + // Nothing to do + } } diff --git a/server/src/com/vaadin/ui/AbsoluteLayout.java b/server/src/com/vaadin/ui/AbsoluteLayout.java index 9851a79bcd..a3bc577fe3 100644 --- a/server/src/com/vaadin/ui/AbsoluteLayout.java +++ b/server/src/com/vaadin/ui/AbsoluteLayout.java @@ -169,8 +169,8 @@ public class AbsoluteLayout extends AbstractLayout implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // This could be in internalRemoveComponent and internalSetComponent if // Map was supported. We cannot get the child diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index fb3993d0cf..cde5217ca1 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -717,13 +717,9 @@ public abstract class AbstractComponent extends AbstractClientConnector return (ComponentState) super.getState(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Component#updateState() - */ @Override - public void updateState() { + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // TODO This logic should be on the client side and the state should // simply be a data object with "width" and "height". if (getHeight() >= 0 diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 2d14acf442..67a1826100 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -1620,8 +1620,8 @@ public abstract class AbstractField extends AbstractComponent implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); // Hide the error indicator if needed getState().setHideErrors(shouldHideErrors()); diff --git a/server/src/com/vaadin/ui/AbstractTextField.java b/server/src/com/vaadin/ui/AbstractTextField.java index c8bbadd0ab..86315f801f 100644 --- a/server/src/com/vaadin/ui/AbstractTextField.java +++ b/server/src/com/vaadin/ui/AbstractTextField.java @@ -97,8 +97,8 @@ public abstract class AbstractTextField extends AbstractField implements } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); String value = getValue(); if (value == null) { diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index ac668168f2..ff7ed47930 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -636,18 +636,6 @@ public interface Component extends ClientConnector, Sizeable, Serializable { @Override public ComponentState getState(); - /** - * Called before the shared state is sent to the client. Gives the component - * an opportunity to set computed/dynamic state values e.g. state values - * that depend on other component features. - *

- * This method must not alter the component hierarchy in any way. - *

- * - * @since 7.0 - */ - public void updateState(); - /** * Adds an unique id for component that get's transferred to terminal for * testing purposes. Keeping identifiers unique is the responsibility of the diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index 12ad377b62..27dfebd95e 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -25,6 +25,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.terminal.AbstractClientConnector; +import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.server.ClientConnector; /** @@ -50,6 +51,7 @@ public class ConnectorTracker implements Serializable { private final HashMap connectorIdToConnector = new HashMap(); private Set dirtyConnectors = new HashSet(); + private Set uninitializedConnectors = new HashSet(); private Root root; @@ -91,6 +93,7 @@ public class ConnectorTracker implements Serializable { .get(connectorId); if (previouslyRegistered == null) { connectorIdToConnector.put(connectorId, connector); + uninitializedConnectors.add(connector); getLogger().fine( "Registered " + connector.getClass().getSimpleName() + " (" + connectorId + ")"); @@ -136,6 +139,47 @@ public class ConnectorTracker implements Serializable { "Unregistered " + connector.getClass().getSimpleName() + " (" + connectorId + ")"); connectorIdToConnector.remove(connectorId); + uninitializedConnectors.remove(connector); + } + + /** + * Checks whether the given connector has already been initialized in the + * browser. The given connector should be registered with this connector + * tracker. + * + * @param connector + * the client connector to check + * @return true if the initial state has previously been sent + * to the browser, false if the client-side doesn't + * already know anything about the connector. + */ + public boolean isClientSideInitialized(ClientConnector connector) { + assert connectorIdToConnector.get(connector.getConnectorId()) == connector : "Connector should be registered with this ConnectorTracker"; + return !uninitializedConnectors.contains(connector); + } + + /** + * Marks the given connector as initialized, meaning that the client-side + * state has been initialized for the connector. + * + * @see #isClientSideInitialized(ClientConnector) + * + * @param connector + * the connector that should be marked as initialized + */ + public void markClientSideInitialized(ClientConnector connector) { + uninitializedConnectors.remove(connector); + } + + /** + * Marks all currently registered connectors as uninitialized. This should + * be done when the client-side has been reset but the server-side state is + * retained. + * + * @see #isClientSideInitialized(ClientConnector) + */ + public void markAllClientSidesUninitialized() { + uninitializedConnectors.addAll(connectorIdToConnector.values()); } /** @@ -175,6 +219,7 @@ public class ConnectorTracker implements Serializable { "cleanConnectorMap unregistered connector " + getConnectorAndParentInfo(connector) + "). This should have been done when the connector was detached."); + uninitializedConnectors.remove(connector); iterator.remove(); } } diff --git a/server/src/com/vaadin/ui/CssLayout.java b/server/src/com/vaadin/ui/CssLayout.java index c43f347e68..0192debc4a 100644 --- a/server/src/com/vaadin/ui/CssLayout.java +++ b/server/src/com/vaadin/ui/CssLayout.java @@ -197,8 +197,8 @@ public class CssLayout extends AbstractLayout implements LayoutClickNotifier { } @Override - public void updateState() { - super.updateState(); + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); getState().getChildCss().clear(); for (Iterator ci = getComponentIterator(); ci.hasNext();) { Component child = ci.next(); -- cgit v1.2.3 From 44758a2791a568f97a11e7da918444e4fffec84e Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 16 Aug 2012 09:47:14 +0300 Subject: Don't decode enum as an object (#9333) --- .../com/vaadin/terminal/gwt/server/JsonCodec.java | 13 ++++--- .../vaadin/tests/serialization/SerializerTest.html | 40 ++++++++++++---------- .../vaadin/tests/serialization/SerializerTest.java | 12 +++++++ .../widgetset/client/SerializerTestConnector.java | 11 ++++++ .../tests/widgetset/client/SerializerTestRpc.java | 3 ++ 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index 60197b0b3a..94d860a200 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -165,6 +165,10 @@ public class JsonCodec implements Serializable { } else if (targetType == JSONObject.class || targetType == JSONArray.class) { return value; + } else if (Enum.class.isAssignableFrom(getClassForType(targetType))) { + Class classForType = getClassForType(targetType); + return decodeEnum(classForType.asSubclass(Enum.class), + (String) value); } else { return decodeObject(targetType, (JSONObject) value, connectorTracker); @@ -420,9 +424,8 @@ public class JsonCodec implements Serializable { } } - private static Object decodeEnum(Class cls, JSONObject value) { - String enumIdentifier = String.valueOf(value); - return Enum.valueOf(cls, enumIdentifier); + private static Object decodeEnum(Class cls, String value) { + return Enum.valueOf(cls, value); } private static String[] decodeStringArray(JSONArray jsonArray) @@ -491,10 +494,6 @@ public class JsonCodec implements Serializable { throws JSONException { Class targetClass = getClassForType(targetType); - if (Enum.class.isAssignableFrom(targetClass)) { - return decodeEnum(targetClass.asSubclass(Enum.class), - serializedObject); - } try { Object decodedObject = targetClass.newInstance(); diff --git a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html index 3d52356cab..4417fabf14 100644 --- a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html +++ b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.html @@ -18,90 +18,94 @@ assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[16] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[17] 1. sendBoolean: false, false, [false, false, true, false, true, true] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[15] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[16] 2. sendByte: 5, -12, [3, 1, 2] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[14] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[15] 3. sendChar: Å, ∫, [a, b, c, d] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[13] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[14] 4. sendInt: 2, 5, [2147483647, 0] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[12] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[13] 5. sendLong: -57841235865, 577431841358, [57, 0] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[11] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[12] 6. sendFloat: 1.0000001, 3.14159, [-12.0, 0.0, 57.0] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[10] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[11] 7. sendDouble: 0.423310825130748, 5.859874482048838, [2.0, 1.7976931348623157E308, 4.9E-324] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[9] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[10] 8. sendString: Taegghiiiinnrsssstt‡ assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[8] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[9] 9. sendConnector: com.vaadin.tests.widgetset.server.SerializerTestExtension assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[7] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[8] 10. sendBean: ComplexTestBean [innerBean1=SimpleTestBean(1), innerBean2=SimpleTestBean(3), innerBeanCollection=[SimpleTestBean(6), SimpleTestBean(0)], privimite=6], SimpleTestBean(0), [SimpleTestBean(7)] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[6] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[7] 11. sendNull: null, Not null assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[5] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[6] 12. sendNestedArray: [[7, 5]], [[SimpleTestBean(2)], [SimpleTestBean(4)]] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[4] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[5] 13. sendList: [-234, 5, 8], class com.vaadin.tests.widgetset.server.SerializerTestExtension, class com.vaadin.tests.serialization.SerializerTest, [SimpleTestBean(-568), SimpleTestBean(234)] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[3] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[4] 14. sendArrayList: [[2], [2]], [[2, 1], [2, 3]], [[SimpleTestBean(7)]] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[3] 15. sendSet: [-12, -7, -4], class com.vaadin.tests.serialization.SerializerTest, [SimpleTestBean(2), SimpleTestBean(3)] assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[2] 16. sendMap: {a=null}, [com.vaadin.tests.widgetset.server.SerializerTestExtension=false], [2=com.vaadin.tests.widgetset.server.SerializerTestExtension], {SimpleTestBean(4)=SimpleTestBean(-4), SimpleTestBean(-5)=SimpleTestBean(5)} assertText - vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0] + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1] 17. sendWrappedGenerics: {[SimpleTestBean(1)]={1=[SimpleTestBean(42)]}} - + + assertText + vaadin=runcomvaadintestsserializationSerializerTest::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0] + 18. sendEnum: PREFORMATTED, [XHTML, RAW], [PREFORMATTED, XML] + diff --git a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java index da4b5dd7d9..a301ecf828 100644 --- a/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java +++ b/tests/testbench/com/vaadin/tests/serialization/SerializerTest.java @@ -28,6 +28,7 @@ import java.util.Set; import com.vaadin.annotations.Widgetset; import com.vaadin.shared.Connector; +import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestRoot; import com.vaadin.tests.util.Log; @@ -122,6 +123,10 @@ public class SerializerTest extends AbstractTestRoot { } }); + rpc.sendEnum(ContentMode.TEXT, new ContentMode[] { + ContentMode.PREFORMATTED, ContentMode.XML }, + Arrays.asList(ContentMode.XHTML, ContentMode.RAW)); + testExtension.registerRpc(new SerializerTestRpc() { @Override public void sendBoolean(boolean value, Boolean boxedValue, @@ -288,6 +293,13 @@ public class SerializerTest extends AbstractTestRoot { log.log("sendWrappedGenerics: " + generics.toString()); } + @Override + public void sendEnum(ContentMode contentMode, ContentMode[] array, + List list) { + log.log("sendEnum: " + contentMode + ", " + + Arrays.toString(array) + ", " + list); + } + }); } diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java index 3977ff7f71..9fb6807bb7 100644 --- a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java +++ b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestConnector.java @@ -28,6 +28,7 @@ import java.util.Set; import com.vaadin.shared.Connector; import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.gwt.client.communication.RpcProxy; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.extensions.AbstractExtensionConnector; @@ -231,6 +232,16 @@ public class SerializerTestConnector extends AbstractExtensionConnector { objectListArray[0] }, new List[] { Collections .singletonList(beanListArray[0].get(0)) }); } + + @Override + public void sendEnum(ContentMode contentMode, ContentMode[] array, + List list) { + ContentMode nextContentMode = ContentMode.values()[contentMode + .ordinal() + 1]; + rpc.sendEnum(nextContentMode, + list.toArray(new ContentMode[list.size()]), + Arrays.asList(array)); + } }); } diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java index 47a26b7408..eb3a20e90e 100644 --- a/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java +++ b/tests/testbench/com/vaadin/tests/widgetset/client/SerializerTestRpc.java @@ -23,6 +23,7 @@ import java.util.Set; import com.vaadin.shared.Connector; import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; +import com.vaadin.shared.ui.label.ContentMode; @SuppressWarnings("javadoc") public interface SerializerTestRpc extends ServerRpc, ClientRpc { @@ -73,4 +74,6 @@ public interface SerializerTestRpc extends ServerRpc, ClientRpc { public void sendWrappedGenerics( Map, Map>> generics); + public void sendEnum(ContentMode contentMode, ContentMode[] array, List list); + } -- cgit v1.2.3 From 4863e078780a3d0ca94c4edcc153d1bdfe5a7f92 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 16 Aug 2012 13:42:07 +0300 Subject: Add crude support for only sending state changes (#9026) --- .../gwt/server/AbstractCommunicationManager.java | 38 +++++++++++++++------- .../com/vaadin/terminal/gwt/server/JsonCodec.java | 27 +++++++++------ server/src/com/vaadin/ui/ConnectorTracker.java | 13 ++++++++ 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index ffee517550..99376ffd1f 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -68,6 +68,7 @@ import com.vaadin.external.json.JSONException; import com.vaadin.external.json.JSONObject; import com.vaadin.shared.ApplicationConstants; import com.vaadin.shared.Connector; +import com.vaadin.shared.JavaScriptConnectorState; import com.vaadin.shared.Version; import com.vaadin.shared.communication.LegacyChangeVariablesInvocation; import com.vaadin.shared.communication.MethodInvocation; @@ -885,23 +886,36 @@ public abstract class AbstractCommunicationManager implements Serializable { try { Class stateType = connector .getStateType(); - SharedState referenceState = null; - if (repaintAll) { + Object diffState = rootConnectorTracker + .getDiffState(connector); + if (diffState == null) { + diffState = new JSONObject(); // Use an empty state object as reference for full // repaints - try { - referenceState = stateType.newInstance(); - } catch (Exception e) { - getLogger().log( - Level.WARNING, - "Error creating reference object for state of type " - + stateType.getName()); + boolean emptyInitialState = JavaScriptConnectorState.class + .isAssignableFrom(stateType); + if (!emptyInitialState) { + try { + SharedState referenceState = stateType + .newInstance(); + diffState = JsonCodec.encode(referenceState, + null, stateType, + root.getConnectorTracker()); + } catch (Exception e) { + getLogger().log( + Level.WARNING, + "Error creating reference object for state of type " + + stateType.getName()); + } } + rootConnectorTracker.setDiffState(connector, diffState); } - Object stateJson = JsonCodec.encode(state, referenceState, - stateType, root.getConnectorTracker()); + JSONObject stateJson = (JSONObject) JsonCodec.encode(state, + diffState, stateType, root.getConnectorTracker()); - sharedStates.put(connector.getConnectorId(), stateJson); + if (stateJson.length() != 0) { + sharedStates.put(connector.getConnectorId(), stateJson); + } } catch (JSONException e) { throw new PaintException( "Failed to serialize shared state for connector " diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index 94d860a200..884e01f9a5 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -526,9 +526,8 @@ public class JsonCodec implements Serializable { } } - public static Object encode(Object value, Object referenceValue, - Type valueType, ConnectorTracker connectorTracker) - throws JSONException { + public static Object encode(Object value, Object diffState, Type valueType, + ConnectorTracker connectorTracker) throws JSONException { if (valueType == null) { throw new IllegalArgumentException("type must be defined"); @@ -595,7 +594,7 @@ public class JsonCodec implements Serializable { } else { // Any object that we do not know how to encode we encode by looping // through fields - return encodeObject(value, referenceValue, connectorTracker); + return encodeObject(value, (JSONObject) diffState, connectorTracker); } } @@ -603,7 +602,7 @@ public class JsonCodec implements Serializable { return JSONObject.NULL; } - private static Object encodeObject(Object value, Object referenceValue, + private static Object encodeObject(Object value, JSONObject diffState, ConnectorTracker connectorTracker) throws JSONException { JSONObject jsonMap = new JSONObject(); @@ -620,10 +619,11 @@ public class JsonCodec implements Serializable { Type fieldType = getterMethod.getGenericReturnType(); Object fieldValue = getterMethod.invoke(value, (Object[]) null); boolean equals = false; - Object referenceFieldValue = null; - if (referenceValue != null) { - referenceFieldValue = getterMethod.invoke(referenceValue, - (Object[]) null); + Object diffStateValue = null; + if (diffState != null) { + diffStateValue = diffState.get(fieldName); + Object referenceFieldValue = decodeInternalOrCustomType( + fieldType, diffStateValue, connectorTracker); equals = equals(fieldValue, referenceFieldValue); } if (!equals) { @@ -637,8 +637,15 @@ public class JsonCodec implements Serializable { } jsonMap.put( fieldName, - encode(fieldValue, referenceFieldValue, fieldType, + encode(fieldValue, diffStateValue, fieldType, connectorTracker)); + if (diffState != null) { + diffState.put( + fieldName, + encode(fieldValue, null, fieldType, + connectorTracker)); + } + // } else { // System.out.println("Skipping field " + fieldName // + " of type " + fieldType.getName() diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index 27dfebd95e..f16642d91b 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -54,6 +55,7 @@ public class ConnectorTracker implements Serializable { private Set uninitializedConnectors = new HashSet(); private Root root; + private Map diffStates = new HashMap(); /** * Gets a logger for this class @@ -140,6 +142,7 @@ public class ConnectorTracker implements Serializable { + connectorId + ")"); connectorIdToConnector.remove(connectorId); uninitializedConnectors.remove(connector); + diffStates.remove(connector); } /** @@ -180,6 +183,7 @@ public class ConnectorTracker implements Serializable { */ public void markAllClientSidesUninitialized() { uninitializedConnectors.addAll(connectorIdToConnector.values()); + diffStates.clear(); } /** @@ -220,6 +224,7 @@ public class ConnectorTracker implements Serializable { + getConnectorAndParentInfo(connector) + "). This should have been done when the connector was detached."); uninitializedConnectors.remove(connector); + diffStates.remove(connector); iterator.remove(); } } @@ -372,4 +377,12 @@ public class ConnectorTracker implements Serializable { return dirtyConnectors; } + public Object getDiffState(ClientConnector connector) { + return diffStates.get(connector); + } + + public void setDiffState(ClientConnector connector, Object diffState) { + diffStates.put(connector, diffState); + } + } -- cgit v1.2.3 From e81cf22601718cd7909fea1db295bb538b104c9a Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 16 Aug 2012 15:46:11 +0300 Subject: Support StateChangeHandler for selected parts of the state (#8598) --- .../terminal/gwt/client/ApplicationConnection.java | 33 ++++++++- .../terminal/gwt/client/ServerConnector.java | 17 ++++- .../gwt/client/communication/StateChangeEvent.java | 41 ++++++++++- .../terminal/gwt/client/ui/AbstractConnector.java | 31 ++++++++ .../gwt/client/ui/button/ButtonConnector.java | 84 +++++++++++++--------- 5 files changed, 169 insertions(+), 37 deletions(-) diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 664a73dc12..32b15d6d87 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -1473,9 +1473,12 @@ public class ApplicationConnection { .getName(), null), stateJson, state, ApplicationConnection.this); - StateChangeEvent event = GWT - .create(StateChangeEvent.class); - event.setConnector(connector); + Set changedProperties = new HashSet(); + addJsonFields(stateJson, changedProperties, ""); + + StateChangeEvent event = new StateChangeEvent( + connector, changedProperties); + events.add(event); } } catch (final Throwable e) { @@ -1486,6 +1489,30 @@ public class ApplicationConnection { return events; } + /** + * Recursively adds the names of all fields in all objects in the + * provided json object. + * + * @param json + * the json object to process + * @param fields + * a set of all currently added fields + * @param context + * the base name of the current object + */ + private void addJsonFields(JSONObject json, Set fields, + String context) { + for (String key : json.keySet()) { + String fieldName = context + key; + fields.add(fieldName); + + JSONObject object = json.get(key).isObject(); + if (object != null) { + addJsonFields(object, fields, fieldName + "."); + } + } + } + /** * Updates the connector hierarchy and returns a list of events that * should be fired after update of the hierarchy and the state is diff --git a/client/src/com/vaadin/terminal/gwt/client/ServerConnector.java b/client/src/com/vaadin/terminal/gwt/client/ServerConnector.java index ff37f04f04..8788de74bf 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ServerConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ServerConnector.java @@ -75,7 +75,7 @@ public interface ServerConnector extends Connector { String rpcInterfaceId); /** - * Adds a handler that is called whenever some part of the state has been + * Adds a handler that is called whenever any part of the state has been * updated by the server. * * @param handler @@ -85,6 +85,21 @@ public interface ServerConnector extends Connector { */ public HandlerRegistration addStateChangeHandler(StateChangeHandler handler); + /** + * Adds a handler that is called whenever the given part of the state has + * been updated by the server. + * + * @param propertyName + * the name of the property for which the handler should be + * called + * @param handler + * The handler that should be added. + * @return A handler registration reference that can be used to unregister + * the handler + */ + public HandlerRegistration addStateChangeHandler(String propertyName, + StateChangeHandler handler); + /** * Sends the given event to all registered handlers. * diff --git a/client/src/com/vaadin/terminal/gwt/client/communication/StateChangeEvent.java b/client/src/com/vaadin/terminal/gwt/client/communication/StateChangeEvent.java index e1847bdab7..8ed32bc94b 100644 --- a/client/src/com/vaadin/terminal/gwt/client/communication/StateChangeEvent.java +++ b/client/src/com/vaadin/terminal/gwt/client/communication/StateChangeEvent.java @@ -16,8 +16,11 @@ package com.vaadin.terminal.gwt.client.communication; import java.io.Serializable; +import java.util.Collections; +import java.util.Set; import com.google.gwt.event.shared.EventHandler; +import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; public class StateChangeEvent extends @@ -27,12 +30,25 @@ public class StateChangeEvent extends */ public static final Type TYPE = new Type(); + private Set changedProperties; + @Override public Type getAssociatedType() { return TYPE; } - public StateChangeEvent() { + /** + * Creates a new state change event. + * + * @param connector + * the event whose state has changed + * @param changedProperties + * a set of names of the changed properties + */ + public StateChangeEvent(ServerConnector connector, + Set changedProperties) { + setConnector(connector); + this.changedProperties = changedProperties; } @Override @@ -40,7 +56,30 @@ public class StateChangeEvent extends listener.onStateChanged(this); } + /** + * Event handler that gets notified whenever any part of the state has been + * updated by the server. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ public interface StateChangeHandler extends Serializable, EventHandler { + /** + * Notifies the event handler that the state has changed. + * + * @param stateChangeEvent + * the state change event with details about the change + */ public void onStateChanged(StateChangeEvent stateChangeEvent); } + + /** + * Gets the properties that have changed. + * + * @return a set of names of the changed properties + */ + public Set getChangedProperties() { + return Collections.unmodifiableSet(changedProperties); + } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java index 514f63fdd8..435fff8a5b 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java @@ -48,6 +48,7 @@ public abstract class AbstractConnector implements ServerConnector, private String id; private HandlerManager handlerManager; + private Map statePropertyHandlerManagers; private Map> rpcImplementations; private final boolean debugLogging = false; @@ -168,6 +169,17 @@ public abstract class AbstractConnector implements ServerConnector, if (handlerManager != null) { handlerManager.fireEvent(event); } + if (statePropertyHandlerManagers != null + && event instanceof StateChangeEvent) { + for (String property : ((StateChangeEvent) event) + .getChangedProperties()) { + HandlerManager manager = statePropertyHandlerManagers + .get(property); + if (manager != null) { + manager.fireEvent(event); + } + } + } } protected HandlerManager ensureHandlerManager() { @@ -184,6 +196,25 @@ public abstract class AbstractConnector implements ServerConnector, .addHandler(StateChangeEvent.TYPE, handler); } + @Override + public HandlerRegistration addStateChangeHandler(String propertyName, + StateChangeHandler handler) { + return ensureHandlerManager(propertyName).addHandler( + StateChangeEvent.TYPE, handler); + } + + private HandlerManager ensureHandlerManager(String propertyName) { + if (statePropertyHandlerManagers == null) { + statePropertyHandlerManagers = new HashMap(); + } + HandlerManager manager = statePropertyHandlerManagers.get(propertyName); + if (manager == null) { + manager = new HandlerManager(this); + statePropertyHandlerManagers.put(propertyName, manager); + } + return manager; + } + @Override public void onStateChanged(StateChangeEvent stateChangeEvent) { if (debugLogging) { diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java index 59e187014c..59f90a9840 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/button/ButtonConnector.java @@ -16,6 +16,8 @@ package com.vaadin.terminal.gwt.client.ui.button; +import java.util.Set; + import com.google.gwt.event.dom.client.BlurEvent; import com.google.gwt.event.dom.client.BlurHandler; import com.google.gwt.event.dom.client.ClickEvent; @@ -34,6 +36,7 @@ import com.vaadin.terminal.gwt.client.EventHelper; import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; import com.vaadin.terminal.gwt.client.communication.RpcProxy; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; import com.vaadin.terminal.gwt.client.ui.Icon; import com.vaadin.ui.Button; @@ -59,6 +62,47 @@ public class ButtonConnector extends AbstractComponentConnector implements super.init(); getWidget().addClickHandler(this); getWidget().client = getConnection(); + addStateChangeHandler("errorMessage", new StateChangeHandler() { + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + if (null != getState().getErrorMessage()) { + if (getWidget().errorIndicatorElement == null) { + getWidget().errorIndicatorElement = DOM.createSpan(); + getWidget().errorIndicatorElement + .setClassName("v-errorindicator"); + } + getWidget().wrapper.insertBefore( + getWidget().errorIndicatorElement, + getWidget().captionElement); + + } else if (getWidget().errorIndicatorElement != null) { + getWidget().wrapper + .removeChild(getWidget().errorIndicatorElement); + getWidget().errorIndicatorElement = null; + } + } + }); + + addStateChangeHandler("icon", new StateChangeHandler() { + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + if (getState().getIcon() != null) { + if (getWidget().icon == null) { + getWidget().icon = new Icon(getConnection()); + getWidget().wrapper.insertBefore( + getWidget().icon.getElement(), + getWidget().captionElement); + } + getWidget().icon.setUri(getState().getIcon().getURL()); + } else { + if (getWidget().icon != null) { + getWidget().wrapper.removeChild(getWidget().icon + .getElement()); + getWidget().icon = null; + } + } + } + }); } @Override @@ -68,39 +112,15 @@ public class ButtonConnector extends AbstractComponentConnector implements focusHandlerRegistration); blurHandlerRegistration = EventHelper.updateBlurHandler(this, blurHandlerRegistration); - // Set text - if (getState().isHtmlContentAllowed()) { - getWidget().setHtml(getState().getCaption()); - } else { - getWidget().setText(getState().getCaption()); - } - // handle error - if (null != getState().getErrorMessage()) { - if (getWidget().errorIndicatorElement == null) { - getWidget().errorIndicatorElement = DOM.createSpan(); - getWidget().errorIndicatorElement - .setClassName("v-errorindicator"); - } - getWidget().wrapper.insertBefore(getWidget().errorIndicatorElement, - getWidget().captionElement); - - } else if (getWidget().errorIndicatorElement != null) { - getWidget().wrapper.removeChild(getWidget().errorIndicatorElement); - getWidget().errorIndicatorElement = null; - } - - if (getState().getIcon() != null) { - if (getWidget().icon == null) { - getWidget().icon = new Icon(getConnection()); - getWidget().wrapper.insertBefore(getWidget().icon.getElement(), - getWidget().captionElement); - } - getWidget().icon.setUri(getState().getIcon().getURL()); - } else { - if (getWidget().icon != null) { - getWidget().wrapper.removeChild(getWidget().icon.getElement()); - getWidget().icon = null; + Set changedProperties = stateChangeEvent.getChangedProperties(); + if (changedProperties.contains("caption") + || changedProperties.contains("htmlContentAllowed")) { + // Set text + if (getState().isHtmlContentAllowed()) { + getWidget().setHtml(getState().getCaption()); + } else { + getWidget().setText(getState().getCaption()); } } -- cgit v1.2.3 From 95411dc8c260fc5dcd548f11a8de50a2b8bb9770 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 20 Aug 2012 08:55:20 +0300 Subject: Preserve package name for state serializers (#8683) --- .../gwt/widgetsetutils/SerializerGenerator.java | 21 ++++++--- .../serialization/SerializerNamespaceTest.java | 44 +++++++++++++++++++ .../widgetset/client/DummyLabelConnector.java | 50 ++++++++++++++++++++++ .../vaadin/tests/widgetset/client/LabelState.java | 41 ++++++++++++++++++ .../vaadin/tests/widgetset/server/DummyLabel.java | 38 ++++++++++++++++ 5 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/serialization/SerializerNamespaceTest.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/client/DummyLabelConnector.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/client/LabelState.java create mode 100644 tests/testbench/com/vaadin/tests/widgetset/server/DummyLabel.java diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java index 2fc9645940..0235fb277d 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java @@ -32,6 +32,7 @@ import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JEnumConstant; import com.google.gwt.core.ext.typeinfo.JEnumType; import com.google.gwt.core.ext.typeinfo.JMethod; +import com.google.gwt.core.ext.typeinfo.JPackage; import com.google.gwt.core.ext.typeinfo.JPrimitiveType; import com.google.gwt.core.ext.typeinfo.JType; import com.google.gwt.core.ext.typeinfo.TypeOracleException; @@ -59,8 +60,6 @@ import com.vaadin.terminal.gwt.client.communication.SerializerMap; public class SerializerGenerator extends Generator { private static final String SUBTYPE_SEPARATOR = "___"; - private static String serializerPackageName = SerializerMap.class - .getPackage().getName(); @Override public String generate(TreeLogger logger, GeneratorContext context, @@ -75,8 +74,8 @@ public class SerializerGenerator extends Generator { String serializerClassName = getSerializerSimpleClassName(type); try { // Generate class source code - generateClass(logger, context, type, serializerPackageName, - serializerClassName); + generateClass(logger, context, type, + getSerializerPackageName(type), serializerClassName); } catch (Exception e) { logger.log(TreeLogger.ERROR, "SerializerGenerator failed for " + type.getQualifiedSourceName(), e); @@ -465,6 +464,18 @@ public class SerializerGenerator extends Generator { } public static String getFullyQualifiedSerializerClassName(JClassType type) { - return serializerPackageName + "." + getSerializerSimpleClassName(type); + return getSerializerPackageName(type) + "." + + getSerializerSimpleClassName(type); + } + + private static String getSerializerPackageName(JClassType type) { + JPackage typePackage = type.getPackage(); + if (typePackage == null) { + return SerializerMap.class.getPackage().getName(); + } else { + // What about e.g. java.* packages, can we create classes there or + // should we use e.g. com.vaadin.java.* + return typePackage.getName(); + } } } diff --git a/tests/testbench/com/vaadin/tests/serialization/SerializerNamespaceTest.java b/tests/testbench/com/vaadin/tests/serialization/SerializerNamespaceTest.java new file mode 100644 index 0000000000..6a873a6be3 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/serialization/SerializerNamespaceTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2011 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.serialization; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.tests.components.AbstractTestRoot; +import com.vaadin.tests.widgetset.server.DummyLabel; +import com.vaadin.ui.Label; + +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class SerializerNamespaceTest extends AbstractTestRoot { + + @Override + protected void setup(WrappedRequest request) { + addComponent(new Label("The real label")); + addComponent(new DummyLabel("The dummy label")); + } + + @Override + protected String getTestDescription() { + return "Using connectors with different state classes having the same simple name should not cause any clietn-side exceptions"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(8683); + } + +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/DummyLabelConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/DummyLabelConnector.java new file mode 100644 index 0000000000..bf3a472b33 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/DummyLabelConnector.java @@ -0,0 +1,50 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset.client; + +import com.vaadin.shared.ui.Connect; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.label.VLabel; +import com.vaadin.tests.widgetset.server.DummyLabel; + +/** + * Dummy connector just to cause {@link LabelState} to be used to test #8683 + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +@Connect(DummyLabel.class) +public class DummyLabelConnector extends AbstractComponentConnector { + @Override + public LabelState getState() { + return (LabelState) super.getState(); + } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + getWidget().setText(getState().getText()); + } + + @Override + public VLabel getWidget() { + return (VLabel) super.getWidget(); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/LabelState.java b/tests/testbench/com/vaadin/tests/widgetset/client/LabelState.java new file mode 100644 index 0000000000..91a269e33f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/LabelState.java @@ -0,0 +1,41 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset.client; + +import com.vaadin.shared.ComponentState; + +/** + * State class with the same simple name as + * {@link com.vaadin.shared.ui.label.LabelState} to test #8683 + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +public class LabelState extends ComponentState { + + private String text; + + public void setText(String text) { + this.text = text; + } + + public String getText() { + return text; + } + +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/server/DummyLabel.java b/tests/testbench/com/vaadin/tests/widgetset/server/DummyLabel.java new file mode 100644 index 0000000000..bda36d64a8 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/server/DummyLabel.java @@ -0,0 +1,38 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.widgetset.server; + +import com.vaadin.tests.widgetset.client.LabelState; +import com.vaadin.ui.AbstractComponent; + +/** + * Dummy component to cause {@link LabelState} to be used to test #8683 + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +public class DummyLabel extends AbstractComponent { + public DummyLabel(String text) { + getState().setText(text); + } + + @Override + public LabelState getState() { + return (LabelState) super.getState(); + } +} -- cgit v1.2.3 From 80cc4976fc7f7931d75f3b31dde6da168936f01f Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 16 Aug 2012 20:16:29 +0300 Subject: Abort widgetset compile for conflicting @Connect mappings (#9343) --- .../gwt/widgetsetutils/WidgetMapGenerator.java | 30 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java index dae6f2821e..1f5b301802 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetMapGenerator.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; +import java.util.Map; import java.util.TreeSet; import com.google.gwt.core.ext.Generator; @@ -116,8 +117,10 @@ public class WidgetMapGenerator extends Generator { * Logger object * @param context * Generator context + * @throws UnableToCompleteException */ - private void generateClass(TreeLogger logger, GeneratorContext context) { + private void generateClass(TreeLogger logger, GeneratorContext context) + throws UnableToCompleteException { // get print writer that receives the source code PrintWriter printWriter = null; printWriter = context.tryCreate(logger, packageName, className); @@ -147,7 +150,7 @@ public class WidgetMapGenerator extends Generator { logConnectors(logger, context, connectors); // generator constructor source code - generateImplementationDetector(sourceWriter, connectors); + generateImplementationDetector(logger, sourceWriter, connectors); generateInstantiatorMethod(sourceWriter, connectors); // close generated class sourceWriter.outdent(); @@ -369,13 +372,18 @@ public class WidgetMapGenerator extends Generator { /** * + * @param logger + * logger to print messages to * @param sourceWriter * Source writer to output source code * @param paintablesHavingWidgetAnnotation + * @throws UnableToCompleteException */ private void generateImplementationDetector( + TreeLogger logger, SourceWriter sourceWriter, - Collection> paintablesHavingWidgetAnnotation) { + Collection> paintablesHavingWidgetAnnotation) + throws UnableToCompleteException { sourceWriter .println("public Class, Class> mappings = new HashMap, Class>(); + for (Class connectorClass : paintablesHavingWidgetAnnotation) { Class clientConnectorClass = getClientConnectorClass(connectorClass); + + // Check for conflicts + Class prevousMapping = mappings.put( + clientConnectorClass, connectorClass); + if (prevousMapping != null) { + logger.log(Type.ERROR, + "Both " + connectorClass.getName() + " and " + + prevousMapping.getName() + + " have @Connect referring to " + + clientConnectorClass.getName() + "."); + throw new UnableToCompleteException(); + } + sourceWriter.print("if ( fullyQualifiedName == \""); sourceWriter.print(clientConnectorClass.getName()); sourceWriter.print("\" ) { ensureInstantiator(" -- cgit v1.2.3 From 8ed4b539378c2150af99ff4a102c47d2cf0a4a8d Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Fri, 17 Aug 2012 12:38:22 +0300 Subject: Don't use java.* package names (#8683) --- .../vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java index 0235fb277d..cc92551846 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/SerializerGenerator.java @@ -473,9 +473,12 @@ public class SerializerGenerator extends Generator { if (typePackage == null) { return SerializerMap.class.getPackage().getName(); } else { - // What about e.g. java.* packages, can we create classes there or - // should we use e.g. com.vaadin.java.* - return typePackage.getName(); + String packageName = typePackage.getName(); + // Dev mode classloader gets unhappy for some java packages + if (packageName.startsWith("java.")) { + packageName = "com.vaadin." + packageName; + } + return packageName; } } } -- cgit v1.2.3 From c9689846a8ba1254fb51c164cee6c3c157740eac Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 20 Aug 2012 11:49:48 +0300 Subject: Don't import from client even for javadoc (#9026) --- server/src/com/vaadin/ui/ConnectorTracker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/com/vaadin/ui/ConnectorTracker.java b/server/src/com/vaadin/ui/ConnectorTracker.java index f16642d91b..2afe7f9025 100644 --- a/server/src/com/vaadin/ui/ConnectorTracker.java +++ b/server/src/com/vaadin/ui/ConnectorTracker.java @@ -26,7 +26,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.vaadin.terminal.AbstractClientConnector; -import com.vaadin.terminal.gwt.client.ServerConnector; import com.vaadin.terminal.gwt.server.ClientConnector; /** @@ -41,7 +40,8 @@ import com.vaadin.terminal.gwt.server.ClientConnector; * Tracks which {@link ClientConnector}s are dirty so they can be updated to the * client when the following response is sent. A connector is dirty when an * operation has been performed on it on the server and as a result of this - * operation new information needs to be sent to its {@link ServerConnector}. + * operation new information needs to be sent to its + * {@link com.vaadin.terminal.gwt.client.ServerConnector}. *

* * @author Vaadin Ltd -- cgit v1.2.3 From 72d9cc9ec098952dfdb03708f808da555307e78d Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 20 Aug 2012 19:19:47 +0300 Subject: Add RootProvider for Root selection without custom Application (#8159) --- server/src/com/vaadin/Application.java | 70 ++++++++-------------- .../com/vaadin/terminal/AbstractRootProvider.java | 35 +++++++++++ .../com/vaadin/terminal/DefaultRootProvider.java | 51 ++++++++++++++++ server/src/com/vaadin/terminal/RootProvider.java | 29 +++++++++ .../terminal/gwt/server/ApplicationServlet.java | 2 + .../component/root/CustomRootClassLoader.java | 18 ++++-- .../vaadin/launcher/ApplicationRunnerServlet.java | 33 +++++----- .../tests/application/RefreshStatePreserve.java | 16 +++-- .../tests/components/root/RootsInMultipleTabs.java | 15 ++++- 9 files changed, 191 insertions(+), 78 deletions(-) create mode 100644 server/src/com/vaadin/terminal/AbstractRootProvider.java create mode 100644 server/src/com/vaadin/terminal/DefaultRootProvider.java create mode 100644 server/src/com/vaadin/terminal/RootProvider.java diff --git a/server/src/com/vaadin/Application.java b/server/src/com/vaadin/Application.java index b120c8455a..d2924eb716 100644 --- a/server/src/com/vaadin/Application.java +++ b/server/src/com/vaadin/Application.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.LinkedList; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -56,6 +57,7 @@ import com.vaadin.terminal.ApplicationResource; import com.vaadin.terminal.CombinedRequest; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.RequestHandler; +import com.vaadin.terminal.RootProvider; import com.vaadin.terminal.Terminal; import com.vaadin.terminal.VariableOwner; import com.vaadin.terminal.WrappedRequest; @@ -503,6 +505,8 @@ public class Application implements Terminal.ErrorListener, Serializable { */ private Set initedRoots = new HashSet(); + private List rootProviders = new LinkedList(); + /** * Gets the user of the application. * @@ -1873,55 +1877,21 @@ public class Application implements Terminal.ErrorListener, Serializable { */ protected Root getRoot(WrappedRequest request) throws RootRequiresMoreInformationException { - String rootClassName = getRootClassName(request); - try { - ClassLoader classLoader = request.getDeploymentConfiguration() - .getClassLoader(); - if (classLoader == null) { - classLoader = getClass().getClassLoader(); - } - Class rootClass = Class.forName(rootClassName, - true, classLoader).asSubclass(Root.class); - try { - Root root = rootClass.newInstance(); - return root; - } catch (Exception e) { - throw new RuntimeException("Could not instantiate root class " - + rootClassName, e); + + // Iterate in reverse order - test check newest provider first + for (int i = rootProviders.size() - 1; i >= 0; i--) { + RootProvider provider = rootProviders.get(i); + + Class rootClass = provider.getRootClass(this, + request); + + if (rootClass != null) { + return provider.instantiateRoot(this, rootClass, request); } - } catch (ClassNotFoundException e) { - throw new RuntimeException("Could not load root class " - + rootClassName, e); } - } - /** - * Provides the name of the Root class that should be used for - * a request. The class must have an accessible no-args constructor. - *

- * The default implementation uses the {@value #ROOT_PARAMETER} parameter - * from web.xml. - *

- *

- * This method is mainly used by the default implementation of - * {@link #getRoot(WrappedRequest)}. If you override that method with your - * own functionality, the results of this method might not be used. - *

- * - * @param request - * the request for which a new root is required - * @return the name of the root class to use - * - * @since 7.0 - */ - protected String getRootClassName(WrappedRequest request) { - Object rootClassNameObj = getProperties().get(ROOT_PARAMETER); - if (rootClassNameObj instanceof String) { - return (String) rootClassNameObj; - } else { - throw new RuntimeException("No " + ROOT_PARAMETER - + " defined in web.xml"); - } + throw new RuntimeException( + "No root providers available or providers are not able to find root instance"); } /** @@ -2169,6 +2139,14 @@ public class Application implements Terminal.ErrorListener, Serializable { return configuration.isProductionMode(); } + public void addRootProvider(RootProvider rootProvider) { + rootProviders.add(rootProvider); + } + + public void removeRootProvider(RootProvider rootProvider) { + rootProviders.remove(rootProvider); + } + /** * Finds the {@link Root} to which a particular request belongs. If the * request originates from an existing Root, that root is returned. In other diff --git a/server/src/com/vaadin/terminal/AbstractRootProvider.java b/server/src/com/vaadin/terminal/AbstractRootProvider.java new file mode 100644 index 0000000000..0b63003440 --- /dev/null +++ b/server/src/com/vaadin/terminal/AbstractRootProvider.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 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.terminal; + +import com.vaadin.Application; +import com.vaadin.ui.Root; + +public abstract class AbstractRootProvider implements RootProvider { + + @Override + public Root instantiateRoot(Application application, + Class type, WrappedRequest request) { + try { + return type.newInstance(); + } catch (InstantiationException e) { + throw new RuntimeException("Could not instantiate root class", e); + } catch (IllegalAccessException e) { + throw new RuntimeException("Could not access root class", e); + } + } +} diff --git a/server/src/com/vaadin/terminal/DefaultRootProvider.java b/server/src/com/vaadin/terminal/DefaultRootProvider.java new file mode 100644 index 0000000000..cbf8c98828 --- /dev/null +++ b/server/src/com/vaadin/terminal/DefaultRootProvider.java @@ -0,0 +1,51 @@ +/* + * Copyright 2011 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.terminal; + +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.ui.Root; + +public class DefaultRootProvider extends AbstractRootProvider { + + @Override + public Class getRootClass(Application application, + WrappedRequest request) throws RootRequiresMoreInformationException { + Object rootClassNameObj = application + .getProperty(Application.ROOT_PARAMETER); + + if (rootClassNameObj instanceof String) { + String rootClassName = rootClassNameObj.toString(); + + ClassLoader classLoader = request.getDeploymentConfiguration() + .getClassLoader(); + if (classLoader == null) { + classLoader = getClass().getClassLoader(); + } + try { + Class rootClass = Class.forName(rootClassName, + true, classLoader).asSubclass(Root.class); + + return rootClass; + } catch (ClassNotFoundException e) { + throw new RuntimeException("Could not find root class", e); + } + } + + return null; + } +} diff --git a/server/src/com/vaadin/terminal/RootProvider.java b/server/src/com/vaadin/terminal/RootProvider.java new file mode 100644 index 0000000000..476cf1bd78 --- /dev/null +++ b/server/src/com/vaadin/terminal/RootProvider.java @@ -0,0 +1,29 @@ +/* + * Copyright 2011 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.terminal; + +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.ui.Root; + +public interface RootProvider { + public Class getRootClass(Application application, + WrappedRequest request) throws RootRequiresMoreInformationException; + + public Root instantiateRoot(Application application, + Class type, WrappedRequest request); +} diff --git a/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java b/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java index 06bc70872d..52885f3fbb 100644 --- a/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/ApplicationServlet.java @@ -20,6 +20,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import com.vaadin.Application; +import com.vaadin.terminal.DefaultRootProvider; import com.vaadin.terminal.gwt.server.ServletPortletHelper.ApplicationClassException; /** @@ -69,6 +70,7 @@ public class ApplicationServlet extends AbstractApplicationServlet { // Creates a new application instance try { final Application application = getApplicationClass().newInstance(); + application.addRootProvider(new DefaultRootProvider()); return application; } catch (final IllegalAccessException e) { diff --git a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java index fa730515a2..74770f8652 100644 --- a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java +++ b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java @@ -6,15 +6,16 @@ import java.util.Properties; import junit.framework.TestCase; +import org.easymock.EasyMock; + import com.vaadin.Application; import com.vaadin.Application.ApplicationStartEvent; import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.DefaultRootProvider; import com.vaadin.terminal.DeploymentConfiguration; import com.vaadin.terminal.WrappedRequest; import com.vaadin.ui.Root; -import org.easymock.EasyMock; - public class CustomRootClassLoader extends TestCase { /** @@ -111,10 +112,17 @@ public class CustomRootClassLoader extends TestCase { private Application createStubApplication() { return new Application() { + { + addRootProvider(new DefaultRootProvider()); + } + @Override - protected String getRootClassName(WrappedRequest request) { - // Always use the same root class - return MyRoot.class.getName(); + public String getProperty(String name) { + if (name.equals(ROOT_PARAMETER)) { + return MyRoot.class.getName(); + } else { + return super.getProperty(name); + } } @Override diff --git a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java index 6b7b36c3f3..bb37082d30 100644 --- a/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/tests/testbench/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -30,6 +30,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; import com.vaadin.terminal.gwt.server.WrappedHttpServletRequest; @@ -39,23 +41,6 @@ import com.vaadin.ui.Root; @SuppressWarnings("serial") public class ApplicationRunnerServlet extends AbstractApplicationServlet { - /** - * Internal implementation of an application with a dynamically selected - * Root implementation; - */ - private static class RootRunnerApplication extends Application { - private final Class runnableClass; - - private RootRunnerApplication(Class runnableClass) { - this.runnableClass = runnableClass; - } - - @Override - protected String getRootClassName(WrappedRequest request) { - return runnableClass.getCanonicalName(); - } - } - /** * The name of the application class currently used. Only valid within one * request. @@ -126,7 +111,17 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { try { final Class classToRun = getClassToRun(); if (Root.class.isAssignableFrom(classToRun)) { - return new RootRunnerApplication(classToRun); + Application application = new Application(); + application.addRootProvider(new AbstractRootProvider() { + + @Override + public Class getRootClass( + Application application, WrappedRequest request) + throws RootRequiresMoreInformationException { + return (Class) classToRun; + } + }); + return application; } else if (Application.class.isAssignableFrom(classToRun)) { return (Application) classToRun.newInstance(); } else { @@ -221,7 +216,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { throws ClassNotFoundException { Class classToRun = getClassToRun(); if (Root.class.isAssignableFrom(classToRun)) { - return RootRunnerApplication.class; + return Application.class; } else if (Application.class.isAssignableFrom(classToRun)) { return classToRun.asSubclass(Application.class); } else { diff --git a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java index 36a793bd6d..bd2aea3756 100644 --- a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java @@ -1,5 +1,8 @@ package com.vaadin.tests.application; +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -20,11 +23,14 @@ public class RefreshStatePreserve extends AbstractTestApplication { public void init() { super.init(); setRootPreserved(true); - } - - @Override - protected String getRootClassName(WrappedRequest request) { - return RefreshStateRoot.class.getName(); + addRootProvider(new AbstractRootProvider() { + @Override + public Class getRootClass(Application application, + WrappedRequest request) + throws RootRequiresMoreInformationException { + return RefreshStateRoot.class; + } + }); } @Override diff --git a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java index c3b20c5e7c..ae3182401d 100644 --- a/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java +++ b/tests/testbench/com/vaadin/tests/components/root/RootsInMultipleTabs.java @@ -1,5 +1,8 @@ package com.vaadin.tests.components.root; +import com.vaadin.Application; +import com.vaadin.RootRequiresMoreInformationException; +import com.vaadin.terminal.AbstractRootProvider; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -19,9 +22,15 @@ public class RootsInMultipleTabs extends AbstractTestApplication { } } - @Override - protected String getRootClassName(WrappedRequest request) { - return TabRoot.class.getName(); + public RootsInMultipleTabs() { + addRootProvider(new AbstractRootProvider() { + @Override + public Class getRootClass(Application application, + WrappedRequest request) + throws RootRequiresMoreInformationException { + return TabRoot.class; + } + }); } @Override -- cgit v1.2.3 From c87c0861ce82e6aab6534aba0e30075ca3588635 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Tue, 21 Aug 2012 12:34:06 +0300 Subject: Revert "Added a heartbeat timer to RootConnector (#9265)" This reverts commit ff4988f6beaa0a1c8b908e098525afc3505ece64. Conflicts: client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java --- .../terminal/gwt/client/ui/root/RootConnector.java | 38 ---------------------- .../src/com/vaadin/shared/ui/root/RootState.java | 8 ----- 2 files changed, 46 deletions(-) diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java index 9b5c3cd767..b3490effa7 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/root/RootConnector.java @@ -25,16 +25,10 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Position; import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; -import com.google.gwt.http.client.Request; -import com.google.gwt.http.client.RequestBuilder; -import com.google.gwt.http.client.RequestCallback; -import com.google.gwt.http.client.RequestException; -import com.google.gwt.http.client.Response; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.History; -import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; @@ -92,14 +86,6 @@ public class RootConnector extends AbstractComponentContainerConnector com.google.gwt.user.client.Window.setTitle(title); } }); - final int heartbeatInterval = getState().getHeartbeatInterval(); - new Timer() { - @Override - public void run() { - sendHeartbeat(); - schedule(heartbeatInterval); - } - }.schedule(heartbeatInterval); getWidget().addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { @@ -468,28 +454,4 @@ public class RootConnector extends AbstractComponentContainerConnector }); } - private void sendHeartbeat() { - RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "url"); - - rb.setCallback(new RequestCallback() { - - @Override - public void onResponseReceived(Request request, Response response) { - // TODO Auto-generated method stub - - } - - @Override - public void onError(Request request, Throwable exception) { - // TODO Auto-generated method stub - - } - }); - - try { - rb.send(); - } catch (RequestException re) { - - } - } } diff --git a/shared/src/com/vaadin/shared/ui/root/RootState.java b/shared/src/com/vaadin/shared/ui/root/RootState.java index 07c71c8167..b7c2c88ce5 100644 --- a/shared/src/com/vaadin/shared/ui/root/RootState.java +++ b/shared/src/com/vaadin/shared/ui/root/RootState.java @@ -20,7 +20,6 @@ import com.vaadin.shared.Connector; public class RootState extends ComponentState { private Connector content; - private int heartbeatInterval; public Connector getContent() { return content; @@ -30,11 +29,4 @@ public class RootState extends ComponentState { this.content = content; } - public int getHeartbeatInterval() { - return heartbeatInterval; - } - - public void setHeartbeatInterval(int heartbeatInterval) { - this.heartbeatInterval = heartbeatInterval; - } } \ No newline at end of file -- cgit v1.2.3 From 7bfa8f43d14d1823b27cfd84f925e23853fbf4c7 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 21 Aug 2012 13:12:17 +0300 Subject: Don't pass JSONObject.Null as diffstate value (#9026) --- server/src/com/vaadin/terminal/gwt/server/JsonCodec.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index 884e01f9a5..cb0a604b89 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -624,6 +624,9 @@ public class JsonCodec implements Serializable { diffStateValue = diffState.get(fieldName); Object referenceFieldValue = decodeInternalOrCustomType( fieldType, diffStateValue, connectorTracker); + if (JSONObject.NULL.equals(diffStateValue)) { + diffStateValue = null; + } equals = equals(fieldValue, referenceFieldValue); } if (!equals) { -- cgit v1.2.3 From b02028c90b9143ad16864ad371b4b9429e20573a Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Tue, 21 Aug 2012 17:57:51 +0300 Subject: Add "As of 7.0" to relevant @deprecated tags --- server/src/com/vaadin/data/Buffered.java | 16 ++++++++-------- server/src/com/vaadin/ui/AbstractField.java | 8 ++++---- server/src/com/vaadin/ui/DateField.java | 12 ++++++------ server/src/com/vaadin/ui/Table.java | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/server/src/com/vaadin/data/Buffered.java b/server/src/com/vaadin/data/Buffered.java index 5461d34fbd..2472524bbc 100644 --- a/server/src/com/vaadin/data/Buffered.java +++ b/server/src/com/vaadin/data/Buffered.java @@ -83,8 +83,8 @@ public interface Buffered extends Serializable { * * @return true if the object is in write-through mode, * false if it's not. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated @@ -105,8 +105,8 @@ public interface Buffered extends Serializable { * If the implicit commit operation fails because of a * validation error. * - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated @@ -126,8 +126,8 @@ public interface Buffered extends Serializable { * * @return true if the object is in read-through mode, * false if it's not. - * @deprecated Use {@link #isBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #isBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated @@ -145,8 +145,8 @@ public interface Buffered extends Serializable { * @throws SourceException * If the operation fails because of an exception is thrown by * the data source. The cause is included in the exception. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Deprecated diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 67a1826100..b914fb4c46 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -394,8 +394,8 @@ public abstract class AbstractField extends AbstractComponent implements * @throws InvalidValueException * If the implicit commit operation fails because of a * validation error. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Override @@ -435,8 +435,8 @@ public abstract class AbstractField extends AbstractComponent implements * @throws SourceException * If the operation fails because of an exception is thrown by * the data source. The cause is included in the exception. - * @deprecated Use {@link #setBuffered(boolean)} instead. Note that - * setReadThrough(true), setWriteThrough(true) equals + * @deprecated As of 7.0, use {@link #setBuffered(boolean)} instead. Note + * that setReadThrough(true), setWriteThrough(true) equals * setBuffered(false) */ @Override diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java index 5130d665eb..790f3568d5 100644 --- a/server/src/com/vaadin/ui/DateField.java +++ b/server/src/com/vaadin/ui/DateField.java @@ -131,7 +131,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: seconds. * - * @deprecated Use {@link Resolution#SECOND} + * @deprecated As of 7.0, use {@link Resolution#SECOND} */ @Deprecated public static final Resolution RESOLUTION_SEC = Resolution.SECOND; @@ -139,7 +139,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: minutes. * - * @deprecated Use {@link Resolution#MINUTE} + * @deprecated As of 7.0, use {@link Resolution#MINUTE} */ @Deprecated public static final Resolution RESOLUTION_MIN = Resolution.MINUTE; @@ -147,7 +147,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: hours. * - * @deprecated Use {@link Resolution#HOUR} + * @deprecated As of 7.0, use {@link Resolution#HOUR} */ @Deprecated public static final Resolution RESOLUTION_HOUR = Resolution.HOUR; @@ -155,7 +155,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: days. * - * @deprecated Use {@link Resolution#DAY} + * @deprecated As of 7.0, use {@link Resolution#DAY} */ @Deprecated public static final Resolution RESOLUTION_DAY = Resolution.DAY; @@ -163,7 +163,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: months. * - * @deprecated Use {@link Resolution#MONTH} + * @deprecated As of 7.0, use {@link Resolution#MONTH} */ @Deprecated public static final Resolution RESOLUTION_MONTH = Resolution.MONTH; @@ -171,7 +171,7 @@ public class DateField extends AbstractField implements /** * Resolution identifier: years. * - * @deprecated Use {@link Resolution#YEAR} + * @deprecated As of 7.0, use {@link Resolution#YEAR} */ @Deprecated public static final Resolution RESOLUTION_YEAR = Resolution.YEAR; diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 6f7f88f883..2bbb69beaf 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -4470,7 +4470,7 @@ public class Table extends AbstractSelect implements Action.Container, * would support this. * * @return True iff sorting is disabled. - * @deprecated Use {@link #isSortEnabled()} instead + * @deprecated As of 7.0, use {@link #isSortEnabled()} instead */ @Deprecated public boolean isSortDisabled() { @@ -4491,7 +4491,7 @@ public class Table extends AbstractSelect implements Action.Container, * * @param sortDisabled * True iff sorting is disabled. - * @deprecated Use {@link #setSortEnabled(boolean)} instead + * @deprecated As of 7.0, use {@link #setSortEnabled(boolean)} instead */ @Deprecated public void setSortDisabled(boolean sortDisabled) { -- cgit v1.2.3 From c680e97bc0a879041f3c24a5c6acdfa1829a8506 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 21 Aug 2012 18:45:27 +0300 Subject: Don't use diffstate value if it isn't there (#9026) --- server/src/com/vaadin/terminal/gwt/server/JsonCodec.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java index cb0a604b89..892f7ec526 100644 --- a/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java +++ b/server/src/com/vaadin/terminal/gwt/server/JsonCodec.java @@ -620,7 +620,7 @@ public class JsonCodec implements Serializable { Object fieldValue = getterMethod.invoke(value, (Object[]) null); boolean equals = false; Object diffStateValue = null; - if (diffState != null) { + if (diffState != null && diffState.has(fieldName)) { diffStateValue = diffState.get(fieldName); Object referenceFieldValue = decodeInternalOrCustomType( fieldType, diffStateValue, connectorTracker); -- cgit v1.2.3 From 514bffe7a6aa2c599ab9f4ba239295d63f229125 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 20 Aug 2012 16:03:21 +0300 Subject: Removed remaining methods from Terminal (#4355, #8027) --- server/src/com/vaadin/terminal/Terminal.java | 36 ++-------------------- .../com/vaadin/terminal/gwt/server/WebBrowser.java | 30 +++++------------- 2 files changed, 10 insertions(+), 56 deletions(-) diff --git a/server/src/com/vaadin/terminal/Terminal.java b/server/src/com/vaadin/terminal/Terminal.java index 29cb649d54..a02bcb50bb 100644 --- a/server/src/com/vaadin/terminal/Terminal.java +++ b/server/src/com/vaadin/terminal/Terminal.java @@ -25,43 +25,11 @@ import java.io.Serializable; * * @author Vaadin Ltd. * @since 3.0 + * @deprecated Currently only a container for ErrorEvent and ErrorListener */ +@Deprecated public interface Terminal extends Serializable { - /** - * Gets the name of the default theme for this terminal. - * - * @return the name of the theme that is used by default by this terminal. - */ - public String getDefaultTheme(); - - /** - * Gets the width of the terminal screen in pixels. This is the width of the - * screen and not the width available for the application. - *

- * Note that the screen width is typically not available in the - * {@link com.vaadin.Application#init()} method as this is called before the - * browser has a chance to report the screen size to the server. - *

- * - * @return the width of the terminal screen. - */ - public int getScreenWidth(); - - /** - * Gets the height of the terminal screen in pixels. This is the height of - * the screen and not the height available for the application. - * - *

- * Note that the screen height is typically not available in the - * {@link com.vaadin.Application#init()} method as this is called before the - * browser has a chance to report the screen size to the server. - *

- * - * @return the height of the terminal screen. - */ - public int getScreenHeight(); - /** * An error event implementation for Terminal. */ diff --git a/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java b/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java index 90aef4283d..37bc81cfcf 100644 --- a/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java +++ b/server/src/com/vaadin/terminal/gwt/server/WebBrowser.java @@ -20,7 +20,6 @@ import java.util.Date; import java.util.Locale; import com.vaadin.shared.VBrowserDetails; -import com.vaadin.terminal.Terminal; import com.vaadin.terminal.WrappedRequest; /** @@ -30,7 +29,7 @@ import com.vaadin.terminal.WrappedRequest; * * @author Vaadin Ltd. */ -public class WebBrowser implements Terminal { +public class WebBrowser { private int screenHeight = 0; private int screenWidth = 0; @@ -48,34 +47,21 @@ public class WebBrowser implements Terminal { private long clientServerTimeDelta; /** - * There is no default-theme for this terminal type. + * Gets the height of the screen in pixels. This is the full screen + * resolution and not the height available for the application. * - * @return Always returns null. + * @return the height of the screen in pixels. */ - - @Override - public String getDefaultTheme() { - return null; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.terminal.Terminal#getScreenHeight() - */ - - @Override public int getScreenHeight() { return screenHeight; } - /* - * (non-Javadoc) + /** + * Gets the width of the screen in pixels. This is the full screen + * resolution and not the width available for the application. * - * @see com.vaadin.terminal.Terminal#getScreenWidth() + * @return the width of the screen in pixels. */ - - @Override public int getScreenWidth() { return screenWidth; } -- cgit v1.2.3 From 667ef9c144bf3522100e5c8eac4d76a3c4faf65b Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 20 Aug 2012 19:29:04 +0300 Subject: Refactored margin handlers (#8292) Only layouts actually supporting margins now implement MarginHandler CssLayout should be simplified before 7.0.0 so margin support was removed. GridLayout, VerticalLayout and HorizontalLayout were the only other layouts which actually supported margin. MarginInfo is now passed directly in the state. --- .../client/ui/csslayout/CssLayoutConnector.java | 4 - .../gwt/client/ui/csslayout/VCssLayout.java | 19 ----- .../client/ui/formlayout/FormLayoutConnector.java | 4 +- .../gwt/client/ui/formlayout/VFormLayout.java | 4 +- .../client/ui/gridlayout/GridLayoutConnector.java | 4 +- .../gwt/client/ui/gridlayout/VGridLayout.java | 4 +- .../AbstractOrderedLayoutConnector.java | 5 +- .../ui/orderedlayout/VMeasuringOrderedLayout.java | 4 +- server/src/com/vaadin/ui/AbstractLayout.java | 53 +----------- .../src/com/vaadin/ui/AbstractOrderedLayout.java | 26 +++++- server/src/com/vaadin/ui/CustomLayout.java | 27 ------ server/src/com/vaadin/ui/FormLayout.java | 4 +- server/src/com/vaadin/ui/GridLayout.java | 38 ++++++++- server/src/com/vaadin/ui/Layout.java | 51 ++++-------- .../com/vaadin/shared/ui/AbstractLayoutState.java | 9 -- shared/src/com/vaadin/shared/ui/MarginInfo.java | 96 ++++++++++++++++++++++ shared/src/com/vaadin/shared/ui/VMarginInfo.java | 93 --------------------- .../shared/ui/gridlayout/GridLayoutState.java | 9 ++ .../orderedlayout/AbstractOrderedLayoutState.java | 10 +++ tests/testbench/com/vaadin/tests/Parameters.java | 4 +- .../tests/components/AbstractLayoutTest.java | 9 +- .../components/customfield/NestedPersonForm.java | 5 +- .../vaadin/tests/integration/LiferayThemeDemo.java | 6 +- .../vaadin/tests/layouts/CssLayoutCustomCss.java | 3 +- .../tests/layouts/GridLayoutInsidePanel.java | 6 +- .../com/vaadin/tests/tickets/Ticket1435.java | 3 +- .../com/vaadin/tests/tickets/Ticket1572.java | 9 +- .../com/vaadin/tests/tickets/Ticket1710.java | 12 ++- .../com/vaadin/tests/tickets/Ticket1805.java | 4 +- .../com/vaadin/tests/tickets/Ticket2021.java | 3 +- .../com/vaadin/tests/tickets/Ticket2040.java | 4 +- .../com/vaadin/tests/tickets/Ticket2405.java | 4 +- .../com/vaadin/tests/tickets/Ticket2998.java | 3 +- 33 files changed, 251 insertions(+), 288 deletions(-) create mode 100644 shared/src/com/vaadin/shared/ui/MarginInfo.java delete mode 100644 shared/src/com/vaadin/shared/ui/VMarginInfo.java diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java index 47c2049a67..2e51d717a4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/CssLayoutConnector.java @@ -23,7 +23,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; import com.vaadin.shared.ui.csslayout.CssLayoutServerRpc; import com.vaadin.shared.ui.csslayout.CssLayoutState; import com.vaadin.terminal.gwt.client.BrowserInfo; @@ -75,9 +74,6 @@ public class CssLayoutConnector extends AbstractLayoutConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - getWidget().setMarginStyles( - new VMarginInfo(getState().getMarginsBitmask())); - for (ComponentConnector child : getChildComponents()) { if (!getState().getChildCss().containsKey(child)) { continue; diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java index 813e95e3ed..e66b1c4208 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/csslayout/VCssLayout.java @@ -21,8 +21,6 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.shared.ui.VMarginInfo; -import com.vaadin.terminal.gwt.client.StyleConstants; public class VCssLayout extends SimplePanel { public static final String TAGNAME = "csslayout"; @@ -64,21 +62,4 @@ public class VCssLayout extends SimplePanel { } - /** - * Sets CSS classes for margin based on the given parameters. - * - * @param margins - * A {@link VMarginInfo} object that provides info on - * top/left/bottom/right margins - */ - protected void setMarginStyles(VMarginInfo margins) { - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_TOP, margins.hasTop()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_RIGHT, margins.hasRight()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_BOTTOM, margins.hasBottom()); - setStyleName(margin, VCssLayout.CLASSNAME + "-" - + StyleConstants.MARGIN_LEFT, margins.hasLeft()); - } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java index 7d5edfadf5..cbe06244af 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/FormLayoutConnector.java @@ -18,7 +18,7 @@ package com.vaadin.terminal.gwt.client.ui.formlayout; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.Connect; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; @@ -46,7 +46,7 @@ public class FormLayoutConnector extends AbstractLayoutConnector { VFormLayoutTable formLayoutTable = getWidget().table; - formLayoutTable.setMargins(new VMarginInfo(getState() + formLayoutTable.setMargins(new MarginInfo(getState() .getMarginsBitmask())); formLayoutTable.setSpacing(getState().isSpacing()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java index d3ce6f3d3f..7f211aaf9c 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/formlayout/VFormLayout.java @@ -29,7 +29,7 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ComponentState; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -112,7 +112,7 @@ public class VFormLayout extends SimplePanel { } } - public void setMargins(VMarginInfo margins) { + public void setMargins(MarginInfo margins) { Element margin = getElement(); setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP, margins.hasTop()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java index 520afb778d..9a2732e408 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/GridLayoutConnector.java @@ -22,7 +22,7 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc; import com.vaadin.shared.ui.gridlayout.GridLayoutState; import com.vaadin.terminal.gwt.client.ApplicationConnection; @@ -163,7 +163,7 @@ public class GridLayoutConnector extends AbstractComponentContainerConnector layout.colExpandRatioArray = uidl.getIntArrayAttribute("colExpand"); layout.rowExpandRatioArray = uidl.getIntArrayAttribute("rowExpand"); - layout.updateMarginStyleNames(new VMarginInfo(getState() + layout.updateMarginStyleNames(new MarginInfo(getState() .getMarginsBitmask())); layout.updateSpacingStyleName(getState().isSpacing()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java index 25d7de6ee6..ef44964da7 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/gridlayout/VGridLayout.java @@ -29,7 +29,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorMap; @@ -677,7 +677,7 @@ public class VGridLayout extends ComplexPanel { } } - void updateMarginStyleNames(VMarginInfo marginInfo) { + void updateMarginStyleNames(MarginInfo marginInfo) { togglePrefixedStyleName("margin-top", marginInfo.hasTop()); togglePrefixedStyleName("margin-right", marginInfo.hasRight()); togglePrefixedStyleName("margin-bottom", marginInfo.hasBottom()); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index 5da01bf127..122547ddb4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -23,7 +23,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Widget; import com.vaadin.shared.ui.AlignmentInfo; import com.vaadin.shared.ui.LayoutClickRpc; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.terminal.gwt.client.ComponentConnector; @@ -133,9 +133,8 @@ public abstract class AbstractOrderedLayoutConnector extends slot.setExpandRatio(expandRatio); } - layout.updateMarginStyleNames(new VMarginInfo(getState() + layout.updateMarginStyleNames(new MarginInfo(getState() .getMarginsBitmask())); - layout.updateSpacingStyleName(getState().isSpacing()); getLayoutManager().setNeedsLayout(this); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java index ec2c4afa97..ee55bc07ba 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/orderedlayout/VMeasuringOrderedLayout.java @@ -27,7 +27,7 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.WidgetCollection; -import com.vaadin.shared.ui.VMarginInfo; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.gwt.client.VCaption; import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot; @@ -75,7 +75,7 @@ public class VMeasuringOrderedLayout extends ComplexPanel { } } - void updateMarginStyleNames(VMarginInfo marginInfo) { + void updateMarginStyleNames(MarginInfo marginInfo) { togglePrefixedStyleName("margin-top", marginInfo.hasTop()); togglePrefixedStyleName("margin-right", marginInfo.hasRight()); togglePrefixedStyleName("margin-bottom", marginInfo.hasBottom()); diff --git a/server/src/com/vaadin/ui/AbstractLayout.java b/server/src/com/vaadin/ui/AbstractLayout.java index c26812f3fc..dd1d5eab12 100644 --- a/server/src/com/vaadin/ui/AbstractLayout.java +++ b/server/src/com/vaadin/ui/AbstractLayout.java @@ -17,7 +17,6 @@ package com.vaadin.ui; import com.vaadin.shared.ui.AbstractLayoutState; -import com.vaadin.ui.Layout.MarginHandler; /** * An abstract class that defines default implementation for the {@link Layout} @@ -26,62 +25,12 @@ import com.vaadin.ui.Layout.MarginHandler; * @author Vaadin Ltd. * @since 5.0 */ -@SuppressWarnings("serial") public abstract class AbstractLayout extends AbstractComponentContainer - implements Layout, MarginHandler { - - protected MarginInfo margins = new MarginInfo(false); + implements Layout { @Override public AbstractLayoutState getState() { return (AbstractLayoutState) super.getState(); } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout#setMargin(boolean) - */ - @Override - public void setMargin(boolean enabled) { - margins.setMargins(enabled); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout.MarginHandler#getMargin() - */ - @Override - public MarginInfo getMargin() { - return margins; - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo) - */ - @Override - public void setMargin(MarginInfo marginInfo) { - margins.setMargins(marginInfo); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Layout#setMargin(boolean, boolean, boolean, boolean) - */ - @Override - public void setMargin(boolean topEnabled, boolean rightEnabled, - boolean bottomEnabled, boolean leftEnabled) { - margins.setMargins(topEnabled, rightEnabled, bottomEnabled, leftEnabled); - getState().setMarginsBitmask(margins.getBitMask()); - requestRepaint(); - } - } diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index a7cc780414..3ac4e76bdb 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -25,6 +25,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState; import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutState.ChildComponentData; @@ -32,7 +33,8 @@ import com.vaadin.terminal.Sizeable; @SuppressWarnings("serial") public abstract class AbstractOrderedLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { + Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, + Layout.MarginHandler { private AbstractOrderedLayoutServerRpc rpc = new AbstractOrderedLayoutServerRpc() { @@ -392,4 +394,26 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements return components.get(index); } + public void setMargin(boolean enabled) { + setMargin(new MarginInfo(enabled)); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#getMargin() + */ + public MarginInfo getMargin() { + return new MarginInfo(getState().getMarginsBitmask()); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#setMargin(MarginInfo) + */ + public void setMargin(MarginInfo marginInfo) { + getState().setMarginsBitmask(marginInfo.getBitMask()); + requestRepaint(); + } } diff --git a/server/src/com/vaadin/ui/CustomLayout.java b/server/src/com/vaadin/ui/CustomLayout.java index 2da443bfa5..d47b2f92b3 100644 --- a/server/src/com/vaadin/ui/CustomLayout.java +++ b/server/src/com/vaadin/ui/CustomLayout.java @@ -291,33 +291,6 @@ public class CustomLayout extends AbstractLayout implements Vaadin6Component { requestRepaint(); } - /** - * Although most layouts support margins, CustomLayout does not. The - * behaviour of this layout is determined almost completely by the actual - * template. - * - * @throws UnsupportedOperationException - */ - @Override - public void setMargin(boolean enabled) { - throw new UnsupportedOperationException( - "CustomLayout does not support margins."); - } - - /** - * Although most layouts support margins, CustomLayout does not. The - * behaviour of this layout is determined almost completely by the actual - * template. - * - * @throws UnsupportedOperationException - */ - @Override - public void setMargin(boolean topEnabled, boolean rightEnabled, - boolean bottomEnabled, boolean leftEnabled) { - throw new UnsupportedOperationException( - "CustomLayout does not support margins."); - } - @Override public void changeVariables(Object source, Map variables) { // Nothing to see here diff --git a/server/src/com/vaadin/ui/FormLayout.java b/server/src/com/vaadin/ui/FormLayout.java index c4ba4665ea..15ea478597 100644 --- a/server/src/com/vaadin/ui/FormLayout.java +++ b/server/src/com/vaadin/ui/FormLayout.java @@ -16,6 +16,8 @@ package com.vaadin.ui; +import com.vaadin.shared.ui.MarginInfo; + /** * FormLayout is used by {@link Form} to layout fields. It may also be used * separately without {@link Form}. @@ -36,7 +38,7 @@ public class FormLayout extends AbstractOrderedLayout { public FormLayout() { super(); setSpacing(true); - setMargin(true, false, true, false); + setMargin(new MarginInfo(true, false, true, false)); setWidth(100, UNITS_PERCENTAGE); } diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 5a748c04f6..b31ab82741 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -30,6 +30,7 @@ import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.gridlayout.GridLayoutServerRpc; import com.vaadin.shared.ui.gridlayout.GridLayoutState; import com.vaadin.terminal.LegacyPaint; @@ -63,8 +64,8 @@ import com.vaadin.terminal.Vaadin6Component; */ @SuppressWarnings("serial") public class GridLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier, - Vaadin6Component { + Layout.AlignmentHandler, Layout.SpacingHandler, Layout.MarginHandler, + LayoutClickNotifier, Vaadin6Component { private GridLayoutServerRpc rpc = new GridLayoutServerRpc() { @@ -1416,4 +1417,37 @@ public class GridLayout extends AbstractLayout implements LayoutClickEvent.class, listener); } + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#setMargin(boolean) + */ + @Override + public void setMargin(boolean enabled) { + setMargin(new MarginInfo(enabled)); + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.ui.Layout.MarginHandler#setMargin(com.vaadin.shared.ui.MarginInfo + * ) + */ + @Override + public void setMargin(MarginInfo marginInfo) { + getState().setMarginsBitmask(marginInfo.getBitMask()); + requestRepaint(); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Layout.MarginHandler#getMargin() + */ + @Override + public MarginInfo getMargin() { + return new MarginInfo(getState().getMarginsBitmask()); + } + } diff --git a/server/src/com/vaadin/ui/Layout.java b/server/src/com/vaadin/ui/Layout.java index 6a95d23f8c..9c7cd2b477 100644 --- a/server/src/com/vaadin/ui/Layout.java +++ b/server/src/com/vaadin/ui/Layout.java @@ -18,8 +18,8 @@ package com.vaadin.ui; import java.io.Serializable; -import com.vaadin.shared.ui.VMarginInfo; import com.vaadin.shared.ui.AlignmentInfo.Bits; +import com.vaadin.shared.ui.MarginInfo; /** * Extension to the {@link ComponentContainer} interface which adds the @@ -32,30 +32,6 @@ import com.vaadin.shared.ui.AlignmentInfo.Bits; */ public interface Layout extends ComponentContainer, Serializable { - /** - * Enable layout margins. Affects all four sides of the layout. This will - * tell the client-side implementation to leave extra space around the - * layout. The client-side implementation decides the actual amount, and it - * can vary between themes. - * - * @param enabled - */ - public void setMargin(boolean enabled); - - /** - * Enable specific layout margins. This will tell the client-side - * implementation to leave extra space around the layout in specified edges, - * clockwise from top (top, right, bottom, left). The client-side - * implementation decides the actual amount, and it can vary between themes. - * - * @param top - * @param right - * @param bottom - * @param left - */ - public void setMargin(boolean top, boolean right, boolean bottom, - boolean left); - /** * AlignmentHandler is most commonly an advanced {@link Layout} that can * align its components. @@ -197,6 +173,19 @@ public interface Layout extends ComponentContainer, Serializable { * its components). */ public interface MarginHandler extends Serializable { + + /** + * Enable layout margins. Affects all four sides of the layout. This + * will tell the client-side implementation to leave extra space around + * the layout. The client-side implementation decides the actual amount, + * and it can vary between themes. + * + * @param enabled + * true if margins should be enabled on all sides, false to + * disable all margins + */ + public void setMargin(boolean enabled); + /** * Enable margins for this layout. * @@ -224,16 +213,4 @@ public interface Layout extends ComponentContainer, Serializable { public MarginInfo getMargin(); } - @SuppressWarnings("serial") - public static class MarginInfo extends VMarginInfo implements Serializable { - - public MarginInfo(boolean enabled) { - super(enabled, enabled, enabled, enabled); - } - - public MarginInfo(boolean top, boolean right, boolean bottom, - boolean left) { - super(top, right, bottom, left); - } - } } diff --git a/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java b/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java index 675d11d0b7..4fc865626c 100644 --- a/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/AbstractLayoutState.java @@ -18,14 +18,5 @@ package com.vaadin.shared.ui; import com.vaadin.shared.ComponentState; public class AbstractLayoutState extends ComponentState { - private int marginsBitmask; - - public int getMarginsBitmask() { - return marginsBitmask; - } - - public void setMarginsBitmask(int marginsBitmask) { - this.marginsBitmask = marginsBitmask; - } } \ No newline at end of file diff --git a/shared/src/com/vaadin/shared/ui/MarginInfo.java b/shared/src/com/vaadin/shared/ui/MarginInfo.java new file mode 100644 index 0000000000..21e52f258a --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/MarginInfo.java @@ -0,0 +1,96 @@ +/* + * Copyright 2011 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.shared.ui; + +import java.io.Serializable; + +public class MarginInfo implements Serializable { + + private static final int TOP = 1; + private static final int RIGHT = 2; + private static final int BOTTOM = 4; + private static final int LEFT = 8; + + private int bitMask; + + public MarginInfo(boolean enabled) { + this(enabled, enabled, enabled, enabled); + } + + public MarginInfo(int bitMask) { + this.bitMask = bitMask; + } + + public MarginInfo(boolean top, boolean right, boolean bottom, boolean left) { + setMargins(top, right, bottom, left); + } + + public void setMargins(boolean top, boolean right, boolean bottom, + boolean left) { + bitMask = top ? TOP : 0; + bitMask += right ? RIGHT : 0; + bitMask += bottom ? BOTTOM : 0; + bitMask += left ? LEFT : 0; + } + + public void setMargins(MarginInfo marginInfo) { + bitMask = marginInfo.bitMask; + } + + public boolean hasLeft() { + return (bitMask & LEFT) == LEFT; + } + + public boolean hasRight() { + return (bitMask & RIGHT) == RIGHT; + } + + public boolean hasTop() { + return (bitMask & TOP) == TOP; + } + + public boolean hasBottom() { + return (bitMask & BOTTOM) == BOTTOM; + } + + public int getBitMask() { + return bitMask; + } + + public void setMargins(boolean enabled) { + if (enabled) { + bitMask = TOP + RIGHT + BOTTOM + LEFT; + } else { + bitMask = 0; + } + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MarginInfo)) { + return false; + } + + return ((MarginInfo) obj).bitMask == bitMask; + } + + @Override + public int hashCode() { + return bitMask; + } + +} diff --git a/shared/src/com/vaadin/shared/ui/VMarginInfo.java b/shared/src/com/vaadin/shared/ui/VMarginInfo.java deleted file mode 100644 index 9e9e0a4bb4..0000000000 --- a/shared/src/com/vaadin/shared/ui/VMarginInfo.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2011 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.shared.ui; - -import java.io.Serializable; - -@SuppressWarnings("serial") -public class VMarginInfo implements Serializable { - - private static final int TOP = 1; - private static final int RIGHT = 2; - private static final int BOTTOM = 4; - private static final int LEFT = 8; - - private int bitMask; - - public VMarginInfo(int bitMask) { - this.bitMask = bitMask; - } - - public VMarginInfo(boolean top, boolean right, boolean bottom, boolean left) { - setMargins(top, right, bottom, left); - } - - public void setMargins(boolean top, boolean right, boolean bottom, - boolean left) { - bitMask = top ? TOP : 0; - bitMask += right ? RIGHT : 0; - bitMask += bottom ? BOTTOM : 0; - bitMask += left ? LEFT : 0; - } - - public void setMargins(VMarginInfo marginInfo) { - bitMask = marginInfo.bitMask; - } - - public boolean hasLeft() { - return (bitMask & LEFT) == LEFT; - } - - public boolean hasRight() { - return (bitMask & RIGHT) == RIGHT; - } - - public boolean hasTop() { - return (bitMask & TOP) == TOP; - } - - public boolean hasBottom() { - return (bitMask & BOTTOM) == BOTTOM; - } - - public int getBitMask() { - return bitMask; - } - - public void setMargins(boolean enabled) { - if (enabled) { - bitMask = TOP + RIGHT + BOTTOM + LEFT; - } else { - bitMask = 0; - } - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof VMarginInfo)) { - return false; - } - - return ((VMarginInfo) obj).bitMask == bitMask; - } - - @Override - public int hashCode() { - return bitMask; - } - -} diff --git a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java index d2e685d8cb..381a6a7f85 100644 --- a/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/gridlayout/GridLayoutState.java @@ -21,6 +21,7 @@ public class GridLayoutState extends AbstractLayoutState { private boolean spacing = false; private int rows = 0; private int columns = 0; + private int marginsBitmask = 0; public boolean isSpacing() { return spacing; @@ -30,6 +31,14 @@ public class GridLayoutState extends AbstractLayoutState { this.spacing = spacing; } + public int getMarginsBitmask() { + return marginsBitmask; + } + + public void setMarginsBitmask(int marginsBitmask) { + this.marginsBitmask = marginsBitmask; + } + public int getRows() { return rows; } diff --git a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java index 235c9eab13..3fa2ad771c 100644 --- a/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java +++ b/shared/src/com/vaadin/shared/ui/orderedlayout/AbstractOrderedLayoutState.java @@ -27,6 +27,8 @@ public class AbstractOrderedLayoutState extends AbstractLayoutState { public HashMap childData = new HashMap(); + private int marginsBitmask = 0; + public static class ChildComponentData implements Serializable { private int alignmentBitmask = AlignmentInfo.TOP_LEFT.getBitMask(); private float expandRatio = 0.0f; @@ -65,4 +67,12 @@ public class AbstractOrderedLayoutState extends AbstractLayoutState { this.spacing = spacing; } + public int getMarginsBitmask() { + return marginsBitmask; + } + + public void setMarginsBitmask(int marginsBitmask) { + this.marginsBitmask = marginsBitmask; + } + } \ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/Parameters.java b/tests/testbench/com/vaadin/tests/Parameters.java index 4fb224eb19..e9824d9c40 100644 --- a/tests/testbench/com/vaadin/tests/Parameters.java +++ b/tests/testbench/com/vaadin/tests/Parameters.java @@ -27,7 +27,7 @@ import com.vaadin.terminal.RequestHandler; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedResponse; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Link; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; @@ -90,7 +90,7 @@ public class Parameters extends com.vaadin.Application.LegacyApplication final Panel panel2 = new Panel("Parameter Handler"); params.setSizeFull(); panel2.setContent(new VerticalLayout()); - ((Layout) panel2.getContent()).setMargin(true); + ((MarginHandler) panel2.getContent()).setMargin(true); params.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); panel2.addComponent(params); diff --git a/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java b/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java index af62e5e4a4..c04be3d724 100644 --- a/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java +++ b/tests/testbench/com/vaadin/tests/components/AbstractLayoutTest.java @@ -2,11 +2,12 @@ package com.vaadin.tests.components; import java.util.LinkedHashMap; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.Alignment; import com.vaadin.ui.Component; import com.vaadin.ui.Layout.AlignmentHandler; -import com.vaadin.ui.Layout.MarginInfo; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Layout.SpacingHandler; public abstract class AbstractLayoutTest extends @@ -17,7 +18,7 @@ public abstract class AbstractLayoutTest extends @Override public void execute(T c, MarginInfo value, Object data) { - c.setMargin(value); + ((MarginHandler) c).setMargin(value); } }; @@ -42,7 +43,9 @@ public abstract class AbstractLayoutTest extends @Override protected void createActions() { super.createActions(); - createMarginsSelect(CATEGORY_LAYOUT_FEATURES); + if (MarginHandler.class.isAssignableFrom(getTestClass())) { + createMarginsSelect(CATEGORY_LAYOUT_FEATURES); + } if (SpacingHandler.class.isAssignableFrom(getTestClass())) { createSpacingSelect(CATEGORY_LAYOUT_FEATURES); } diff --git a/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java b/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java index 0bc4f45545..0655c09102 100644 --- a/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java +++ b/tests/testbench/com/vaadin/tests/components/customfield/NestedPersonForm.java @@ -4,6 +4,7 @@ import java.util.Arrays; import com.vaadin.data.Item; import com.vaadin.data.util.BeanItem; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.tests.util.Person; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; @@ -13,6 +14,7 @@ import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.Form; import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout.MarginHandler; /** * Example of nested forms @@ -37,7 +39,8 @@ public class NestedPersonForm extends Form { setItemDataSource(beanItem, Arrays.asList("firstName", "lastName", "address", "email", "phoneNumber")); getFooter().addComponent(getButtonsLayout()); - getFooter().setMargin(false, false, true, true); + ((MarginHandler) getFooter()).setMargin(new MarginInfo(false, false, + true, true)); } /** diff --git a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java index 1ea800821b..a35b78c219 100644 --- a/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java +++ b/tests/testbench/com/vaadin/tests/integration/LiferayThemeDemo.java @@ -8,6 +8,7 @@ import com.vaadin.Application; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.event.Action; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.terminal.ExternalResource; import com.vaadin.terminal.Page; @@ -103,7 +104,6 @@ public class LiferayThemeDemo extends Application.LegacyApplication { mainLayout.addComponent(getTopMenu()); CssLayout margin = new CssLayout(); - margin.setMargin(false, true, true, true); margin.setSizeFull(); tabs = new TabSheet(); tabs.setSizeFull(); @@ -239,7 +239,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); - hl.setMargin(true, false, false, false); + hl.setMargin(new MarginInfo(true, false, false, false)); l.addComponent(hl); AbstractSelect cb = new ComboBox(); @@ -270,7 +270,7 @@ public class LiferayThemeDemo extends Application.LegacyApplication { HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); - hl.setMargin(true, false, false, false); + hl.setMargin(new MarginInfo(true, false, false, false)); l.addComponent(hl); DateField df = new DateField(); diff --git a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java index 792bcb1aab..ed35d39ef7 100644 --- a/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java +++ b/tests/testbench/com/vaadin/tests/layouts/CssLayoutCustomCss.java @@ -12,6 +12,7 @@ import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.NativeButton; public class CssLayoutCustomCss extends TestBase implements ClickListener { @@ -48,7 +49,7 @@ public class CssLayoutCustomCss extends TestBase implements ClickListener { @Override public void valueChange(ValueChangeEvent event) { - layout.setMargin(cb.getValue()); + ((MarginHandler) layout).setMargin(cb.getValue()); } }); diff --git a/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java b/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java index 1c864fdb47..e200c40744 100644 --- a/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java +++ b/tests/testbench/com/vaadin/tests/layouts/GridLayoutInsidePanel.java @@ -3,7 +3,7 @@ package com.vaadin.tests.layouts; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; public class GridLayoutInsidePanel extends TestBase { @@ -27,7 +27,7 @@ public class GridLayoutInsidePanel extends TestBase { "A label which defines the size of the GL")); Panel p = new Panel("Panel 1"); - ((Layout) p.getContent()).setMargin(false); + ((MarginHandler) p.getContent()).setMargin(false); p.setSizeUndefined(); p.getContent().setSizeUndefined(); @@ -41,7 +41,7 @@ public class GridLayoutInsidePanel extends TestBase { "A label which defines the size of the GL")); Panel p = new Panel("Panel 2", gl); - ((Layout) p.getContent()).setMargin(false); + ((MarginHandler) p.getContent()).setMargin(false); p.setSizeUndefined(); p.getContent().setSizeUndefined(); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java index 438f7e2d5f..d6d3b132c3 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1435.java @@ -10,6 +10,7 @@ import com.vaadin.ui.CustomComponent; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.Table; @@ -159,7 +160,7 @@ public class Ticket1435 extends Application.LegacyApplication { private void initContainer() { container.setStyleName("custompanel"); container.setSizeFull(); - ((Layout) container.getContent()).setMargin(false); + ((MarginHandler) container.getContent()).setMargin(false); container.getContent().setSizeFull(); root.addComponent(container); root.setExpandRatio(container, 1); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java index b9fd2debd5..87ea7e86a8 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1572.java @@ -1,5 +1,6 @@ package com.vaadin.tests.tickets; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.GridLayout; @@ -82,19 +83,19 @@ public class Ticket1572 extends com.vaadin.Application.LegacyApplication { state.setValue("Margin on"); break; case 2: - gl.setMargin(true, false, false, false); + gl.setMargin(new MarginInfo(true, false, false, false)); state.setValue("Margin top"); break; case 3: - gl.setMargin(false, true, false, false); + gl.setMargin(new MarginInfo(false, true, false, false)); state.setValue("Margin right"); break; case 4: - gl.setMargin(false, false, true, false); + gl.setMargin(new MarginInfo(false, false, true, false)); state.setValue("Margin bottom"); break; case 5: - gl.setMargin(false, false, false, true); + gl.setMargin(new MarginInfo(false, false, false, true)); state.setValue("Margin left"); break; default: diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java index 01792aeb89..1f2c9624c3 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1710.java @@ -5,6 +5,7 @@ import java.util.Iterator; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.util.MethodProperty; +import com.vaadin.shared.ui.MarginInfo; import com.vaadin.terminal.SystemError; import com.vaadin.terminal.ThemeResource; import com.vaadin.ui.AbstractComponent; @@ -393,10 +394,13 @@ public class Ticket1710 extends com.vaadin.Application.LegacyApplication { } private void updateMarginsAndSpacing() { - testedLayout.setMargin(marginTop.getValue().booleanValue(), - marginRight.getValue().booleanValue(), marginBottom - .getValue().booleanValue(), marginLeft.getValue() - .booleanValue()); + if (testedLayout instanceof Layout.MarginHandler) { + ((Layout.MarginHandler) testedLayout).setMargin(new MarginInfo( + marginTop.getValue().booleanValue(), marginRight + .getValue().booleanValue(), marginBottom + .getValue().booleanValue(), marginLeft + .getValue().booleanValue())); + } if (testedLayout instanceof Layout.SpacingHandler) { ((Layout.SpacingHandler) testedLayout).setSpacing(spacing .getValue().booleanValue()); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java index a40f5b25b9..e5fcf59db8 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1805.java @@ -6,7 +6,7 @@ import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextField; @@ -17,7 +17,7 @@ public class Ticket1805 extends com.vaadin.Application.LegacyApplication { final LegacyWindow main = new LegacyWindow(getClass().getName() .substring(getClass().getName().lastIndexOf(".") + 1)); setMainWindow(main); - ((Layout) main.getContent()).setMargin(false); + ((MarginHandler) main.getContent()).setMargin(false); Label description = new Label( "GridLayout with 100% (no height), is wanted to " diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java index c36bb5c25e..f6d8ce5e01 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2021.java @@ -9,6 +9,7 @@ import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Panel; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextArea; @@ -78,7 +79,7 @@ public class Ticket2021 extends Application.LegacyApplication { p3.setHeight("500px"); // p3.setContent(new GridLayout()); p3.getContent().setSizeFull(); - ((Layout) p3.getContent()).setMargin(false); + ((MarginHandler) p3.getContent()).setMargin(false); GridLayout gl = new GridLayout(); gl.setSizeFull(); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java index ac8928d110..d98656b9ca 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2040.java @@ -2,7 +2,7 @@ package com.vaadin.tests.tickets; import com.vaadin.ui.Accordion; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; @@ -17,7 +17,7 @@ public class Ticket2040 extends com.vaadin.Application.LegacyApplication { setMainWindow(main); main.getContent().setSizeFull(); - ((Layout) main.getContent()).setMargin(true); + ((MarginHandler) main.getContent()).setMargin(true); setTheme("tests-tickets"); diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java index 16a552e37a..c5ef9ec0b0 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2405.java @@ -8,7 +8,7 @@ import com.vaadin.ui.Embedded; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.HorizontalSplitPanel; import com.vaadin.ui.Label; -import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Root.LegacyWindow; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; @@ -31,7 +31,7 @@ public class Ticket2405 extends Application.LegacyApplication { setMainWindow(root); root.getContent().setSizeFull(); - ((Layout) root.getContent()).setMargin(false); + ((MarginHandler) root.getContent()).setMargin(false); // Top area, containing playback and volume controls, play status, view // modes and search diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java index ee60c0ce7e..2d2970d36e 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2998.java @@ -19,6 +19,7 @@ import com.vaadin.ui.DefaultFieldFactory; import com.vaadin.ui.Field; import com.vaadin.ui.FormLayout; import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.ListSelect; import com.vaadin.ui.Notification; import com.vaadin.ui.Panel; @@ -252,7 +253,7 @@ public class Ticket2998 extends Application.LegacyApplication { // set theme and some layout stuff setMainWindow(w); w.getContent().setSizeFull(); - ((Layout) w.getContent()).setMargin(false); + ((MarginHandler) w.getContent()).setMargin(false); Panel p = new Panel("Workout Log"); p.setStyleName(Reindeer.PANEL_LIGHT); -- cgit v1.2.3 From 88776600733901f3f9891aa90a11a5aeb2b97ef4 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 22 Aug 2012 08:53:23 +0300 Subject: Changed border style to enum (#9072) --- .../terminal/gwt/client/ui/link/LinkConnector.java | 7 ++--- .../vaadin/terminal/gwt/client/ui/link/VLink.java | 18 ++++++++----- server/src/com/vaadin/terminal/Page.java | 21 ++++++++------- server/src/com/vaadin/ui/Link.java | 31 +++++++++++----------- server/src/com/vaadin/ui/Root.java | 6 ++--- shared/src/com/vaadin/shared/ui/BorderStyle.java | 20 ++++++++++++++ 6 files changed, 65 insertions(+), 38 deletions(-) create mode 100755 shared/src/com/vaadin/shared/ui/BorderStyle.java diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java index c4bbcd34f7..f2b8361f2b 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/link/LinkConnector.java @@ -17,6 +17,7 @@ package com.vaadin.terminal.gwt.client.ui.link; import com.google.gwt.user.client.DOM; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.Connect; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Paintable; @@ -57,12 +58,12 @@ public class LinkConnector extends AbstractComponentConnector implements if (uidl.hasAttribute("border")) { if ("none".equals(uidl.getStringAttribute("border"))) { - getWidget().borderStyle = VLink.BORDER_STYLE_NONE; + getWidget().borderStyle = BorderStyle.NONE; } else { - getWidget().borderStyle = VLink.BORDER_STYLE_MINIMAL; + getWidget().borderStyle = BorderStyle.MINIMAL; } } else { - getWidget().borderStyle = VLink.BORDER_STYLE_DEFAULT; + getWidget().borderStyle = BorderStyle.DEFAULT; } getWidget().targetHeight = uidl.hasAttribute("targetHeight") ? uidl diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java b/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java index e312d4d489..b0e44c9d13 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/link/VLink.java @@ -23,6 +23,7 @@ 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.HTML; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.ui.Icon; @@ -31,15 +32,20 @@ public class VLink extends HTML implements ClickHandler { public static final String CLASSNAME = "v-link"; - protected static final int BORDER_STYLE_DEFAULT = 0; - protected static final int BORDER_STYLE_MINIMAL = 1; - protected static final int BORDER_STYLE_NONE = 2; + @Deprecated + protected static final BorderStyle BORDER_STYLE_DEFAULT = BorderStyle.DEFAULT; + + @Deprecated + protected static final BorderStyle BORDER_STYLE_MINIMAL = BorderStyle.MINIMAL; + + @Deprecated + protected static final BorderStyle BORDER_STYLE_NONE = BorderStyle.NONE; protected String src; protected String target; - protected int borderStyle = BORDER_STYLE_DEFAULT; + protected BorderStyle borderStyle = BorderStyle.DEFAULT; protected boolean enabled; @@ -73,10 +79,10 @@ public class VLink extends HTML implements ClickHandler { } String features; switch (borderStyle) { - case BORDER_STYLE_NONE: + case NONE: features = "menubar=no,location=no,status=no"; break; - case BORDER_STYLE_MINIMAL: + case MINIMAL: features = "menubar=yes,location=no,status=no"; break; default: diff --git a/server/src/com/vaadin/terminal/Page.java b/server/src/com/vaadin/terminal/Page.java index 933f9b39e6..8eb77b7d0d 100644 --- a/server/src/com/vaadin/terminal/Page.java +++ b/server/src/com/vaadin/terminal/Page.java @@ -24,6 +24,7 @@ import java.util.LinkedList; import java.util.List; import com.vaadin.event.EventRouter; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.root.PageClientRpc; import com.vaadin.shared.ui.root.RootConstants; import com.vaadin.terminal.WrappedRequest.BrowserDetails; @@ -128,7 +129,7 @@ public class Page implements Serializable { /** * The border style of the target window */ - private final int border; + private final BorderStyle border; /** * Creates a new open resource. @@ -145,7 +146,7 @@ public class Page implements Serializable { * The border style of the target window */ private OpenResource(Resource resource, String name, int width, - int height, int border) { + int height, BorderStyle border) { this.resource = resource; this.name = name; this.width = width; @@ -174,10 +175,10 @@ public class Page implements Serializable { target.addAttribute("height", height); } switch (border) { - case BORDER_MINIMAL: + case MINIMAL: target.addAttribute("border", "minimal"); break; - case BORDER_NONE: + case NONE: target.addAttribute("border", "none"); break; } @@ -193,19 +194,20 @@ public class Page implements Serializable { /** * A border style used for opening resources in a window without a border. */ - public static final int BORDER_NONE = 0; + @Deprecated + public static final BorderStyle BORDER_NONE = BorderStyle.NONE; /** * A border style used for opening resources in a window with a minimal * border. */ - public static final int BORDER_MINIMAL = 1; + public static final BorderStyle BORDER_MINIMAL = BorderStyle.MINIMAL; /** * A border style that indicates that the default border style should be * used when opening resources. */ - public static final int BORDER_DEFAULT = 2; + public static final BorderStyle BORDER_DEFAULT = BorderStyle.DEFAULT; /** * Listener that listens changes in URI fragment. @@ -581,11 +583,10 @@ public class Page implements Serializable { * @param height * the height of the window in pixels * @param border - * the border style of the window. See {@link #BORDER_NONE - * Window.BORDER_* constants} + * the border style of the window. */ public void open(Resource resource, String windowName, int width, - int height, int border) { + int height, BorderStyle border) { openList.add(new OpenResource(resource, windowName, width, height, border)); root.requestRepaint(); diff --git a/server/src/com/vaadin/ui/Link.java b/server/src/com/vaadin/ui/Link.java index 57f2088054..ae2934f878 100644 --- a/server/src/com/vaadin/ui/Link.java +++ b/server/src/com/vaadin/ui/Link.java @@ -18,7 +18,7 @@ package com.vaadin.ui; import java.util.Map; -import com.vaadin.terminal.Page; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Resource; @@ -34,19 +34,22 @@ import com.vaadin.terminal.Vaadin6Component; public class Link extends AbstractComponent implements Vaadin6Component { /* Target window border type constant: No window border */ - public static final int TARGET_BORDER_NONE = Page.BORDER_NONE; + @Deprecated + public static final BorderStyle TARGET_BORDER_NONE = BorderStyle.NONE; /* Target window border type constant: Minimal window border */ - public static final int TARGET_BORDER_MINIMAL = Page.BORDER_MINIMAL; + @Deprecated + public static final BorderStyle TARGET_BORDER_MINIMAL = BorderStyle.MINIMAL; /* Target window border type constant: Default window border */ - public static final int TARGET_BORDER_DEFAULT = Page.BORDER_DEFAULT; + @Deprecated + public static final BorderStyle TARGET_BORDER_DEFAULT = BorderStyle.DEFAULT; private Resource resource = null; private String targetName; - private int targetBorder = TARGET_BORDER_DEFAULT; + private BorderStyle targetBorder = BorderStyle.DEFAULT; private int targetWidth = -1; @@ -89,7 +92,7 @@ public class Link extends AbstractComponent implements Vaadin6Component { * */ public Link(String caption, Resource resource, String targetName, - int width, int height, int border) { + int width, int height, BorderStyle border) { setCaption(caption); this.resource = resource; setTargetName(targetName); @@ -131,10 +134,10 @@ public class Link extends AbstractComponent implements Vaadin6Component { // Target window border switch (getTargetBorder()) { - case TARGET_BORDER_MINIMAL: + case MINIMAL: target.addAttribute("border", "minimal"); break; - case TARGET_BORDER_NONE: + case NONE: target.addAttribute("border", "none"); break; } @@ -145,7 +148,7 @@ public class Link extends AbstractComponent implements Vaadin6Component { * * @return the target window border. */ - public int getTargetBorder() { + public BorderStyle getTargetBorder() { return targetBorder; } @@ -183,13 +186,9 @@ public class Link extends AbstractComponent implements Vaadin6Component { * @param targetBorder * the targetBorder to set. */ - public void setTargetBorder(int targetBorder) { - if (targetBorder == TARGET_BORDER_DEFAULT - || targetBorder == TARGET_BORDER_MINIMAL - || targetBorder == TARGET_BORDER_NONE) { - this.targetBorder = targetBorder; - requestRepaint(); - } + public void setTargetBorder(BorderStyle targetBorder) { + this.targetBorder = targetBorder; + requestRepaint(); } /** diff --git a/server/src/com/vaadin/ui/Root.java b/server/src/com/vaadin/ui/Root.java index b37005a16e..020ff869fa 100644 --- a/server/src/com/vaadin/ui/Root.java +++ b/server/src/com/vaadin/ui/Root.java @@ -34,6 +34,7 @@ import com.vaadin.event.MouseEvents.ClickEvent; import com.vaadin.event.MouseEvents.ClickListener; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; +import com.vaadin.shared.ui.BorderStyle; import com.vaadin.shared.ui.root.RootConstants; import com.vaadin.shared.ui.root.RootServerRpc; import com.vaadin.shared.ui.root.RootState; @@ -283,13 +284,12 @@ public abstract class Root extends AbstractComponentContainer implements * @param height * the height of the window in pixels * @param border - * the border style of the window. See {@link #BORDER_NONE - * Window.BORDER_* constants} + * the border style of the window. * @deprecated As of 7.0, use getPage().open instead */ @Deprecated public void open(Resource resource, String windowName, int width, - int height, int border) { + int height, BorderStyle border) { getPage().open(resource, windowName, width, height, border); } diff --git a/shared/src/com/vaadin/shared/ui/BorderStyle.java b/shared/src/com/vaadin/shared/ui/BorderStyle.java new file mode 100755 index 0000000000..786d340f1c --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/BorderStyle.java @@ -0,0 +1,20 @@ +/* + * Copyright 2011 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.shared.ui; + +public enum BorderStyle { + NONE, MINIMAL, DEFAULT; +} -- cgit v1.2.3