Browse Source

Fix moving a single component inside a split panel (#11920)

Change-Id: Ib9b3625e4104763143906eb1b7986ef7b3b80737
tags/7.3.0.beta1
Artur Signell 10 years ago
parent
commit
0f38151da3

+ 8
- 0
client/src/com/vaadin/client/ui/VAbstractSplitPanel.java View File

@@ -511,6 +511,10 @@ public class VAbstractSplitPanel extends ComplexPanel {
firstChild = w;
}

public Widget getFirstWidget() {
return firstChild;
}

/** For internal use only. May be removed or replaced in the future. */
public void setSecondWidget(Widget w) {
if (secondChild == w) {
@@ -525,6 +529,10 @@ public class VAbstractSplitPanel extends ComplexPanel {
secondChild = w;
}

public Widget getSecondWidget() {
return secondChild;
}

@Override
public void onBrowserEvent(Event event) {
switch (DOM.eventGetType(event)) {

+ 33
- 0
client/src/com/vaadin/client/ui/splitpanel/AbstractSplitPanelConnector.java View File

@@ -161,6 +161,35 @@ public abstract class AbstractSplitPanelConnector extends
getLayoutManager().setNeedsLayout(this);

getWidget().makeScrollable();

handleSingleComponentMove();
}

/**
* Handles the case when there is only one child component and that
* component is moved between first <-> second. This does not trigger a
* hierarchy change event as the list of children contains the same
* component in both cases.
*/
private void handleSingleComponentMove() {
if (getChildComponents().size() == 1) {
Widget stateFirstChild = null;
Widget stateSecondChild = null;
if (getState().firstChild != null) {
stateFirstChild = ((ComponentConnector) getState().firstChild)
.getWidget();
}
if (getState().secondChild != null) {
stateSecondChild = ((ComponentConnector) getState().secondChild)
.getWidget();
}

if (stateFirstChild == getWidget().getSecondWidget()
|| stateSecondChild == getWidget().getFirstWidget()) {
handleHierarchyChange();
}
}

}

@Override
@@ -212,6 +241,10 @@ public abstract class AbstractSplitPanelConnector extends

@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
handleHierarchyChange();
}

private void handleHierarchyChange() {
/*
* When the connector gets detached, the state isn't updated but there's
* still a hierarchy change -> verify that the child from the state is

+ 64
- 0
uitest/src/com/vaadin/tests/components/splitpanel/SplitPanelMoveComponent.java View File

@@ -0,0 +1,64 @@
/*
* Copyright 2000-2013 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.splitpanel;

import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.HorizontalSplitPanel;

public class SplitPanelMoveComponent extends AbstractTestUI {

@Override
protected void setup(VaadinRequest request) {
final HorizontalSplitPanel split = new HorizontalSplitPanel();
split.setHeight("200px");
final Button targetComponent = new Button(
"Button in splitpanel. Click to move to the other side");
split.setFirstComponent(targetComponent);

targetComponent.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
if (split.getFirstComponent() != null) {
split.setFirstComponent(null);
split.setSecondComponent(targetComponent);
} else {
split.setSecondComponent(null);
split.setFirstComponent(targetComponent);

}
}

});

addComponent(split);
}

@Override
protected String getTestDescription() {
return "Fail to swap components in HorizontalSplitPanel";
}

@Override
protected Integer getTicketNumber() {
return 11920;
}

}

+ 55
- 0
uitest/src/com/vaadin/tests/components/splitpanel/SplitPanelMoveComponentTest.java View File

@@ -0,0 +1,55 @@
/*
* Copyright 2000-2013 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.tests.components.splitpanel;

import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.vaadin.tests.tb3.MultiBrowserTest;

public class SplitPanelMoveComponentTest extends MultiBrowserTest {

private static final String BUTTON_TEXT = "Button in splitpanel. Click to move to the other side";

@Test
public void moveComponent() {
openTestURL();
Assert.assertEquals(BUTTON_TEXT, getFirstChild().getText());
getFirstChild().click();
Assert.assertEquals(BUTTON_TEXT, getSecondChild().getText());
getSecondChild().click();
Assert.assertEquals(BUTTON_TEXT, getFirstChild().getText());
}

private WebElement getFirstChild() {
WebElement container = getDriver()
.findElement(
By.xpath("//div[contains(@class,'v-splitpanel-first-container')]"));
return container.findElement(By
.xpath("//div[contains(@class, 'v-button')]"));
}

private WebElement getSecondChild() {
WebElement container = getDriver()
.findElement(
By.xpath("//div[contains(@class,'v-splitpanel-second-container')]"));
return container.findElement(By
.xpath("//div[contains(@class, 'v-button')]"));
}

}

Loading…
Cancel
Save