Change-Id: If4f3e23a1d58c9f1cec7fc7d5e4e3f470932162ftags/7.0.0.beta11
@@ -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. |
@@ -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); | |||
} | |||
} |
@@ -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> |
@@ -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()); | |||
} | |||
} | |||
} | |||
} |
@@ -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; | |||
} |
@@ -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); | |||
} | |||
} |