Browse Source

Table column width can be changed from defined to expandratio (#15101)

Change-Id: I8dead7fd77b44c8adc5e973f29d5e14bae6fb293
tags/7.4.0.beta1
Sara Seppola 9 years ago
parent
commit
7237b88645

+ 1
- 0
client/src/com/vaadin/client/ui/VScrollTable.java View File

@@ -3630,6 +3630,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
c.setWidth(widthWithoutAddedIndent, true);
}
} else if (col.hasAttribute("er")) {
c.setUndefinedWidth();
c.setExpandRatio(col.getFloatAttribute("er"));

} else if (recalcWidths) {

+ 110
- 0
uitest/src/com/vaadin/tests/components/table/TableExpandRatio.java View File

@@ -0,0 +1,110 @@
/*
* Copyright 2000-2014 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.table;

import java.util.Arrays;

import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.annotations.Theme;
import com.vaadin.data.util.BeanItemContainer;
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.Table;
import com.vaadin.ui.VerticalLayout;

@PreserveOnRefresh
@Theme("valo")
public class TableExpandRatio extends AbstractTestUI {

@Override
protected void setup(VaadinRequest request) {

BeanItemContainer<MyItem> container = new BeanItemContainer<TableExpandRatio.MyItem>(
MyItem.class, Arrays.asList(new MyItem("one", 1), new MyItem(
"two", 2)));

final Table table = new Table(null, container);

table.setWidth("800px");
table.setImmediate(true);

Button widthButton = new Button("Set Width",
new Button.ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
table.setColumnWidth("value", 300);

}
});

Button expandButton = new Button("Set Expand Ratio",
new Button.ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
table.setColumnExpandRatio("value", 1);

}
});

widthButton.setId("widthbutton");
expandButton.setId("expandbutton");

VerticalLayout layout = new VerticalLayout(widthButton, expandButton,
table);
addComponent(layout);
}

public class MyItem {

private String name;
private Integer value;

public MyItem(String name, Integer value) {
this.name = name;
this.value = value;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getValue() {
return value;
}

public void setValue(Integer value) {
this.value = value;
}
}

@Override
protected String getTestDescription() {
return "When a column has fixed width and it is changed to expand ratio, the width should update accordingly";
}

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

+ 88
- 0
uitest/src/com/vaadin/tests/components/table/TableExpandRatioTest.java View File

@@ -0,0 +1,88 @@
/*
* Copyright 2000-2014 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.table;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.number.IsCloseTo.closeTo;

import java.util.List;

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

import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class TableExpandRatioTest extends MultiBrowserTest {

@Override
public void setup() throws Exception {
super.setup();

openTestURL();
}

/*
* Needed for IE to get focus when button is clicked
*/
@Override
protected boolean requireWindowFocusForIE() {

return true;
}

@Test
public void cellWidthUpdatesWhenExpandRatioSetAfterDefinedWidth() {

// test that after setting defined size to the second column, the first
// column will have correct size

setDefinedWidth();

assertThat(getFirstCellWidth(), closeTo(500, 10));

// test that after setting expandratio to the second column, it is
// correct

setExpandRatio();

assertThat(getFirstCellWidth(), closeTo(65, 5));

}

private void setExpandRatio() {
$(ButtonElement.class).id("expandbutton").click();
}

private void setDefinedWidth() {
$(ButtonElement.class).id("widthbutton").click();
}

private double getFirstCellWidth() {

List<WebElement> rows = $(TableElement.class).first()
.findElement(By.className("v-table-body"))
.findElements(By.tagName("tr"));
WebElement firstrow = rows.get(0);
List<WebElement> cells = firstrow.findElements(By
.className("v-table-cell-content"));

int cellwidth = cells.get(0).getSize().getWidth();
return cellwidth;
}
}

Loading…
Cancel
Save