Author: orudyy
Date: Sat Sep 14 11:23:18 2013
New Revision: 1523216

URL: http://svn.apache.org/r1523216
Log:
Introduce UpdatableGrid widget

Added:
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js
Modified:
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js
    
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js

Modified: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js?rev=1523216&r1=1523215&r2=1523216&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/EnhancedFilter.js
 Sat Sep 14 11:23:18 2013
@@ -161,6 +161,11 @@ define([
       this.inherited(arguments);
       try
       {
+        if (this.filterDefDialog)
+        {
+          this.filterDefDialog.destroy();
+          this.filterDefDialog = null;
+        }
         if (this.grid)
         {
           this.grid.unwrap("filter");
@@ -186,11 +191,6 @@ define([
           this.filterStatusTip.destroy();
           this.filterStatusTip = null;
         }
-        if (this.filterDefDialog)
-        {
-          this.filterDefDialog.destroy();
-          this.filterDefDialog = null;
-        }
         this.args = null;
 
       }catch(e){

Modified: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js?rev=1523216&r1=1523215&r2=1523216&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/GridUpdater.js
 Sat Sep 14 11:23:18 2013
@@ -28,40 +28,31 @@ define(["dojo/_base/xhr",
         "qpid/common/updater",
         "qpid/common/UpdatableStore",
         "qpid/common/util",
-        "dojox/grid/EnhancedGrid",
+        "dojo/store/Memory",
+        "dojo/data/ObjectStore",
         "qpid/common/grid/EnhancedFilter",
         "dojox/grid/enhanced/plugins/NestedSorting",
         "dojo/domReady!"],
-       function (xhr, parser, array, lang, properties, updater, 
UpdatableStore, util, EnhancedGrid, EnhancedFilter, NestedSorting) {
+       function (xhr, parser, array, lang, properties, updater, 
UpdatableStore, util, Memory, ObjectStore) {
 
-          /*
-           * Construct GridUpdater from the following arguments:
-           * serviceUrl - service URL to fetch data for the grid. Optional, if 
data is specified
-           * data - array containing data for the grid. Optional, if 
serviceUrl is specified
-           * node - dom node or dom node id to
-           * structure,
-           * funct,
-           * gridProperties,
-           * gridConstructor
-           */
-           function GridUpdater(args) {
-
-             var self = this;
-
-             // GridUpdater fields
+           function GridUpdater(args, store) {
              this.updatable = args.hasOwnProperty("updatable") ? 
args.updatable : true ;
              this.serviceUrl = args.serviceUrl;
-             this.updatableStore = null;
-             this.grid = null;
+
              this.onUpdate = args.onUpdate;
-             this._args = args;
+
              this.appendData = args.append;
              this.appendLimit = args.appendLimit;
+             this.initialData = args.data;
+             this.initializeStore(store);
+           };
+
+           GridUpdater.prototype.buildUpdatableGridArguments = function(args)
+           {
+             var filterPluginFound = args && args.hasOwnProperty("plugins") && 
args.plugins.filter ? true: false;
 
-             // default grid properties
              var gridProperties = {
                  autoHeight: true,
-                 updateDelay: 0, // no delay updates when receiving 
notifications from a datastore
                  plugins: {
                    pagination: {
                      defaultPageSize: 25,
@@ -73,30 +64,23 @@ define(["dojo/_base/xhr",
                      maxPageStep: 4,
                      position: "bottom"
                  },
-                 enhancedFilter: {}
+                 enhancedFilter: {
+                     disableFiltering: filterPluginFound
+                 }
                 }
              };
 
-             var filterPluginFound = false;
-
-             // merge args grid properties with default grid properties
-             if(args && args.gridProperties)
+             if(args)
              {
-               var argProperties = args.gridProperties;
-               for(var argProperty in argProperties)
+               for(var argProperty in args)
                {
-                   if(argProperties.hasOwnProperty(argProperty))
+                   if(args.hasOwnProperty(argProperty))
                    {
                        if (argProperty == "plugins")
                        {
-                         var argPlugins = argProperties[ argProperty ];
+                         var argPlugins = args[ argProperty ];
                          for(var argPlugin in argPlugins)
                          {
-                           if (argPlugin == "filter")
-                           {
-                               // we need to switch off filtering in 
EnhancedFilter
-                               filterPluginFound = true;
-                           }
                            if(argPlugins.hasOwnProperty(argPlugin))
                            {
                              var argPluginProperties = argPlugins[ argPlugin ];
@@ -120,65 +104,95 @@ define(["dojo/_base/xhr",
                        }
                        else
                        {
-                         gridProperties[ argProperty ] = argProperties[ 
argProperty ];
+                         gridProperties[ argProperty ] = args[ argProperty ];
                        }
                    }
                }
              }
 
-             if (filterPluginFound)
-             {
-                 gridProperties.plugins.enhancedFilter.disableFiltering = true;
-             }
+             gridProperties.updater = this;
+             gridProperties.store = this.dataStore;
+
+             return gridProperties;
+           };
+
+           GridUpdater.prototype.initializeStore = function(store)
+           {
+             var self = this;
 
-             var updatableStoreFactory = function(data)
+             function processData(data)
              {
-               try
-               {
-                 self.updatableStore = new UpdatableStore(data, 
self._args.node, self._args.structure,
-                     self._args.funct, gridProperties, 
self._args.GridConstructor || EnhancedGrid, self.appendData);
-               }
-               catch(e)
-               {
-                 console.error(e);
-                 throw e;
-               }
-               self.grid = self.updatableStore.grid;
-               self.grid.updater = self;
-               if (self.onUpdate)
-               {
-                 self.onUpdate(data);
-               }
-               if (self.serviceUrl)
-               {
-                 updater.add(self);
-               }
+                 var dataSet = false;
+                 if (!store)
+                 {
+                     store = new ObjectStore({objectStore: new Memory({data: 
data, idProperty: "id"})});
+                     dataSet = true;
+                 }
+                 self.dataStore = store
+                 self.store = store;
+                 if (store instanceof ObjectStore)
+                 {
+                     if( store.objectStore instanceof Memory)
+                     {
+                         self.memoryStore = store.objectStore;
+                     }
+                     self.store = store.objectStore
+                 }
+
+                 if (data)
+                 {
+                     try
+                     {
+                         if ((dataSet || self.updateOrAppend(data)) && 
self.onUpdate)
+                         {
+                             self.onUpdate(data);
+                         }
+                     }
+                     catch(e)
+                     {
+                         console.error(e);
+                     }
+                 }
              };
 
-             if (args && args.serviceUrl)
+             if (this.serviceUrl)
              {
                var requestUrl = lang.isFunction(this.serviceUrl) ? 
this.serviceUrl() : this.serviceUrl;
-               xhr.get({url: requestUrl, sync: properties.useSyncGet, 
handleAs: "json"}).then(updatableStoreFactory, util.errorHandler);
+               xhr.get({url: requestUrl, sync: true, handleAs: 
"json"}).then(processData, util.errorHandler);
              }
-             else if (args && args.data)
+             else
              {
-               updatableStoreFactory(args.data);
+                 processData(this.initialData);
              }
-           }
+           };
+
+           GridUpdater.prototype.start = function(grid)
+           {
+               this.grid = grid;
+               if (this.serviceUrl)
+               {
+                 updater.add(this);
+               }
+           };
 
            GridUpdater.prototype.destroy = function()
            {
              updater.remove(this);
-             if (this.updatableStore)
+             if (this.dataStore)
              {
-                 this.updatableStore.close();
-                 this.updatableStore = null;
-             }
-             if (this.grid)
-             {
-                 this.grid.destroy();
-                 this.grid = null;
+                 this.dataStore.close();
+                 this.dataStore = null;
              }
+             this.store = null;
+             this.memoryStore = null;
+             this.grid = null;
+           };
+
+           GridUpdater.prototype.updateOrAppend = function(data)
+           {
+               return this.appendData ?
+                       UpdatableStore.prototype.append.call(this, data, 
this.appendLimit):
+                           UpdatableStore.prototype.update.call(this, data);
            };
 
            GridUpdater.prototype.refresh = function(data)
@@ -186,7 +200,7 @@ define(["dojo/_base/xhr",
                this.updating = true;
                try
                {
-                   if (this.appendData ? this.updatableStore.append(data, 
this.appendLimit): this.updatableStore.update(data))
+                   if (this.updateOrAppend(data))
                    {
                      // EnhancedGrid with Filter plugin has "filter" layer.
                      // The filter expression needs to be re-applied after the 
data update

Added: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js?rev=1523216&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/grid/UpdatableGrid.js
 Sat Sep 14 11:23:18 2013
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+define([
+  "dojo/_base/declare",
+  "dojox/grid/EnhancedGrid",
+  "dojo/domReady!"], function(declare, EnhancedGrid){
+
+  return declare("qpid.common.grid.UpdatableGrid", [EnhancedGrid], {
+
+    updater: null,
+
+    postCreate: function(){
+        this.inherited(arguments);
+        if (this.updater)
+        {
+            this.updater.start(this);
+        }
+    },
+
+    destroy: function(){
+      if (this.updater)
+      {
+          try
+          {
+              this.updater.destroy();
+          }
+          catch(e)
+          {
+              console.error(e)
+          }
+          this.updater = null;
+      }
+      this.inherited(arguments);
+    }
+  });
+
+});

Modified: 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js?rev=1523216&r1=1523215&r2=1523216&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/logs/LogViewer.js
 Sat Sep 14 11:23:18 2013
@@ -24,10 +24,11 @@ define(["dojo/_base/xhr",
         "dojo/date/locale",
         "dijit/registry",
         "qpid/common/grid/GridUpdater",
+        "qpid/common/grid/UpdatableGrid",
         "qpid/management/logs/LogFileDownloadDialog",
         "dojo/text!../../../logs/showLogViewer.html",
         "dojo/domReady!"],
-       function (xhr, parser, query, locale, registry, GridUpdater, 
LogFileDownloadDialog, markup) {
+       function (xhr, parser, query, locale, registry, GridUpdater, 
UpdatableGrid, LogFileDownloadDialog, markup) {
 
            var defaulGridRowLimit = 4096;
 
@@ -58,6 +59,11 @@ define(["dojo/_base/xhr",
                this.downloadLogsButton.on("click", function(evt){
                    self.downloadLogDialog.showDialog();
                });
+               this._buildGrid();
+           };
+
+           LogViewer.prototype._buildGrid = function() {
+               var self = this;
 
                var gridStructure = [
                     {
@@ -97,44 +103,39 @@ define(["dojo/_base/xhr",
                    { name: "Log Message", field: "message", width: "auto", 
datatype: "string"}
                ];
 
-               this._buildGrid(gridStructure);
-           };
-
-           LogViewer.prototype._buildGrid = function(gridStructure) {
-               var self = this;
                var gridNode = query("#broker-logfile", 
this.contentPane.containerNode)[0];
                try
                {
-                 this.updater = new GridUpdater({
-                   updatable: false,
-                   serviceUrl: function()
-                   {
-                     return "rest/logrecords?lastLogId=" + self.lastLogId;
-                   },
-                   onUpdate: function(items)
-                   {
-                     if (items)
+                 var updater = new GridUpdater({
+                     updatable: false,
+                     serviceUrl: function()
+                     {
+                       return "rest/logrecords?lastLogId=" + self.lastLogId;
+                     },
+                     onUpdate: function(items)
                      {
-                       var maxId = -1;
-                       for(var i in items)
+                       if (items)
                        {
-                         var item = items[i];
-                         if (item.id > maxId)
+                         var maxId = -1;
+                         for(var i in items)
                          {
-                           maxId = item.id
+                           var item = items[i];
+                           if (item.id > maxId)
+                           {
+                             maxId = item.id
+                           }
+                         }
+                         if (maxId != -1)
+                         {
+                           self.lastLogId = maxId
                          }
                        }
-                       if (maxId != -1)
-                       {
-                         self.lastLogId = maxId
-                       }
-                     }
-                   },
-                   append: true,
-                   appendLimit: defaulGridRowLimit,
-                   node: gridNode,
-                   structure: gridStructure,
-                   gridProperties: {
+                     },
+                     append: true,
+                     appendLimit: defaulGridRowLimit
+                 });
+                 this.grid = new 
UpdatableGrid(updater.buildUpdatableGridArguments({
+                     structure: gridStructure,
                      selectable: true,
                      selectionMode: "none",
                      sortInfo: -1,
@@ -144,35 +145,31 @@ define(["dojo/_base/xhr",
                        enhancedFilter:{defaulGridRowLimit: defaulGridRowLimit},
                        indirectSelection: false
                      }
-                   },
-                   funct: function (obj)
-                   {
-                     var onStyleRow = function(row)
-                     {
-                       var item = obj.grid.getItem(row.index);
-                       if(item){
-                          var level = obj.dataStore.getValue(item, "level", 
null);
-                          var changed = false;
-                          if(level == "ERROR"){
-                              row.customClasses += " redBackground";
-                              changed = true;
-                          } else if(level == "WARN"){
-                              row.customClasses += " yellowBackground";
-                              changed = true;
-                          } else if(level == "DEBUG"){
-                              row.customClasses += " grayBackground";
-                              changed = true;
-                          }
-                          if (changed)
-                          {
-                            obj.grid.focus.styleRow(row);
-                          }
-                       }
-                     };
-                     obj.grid.on("styleRow", onStyleRow);
-                     obj.grid.startup();
+                  }), gridNode);
+                 var onStyleRow = function(row)
+                 {
+                   var item = self.grid.getItem(row.index);
+                   if(item){
+                      var level = self.grid.store.getValue(item, "level", 
null);
+                      var changed = false;
+                      if(level == "ERROR"){
+                          row.customClasses += " redBackground";
+                          changed = true;
+                      } else if(level == "WARN"){
+                          row.customClasses += " yellowBackground";
+                          changed = true;
+                      } else if(level == "DEBUG"){
+                          row.customClasses += " grayBackground";
+                          changed = true;
+                      }
+                      if (changed)
+                      {
+                          self.grid.focus.styleRow(row);
+                      }
                    }
-                 });
+                 };
+                 this.grid.on("styleRow", onStyleRow);
+                 this.grid.startup();
                }
                catch(err)
                {
@@ -181,10 +178,10 @@ define(["dojo/_base/xhr",
            };
 
            LogViewer.prototype.close = function() {
-             if (this.updater)
+             if (this.grid)
              {
-                 this.updater.destroy();
-                 this.updater = null;
+                 this.grid.destroy();
+                 this.grid = null;
              }
              if (this.downloadLogDialog)
              {



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to