Add collection sort filter that knows how to sort identities.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 14:36:20 +0000 (16:36 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 14:38:36 +0000 (16:38 +0200)
src/main/java/net/pterodactylus/wotns/ui/web/BasicPage.java
src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java

index ff5ffd2..f8ba131 100644 (file)
 
 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<OwnIdentity> ownIdentities = new ArrayList<OwnIdentity>(webInterface.getWoTNSPlugin().getIdentityManager().getAllOwnIdentities());
-               Collections.sort(ownIdentities, new Comparator<OwnIdentity>() {
-
-                       @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());
        }
 }
index 4151531..16db851 100644 (file)
@@ -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);
        }
 
        //