Add status fields to Sone accessor.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 19 Oct 2010 07:01:17 +0000 (09:01 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 19 Oct 2010 07:01:17 +0000 (09:01 +0200)
src/main/java/net/pterodactylus/sone/template/SoneAccessor.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java

index d0a287f..e22738a 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.template;
 
+import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.core.Core.SoneStatus;
 import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.template.Accessor;
@@ -42,6 +44,19 @@ import net.pterodactylus.util.template.ReflectionAccessor;
  */
 public class SoneAccessor extends ReflectionAccessor {
 
+       /** The core. */
+       private final Core core;
+
+       /**
+        * Creates a new Sone accessor.
+        *
+        * @param core
+        *            The Sone core
+        */
+       public SoneAccessor(Core core) {
+               this.core = core;
+       }
+
        /**
         * {@inheritDoc}
         */
@@ -61,6 +76,14 @@ public class SoneAccessor extends ReflectionAccessor {
                        return currentSone.isSoneBlocked(sone.getId());
                } else if (member.equals("modified")) {
                        return sone.getModificationCounter() > 0;
+               } else if (member.equals("status")) {
+                       return core.getSoneStatus(sone).toString();
+               } else if (member.equals("idle")) {
+                       return core.getSoneStatus(sone) == SoneStatus.idle;
+               } else if (member.equals("inserting")) {
+                       return core.getSoneStatus(sone) == SoneStatus.inserting;
+               } else if (member.equals("downloading")) {
+                       return core.getSoneStatus(sone) == SoneStatus.downloading;
                }
                return super.get(dataProvider, object, member);
        }
index 5a404f2..2177aab 100644 (file)
@@ -148,7 +148,7 @@ public class WebInterface extends AbstractService {
        private void registerToadlets() {
                DefaultTemplateFactory templateFactory = new DefaultTemplateFactory();
                templateFactory.addAccessor(Object.class, new ReflectionAccessor());
-               templateFactory.addAccessor(Sone.class, new SoneAccessor());
+               templateFactory.addAccessor(Sone.class, new SoneAccessor(core()));
                templateFactory.addAccessor(Post.class, new PostAccessor(core()));
                templateFactory.addFilter("date", new DateFilter());
                templateFactory.addFilter("l10n", new L10nFilter(l10n()));