EventList el = true ? new ObservingEventList() : EventLists.eventList(); this.el = el;
sel = EventLists.sortedEventList(el); el = sel;
fel = EventLists.filteredEventList(el); el = fel;
rel = EventLists.rangedEventList(el, 4); el = rel;
//rel = EventLists.steadyRangedEventList(el, 4); el = rel;
ot = new ObjectListTable(new OLTR(), el);
ot.setWidth("100%");
RootPanel.get("log").add(vp);
db.setText("ObjectListTable in a DialogBox");
db.setPopupPosition(100, 100);
final List objects = ot.getObjects();
objects.add(new Person("Sandy", 28));
objects.add(0, new Person("Keebz", 25));
objects.add(new Person("Bill", 33));
objects.add(new Person("Ted", 55));
if (!false) {
final List l = new ArrayList();
l.add(objects.get(0));
l.add(objects.get(1));
l.add(objects.get(3));
objects.retainAll(l);
} else {
objects.remove(1);
}
RootPanel.get("tableDiv").add(ot);
final FlowPanel fp = new FlowPanel();
final Button remove2 = new Button("Remove 2");
remove2.setTitle("Removes the first and last Person from the list.");
remove2.addClickListener(new ClickListener() {
public void onClick(final Widget sender) {
if (objects.size() > 0) {
final List two = new ArrayList();
if (objects.size() > 1) two.add(objects.get(objects.size() - 1));
two.add(objects.get(0));
objects.removeAll(two);
}
}
});
fp.add(remove2);
final Button addPerson = new Button("Add Person");
addPerson.setTitle("Add a Person instance to the List.");
addPerson.addClickListener(new ClickListener() {
public void onClick(final Widget sender) {
objects.add(new Person("Person " + (pCount++), (int)(Math.random() * 100)));
}
});
fp.add(addPerson);
if (sel == null) {
final Button transpose = new Button("Transpose");
transpose.setTitle("Switch two Person instances in the List");
transpose.addClickListener(new ClickListener() {
public void onClick(final Widget sender) {
final int a = (int)(Math.random() * objects.size());
int b;
do {
b = (int)(Math.random() * objects.size());
} while (a == b);
final Object oa = objects.get(a);
final Object ob = objects.get(b);
objects.set(b, oa);
objects.set(a, ob);
}
});
fp.add(transpose);
}
final int instances = 500;
final Button oneK = new Button("" + instances);
oneK.setTitle("Add " + instances + " Person instances");
oneK.addClickListener(new ClickListener() {
public void onClick(final Widget sender) {
final List l = new ArrayList();
for (int i=0; i < instances; i++) {
l.add(new Person("Person " + (pCount++), (int)(Math.random() * 100)));
}
final long start = System.currentTimeMillis();
DeferredCommand.addCommand(new Command() {
public void execute() {
final long end = System.currentTimeMillis();
vp.add(new Label("addAll took: " + (end - start)));
Window.setTitle("addAll took: " + (end - start));
}
});
objects.addAll(l);
}
});
fp.add(oneK);
final Button clear = new Button("Clear");
clear.setTitle("Calls clear() on the backing EventList.");
clear.addClickListener(new ClickListener() {
public void onClick(final Widget sender) {
TestObjectListTable.this.el.clear();
}
});
fp.add(clear);
final Button attach = new Button("Detach");
attach.addClickListener(new ClickListener() {
public void onClick(final Widget sender) {
final Button attach = (Button)sender;
final long start = System.currentTimeMillis();
DeferredCommand.addCommand(new Command() {
public void execute() {
final long end = System.currentTimeMillis();
vp.add(new Label("Attach/Detach took: " + (end - start)));
Window.setTitle("Attach/Detach took: " + (end - start));
}
});
if (ot.isAttached()) {
// detach
RootPanel.get("tableDiv").remove(ot);
attach.setText("Attach");
} else {
// attach
RootPanel.get("tableDiv").add(ot);
attach.setText("Detach");
}
}
});
fp.add(attach);
final Button dbb = new Button("DialogBox");
dbb.addClickListener(new ClickListener() {
public void onClick(final Widget sender) {
Widget w = db.getWidget();
if (w instanceof HTMLTable) {
w = ((HTMLTable)w).getWidget(1,0);
}
if (w == null) {
db.setWidget(new ObjectListTable(new OLTR(), ot.getObjects()));
}
db.show();
}
});