From 55f69ec8a203137d6bc1acfdb385da96a2f09b47 Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Fri, 18 May 2012 07:52:44 +0000 Subject: [merge from 6.7] #8793 Retain all tab metadata, not just caption and icon, in TabSheet.replaceComponent() svn changeset:23761/svn branch:6.8 --- src/com/vaadin/ui/TabSheet.java | 78 +++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 46 deletions(-) (limited to 'src/com/vaadin/ui') diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index 09d1002b48..6ada797570 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -725,25 +725,6 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, Tab newTab = tabs.get(newComponent); Tab oldTab = tabs.get(oldComponent); - // Gets the captions - String oldCaption = null; - Resource oldIcon = null; - String newCaption = null; - Resource newIcon = null; - - if (oldTab != null) { - oldCaption = oldTab.getCaption(); - oldIcon = oldTab.getIcon(); - } - - if (newTab != null) { - newCaption = newTab.getCaption(); - newIcon = newTab.getIcon(); - } else { - newCaption = newComponent.getCaption(); - newIcon = newComponent.getIcon(); - } - // Gets the locations int oldLocation = -1; int newLocation = -1; @@ -765,35 +746,21 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, addComponent(newComponent); } else if (newLocation == -1) { removeComponent(oldComponent); - keyMapper.remove(oldComponent); - newTab = addTab(newComponent); - components.remove(newComponent); - components.add(oldLocation, newComponent); - newTab.setCaption(oldCaption); - newTab.setIcon(oldIcon); + newTab = addTab(newComponent, oldLocation); + // Copy all relevant metadata to the new tab (#8793) + // TODO Should reuse the old tab instance instead? + copyTabMetadata(oldTab, newTab); } else { - if (oldLocation > newLocation) { - components.remove(oldComponent); - components.add(newLocation, oldComponent); - components.remove(newComponent); - components.add(oldLocation, newComponent); - } else { - components.remove(newComponent); - components.add(oldLocation, newComponent); - components.remove(oldComponent); - components.add(newLocation, oldComponent); - } + components.set(oldLocation, newComponent); + components.set(newLocation, oldComponent); - if (newTab != null) { - // This should always be true - newTab.setCaption(oldCaption); - newTab.setIcon(oldIcon); - } - if (oldTab != null) { - // This should always be true - oldTab.setCaption(newCaption); - oldTab.setIcon(newIcon); - } + // Tab associations are not changed, but metadata is swapped between + // the instances + // TODO Should reassociate the instances instead? + Tab tmp = new TabSheetTabImpl(null, null); + copyTabMetadata(newTab, tmp); + copyTabMetadata(oldTab, newTab); + copyTabMetadata(tmp, oldTab); requestRepaint(); } @@ -1303,4 +1270,23 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener); } + + /** + * Copies properties from one Tab to another. + * + * @param from + * The tab whose data to copy. + * @param to + * The tab to which copy the data. + */ + private static void copyTabMetadata(Tab from, Tab to) { + to.setCaption(from.getCaption()); + to.setIcon(from.getIcon()); + to.setDescription(from.getDescription()); + to.setVisible(from.isVisible()); + to.setEnabled(from.isEnabled()); + to.setClosable(from.isClosable()); + to.setStyleName(from.getStyleName()); + to.setComponentError(from.getComponentError()); + } } -- cgit v1.2.3 From b4eb8571aba35b90df5cf70ad1f4a8ca3f67556d Mon Sep 17 00:00:00 2001 From: Automerge Date: Fri, 18 May 2012 08:44:57 +0000 Subject: [merge from 6.7] #8805 fix flickering of partial first row in table, related manual test svn changeset:23762/svn branch:6.8 --- src/com/vaadin/ui/Table.java | 7 ++ .../components/table/TableFirstRowFlicker.java | 85 ++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 tests/testbench/com/vaadin/tests/components/table/TableFirstRowFlicker.java (limited to 'src/com/vaadin/ui') diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index 7828fdb734..db0809fbd5 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -1458,6 +1458,13 @@ public class Table extends AbstractSelect implements Action.Container, } } else { // initial load + + // #8805 send one extra row in the beginning in case a partial + // row is shown on the UI + if (firstIndex > 0) { + firstIndex = firstIndex - 1; + rows = rows + 1; + } firstToBeRenderedInClient = firstIndex; } if (totalRows > 0) { diff --git a/tests/testbench/com/vaadin/tests/components/table/TableFirstRowFlicker.java b/tests/testbench/com/vaadin/tests/components/table/TableFirstRowFlicker.java new file mode 100644 index 0000000000..776e7956bf --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/table/TableFirstRowFlicker.java @@ -0,0 +1,85 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.Application; +import com.vaadin.data.Container; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.ui.Label; +import com.vaadin.ui.ProgressIndicator; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; + +public class TableFirstRowFlicker extends Application { + + Table t; + + @Override + public void init() { + Window mainWindow = new Window("Table Row Flicker"); + mainWindow.getContent().setSizeFull(); + setMainWindow(mainWindow); + + t = new Table(); + t.setSizeFull(); + t.setSelectable(true); + t.setContainerDataSource(buildContainer()); + mainWindow.addComponent(t); + ((VerticalLayout) mainWindow.getContent()).setExpandRatio(t, 1); + + // Button button = new Button("Refresh"); + // button.addListener(new Button.ClickListener() { + // public void buttonClick(ClickEvent event) { + // t.refreshRowCache(); + // } + // }); + // mainWindow.addComponent(button); + + ProgressIndicator pi = new ProgressIndicator(); + pi.setPollingInterval(1000); + pi.setIndeterminate(true); + mainWindow.addComponent(pi); + + Thread r = new Thread() { + @Override + public void run() { + while (t != null) { + synchronized (t.getApplication()) { + int firstId = t.getCurrentPageFirstItemIndex(); + Object selected = t.getValue(); + t.setContainerDataSource(buildContainer()); + t.setValue(selected); + t.setCurrentPageFirstItemIndex(firstId); + // lighter alternative for all of above + // t.refreshRowCache(); + } + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + System.out.println("Table update thread stopped"); + } + }; + r.start(); + } + + @Override + public void close() { + t = null; + super.close(); + } + + private Container buildContainer() { + IndexedContainer cont = new IndexedContainer(); + cont.addContainerProperty("name", Label.class, null); + for (int i = 0; i < 10000; i++) { + cont.addItem(i); + Label l = new Label("Item " + i); + l.setHeight("50px"); + cont.getContainerProperty(i, "name").setValue(l); + } + return cont; + } + +} \ No newline at end of file -- cgit v1.2.3