aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2011-09-01 12:15:58 +0000
committerHenri Sara <henri.sara@itmill.com>2011-09-01 12:15:58 +0000
commitd1e5bd7216d90993cb95c79ad54f90a40dbff8eb (patch)
tree344bf364c11995376e72fd8686cf9f6306b01760
parent84d95e404d24a639412a4c39712deac948f378b6 (diff)
parent835a4f80470827c8b2a2eeda51b18a9a447036b1 (diff)
downloadvaadin-framework-d1e5bd7216d90993cb95c79ad54f90a40dbff8eb.tar.gz
vaadin-framework-d1e5bd7216d90993cb95c79ad54f90a40dbff8eb.zip
Merged changes from 6.6
svn changeset:20790/svn branch:6.7
-rw-r--r--src/com/vaadin/data/util/AbstractInMemoryContainer.java2
-rw-r--r--src/com/vaadin/data/util/IndexedContainer.java18
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VUpload.java2
-rw-r--r--tests/src/com/vaadin/tests/components/upload/ForceSubmit.java24
-rw-r--r--tests/src/com/vaadin/tests/server/container/PerformanceTestIndexedContainer.java117
5 files changed, 152 insertions, 11 deletions
diff --git a/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/src/com/vaadin/data/util/AbstractInMemoryContainer.java
index d3e981231f..75983d1e4f 100644
--- a/src/com/vaadin/data/util/AbstractInMemoryContainer.java
+++ b/src/com/vaadin/data/util/AbstractInMemoryContainer.java
@@ -725,7 +725,7 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE
getAllItemIds().indexOf(previousItemId) + 1, newItemId,
item);
}
- if (newItem != null) {
+ if (newItem != null && filter) {
// TODO filter only this item, use fireItemAdded()
filterAll();
if (!isFiltered()) {
diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java
index 7fbb1e9128..2f45def4f1 100644
--- a/src/com/vaadin/data/util/IndexedContainer.java
+++ b/src/com/vaadin/data/util/IndexedContainer.java
@@ -106,8 +106,11 @@ public class IndexedContainer extends
this();
if (items != null) {
for (final Iterator<?> 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/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.";
}
}
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<Long> times = new ArrayList<Long>();
+ 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<Long> times = new ArrayList<Long>();
+ 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<Long> times = new ArrayList<Long>();
+ 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<Long> times = new ArrayList<Long>();
+ 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<Object> items = new ArrayList<Object>(50000);
+ for (int i = 0; i < ITEMS; ++i) {
+ items.add(new Object());
+ }
+
+ SortedSet<Long> times = new TreeSet<Long>();
+ 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<Long> 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<Long> times) {
+ ArrayList<Long> list = new ArrayList<Long>(times);
+ Collections.sort(list);
+ // not exact median in some cases, but good enough
+ return list.get(list.size() / 2);
+ }
+
+}