From a8d6138ab0e42a1412d37ef151d77b8e40152271 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 1 Sep 2011 07:06:17 +0000 Subject: #6630 improved submitUpload so that upload started listeners now trigger server side event svn changeset:20781/svn branch:6.6 --- src/com/vaadin/terminal/gwt/client/ui/VUpload.java | 2 +- .../tests/components/upload/ForceSubmit.java | 24 ++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java index a49450e086..25fd1d7604 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java @@ -157,7 +157,7 @@ public class VUpload extends SimplePanel implements Paintable { return; } if (uidl.hasAttribute("forceSubmit")) { - element.submit(); + submit(); return; } setImmediate(uidl.getBooleanAttribute("immediate")); diff --git a/tests/src/com/vaadin/tests/components/upload/ForceSubmit.java b/tests/src/com/vaadin/tests/components/upload/ForceSubmit.java index fef82dd962..9f5c2b67e2 100644 --- a/tests/src/com/vaadin/tests/components/upload/ForceSubmit.java +++ b/tests/src/com/vaadin/tests/components/upload/ForceSubmit.java @@ -5,12 +5,14 @@ import java.io.OutputStream; 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.TextField; import com.vaadin.ui.Upload; -import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Upload.FailedEvent; import com.vaadin.ui.Upload.FinishedEvent; import com.vaadin.ui.Upload.Receiver; +import com.vaadin.ui.Upload.StartedEvent; public class ForceSubmit extends TestBase implements Receiver { @@ -26,6 +28,9 @@ public class ForceSubmit extends TestBase implements Receiver { @Override protected void setup() { + final TextField textField = new TextField("Test field"); + addComponent(textField); + final Upload u; u = new Upload("Upload", this); @@ -49,6 +54,13 @@ public class ForceSubmit extends TestBase implements Receiver { } }); + u.addListener(new Upload.StartedListener() { + public void uploadStarted(StartedEvent event) { + getMainWindow().showNotification( + "Started upload. TF value :" + textField.getValue()); + } + }); + Button button = new Button( "I'm an external button (not the uploads builtin), hit me to start upload."); button.addListener(new ClickListener() { @@ -63,11 +75,11 @@ public class ForceSubmit extends TestBase implements Receiver { @Override protected String getDescription() { - return "Some wireframists are just so web 1.0. If requirements " + - "say the upload must not start until the whole form " + - "is 'Oukeyd', that is what we gotta do. In these cases " + - "developers most probably also want to hide the uploads" + - " internal button by setting its caption to null."; + return "Some wireframists are just so web 1.0. If requirements " + + "say the upload must not start until the whole form " + + "is 'Oukeyd', that is what we gotta do. In these cases " + + "developers most probably also want to hide the uploads" + + " internal button by setting its caption to null."; } } -- cgit v1.2.3 From 835a4f80470827c8b2a2eeda51b18a9a447036b1 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Thu, 1 Sep 2011 12:11:39 +0000 Subject: #7517 IndexedContainer.addItem() performance improvement, related performance test svn changeset:20789/svn branch:6.6 --- .../data/util/AbstractInMemoryContainer.java | 2 +- src/com/vaadin/data/util/IndexedContainer.java | 18 +++- .../container/PerformanceTestIndexedContainer.java | 117 +++++++++++++++++++++ 3 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 tests/src/com/vaadin/tests/server/container/PerformanceTestIndexedContainer.java diff --git a/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/src/com/vaadin/data/util/AbstractInMemoryContainer.java index 3a9a0a8987..3a48d9e0de 100644 --- a/src/com/vaadin/data/util/AbstractInMemoryContainer.java +++ b/src/com/vaadin/data/util/AbstractInMemoryContainer.java @@ -722,7 +722,7 @@ public abstract class AbstractInMemoryContainer i = itemIds.iterator(); i.hasNext();) { - this.addItem(i.next()); + Object itemId = i.next(); + internalAddItemAtEnd(itemId, new IndexedContainerItem(itemId), + false); } + filterAll(); } } @@ -246,8 +249,17 @@ public class IndexedContainer extends */ @Override public Item addItem(Object itemId) { - return internalAddItemAtEnd(itemId, new IndexedContainerItem(itemId), - true); + Item item = internalAddItemAtEnd(itemId, new IndexedContainerItem( + itemId), false); + if (!isFiltered()) { + // always the last item + fireItemAdded(size() - 1, itemId, item); + } else if (passesFilters(itemId)) { + getFilteredItemIds().add(itemId); + // always the last item + fireItemAdded(size() - 1, itemId, item); + } + return item; } /** diff --git a/tests/src/com/vaadin/tests/server/container/PerformanceTestIndexedContainer.java b/tests/src/com/vaadin/tests/server/container/PerformanceTestIndexedContainer.java new file mode 100644 index 0000000000..62e6d88e72 --- /dev/null +++ b/tests/src/com/vaadin/tests/server/container/PerformanceTestIndexedContainer.java @@ -0,0 +1,117 @@ +package com.vaadin.tests.server.container; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.SortedSet; +import java.util.TreeSet; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import com.vaadin.data.util.IndexedContainer; + +public class PerformanceTestIndexedContainer extends TestCase { + + private static final int REPEATS = 10; + private final static int ITEMS = 50000; + private static final long ADD_ITEM_FAIL_THRESHOLD = 200; + // TODO should improve performance of these methods + private static final long ADD_ITEM_AT_FAIL_THRESHOLD = 5000; + private static final long ADD_ITEM_AFTER_FAIL_THRESHOLD = 5000; + private static final long ADD_ITEM_AFTER_LAST_FAIL_THRESHOLD = 5000; + private static final long ADD_ITEMS_CONSTRUCTOR_FAIL_THRESHOLD = 200; + + public void testAddItemPerformance() { + Collection times = new ArrayList(); + for (int j = 0; j < REPEATS; ++j) { + IndexedContainer c = new IndexedContainer(); + long start = System.currentTimeMillis(); + for (int i = 0; i < ITEMS; i++) { + c.addItem(); + } + times.add(System.currentTimeMillis() - start); + } + checkMedian(ITEMS, times, "IndexedContainer.addItem()", + ADD_ITEM_FAIL_THRESHOLD); + } + + public void testAddItemAtPerformance() { + Collection times = new ArrayList(); + for (int j = 0; j < REPEATS; ++j) { + IndexedContainer c = new IndexedContainer(); + long start = System.currentTimeMillis(); + for (int i = 0; i < ITEMS; i++) { + c.addItemAt(0); + } + times.add(System.currentTimeMillis() - start); + } + checkMedian(ITEMS, times, "IndexedContainer.addItemAt()", + ADD_ITEM_AT_FAIL_THRESHOLD); + } + + public void testAddItemAfterPerformance() { + Object initialId = "Item0"; + Collection times = new ArrayList(); + for (int j = 0; j < REPEATS; ++j) { + IndexedContainer c = new IndexedContainer(); + c.addItem(initialId); + long start = System.currentTimeMillis(); + for (int i = 0; i < ITEMS; i++) { + c.addItemAfter(initialId); + } + times.add(System.currentTimeMillis() - start); + } + checkMedian(ITEMS, times, "IndexedContainer.addItemAfter()", + ADD_ITEM_AFTER_FAIL_THRESHOLD); + } + + public void testAddItemAfterLastPerformance() { + // TODO running with less items because slow otherwise + Collection times = new ArrayList(); + for (int j = 0; j < REPEATS; ++j) { + IndexedContainer c = new IndexedContainer(); + c.addItem(); + long start = System.currentTimeMillis(); + for (int i = 0; i < ITEMS / 3; i++) { + c.addItemAfter(c.lastItemId()); + } + times.add(System.currentTimeMillis() - start); + } + checkMedian(ITEMS / 3, times, "IndexedContainer.addItemAfter(lastId)", + ADD_ITEM_AFTER_LAST_FAIL_THRESHOLD); + } + + public void testAddItemsConstructorPerformance() { + Collection items = new ArrayList(50000); + for (int i = 0; i < ITEMS; ++i) { + items.add(new Object()); + } + + SortedSet times = new TreeSet(); + for (int j = 0; j < REPEATS; ++j) { + long start = System.currentTimeMillis(); + new IndexedContainer(items); + times.add(System.currentTimeMillis() - start); + } + checkMedian(ITEMS, times, "IndexedContainer(Collection)", + ADD_ITEMS_CONSTRUCTOR_FAIL_THRESHOLD); + } + + private void checkMedian(int items, Collection times, + String methodName, long threshold) { + long median = median(times); + System.out.println(methodName + " timings (ms) for " + items + + " items: " + times); + Assert.assertTrue(methodName + " too slow, median time " + median + + "ms for " + items + " items", median <= threshold); + } + + private Long median(Collection times) { + ArrayList list = new ArrayList(times); + Collections.sort(list); + // not exact median in some cases, but good enough + return list.get(list.size() / 2); + } + +} -- cgit v1.2.3