Author: vvalchev
Date: Mon Mar 15 14:17:58 2010
New Revision: 923242

URL: http://svn.apache.org/viewvc?rev=923242&view=rev
Log:
Implemented FELIX-2202
Update Events plugin to JQuery UI

Added:
    felix/trunk/webconsole-plugins/event/src/main/native2ascii/
    felix/trunk/webconsole-plugins/event/src/main/native2ascii/OSGI-INF/
    felix/trunk/webconsole-plugins/event/src/main/native2ascii/OSGI-INF/l10n/
    
felix/trunk/webconsole-plugins/event/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties
    felix/trunk/webconsole-plugins/event/src/main/resources/OSGI-INF/l10n/
    
felix/trunk/webconsole-plugins/event/src/main/resources/OSGI-INF/l10n/bundle.properties
    felix/trunk/webconsole-plugins/event/src/main/resources/res/events.html
Modified:
    felix/trunk/webconsole-plugins/event/pom.xml
    
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java
    
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
    felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.css
    felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js

Modified: felix/trunk/webconsole-plugins/event/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/pom.xml?rev=923242&r1=923241&r2=923242&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/pom.xml (original)
+++ felix/trunk/webconsole-plugins/event/pom.xml Mon Mar 15 14:17:58 2010
@@ -44,6 +44,23 @@
 
     <build>
         <plugins>
+                       <!-- translate UTF-8 encoded properties files to 
ISO-8859-1 -->
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>native2ascii-maven-plugin</artifactId>
+                <version>1.0-alpha-1</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>native2ascii</goal>
+                        </goals>
+                        <configuration>
+                            <encoding>UTF-8</encoding>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>

Modified: 
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java?rev=923242&r1=923241&r2=923242&view=diff
==============================================================================
--- 
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java
 (original)
+++ 
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/Activator.java
 Mon Mar 15 14:17:58 2010
@@ -59,7 +59,7 @@ public class Activator implements Bundle
         props.put( Constants.SERVICE_DESCRIPTION, "Event Plugin for the Apache 
Felix Web Console" );
         props.put( Constants.SERVICE_VENDOR, "The Apache Software Foundation" 
);
         props.put( "felix.webconsole.label", "events");
-        props.put( "felix.webconsole.title", "Events");
+        props.put( "felix.webconsole.title", "%plugin.events.title");
         props.put( "felix.webconsole.css", "/events/res/ui/events.css");
         this.pluginRegistration = 
context.registerService(Servlet.class.getName(),
                                 plugin,

Modified: 
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java?rev=923242&r1=923241&r2=923242&view=diff
==============================================================================
--- 
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
 (original)
+++ 
felix/trunk/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/PluginServlet.java
 Mon Mar 15 14:17:58 2010
@@ -17,7 +17,9 @@
 package org.apache.felix.webconsole.plugins.event.internal;
 
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.PrintWriter;
 import java.net.URL;
 import java.util.*;
@@ -43,10 +45,55 @@ public class PluginServlet extends HttpS
 
     /** Is the config admin available? */
     private volatile boolean configAdminAvailable = false;
+    
+    private final String TEMPLATE;
 
     public PluginServlet()
     {
         this.collector = new EventCollector(null);
+        TEMPLATE = readTemplateFile(getClass(), "/res/events.html");
+    }
+    
+    private final String readTemplateFile(final Class clazz, final String 
templateFile)
+    {
+        InputStream templateStream = 
getClass().getResourceAsStream(templateFile);
+        if (templateStream != null)
+        {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            byte[] data = new byte[1024];
+            try
+            {
+                int len = 0;
+                while ((len = templateStream.read(data)) > 0)
+                {
+                    baos.write(data, 0, len);
+                }
+                return baos.toString("UTF-8");
+            }
+            catch (IOException e)
+            {
+                // don't use new Exception(message, cause) because cause is 
1.4+
+                throw new RuntimeException("readTemplateFile: Error loading "
+                    + templateFile + ": " + e);
+            }
+            finally
+            {
+                try
+                {
+                    templateStream.close();
+                }
+                catch (IOException e)
+                {
+                    /* ignore */
+                }
+
+            }
+        }
+
+        // template file does not exist, return an empty string
+        log("readTemplateFile: File '" + templateFile + "' not found through 
class "
+            + clazz);
+        return "";
     }
 
     /**
@@ -154,17 +201,9 @@ public class PluginServlet extends HttpS
     throws ServletException, IOException
     {
         final PrintWriter pw = response.getWriter();
-
-        final String appRoot = ( String ) request.getAttribute( 
"felix.webconsole.appRoot" );
-        pw.println( "<script src='" + appRoot + "/events/res/ui/" + 
"events.js" + "' language='JavaScript'></script>" );
-
-        pw.println( "<div id='plugin_content'/>");
-
-        pw.println( "<script type='text/javascript'>" );
-        pw.println( "// <![CDATA[" );
-        pw.println( "renderEvents( );" );
-        pw.println( "// ]]>" );
-        pw.println( "</script>" );
+        //final String appRoot = ( String ) request.getAttribute( 
"felix.webconsole.appRoot" );
+        //pw.println( "<script src='" + appRoot + "/events/res/ui/" + 
"events.js" + "' type='text/javascript'></script>" );
+        pw.print(TEMPLATE);
     }
 
     public URL getResource(String path)

Added: 
felix/trunk/webconsole-plugins/event/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties?rev=923242&view=auto
==============================================================================
--- 
felix/trunk/webconsole-plugins/event/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties
 (added)
+++ 
felix/trunk/webconsole-plugins/event/src/main/native2ascii/OSGI-INF/l10n/bundle_bg.properties
 Mon Mar 15 14:17:58 2010
@@ -0,0 +1,40 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Web Console strings for reference all strings here are commented.
+# This file may be used to produce a translation of the strings
+#
+# Note that properties files are ISO-8859-1 encoded. To provide translations
+# for languages requiring different character encodings, you may use the
+# native2ascii Maven Plugin from 
http://mojo.codehaus.org/native2ascii-maven-plugin/
+# to translate the natively encoded files to ISO-8859-1 during bundle build
+#
+# Translations requiring non-ISO-8859-1 encoding are placed in the
+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
+# plugin while building the bundle
+#
+
+# buttons on top
+displayTimeline=??????? ????????
+displayList=??????
+clear=??????????
+
+# table headers
+received=???????
+topic=????
+properties=????????
+
+plugin.events.title=???????

Added: 
felix/trunk/webconsole-plugins/event/src/main/resources/OSGI-INF/l10n/bundle.properties
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/resources/OSGI-INF/l10n/bundle.properties?rev=923242&view=auto
==============================================================================
--- 
felix/trunk/webconsole-plugins/event/src/main/resources/OSGI-INF/l10n/bundle.properties
 (added)
+++ 
felix/trunk/webconsole-plugins/event/src/main/resources/OSGI-INF/l10n/bundle.properties
 Mon Mar 15 14:17:58 2010
@@ -0,0 +1,40 @@
+#Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# Web Console strings for reference all strings here are commented.
+# This file may be used to produce a translation of the strings
+#
+# Note that properties files are ISO-8859-1 encoded. To provide translations
+# for languages requiring different character encodings, you may use the
+# native2ascii Maven Plugin from 
http://mojo.codehaus.org/native2ascii-maven-plugin/
+# to translate the natively encoded files to ISO-8859-1 during bundle build
+#
+# Translations requiring non-ISO-8859-1 encoding are placed in the
+# src/main/native2ascii/OSGI-INF/l10n folder and are converted using said
+# plugin while building the bundle
+#
+
+# buttons on top
+displayTimeline=Timeline
+displayList=List
+clear=Clear Events
+
+# table headers
+received=Received
+topic=Event Topic
+properties=Event Properties
+
+plugin.events.title=Events
\ No newline at end of file

Added: felix/trunk/webconsole-plugins/event/src/main/resources/res/events.html
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/resources/res/events.html?rev=923242&view=auto
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/resources/res/events.html 
(added)
+++ felix/trunk/webconsole-plugins/event/src/main/resources/res/events.html Mon 
Mar 15 14:17:58 2010
@@ -0,0 +1,37 @@
+<script type="text/javascript" src="${pluginRoot}/res/ui/events.js"></script>
+<script type="text/javascript">
+var i18n = {
+       displayTimeline: '${displayTimeline}',
+       displayList    : '${displayList}'
+}
+</script>
+
+<!-- status line -->
+<p class="statline">&nbsp;</p>
+
+<!-- table caption -->
+<div class="ui-widget-header ui-corner-top buttonGroup">
+       <button id="switch">${displayTimeline}</button>
+       <button id="clear">${clear}</button>
+       <button id="reload">${reload}</button>
+</div>
+
+<!-- table -->
+<table id="eventsTable" class="tablesorter nicetable">
+       <thead>
+               <tr>
+                       <th class="col_Received">${received}</th>
+                       <th class="col_Topic">${topic}</th>
+                       <th class="col_Props">${properties}</th>
+               </tr>
+       </thead>
+       <tbody>
+               <tr>
+                       <td>&nbsp;</td>
+                       <td>&nbsp;</td>
+                       <td>&nbsp;</td>
+               </tr>
+       </tbody>
+</table>
+
+<div id="timeline" class="ui-helper-hidden">&nbsp;</div>

Modified: 
felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.css
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.css?rev=923242&r1=923241&r2=923242&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.css 
(original)
+++ felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.css 
Mon Mar 15 14:17:58 2010
@@ -14,15 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-.eventservice {
-    background-color: #ADFF2F;
-}
-.eventbundle {
-    background-color: #FFCACD;
-}
-.eventframework {
-    background-color: #DCDCDC;
-}
-.eventconfig {
-    background-color: #FFD700;
-}
\ No newline at end of file
+#timeline          { width: 100%; overflow-x: scroll }
+.event                 { overflow:visible; white-space:nowrap }
+.eventservice { background-color: #ADFF2F }
+.eventbundle   { background-color: #FFCACD }
+.eventconfig   { background-color: #FFD700 }
+.eventframework { background-color: #DCDCDC }
+
+.propName { padding: 0 4px 0 0 }
+.propVal   { padding: 0 0 0 4px }
\ No newline at end of file

Modified: 
felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js
URL: 
http://svn.apache.org/viewvc/felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js?rev=923242&r1=923241&r2=923242&view=diff
==============================================================================
--- felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js 
(original)
+++ felix/trunk/webconsole-plugins/event/src/main/resources/res/ui/events.js 
Mon Mar 15 14:17:58 2010
@@ -14,136 +14,85 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-var view = 0;
+var eventsTable = false;
 
-function renderStatusLine() {
-       $("#plugin_content").append( "<div class='fullwidth'><div 
class='statusline'/></div>" );
-}
-
-function renderView( /* Array of String */ columns, /* String */ buttons ) {
-    renderStatusLine();
-    renderButtons(buttons);
-    var txt = "<div class='table'><table id='plugin_table' 
class='tablelayout'><thead><tr>";
-    for ( var name in columns ) {
-       txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + 
"</th>";
-    }
-    txt = txt + "</tr></thead><tbody></tbody></table></div>";
-    $("#plugin_content").append( txt );
-    renderButtons(buttons);
-    renderStatusLine();        
-}
-
-function renderButtons( buttons ) {
-       $("#plugin_content").append( "<form method='post' 
enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" +
-                                    buttons + "</div></div></form>" );
+/* displays a date in the user's local timezone */
+function printDate(time) {
+    var date = time ? new Date(time) : new Date();
+    return date.toLocaleString();
 }
 
 function renderData( eventData )  {
-       $(".statusline").empty().append(eventData.status);
-       $("#plugin_table > tbody > tr").remove();       
-    for ( var idx in eventData.data ) {
-        entry( eventData.data[idx] );
-    }
-    $("#plugin_table").trigger("update");
-    if ( view == 1 ) {
-               $("#timeline").remove();
-               $("div.table").append( "<div id='timeline' width='100%'></div>" 
);
-        for ( var idx in eventData.data ) {
-            entryTimeline( eventData.data[idx] );
-        }
-    }
-}
+       $('.statline').html(eventData.status); // FIXME:
 
-function entry( /* Object */ dataEntry ) {
-    var trElement = tr( null, { id: "entry" + dataEntry.id } );
-    entryInternal( trElement,  dataEntry );
-       $("#plugin_table > tbody").append(trElement);   
+       // append table view
+       eventsBody.empty();
+    for ( var i in eventData.data ) entry( eventData.data[i] );
+       eventsTable.trigger('update').trigger('applyWidgets');
+
+       // append timeline view
+       timeline.empty();
+    for ( var i in eventData.data ) entryTimeline( eventData.data[i] );
 }
 
+
 function entryTimeline( /* Object */ dataEntry ) {
-       var txt = "<div class='event" + dataEntry.category + "' 
style='overflow:visible;white-space:nowrap;width:" + dataEntry.width + "%;'>";
-       txt = txt + "<b>" + dataEntry.offset + "</b>&nbsp;<b>" + 
dataEntry.topic + "</b>";
-       if ( dataEntry.info ) {
-           txt = txt + "&nbsp;:&nbsp;" + dataEntry.info;
-       }
-    txt = txt + "</div>";
-       $("#timeline").prepend(txt);    
+       var txt = '<div class="event event' + dataEntry.category + '" 
style="width:' + dataEntry.width + '%">' +
+               '<b>' + dataEntry.offset + '</b>&nbsp;<b>' + dataEntry.topic + 
'</b>';
+       if ( dataEntry.info )  txt += '&nbsp;:&nbsp;' + dataEntry.info;
+    txt += '</div>';
+       timeline.prepend(txt);  
 }
 
-function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
-    var id = dataEntry.id;
-    var topic = dataEntry.topic;
+function entry( /* Object */ dataEntry ) {
     var properties = dataEntry.properties;
-    
-    parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) 
) ] ) );
-    parent.appendChild( td( null, null, [ text( topic ) ] ) );
 
     var propE;
     if ( dataEntry.info ) {
        propE = text(dataEntry.info);
     } else {
-           var tableE = createElement("table");
-           var bodyE = createElement("tbody");
-           tableE.appendChild(bodyE);
+           var propE = createElement('table', 'nicetable');
+           var bodyE = createElement('tbody');
+           propE.appendChild(bodyE);
        
            for( var p in dataEntry.properties ) {
-               var c1 = td(null, null, [text(p)]);
-               $(c1).css("border", "0px none");
-            $(c1).css("padding", "0 4px 0 0");
-               var c2 = td(null, null, [text(dataEntry.properties[p])]);
-               $(c2).css("border", "0px none");
-            $(c2).css("padding", "0 0 0 4px");
-               bodyE.appendChild(tr(null, null, [ c1, c2 ]));
+               bodyE.appendChild(tr(null, null, [ 
+                               td(null, 'propName', [text(p)]),
+                               td(null, 'propVal', 
[text(dataEntry.properties[p])])
+                       ]));
            }
-           propE = tableE;
     }
-    
-    parent.appendChild( td( null, null, [propE] ) );
-}
 
-/* displays a date in the user's local timezone */
-function printDate(time) {
-    var date = time ? new Date(time) : new Date();
-    return date.toLocaleString();
+       $(tr( null, { id: 'entry' + dataEntry.id }, [
+               td( null, null, [ text( printDate(dataEntry.received) ) ] ),
+               td( null, null, [ text( dataEntry.topic ) ] ),
+               propE
+       ])).appendTo(eventsBody);
 }
 
-function loadData() {
-       $.get(pluginRoot + "/data.json", null, function(data) {
-           renderData(data);
-       }, "json");     
-}
+var timeline = false;
+$(document).ready(function(){
+       eventsTable = $('#eventsTable');
+       eventsBody  = eventsTable.find('tbody');
+       timeline = $('#timeline');
 
-function switchView() {
-       if ( view == 0 ) {
-               view = 1;
-               $("#plugin_table").hide();
-               $(".switchButton").empty();
-               $(".switchButton").append("List");
-               loadData();
-       } else {
-               view = 0;
-               $("#timeline").remove();
-               $("#plugin_table").show();
-               $(".switchButton").empty();
-               $(".switchButton").append("Timeline");
-       }
-}
-function renderEvents() {
-       $(document).ready(function(){
-           renderView( ["Received", "Topic", "Properties"],
-                        "<button class='switchButton' type='button' 
name='switch'>Timeline</button>" +
-                        "<button class='clearButton' type='button' 
name='clear'>Clear List</button>" +
-                        "<button class='reloadButton' type='button' 
name='reload'>Reload</button>");
-           loadData();
-           
-           $("#plugin_table").tablesorter();
-           $(".reloadButton").click(loadData);
-           $(".switchButton").click(switchView);
-           $(".clearButton").click(function () {
-               $("#plugin_table > tbody > tr").remove();
-               $.post(pluginRoot, { "action":"clear" }, function(data) {
-                   renderData(data);
-               }, "json");
-           });
+       $('#clear').click(function () {
+               $.post(pluginRoot, { 'action':'clear' }, renderData, 'json');
        });
-}
+       $('#switch').click(function() {
+               var timelineHidden = timeline.hasClass('ui-helper-hidden');
+               if (timelineHidden) {
+                       $(this).text(i18n.displayList);
+                       timeline.removeClass('ui-helper-hidden');
+                       eventsTable.addClass('ui-helper-hidden');
+               } else {
+                       $(this).text(i18n.displayTimeline);
+                       timeline.addClass('ui-helper-hidden');
+                       eventsTable.removeClass('ui-helper-hidden');
+               }
+       });
+       $('#reload').click(function() {
+               $.get(pluginRoot + '/data.json', null, renderData, 'json');
+               //renderData(eventData);
+       }).click();
+});


Reply via email to