From 1e65f6a661aabd7342c2a5f1bac6b65625c5f607 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 15 Sep 2011 16:36:20 +0200 Subject: [PATCH] Add collection sort filter that knows how to sort identities. --- .../java/net/pterodactylus/wotns/ui/web/BasicPage.java | 17 +---------------- .../net/pterodactylus/wotns/ui/web/WebInterface.java | 5 +++++ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/pterodactylus/wotns/ui/web/BasicPage.java b/src/main/java/net/pterodactylus/wotns/ui/web/BasicPage.java index ff5ffd2..f8ba131 100644 --- a/src/main/java/net/pterodactylus/wotns/ui/web/BasicPage.java +++ b/src/main/java/net/pterodactylus/wotns/ui/web/BasicPage.java @@ -17,11 +17,6 @@ package net.pterodactylus.wotns.ui.web; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; import net.pterodactylus.wotns.freenet.wot.IdentityManager; @@ -55,17 +50,7 @@ public class BasicPage extends FreenetTemplatePage { @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - - List ownIdentities = new ArrayList(webInterface.getWoTNSPlugin().getIdentityManager().getAllOwnIdentities()); - Collections.sort(ownIdentities, new Comparator() { - - @Override - public int compare(OwnIdentity leftOwnIdentity, OwnIdentity rightOwnIdentity) { - return leftOwnIdentity.getNickname().compareTo(rightOwnIdentity.getNickname()); - } - }); - - templateContext.set("ownIdentities", ownIdentities); + templateContext.set("ownIdentities", identityManager.getAllOwnIdentities()); templateContext.set("formPassword", webInterface.getWoTNSPlugin().getToadletContainer().getFormPassword()); } } diff --git a/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java b/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java index 4151531..16db851 100644 --- a/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java @@ -24,12 +24,14 @@ import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; +import net.pterodactylus.util.template.CollectionSortFilter; import net.pterodactylus.util.template.HtmlFilter; import net.pterodactylus.util.template.ReflectionAccessor; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContextFactory; import net.pterodactylus.util.template.TemplateParser; import net.pterodactylus.wotns.freenet.wot.Identity; +import net.pterodactylus.wotns.main.IdentityComparator; import net.pterodactylus.wotns.main.WoTNSPlugin; import net.pterodactylus.wotns.template.IdentityAccessor; import net.pterodactylus.wotns.web.PageToadlet; @@ -56,6 +58,9 @@ public class WebInterface { templateContextFactory.addAccessor(Object.class, new ReflectionAccessor()); templateContextFactory.addAccessor(Identity.class, new IdentityAccessor()); templateContextFactory.addFilter("html", new HtmlFilter()); + CollectionSortFilter sortFilter = new CollectionSortFilter(); + sortFilter.addComparator(Identity.class, IdentityComparator.NAME); + templateContextFactory.addFilter("sort", sortFilter); } // -- 2.7.4