{
th = tr.newTableHeaderCell();
final MenuBar nameMenu = new MenuBar();
final MenuBar nameSubMenu = new MenuBar(true);
final MenuItem nameSortUp = new MenuItem("Sort Up", new Command() {
Comparator c = new Comparator() {
public int compare(final Object o1, final Object o2) {
final Person p1 = (Person)o1;
final Person p2 = (Person)o2;
return p1.getName().compareTo(p2.getName());
}
};
public void execute() {
if (sel != null) {
sel.setComparator(c);
}
}
});
final MenuItem nameSortDown = new MenuItem("Sort Down", new Command() {
Comparator c = new Comparator() {
public int compare(final Object o1, final Object o2) {
final Person p1 = (Person)o1;
final Person p2 = (Person)o2;
return p2.getName().compareTo(p1.getName());
}
};
public void execute() {
if (sel != null) {
sel.setComparator(c);
}
}
});
nameSubMenu.addItem(nameSortUp);
nameSubMenu.addItem(nameSortDown);
final MenuItem nameMenuItem = new MenuItem("Name", nameSubMenu);
nameMenu.addItem(nameMenuItem);
th.add(nameMenu);
tr.add(th);
}
{
th = tr.newTableHeaderCell();
final MenuBar ageMenu = new MenuBar();
final MenuBar ageSubMenu = new MenuBar(true);
final MenuItem ageSortUp = new MenuItem("Sort Up", new Command() {
Comparator c = new Comparator() {
public int compare(final Object o1, final Object o2) {
final Person p1 = (Person)o1;
final Person p2 = (Person)o2;
return p1.getAge() - p2.getAge();
}
};
public void execute() {
if (sel != null) {
sel.setComparator(c);
}
}
});
final MenuItem ageSortDown = new MenuItem("Sort Down", new Command() {
Comparator c = new Comparator() {
public int compare(final Object o1, final Object o2) {
final Person p1 = (Person)o1;
final Person p2 = (Person)o2;
return p2.getAge() - p1.getAge();
}
};
public void execute() {
if (sel != null) {
sel.setComparator(c);
}
}
});
ageSubMenu.addItem(ageSortUp);
ageSubMenu.addItem(ageSortDown);
final MenuItem ageMenuItem = new MenuItem("Age", ageSubMenu);
ageMenu.addItem(ageMenuItem);
th.add(ageMenu);
tr.add(th);
}
th = tr.newTableHeaderCell();