diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-12-04 16:41:49 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-12-07 08:48:06 +0000 |
commit | 50665cb1d34c84bc478cd5306f6c6151fe4d0bc3 (patch) | |
tree | 329772d20abe91f084980cc203fdeec046283620 | |
parent | ece1ab1fa500ad7142b80534dffee0b3883a984e (diff) | |
download | vaadin-framework-50665cb1d34c84bc478cd5306f6c6151fe4d0bc3.tar.gz vaadin-framework-50665cb1d34c84bc478cd5306f6c6151fe4d0bc3.zip |
Reset state before sending hierarchy event to removed connector (#10151)
Change-Id: If4f3e23a1d58c9f1cec7fc7d5e4e3f470932162f
6 files changed, 241 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 354d809622..5f90fe4c19 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -2035,6 +2035,31 @@ public class ApplicationConnection { private void recursivelyDetach(ServerConnector connector, List<ConnectorHierarchyChangeEvent> events) { + + /* + * Reset state in an attempt to keep it consistent with the + * hierarchy. No children and no parent is the initial situation + * for the hierarchy, so changing the state to its initial value + * is the closest we can get without data from the server. + * #10151 + */ + try { + Type stateType = AbstractConnector.getStateType(connector); + + // Empty state instance to get default property values from + Object defaultState = stateType.createInstance(); + + SharedState state = connector.getState(); + + for (Property property : stateType.getProperties()) { + property.setValue(state, + property.getValue(defaultState)); + } + } catch (NoDataException e) { + throw new RuntimeException("Can't reset state for " + + Util.getConnectorString(connector), e); + } + /* * Recursively detach children to make sure they get * setParent(null) and hierarchy change events as needed. diff --git a/uitest/src/com/vaadin/tests/components/abstractcomponent/UseStateFromHierachy.java b/uitest/src/com/vaadin/tests/components/abstractcomponent/UseStateFromHierachy.java new file mode 100644 index 0000000000..0697286f38 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/abstractcomponent/UseStateFromHierachy.java @@ -0,0 +1,55 @@ +/* + * Copyright 2012 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.components.abstractcomponent; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.server.UseStateFromHierachyComponent; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; + +@Widgetset(TestingWidgetSet.NAME) +public class UseStateFromHierachy extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final UseStateFromHierachyComponent component = new UseStateFromHierachyComponent(); + component.setContent(new Label("Content child")); + + addComponent(component); + addComponent(new Button("Remove component", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + removeComponent(component); + } + })); + } + + @Override + protected String getTestDescription() { + return "Tests that shared state and connector hierarchy is consistent when removing components from the hierachy"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(10151); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/abstractcomponent/UseStateFromHierarchy.html b/uitest/src/com/vaadin/tests/components/abstractcomponent/UseStateFromHierarchy.html new file mode 100644 index 0000000000..225b901413 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/abstractcomponent/UseStateFromHierarchy.html @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title></title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">UIScrollTest</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.abstractcomponent.UseStateFromHierachy?restartApplication</td> + <td></td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentsabstractcomponentUseStateFromHierachy::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>vaadin=runcomvaadintestscomponentsabstractcomponentUseStateFromHierachy::Root/VNotification[0]/HTML[0]/domChild[0]</td> + <td></td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/widgetset/client/UseStateFromHierachyChangeConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/UseStateFromHierachyChangeConnector.java new file mode 100644 index 0000000000..948c1ece3d --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/UseStateFromHierachyChangeConnector.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012 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.google.gwt.user.client.ui.SimplePanel; +import com.vaadin.client.ComponentConnector; +import com.vaadin.client.ConnectorHierarchyChangeEvent; +import com.vaadin.client.ui.AbstractSingleComponentContainerConnector; +import com.vaadin.shared.Connector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.UseStateFromHierachyComponent; + +@Connect(UseStateFromHierachyComponent.class) +public class UseStateFromHierachyChangeConnector extends + AbstractSingleComponentContainerConnector { + + @Override + public SimplePanel getWidget() { + return (SimplePanel) super.getWidget(); + } + + @Override + public UseStateFromHierachyChangeConnectorState getState() { + return (UseStateFromHierachyChangeConnectorState) super.getState(); + } + + @Override + public void updateCaption(ComponentConnector connector) { + // Caption not supported + } + + @Override + public void onConnectorHierarchyChange( + ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { + Connector stateChild = getState().child; + if (stateChild == null) { + if (getChildComponents().size() != 0) { + throw new IllegalStateException( + "Hierarchy has child but state has not"); + } else { + getWidget().setWidget(null); + } + } else { + if (getChildComponents().size() != 1 + || getChildComponents().get(0) != stateChild) { + throw new IllegalStateException( + "State has child but hierarchy has not"); + } else { + getWidget().setWidget(getChildComponents().get(0).getWidget()); + } + } + } + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/UseStateFromHierachyChangeConnectorState.java b/uitest/src/com/vaadin/tests/widgetset/client/UseStateFromHierachyChangeConnectorState.java new file mode 100644 index 0000000000..9dbededb50 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/UseStateFromHierachyChangeConnectorState.java @@ -0,0 +1,25 @@ +/* + * Copyright 2012 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.AbstractComponentState; +import com.vaadin.shared.Connector; + +public class UseStateFromHierachyChangeConnectorState extends + AbstractComponentState { + public Connector child; +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/UseStateFromHierachyComponent.java b/uitest/src/com/vaadin/tests/widgetset/server/UseStateFromHierachyComponent.java new file mode 100644 index 0000000000..3349024340 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/UseStateFromHierachyComponent.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012 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.UseStateFromHierachyChangeConnectorState; +import com.vaadin.ui.AbstractSingleComponentContainer; +import com.vaadin.ui.Component; + +public class UseStateFromHierachyComponent extends + AbstractSingleComponentContainer { + + @Override + protected UseStateFromHierachyChangeConnectorState getState() { + return (UseStateFromHierachyChangeConnectorState) super.getState(); + } + + @Override + public void setContent(Component content) { + getState().child = content; + super.setContent(content); + } + +} |