From: David ‘Bombe’ Roden Date: Thu, 15 Sep 2011 14:36:20 +0000 (+0200) Subject: Add collection sort filter that knows how to sort identities. X-Git-Tag: 0.0.1~12 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1e65f6a661aabd7342c2a5f1bac6b65625c5f607;p=WoTNS.git Add collection sort filter that knows how to sort identities. --- 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); } //