incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r734899 - in /incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component: DroidPanel.html DroidPanel.java
Date Fri, 16 Jan 2009 03:05:08 GMT
Author: ryan
Date: Thu Jan 15 19:05:08 2009
New Revision: 734899

URL: http://svn.apache.org/viewvc?rev=734899&view=rev
Log:
wicket panel shows the top few items in the Queue

Modified:
    incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.html
    incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.java

Modified: incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.html
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.html?rev=734899&r1=734898&r2=734899&view=diff
==============================================================================
--- incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.html
(original)
+++ incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.html
Thu Jan 15 19:05:08 2009
@@ -1,20 +1,33 @@
 <wicket:panel>
 
-<table>
-<tr><td>Current&nbsp;Time:&nbsp;</td><td><span wicket:id="currentTime">[current
time]</span></td></tr>
-<tr><td>Started&nbsp;Time:&nbsp;</td><td><span wicket:id="startedTime">[started
time]</span></td></tr>
-<tr><td>Finished&nbsp;Time:&nbsp;</td><td><span wicket:id="finishedTime">[finishedTime]</span></td></tr>
-<tr><td>Completed&nbsp;Tasks:&nbsp;</td><td><span wicket:id="completedTasks">[completed
tasks]</span></td></tr>
-<tr><td>Memory:&nbsp;</td><td><span wicket:id="memory">[completed
tasks]</span></td></tr>
-<tr><td>Last&nbsp;Task:&nbsp;</td><td>
+<table wicket:id="info">
+ <tr><td>Current&nbsp;Time:&nbsp;</td><td><span wicket:id="currentTime">[current
time]</span></td></tr>
+ <tr><td>Started&nbsp;Time:&nbsp;</td><td><span wicket:id="startedTime">[started
time]</span></td></tr>
+ <tr><td>Finished&nbsp;Time:&nbsp;</td><td><span wicket:id="finishedTime">[finishedTime]</span></td></tr>
+ <tr><td>Completed&nbsp;Tasks:&nbsp;</td><td><span wicket:id="completedTasks">[completed
tasks]</span></td></tr>
+ <tr><td>Memory:&nbsp;</td><td><span wicket:id="memory">[completed
tasks]</span></td></tr>
+ <tr><td>Last&nbsp;Task:&nbsp;</td><td>
   <pre style="overflow:hidden;" wicket:id="lastTask">[last task]</pre>
-</td></tr>
+ </td></tr>
 </table>
 
-
-<ul>
+<ul wicket:id="classinfo">
   <li>Droid: <span wicket:id="droid">[droid]</span></li>
   <li>TaskQueue: <span wicket:id="queue">[droid]</span></li>
   <li>TaskMaster: <span wicket:id="taskMaster">[droid]</span></li>
 </ul>
+
+
+
+ <h3>Queue:</h3>
+ <ul wicket:id="queue">
+  <li wicket:id="task">
+    [<span wicket:id="time">00,00,10.xx</span>] 
+    <span wicket:id="text">Task 1 todo</span>
+  </li>
+  <li wicket:id="more">13 more...</li>
+ </ul>
+
+
+
 </wicket:panel>

Modified: incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.java?rev=734899&r1=734898&r2=734899&view=diff
==============================================================================
--- incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.java
(original)
+++ incubator/droids/trunk/droids-wicket/src/main/java/org/apache/droids/wicket/component/DroidPanel.java
Thu Jan 15 19:05:08 2009
@@ -17,7 +17,11 @@
 package org.apache.droids.wicket.component;
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
 
 import org.apache.droids.api.Droid;
 import org.apache.droids.api.Task;
@@ -25,9 +29,13 @@
 import org.apache.droids.api.TaskQueue;
 import org.apache.wicket.ajax.AbstractAjaxTimerBehavior;
 import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.RefreshingView;
 import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.IModel;
 import org.apache.wicket.spring.injection.annot.SpringBean;
 import org.apache.wicket.util.lang.Bytes;
 import org.apache.wicket.util.time.Duration;
@@ -51,15 +59,18 @@
     this.setOutputMarkupId( true );
     this.setVersioned( false );
     
+    final WebMarkupContainer info = new WebMarkupContainer( "info" );
+    info.setOutputMarkupId( true );
+    
     // SHOW INFO
-    this.add( new Label( "currentTime", new AbstractReadOnlyModel<String>() {
+    info.add( new Label( "currentTime", new AbstractReadOnlyModel<String>() {
       @Override
       public String getObject() {
         return timeFormat.format( new Date() );
       }
     }));
 
-    this.add( new Label( "startedTime", new AbstractReadOnlyModel<String>() {
+    info.add( new Label( "startedTime", new AbstractReadOnlyModel<String>() {
       @Override
       public String getObject() {
         Date d = droid.getTaskMaster().getStartTime();
@@ -67,7 +78,7 @@
       }
     }));
 
-    this.add( new Label( "finishedTime", new AbstractReadOnlyModel<String>() {
+    info.add( new Label( "finishedTime", new AbstractReadOnlyModel<String>() {
       @Override
       public String getObject() {
         Date d = droid.getTaskMaster().getFinishedWorking();
@@ -75,14 +86,14 @@
       }
     }));
 
-    this.add( new Label( "completedTasks", new AbstractReadOnlyModel<Integer>() {
+    info.add( new Label( "completedTasks", new AbstractReadOnlyModel<Integer>() {
       @Override
       public Integer getObject() {
         return droid.getTaskMaster().getCompletedTasks();
       }
     }));
     
-    this.add( new Label( "lastTask", new AbstractReadOnlyModel<String>() {
+    info.add( new Label( "lastTask", new AbstractReadOnlyModel<String>() {
       @Override
       public String getObject() {
         Task task = droid.getTaskMaster().getLastCompletedTask();
@@ -90,7 +101,7 @@
       }
     }));
 
-    this.add( new Label( "memory", new AbstractReadOnlyModel<CharSequence>() {
+    info.add( new Label( "memory", new AbstractReadOnlyModel<CharSequence>() {
       @Override
       public CharSequence getObject() {
         Runtime runtime = Runtime.getRuntime();
@@ -103,12 +114,58 @@
         return used + "("+total+")/" +max + " (%"+per+")";
       }
     }));
+    add( info );
+    
+    WebMarkupContainer classinfo = new WebMarkupContainer( "classinfo" );
+    classinfo.add( new Label( "droid", droid.toString() ) );
+    classinfo.add( new Label( "queue", taskQueue.toString() ) );
+    classinfo.add( new Label( "taskMaster", taskMaster.toString() ) );
+    add( classinfo );
+    
+    // QUEUE
     
+
+    final WebMarkupContainer queueDIV = new WebMarkupContainer( "queue" );
+    queueDIV.add( new RefreshingView<Task>("task")
+    {
+      /**
+       * Return an iterator over models for items in the view
+       */
+      @Override
+      protected Iterator<IModel<Task>> getItemModels()
+      {
+        Collection<Task> top = taskQueue.peek( 5 );
+        
+        List<IModel<Task>> models = new ArrayList<IModel<Task>>(
top.size() );
+        for( final Task m : top ) {
+          models.add( new AbstractReadOnlyModel<Task>() {
+            @Override
+            public Task getObject() {
+              return m;
+            }
+          });
+        }
+        return models.iterator();
+      }
+
+      @Override
+      protected void populateItem(final Item<Task> item) {
+        Task task = item.getModelObject();
+        long elapsed = System.currentTimeMillis() - task.getTaskDate().getTime();
+        item.add( new Label("time", elapsed+"" )); //DurationFormatUtil.formatDurationHMS(elapsed)
) );
+        item.add( new Label("text", task.toString() ) );
+      }
+    });
+    queueDIV.add( new Label( "more", new AbstractReadOnlyModel<String>() {
+      @Override
+      public String getObject() {
+        return taskQueue.getSize() + " tasks.";
+      }
+    }));
+    queueDIV.setOutputMarkupId( true );
+    add( queueDIV );
     
     
-    add( new Label( "droid", droid.toString() ) );
-    add( new Label( "queue", taskQueue.toString() ) );
-    add( new Label( "taskMaster", taskMaster.toString() ) );
     
     // Refresh the view every second...
     add(new AbstractAjaxTimerBehavior(Duration.seconds(1))
@@ -116,7 +173,8 @@
       @Override
       protected void onTimer(AjaxRequestTarget target)
       {
-        target.addComponent(DroidPanel.this);
+        target.addComponent( info );
+        target.addComponent( queueDIV );
       }
     });
   }



Mime
View raw message