From f2ec1fa217fa0fe7f98b6a2b95ed075a2e874769 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Tue, 5 Feb 2013 13:08:33 +0200 Subject: [PATCH] Merge of first part of (#10513) to Vaadin 7. Recalculate column widths if vertical scrollbar has been added/removed. Change-Id: I093059b8eaad8ff9f9d87db213dec806993459d5 --- .../com/vaadin/client/ui/VScrollTable.java | 10 +- .../treetable/TreeTableExtraScrollbar.html | 31 +++++ .../treetable/TreeTableExtraScrollbar.java | 112 ++++++++++++++++++ 3 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.html create mode 100644 uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.java diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 75f5550790..75d67b82d6 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -500,7 +500,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, /** * Read from the "recalcWidths" -attribute. When it is true, the table will * recalculate the widths for columns - desirable in some cases. For #1983, - * marked experimental. + * marked experimental. See also variable refreshContentWidths + * in method {@link TableHead#updateCellsFromUIDL(UIDL)}. *

* For internal use only. May be removed or replaced in the future. */ @@ -570,6 +571,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, /** For internal use only. May be removed or replaced in the future. */ public ContextMenuDetails contextMenu = null; + private boolean hadScrollBars = false; + public VScrollTable() { setMultiSelectMode(MULTISELECT_MODE_DEFAULT); @@ -2038,6 +2041,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, Util.runWebkitOverflowAutoFix(scrollBodyPanel.getElement()); } }); + + hadScrollBars = willHaveScrollbarz; } /** @@ -2984,7 +2989,8 @@ public class VScrollTable extends FlowPanel implements HasWidgets, public void updateCellsFromUIDL(UIDL uidl) { Iterator it = uidl.getChildIterator(); HashSet updated = new HashSet(); - boolean refreshContentWidths = false; + boolean refreshContentWidths = initializedAndAttached + && hadScrollBars != willHaveScrollbars(); while (it.hasNext()) { final UIDL col = (UIDL) it.next(); final String cid = col.getStringAttribute("cid"); diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.html b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.html new file mode 100644 index 0000000000..c499747232 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.html @@ -0,0 +1,31 @@ + + + + + + +TreeTableExtraScrollbar + + + + + + + + + + + + + + + + + + + + + +
TreeTableExtraScrollbar
open/run/com.vaadin.tests.components.treetable.TreeTableExtraScrollbar?restartApplication
clickbutton
screenCapture
+ + diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.java new file mode 100644 index 0000000000..4af0da158d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTableExtraScrollbar.java @@ -0,0 +1,112 @@ +package com.vaadin.tests.components.treetable; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Table; +import com.vaadin.ui.TreeTable; + +public class TreeTableExtraScrollbar extends TestBase { + + @Override + protected String getDescription() { + return "Vertical scrollbar should not cause a horizontal scrollbar" + + " if there is more excess space than vertical scrollbar needs."; + } + + @Override + protected Integer getTicketNumber() { + return 10513; + } + + @Override + protected void setup() { + HorizontalLayout layout = new HorizontalLayout(); + layout.setWidth("310px"); + layout.setHeight("300px"); + + final Table table = new TreeTable(); + table.setSizeFull(); + + table.addGeneratedColumn("parameterId", new EmptyColumnGenerator()); + table.addGeneratedColumn("wordingTextId", new TypeColumnGenerator()); + table.addGeneratedColumn("parameterTypeId", new TypeColumnGenerator()); + + table.setColumnWidth("parameterId", 26); + + table.addItem(new TestObject("name 1", "value 1")); + table.addItem(new TestObject("name 2", "value 2")); + table.addItem(new TestObject("name 3", "value 3")); + table.addItem(new TestObject("name 4", "value 4")); + table.addItem(new TestObject("name 5", "value 5")); + + layout.addComponent(table); + + Button button = new Button("Add"); + button.setId("button"); + button.addClickListener(new ClickListener() { + + public void buttonClick(ClickEvent event) { + table.addItem(new TestObject("name 6-1", "value 6-1")); + table.addItem(new TestObject("name 6-2", "value 6-2")); + table.addItem(new TestObject("name 6-3", "value 6-3")); + table.addItem(new TestObject("name 6-4", "value 6-4")); + table.addItem(new TestObject("name 6-5", "value 6-5")); + table.addItem(new TestObject("name 6-6", "value 6-6")); + table.addItem(new TestObject("name 6-7", "value 6-7")); + table.addItem(new TestObject("name 6-8", "value 6-8")); + table.addItem(new TestObject("name 6-9", "value 6-9")); + table.addItem(new TestObject("name 6-9", "value 6-10")); + } + }); + + addComponent(layout); + addComponent(button); + } + + private class EmptyColumnGenerator implements Table.ColumnGenerator { + public Object generateCell(Table table, Object itemId, Object columnId) { + return null; + } + } + + private class TypeColumnGenerator implements Table.ColumnGenerator { + public Object generateCell(Table table, Object itemId, Object columnId) { + if (itemId instanceof TestObject) { + return new Label(((TestObject) itemId).getValue()); + } + return null; + } + } + +} + +class TestObject { + + private String name; + private String value; + + public TestObject(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} -- 2.39.5