You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/10/29 21:27:48 UTC

svn commit: r589840 - in /myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago: component/ taglib/component/ taglib/decl/

Author: bommel
Date: Mon Oct 29 13:27:47 2007
New Revision: 589840

URL: http://svn.apache.org/viewvc?rev=589840&view=rev
Log:
(TOBAGO-526) Width attribute for column

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/FixedLayoutToken.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RelativeLayoutToken.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumn.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTag.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTagDeclaration.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasWidth.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/FixedLayoutToken.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/FixedLayoutToken.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/FixedLayoutToken.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/FixedLayoutToken.java Mon Oct 29 13:27:47 2007
@@ -22,6 +22,7 @@
  * Time: 7:16:18 PM
  */
 public final class FixedLayoutToken extends LayoutToken {
+  public static final FixedLayoutToken INSTANCE = new FixedLayoutToken();
   public String toString() {
     return "fixed";
   }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/LayoutTokens.java Mon Oct 29 13:27:47 2007
@@ -61,7 +61,7 @@
     }
   }
 
-  private void addToken(LayoutToken token) {
+  public void addToken(LayoutToken token) {
     tokens.add(token);
   }
 
@@ -96,26 +96,35 @@
   }
 
   private static void parseToken(String token, LayoutTokens layoutTokens) {
+    LayoutToken layoutToken = parseToken(token);
+    if (layoutToken != null) {
+      layoutTokens.addToken(layoutToken);
+    }
+
+  }
+
+  public static LayoutToken parseToken(String token) {
     try {
     // TODO optimize me
       if ("*".equals(token)) {
-        layoutTokens.addToken(new RelativeLayoutToken(1));
+        return RelativeLayoutToken.DEFAULT_INSTANCE;
       } else if (token.equals("fixed")) {
-        layoutTokens.addToken(new FixedLayoutToken());
+        return FixedLayoutToken.INSTANCE;
       } else if (token.equals("minimum")) {
-        layoutTokens.addToken(new MinimumLayoutToken());
+        return new MinimumLayoutToken();
       } else if (token.matches("\\d+px")) {
-        layoutTokens.addToken(new PixelLayoutToken(Integer.parseInt(token.replaceAll("\\D", ""))));
+        return new PixelLayoutToken(Integer.parseInt(token.replaceAll("\\D", "")));
       } else if (token.matches("^\\d+\\%")) {
-        layoutTokens.addToken(new PercentLayoutToken(Integer.parseInt(token.replaceAll("\\D", ""))));
+        return new PercentLayoutToken(Integer.parseInt(token.replaceAll("\\D", "")));
       } else if (token.matches("^\\d+\\*")) {
-        layoutTokens.addToken(new RelativeLayoutToken(Integer.parseInt(token.replaceAll("\\D", ""))));
+        return new RelativeLayoutToken(Integer.parseInt(token.replaceAll("\\D", "")));
       } else {
         LOG.error("Unknown layout token " + token + " ignoring");
       }
     } catch (NumberFormatException e) {
       LOG.error("Error parsing layout token " + token, e);
     }
+    return null;
   }
 
   public String toString() {

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RelativeLayoutToken.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RelativeLayoutToken.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RelativeLayoutToken.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/RelativeLayoutToken.java Mon Oct 29 13:27:47 2007
@@ -22,6 +22,8 @@
  * Time: 1:34:11 PM
  */
 public class RelativeLayoutToken extends LayoutToken {
+  public static String DEFAULT_TOKEN_STRING = "1*";
+  public static RelativeLayoutToken DEFAULT_INSTANCE = new RelativeLayoutToken(1);
   private int factor = 1;
 
   public RelativeLayoutToken(int factor) {

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumn.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumn.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumn.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIColumn.java Mon Oct 29 13:27:47 2007
@@ -20,6 +20,7 @@
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH;
 
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
@@ -37,6 +38,7 @@
   private String align;
   private String label;
   private String[] markup;
+  private String width;
 
   public void restoreState(FacesContext context, Object state) {
     Object[] values = (Object[]) state;
@@ -45,15 +47,17 @@
     sortable = (Boolean) values[2];
     label = (String) values[3];
     markup = (String[]) values[4];
+    width = (String) values[5];
   }
 
   public Object saveState(FacesContext context) {
-    Object[] values = new Object[5];
+    Object[] values = new Object[6];
     values[0] = super.saveState(context);
     values[1] = align;
     values[2] = sortable;
     values[3] = label;
     values[4] = markup;
+    values[5] = width;
     return values;
   }
 
@@ -114,6 +118,22 @@
 
   public void setLabel(String label) {
     this.label = label;
+  }
+
+  public String getWidth() {
+    if (width != null) {
+      return width;
+    }
+    ValueBinding vb = getValueBinding(ATTR_WIDTH);
+    if (vb != null) {
+      return (String) vb.getValue(getFacesContext());
+    } else {
+      return RelativeLayoutToken.DEFAULT_TOKEN_STRING;
+    }
+  }
+
+  public void setWidth(String width) {
+    this.width = width;
   }
 
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIData.java Mon Oct 29 13:27:47 2007
@@ -98,6 +98,8 @@
 
   private String selectable;
 
+  private transient LayoutTokens columnLayout;
+
   public void encodeBegin(FacesContext facesContext) throws IOException {
     UILayout.prepareDimension(facesContext, this);
     SheetState state = getSheetState(facesContext);
@@ -242,9 +244,19 @@
     }
   }
 
+  public LayoutTokens getColumnLayout() {
+    if (columnLayout==null) {
+      String columns = getColumns();
+      if (columns != null) {
+        columnLayout = LayoutTokens.parse(columns);
+      }
+    }
+    return columnLayout;
+  }
+
   private void ensureColumnWidthList(FacesContext facesContext, SheetState state) {
     List<Integer> currentWidthList = null;
-    List<UIColumn> columns = getRendererdColumns();
+    List<UIColumn> rendererdColumns = getRenderedColumns();
 
     final Map attributes = getAttributes();
     String widthListString = null;
@@ -253,35 +265,42 @@
       widthListString = state.getColumnWidths();
     }
     if (widthListString == null) {
-      widthListString =
-          (String) attributes.get(ATTR_WIDTH_LIST_STRING);
+      widthListString = (String) attributes.get(ATTR_WIDTH_LIST_STRING);
     }
 
     if (widthListString != null) {
       currentWidthList = StringUtil.parseIntegerList(widthListString);
     }
-    if (currentWidthList != null && currentWidthList.size() != columns.size()) {
+    if (currentWidthList != null && currentWidthList.size() != rendererdColumns.size()) {
       currentWidthList = null;
     }
 
 
     if (currentWidthList == null) {
-      String columnLayout =
-          (String) attributes.get(ATTR_COLUMNS);
+      LayoutTokens tokens = getColumnLayout();
       List<UIColumn> allColumns = getAllColumns();
-
-      if (columnLayout == null && allColumns.size() > 0) {
-        StringBuilder sb = new StringBuilder();
-        for (UIColumn allColumn : allColumns) {
-          sb.append("1*;");
-        }
-        columnLayout = sb.deleteCharAt(sb.lastIndexOf(";")).toString();
-        if (LOG.isWarnEnabled()) {
-          LOG.warn(
-              "No columns found! Using created layout tokens: " + columnLayout);
+      LayoutTokens newTokens = new LayoutTokens();
+      if (allColumns.size() > 0) {
+        for (int i = 0; i < allColumns.size(); i++) {
+          UIColumn column = allColumns.get(i);
+          if (column.isRendered())  {
+            if (tokens == null) {
+              if (column instanceof org.apache.myfaces.tobago.component.UIColumn) {
+                newTokens.addToken(LayoutTokens.parseToken(((org.apache.myfaces.tobago.component.UIColumn)column).getWidth()));
+              } else {
+                newTokens.addToken(RelativeLayoutToken.DEFAULT_INSTANCE);
+              }
+            } else {
+              if (i < tokens.getSize()) {
+                newTokens.addToken(tokens.get(i));
+              } else {
+                newTokens.addToken(RelativeLayoutToken.DEFAULT_INSTANCE);
+              }
+            }
+          }
         }
       }
-      String[] layoutTokens
+      /*String[] layoutTokens
           = LayoutInfo.createLayoutTokens(columnLayout, allColumns.size(), "1*");
       if (layoutTokens.length != allColumns.size()) {
         LOG.warn("Count of columnLayout tokens in '" + columnLayout
@@ -289,11 +308,11 @@
             + "Using default token '1*' for all columns");
         layoutTokens
             = LayoutInfo.createLayoutTokens(null, allColumns.size(), "1*");
-      }
+      } */
 
       // here we have layoutTokens for all columns
       // now remove tokens for unrendered columns
-      boolean changed = false;
+      /*boolean changed = false;
       for (int i = 0; i < layoutTokens.length; i++) {
         if (!allColumns.get(i).isRendered()) {
           layoutTokens[i] = null;
@@ -310,7 +329,7 @@
             j++;
           }
         }
-      }
+      } */
 
 
 
@@ -321,17 +340,16 @@
       if (renderer.needVerticalScrollbar(facesContext, this)) {
         space -= renderer.getScrollbarWidth(facesContext, this);
       }
-      LayoutInfo layoutInfo = new LayoutInfo(getRendererdColumns().size(),
-          space, LayoutTokens.parse(layoutTokens), this.getClientId(facesContext), false);
-      parseFixedWidth(facesContext, layoutInfo);
+      LayoutInfo layoutInfo = new LayoutInfo(newTokens.getSize(), space, newTokens, getClientId(facesContext), false);
+      parseFixedWidth(facesContext, layoutInfo, rendererdColumns);
       layoutInfo.parseColumnLayout(space);
       currentWidthList = layoutInfo.getSpaceList();
     }
 
     if (currentWidthList != null) {
-      if (columns.size() != currentWidthList.size()) {
+      if (rendererdColumns.size() != currentWidthList.size()) {
         LOG.warn("widthList.size() = " + currentWidthList.size()
-            + " != columns.size() = " + columns.size() + "  widthList : "
+            + " != columns.size() = " + rendererdColumns.size() + "  widthList : "
             + LayoutInfo.listToTokenString(currentWidthList));
       } else {
         this.widthList = currentWidthList;
@@ -339,16 +357,15 @@
     }
   }
 
-  private void parseFixedWidth(FacesContext facesContext, LayoutInfo layoutInfo) {
+  private void parseFixedWidth(FacesContext facesContext, LayoutInfo layoutInfo, List<UIColumn> rendereredColumns) {
     LayoutTokens tokens = layoutInfo.getLayoutTokens();
     for (int i = 0; i < tokens.getSize(); i++) {
       LayoutToken token = tokens.get(i);
       if (token  instanceof FixedLayoutToken) {
         int width = 0;
-        final List<UIColumn> columns = getRendererdColumns();
-        if (!columns.isEmpty()) {
-          if (i < columns.size()) {
-            UIColumn column = columns.get(i);
+        if (!rendereredColumns.isEmpty()) {
+          if (i < rendereredColumns.size()) {
+            UIColumn column = rendereredColumns.get(i);
             if (column instanceof UIColumnSelector) {
                 LayoutInformationProvider renderer
                     = ComponentUtil.getRenderer(facesContext, column);
@@ -386,7 +403,7 @@
 
     List<Integer> columnWidths = getWidthList();
     int i = 0;
-    for (UIColumn column : getRendererdColumns()) {
+    for (UIColumn column : getRenderedColumns()) {
       if (i < columnWidths.size()) {
         Integer width = columnWidths.get(i);
         if (!(column instanceof UIColumnSelector)) {
@@ -544,7 +561,7 @@
     return columns;
   }
 
-  public List<UIColumn> getRendererdColumns() {
+  public List<UIColumn> getRenderedColumns() {
     List<UIColumn> columns = new ArrayList<UIColumn>();
     for (UIComponent kid : (List<UIComponent>) getChildren()) {
       if (kid instanceof UIColumn && kid.isRendered()) {

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTag.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTag.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTag.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTag.java Mon Oct 29 13:27:47 2007
@@ -20,6 +20,7 @@
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ALIGN;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_SORTABLE;
 import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TIP;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_WIDTH;
 import org.apache.myfaces.tobago.component.ComponentUtil;
 import org.apache.myfaces.tobago.component.UIColumn;
 
@@ -33,21 +34,19 @@
   private String align;
   private String markup;
   private String tip;
+  private String width;
 
   public String getComponentType() {
     return UIColumn.COMPONENT_TYPE;
   }
 
-  public String getRendererType() {
-    return null;
-  }
-
   public void release() {
     super.release();
     sortable = null;
     align = null;
     markup = null;
     tip = null;
+    width = null;
   }
 
   protected void setProperties(UIComponent component) {
@@ -56,6 +55,7 @@
     ComponentUtil.setStringProperty(component, ATTR_ALIGN, align);
     ComponentUtil.setMarkup(component, markup);
     ComponentUtil.setStringProperty(component, ATTR_TIP, tip);
+    ComponentUtil.setStringProperty(component, ATTR_WIDTH, width);
   }
 
   public void setMarkup(String markup) {
@@ -80,5 +80,9 @@
 
   public void setTip(String tip) {
     this.tip = tip;
+  }
+
+  public void setWidth(String width) {
+    this.width = width;
   }
 }

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTagDeclaration.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTagDeclaration.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/component/ColumnTagDeclaration.java Mon Oct 29 13:27:47 2007
@@ -24,6 +24,7 @@
 import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
 import org.apache.myfaces.tobago.taglib.decl.HasLabel;
 import org.apache.myfaces.tobago.taglib.decl.HasTip;
+import org.apache.myfaces.tobago.taglib.decl.HasWidth;
 
 /*
  * Created by IntelliJ IDEA.
@@ -39,7 +40,9 @@
 @Tag(name = "column")
 @UIComponentTag(
     uiComponent = "org.apache.myfaces.tobago.component.UIColumn")
-public interface ColumnTagDeclaration extends TobagoTagDeclaration, HasIdBindingAndRendered, HasLabel, HasTip {
+    //rendererType = "Column")
+public interface ColumnTagDeclaration extends TobagoTagDeclaration, HasIdBindingAndRendered, HasLabel, HasTip,
+    HasWidth {
   /**
    * Alignment of this column.
    */

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasWidth.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasWidth.java?rev=589840&r1=589839&r2=589840&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasWidth.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasWidth.java Mon Oct 29 13:27:47 2007
@@ -24,9 +24,11 @@
  * $Id$
  */
 public interface HasWidth {
-  /**
-   *  The width for this component.
-   */
+ /**
+  *  The width for this component.
+  *  This value is used in the gridLayouts columns attribute.
+  *  See gridLayout tag for valid values.
+  */
   @TagAttribute @UIComponentTagAttribute()
   void setWidth(String width);
 }