myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r634002 - in /myfaces/tobago/trunk/theme: scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/
Date Wed, 05 Mar 2008 19:52:28 GMT
Author: lofwyr
Date: Wed Mar  5 11:52:26 2008
New Revision: 634002

URL: http://svn.apache.org/viewvc?rev=634002&view=rev
Log:
TOBAGO-630: Better performance for selection of long sheet with IE 6 (and other)

Modified:
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
    myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
    myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java?rev=634002&r1=634001&r2=634002&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
(original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/SheetRenderer.java
Wed Mar  5 11:52:26 2008
@@ -25,7 +25,6 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ACTION_ONCLICK;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DIRECT_LINK_COUNT;
@@ -57,17 +56,17 @@
 import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUBAR;
 import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_MENUCOMMAND;
 import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
+import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
 import static org.apache.myfaces.tobago.ajax.api.AjaxResponse.CODE_NOT_MODIFIED;
 import static org.apache.myfaces.tobago.ajax.api.AjaxResponse.CODE_SUCCESS;
-import static org.apache.myfaces.tobago.component.UIData.ATTR_SCROLL_POSITION;
-import static org.apache.myfaces.tobago.component.UIData.NONE;
-import org.apache.myfaces.tobago.ajax.api.AjaxRenderer;
 import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UIColumnEvent;
 import org.apache.myfaces.tobago.component.UIColumnSelector;
 import org.apache.myfaces.tobago.component.UICommand;
 import org.apache.myfaces.tobago.component.UIData;
+import static org.apache.myfaces.tobago.component.UIData.ATTR_SCROLL_POSITION;
+import static org.apache.myfaces.tobago.component.UIData.NONE;
 import org.apache.myfaces.tobago.component.UIMenu;
 import org.apache.myfaces.tobago.component.UIMenuCommand;
 import org.apache.myfaces.tobago.component.UIPage;
@@ -134,6 +133,8 @@
     writer.writeStyleAttribute(sheetStyle);
     UICommand clickAction = null;
     UICommand dblClickAction = null;
+    int columnSelectorIndex = -1;
+    int i = 0;
     for (UIComponent child : (List<UIComponent>) data.getChildren()) {
       if (child instanceof UIColumnEvent) {
         UIColumnEvent columnEvent = (UIColumnEvent) child;
@@ -147,10 +148,12 @@
             dblClickAction = action;
           }
         }
+      } else if (child instanceof UIColumnSelector) {
+        columnSelectorIndex = i;
       }
+      i++;
     }
 
-
     renderSheet(facesContext, data, (clickAction != null || dblClickAction != null));
 
     writer.endElement(HtmlConstants.DIV);
@@ -173,7 +176,8 @@
     }
     final String[] cmds = {
         "new Tobago.Sheet(\"" + sheetId + "\", " + ajaxEnabled
-            + ", \"" + checked + "\", \"" + unchecked + "\", \"" + data.getSelectable() +
"\", "+ frequency
+            + ", \"" + checked + "\", \"" + unchecked + "\", \"" + data.getSelectable()
+            + "\", " + columnSelectorIndex + ", "+ frequency
             + ",  " + (clickAction!=null?HtmlRendererUtil.getJavascriptString(clickAction.getId()):null)
             + ",  " + HtmlRendererUtil.getRenderedPartiallyJavascriptArray(facesContext,
clickAction)
             + ",  " + (dblClickAction!=null?HtmlRendererUtil.getJavascriptString(dblClickAction.getId()):null)

Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js?rev=634002&r1=634001&r2=634002&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
(original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago-sheet.js
Wed Mar  5 11:52:26 2008
@@ -40,7 +40,7 @@
 
 };
 
-Tobago.Sheet = function(sheetId, enableAjax, checkedImage, uncheckedImage, selectable, autoReload,
+Tobago.Sheet = function(sheetId, enableAjax, checkedImage, uncheckedImage, selectable, columnSelectorIndex,
autoReload,
                         clickActionId, clickReloadComponentId, dblClickActionId, dblClickReloadComponentId)
{
   this.startTime = new Date();
   this.id = sheetId;
@@ -49,6 +49,7 @@
   this.checkedImage = checkedImage;
   this.uncheckedImage = uncheckedImage;
   this.selectable = selectable;
+  this.columnSelectorIndex = columnSelectorIndex;
   this.autoReload = autoReload;
   this.clickActionId = clickActionId;
   this.clickReloadComponentId = clickReloadComponentId;
@@ -450,14 +451,13 @@
     var row = Tobago.element(this.firstRowId);
     if (row) {
       var i = this.firstRowIndex;
-      i++;
       while (row) {
         //       LOG.debug("rowId = " + row.id + "   next i=" + i);
         Tobago.addBindEventListener(row, "click", this, "doSelection");
         if (this.dblClickActionId) {
           Tobago.addBindEventListener(row, "dblclick", this, "doDblClick");
         }
-        row = Tobago.element(this.id + "_data_tr_" + i++ );
+        row = this.getSiblingRow(row, ++i)
       }
       //LOG.debug("preSelected rows = " + Tobago.element(sheetId + "::selected").value);
     }
@@ -561,34 +561,50 @@
     }
   };
 
+Tobago.Sheet.prototype.getSelectionElementForRow = function(row) {
+  if (this.columnSelectorIndex >= 0) {
+    return row.childNodes[this.columnSelectorIndex].childNodes[0].childNodes[0].childNodes[0];
+  }
+};
+
+Tobago.Sheet.prototype.getSiblingRow = function(row, i) {
+  return row.parentNode.childNodes[i];
+};
+
 Tobago.Sheet.prototype.updateSelectionView = function(sheetId) {
-    var selected = Tobago.element(this.selectedId).value;
-    var row = Tobago.element(this.firstRowId);
-    var i = this.firstRowIndex;
-    while (row) {
+  var selected = Tobago.element(this.selectedId).value;
+  var row = Tobago.element(this.firstRowId);
+  var i = 0;
 
-      var selector = Tobago.element(this.id + "_data_row_selector_" + i);
-      var re = new RegExp("," + i +",");
-      var classes = row.className;
-      var img = Tobago.element(this.id + "_data_row_selector_" + i);
-      if (selected.search(re) == -1) { // not selected: remove selection class
-        Tobago.removeCssClass(row, "tobago-sheet-row-selected");
+  while (row) {
 
-        if (img && (!selector || !selector.src.match(/Disabled/))) {
-          img.src = this.uncheckedImage;
-        }
+    // you must not use Tobago.element() or document.getElementById() because the IE 6? doen't
index the ids.
+    // to the performace is quadratic aka. O(N*N) when N is the number of rows.
+
+    var rowIndex = i + this.firstRowIndex * 1; // * 1 to keep integer operation
+    var re = new RegExp("," + rowIndex + ",");
+    var classes = row.className;
+    var image = this.getSelectionElementForRow(row);
+
+    if (selected.search(re) == -1) { // not selected: remove selection class
+
+      Tobago.removeCssClass(row, "tobago-sheet-row-selected");
+
+      if (image && !image.src.match(/Disabled/)) {
+        image.src = this.uncheckedImage;
       }
-      else {  // selected: check selection class
-        if (classes.search(/tobago-sheet-row-selected/) == -1) {
-          Tobago.addCssClass(row, "tobago-sheet-row-selected");
-        }
-        if (img && (!selector || !selector.src.match(/Disabled/))) {
-          img.src = this.checkedImage;
-        }
+
+    } else {  // selected: check selection class
+      if (classes.search(/tobago-sheet-row-selected/) == -1) {
+        Tobago.addCssClass(row, "tobago-sheet-row-selected");
+      }
+      if (image && !image.src.match(/Disabled/)) {
+        image.src = this.checkedImage;
       }
-      row = Tobago.element(this.id + "_data_tr_" + ++i );
     }
-  };
+    row = this.getSiblingRow(row, ++i);
+  }
+};
 
 Tobago.Sheet.prototype.toggleSelectionForRow = function(dataRow) {
     var rowIndex = dataRow.id.substring(dataRow.id.lastIndexOf("_data_tr_") + 9);
@@ -596,8 +612,7 @@
   };
 
 Tobago.Sheet.prototype.toggleSelection = function(rowIndex) {
-    this.tobagoLastClickedRowId
-        = Tobago.element(this.id + "_data_tr_" + rowIndex).id;
+    this.tobagoLastClickedRowId = Tobago.element(this.id + "_data_tr_" + rowIndex).id;
     var selector = Tobago.element(this.id + "_data_row_selector_" + rowIndex);
     if (!selector || !selector.src.match(/Disabled/)) {
       var re = new RegExp("," + rowIndex + ",");
@@ -817,14 +832,14 @@
     var i = this.firstRowIndex;
     var selected = Tobago.element(this.selectedId);
     while (row) {
-      var selector = Tobago.element(this.id + "_data_row_selector_" + i);
-      if (!selector || !selector.src.match(/Disabled/)) {
+      var image = this.getSelectionElementForRow(row);
+      if (!image || !image.src.match(/Disabled/)) {
         var re = new RegExp("," + i + ",");
         if (selected.value.search(re) == -1) {
           selected.value = selected.value + "," + i + ",";
         }
       }
-      row = Tobago.element(this.id + "_data_tr_" + ++i );
+      row = this.getSiblingRow(row, ++i);
     }
     this.updateSelectionView();
   };
@@ -832,16 +847,16 @@
 Tobago.Sheet.prototype.unSelectAll = function() {
     var selected = Tobago.element(this.selectedId);
     var row = Tobago.element(this.firstRowId);
-    var selector = Tobago.element(this.id + "_data_row_selector_" + i);
-    if (selector) {
+    var image = this.getSelectionElementForRow(row);
+    if (image) {
       var i = this.firstRowIndex;
       while (row) {
-        selector = Tobago.element(this.id + "_data_row_selector_" + i);
-        if (!selector || !selector.src.match(/Disabled/)) {
+        image = this.getSelectionElementForRow(row);
+        if (!image || !image.src.match(/Disabled/)) {
           var re = new RegExp("," + i + ",", 'g');
           selected.value = selected.value.replace(re, "");
         }
-        row = Tobago.element(this.id + "_data_tr_" + ++i );
+        row = this.getSiblingRow(row, ++i);
       }
     } else {
       selected.value = "";
@@ -854,8 +869,7 @@
     var i = this.firstRowIndex;
     while (row) {
       this.toggleSelection(i);
-      row = Tobago.element(this.id + "_data_tr_" + ++i );
+      row = this.getSiblingRow(row, ++i);
     }
     this.updateSelectionView();
   };
-

Modified: myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js?rev=634002&r1=634001&r2=634002&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
(original)
+++ myfaces/tobago/trunk/theme/standard/src/main/resources/org/apache/myfaces/tobago/renderkit/html/standard/standard/script/tobago.js
Wed Mar  5 11:52:26 2008
@@ -1198,7 +1198,7 @@
       classes = classes.replace(re, " ");
     }
     classes = classes.replace(/  /g, " ");
-    element.className = classes;
+      element.className = classes;
   },
 
   /**



Mime
View raw message