myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1751378 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/model/ tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/ tobago-example/tobago-example-demo/src/main/we...
Date Mon, 04 Jul 2016 20:54:26 GMT
Author: lofwyr
Date: Mon Jul  4 20:54:25 2016
New Revision: 1751378

URL: http://svn.apache.org/viewvc?rev=1751378&view=rev
Log:
TOBAGO-1502: Advanced tc:sheet support for Bootstrap 
* fix column widths, when some columns are not rendered

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/sheet.xhtml
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
    myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java?rev=1751378&r1=1751377&r2=1751378&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
(original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/SheetState.java
Mon Jul  4 20:54:25 2016
@@ -56,7 +56,7 @@ public class SheetState implements Seria
     sortedColumnId = null;
     ascending = true;
     toBeSorted = false;
-    columnWidths = null;
+    columnWidths = new ArrayList<Integer>();
     resetSelected();
     if (expandedState != null) {
       expandedState.reset();

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=1751378&r1=1751377&r2=1751378&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
Mon Jul  4 20:54:25 2016
@@ -150,7 +150,7 @@ public class OverviewController implemen
   public void resetColumnWidths(final ActionEvent event) {
     final UISheet sheet = (UISheet) event.getComponent().findComponent("sheet");
     if (sheet != null) {
-      sheet.getState().setColumnWidths(null);
+      sheet.getState().setColumnWidths(new ArrayList<Integer>());
     } else {
       LOG.warn("Didn't find sheet component!");
     }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/sheet.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/sheet.xhtml?rev=1751378&r1=1751377&r2=1751378&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/sheet.xhtml
(original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/080-sheet/sheet.xhtml
Mon Jul  4 20:54:25 2016
@@ -44,12 +44,12 @@
   &lt;tc:column label="Name">
     &lt;tc:out value="\#{solarobject.name}"/>
       ...</code></pre>
-    <tc:sheet id="s1" value="#{sheetController.solarList}" var="object" rows="4">
+    <tc:sheet id="s1" value="#{sheetController.solarList}" var="object" rows="4" columns="*;*;*;*;*">
       <tc:style maxHeight="500px"/>
       <tc:column label="Name">
         <tc:out value="#{object.name}"/>
       </tc:column>
-      <tc:column label="Orbit">
+      <tc:column label="Orbit" rendered="false">
         <tc:out value="#{object.orbit}"/>
       </tc:column>
       <tc:column label="Period (Days)">

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java?rev=1751378&r1=1751377&r2=1751378&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java
(original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/JsonUtils.java
Mon Jul  4 20:54:25 2016
@@ -275,20 +275,20 @@ public class JsonUtils {
 
   public static List<Integer> decodeIntegerArray(String json) {
     json = json.trim();
+    final List<Integer> result = new ArrayList<Integer>();
     if (json.length() < 2 || json.charAt(0) != '[' || json.charAt(json.length() - 1) !=
']') {
       LOG.error("Can't parse JSON array: no surrounding square brackets []: '{}'", json);
-      return null;
-    }
-    json = json.substring(1, json.length() - 1);
-    final List<Integer> result = new ArrayList<Integer>();
-    final StringTokenizer tokenizer = new StringTokenizer(json, ",");
-    while (tokenizer.hasMoreTokens()) {
-      final String token = tokenizer.nextToken().trim();
-      try {
-        result.add(Integer.parseInt(token));
-      } catch (NumberFormatException e) {
-        LOG.error("Can't parse JSON array: not an integer token: '{}'", token);
-        // ignoring so far
+    } else {
+      json = json.substring(1, json.length() - 1);
+      final StringTokenizer tokenizer = new StringTokenizer(json, ",");
+      while (tokenizer.hasMoreTokens()) {
+        final String token = tokenizer.nextToken().trim();
+        try {
+          result.add(Integer.parseInt(token));
+        } catch (NumberFormatException e) {
+          LOG.error("Can't parse JSON array: not an integer token: '{}'", token);
+          // ignoring so far
+        }
       }
     }
     return result;

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java?rev=1751378&r1=1751377&r2=1751378&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
(original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SheetRenderer.java
Mon Jul  4 20:54:25 2016
@@ -105,13 +105,15 @@ public class SheetRenderer extends Rende
   public void decode(final FacesContext facesContext, final UIComponent component) {
 
     final UISheet sheet = (UISheet) component;
+    final List<AbstractUIColumnBase> columns = sheet.getAllColumns();
     final String clientId = sheet.getClientId(facesContext);
 
     String key = clientId + SUFFIX_WIDTHS;
     final Map requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
+    final SheetState state = sheet.getState();
     if (requestParameterMap.containsKey(key)) {
       final String widths = (String) requestParameterMap.get(key);
-      sheet.getState().setColumnWidths(JsonUtils.decodeIntegerArray(widths));
+      ensureColumnWidthsSize(state.getColumnWidths(), columns, JsonUtils.decodeIntegerArray(widths));
     }
 
     key = clientId + SUFFIX_SELECTED;
@@ -134,7 +136,7 @@ public class SheetRenderer extends Rende
     final String value
         = facesContext.getExternalContext().getRequestParameterMap().get(clientId + SUFFIX_SCROLL_POSITION);
     if (value != null) {
-      sheet.getState().getScrollPosition().update(value);
+      state.getScrollPosition().update(value);
     }
     RenderUtils.decodedStateOfTreeData(facesContext, sheet);
 
@@ -227,18 +229,31 @@ public class SheetRenderer extends Rende
     final Application application = facesContext.getApplication();
     final SheetState state = sheet.getSheetState(facesContext);
     final List<Integer> columnWidths = sheet.getState().getColumnWidths();
+    final boolean cleanColumnWidths = columnWidths.size() == 0;
     final List<Integer> selectedRows = getSelectedRows(sheet, state);
     final List<AbstractUIColumnBase> columns = sheet.getAllColumns();
     final boolean showHeader = sheet.isShowHeader();
     final boolean autoLayout = sheet.isAutoLayout();
     Markup sheetMarkup = sheet.getMarkup() != null ? sheet.getMarkup() : Markup.NULL;
 
+    ensureColumnWidthsSize(columnWidths, columns, Collections.<Integer>emptyList());
+
     if (!autoLayout) {
       writer.startElement(HtmlElements.INPUT);
       writer.writeIdAttribute(sheetId + SUFFIX_WIDTHS);
       writer.writeNameAttribute(sheetId + SUFFIX_WIDTHS);
       writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN);
-      writer.writeAttribute(HtmlAttributes.VALUE, JsonUtils.encode(columnWidths), false);
+      if (!cleanColumnWidths) {
+        final List<Integer> encodedWidths = new ArrayList<Integer>(columnWidths.size());
+        for (int i = 0; i < columns.size(); i++) {
+          AbstractUIColumnBase column = columns.get(i);
+          if (column.isRendered()) {
+            final Integer width = columnWidths.get(i);
+            encodedWidths.add(width > -1 ? width : 100);
+          }
+        }
+        writer.writeAttribute(HtmlAttributes.VALUE, JsonUtils.encode(encodedWidths), false);
+      }
       writer.endElement(HtmlElements.INPUT);
     }
 
@@ -455,12 +470,10 @@ public class SheetRenderer extends Rende
         if (!(column instanceof AbstractUIColumnEvent)) {
           writer.startElement(HtmlElements.TD);
           writer.startElement(HtmlElements.DIV);
-          if (columnWidths != null) {
-            final Integer divWidth = columnWidths.get(j);
-            final Style divStyle = new Style();
-            divStyle.setWidth(Measure.valueOf(divWidth));
-            writer.writeStyleAttribute(divStyle);
-          }
+          final Integer divWidth = columnWidths.get(j);
+          final Style divStyle = new Style();
+          divStyle.setWidth(Measure.valueOf(divWidth));
+          writer.writeStyleAttribute(divStyle);
           writer.endElement(HtmlElements.DIV);
           writer.endElement(HtmlElements.TD);
         }
@@ -675,6 +688,29 @@ public class SheetRenderer extends Rende
     writer.endElement(HtmlElements.DIV);
   }
 
+  private void ensureColumnWidthsSize(
+      final List<Integer> columnWidths, final List<AbstractUIColumnBase> columns,
final List<Integer> samples) {
+    // we have to fill the non rendered positions with some values.
+    // on client site, we don't know nothing about the non-rendered columns.
+    for (int i = 0, j = 0; i < columns.size(); i++) {
+      AbstractUIColumnBase column = columns.get(i);
+      Integer newValue;
+      if (column.isRendered() && j < samples.size()) {
+        newValue = samples.get(j);
+        j++;
+      } else {
+        newValue = null;
+      }
+      if (columnWidths.size() > i) {
+        if (newValue != null) {
+          columnWidths.set(i, newValue);
+        }
+      } else {
+        columnWidths.add(newValue != null ? newValue : -1); // -1 means unknown or undefined
+      }
+    }
+  }
+
   private Markup getMarkupForAlign(UIColumn column) {
     final String textAlign = ComponentUtils.getStringAttribute(column, Attributes.align);
     if (textAlign != null) {
@@ -909,7 +945,8 @@ public class SheetRenderer extends Rende
     for (int i = 0; i < columns.size(); i++) {
       final AbstractUIColumnBase column =  columns.get(i);
       if (column.isRendered() && !(column instanceof AbstractUIColumnEvent)) {
-        writeCol(writer, columnWidths != null ? columnWidths.get(i) : null);
+        final Integer width = columnWidths.get(i);
+        writeCol(writer, width >= 0 ? width : null);
       }
     }
     writeCol(writer, null); // extra entry for resizing...

Modified: myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java?rev=1751378&r1=1751377&r2=1751378&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java
(original)
+++ myfaces/tobago/trunk/tobago-theme/tobago-theme-standard/src/test/java/org/apache/myfaces/tobago/renderkit/html/JsonUtilsUnitTest.java
Mon Jul  4 20:54:25 2016
@@ -144,7 +144,7 @@ public class JsonUtilsUnitTest extends A
 
     Assert.assertEquals(Arrays.asList(2, 3, 4), JsonUtils.decodeIntegerArray("[null,2,3,4]"));
 
-    Assert.assertEquals(null, JsonUtils.decodeIntegerArray("1,2,3,4"));
+    Assert.assertEquals(Arrays.asList(), JsonUtils.decodeIntegerArray("1,2,3,4"));
   }
 
   @Test



Mime
View raw message