You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2017/02/09 15:23:14 UTC

svn commit: r1782344 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/component/ tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/rendere...

Author: lofwyr
Date: Thu Feb  9 15:23:14 2017
New Revision: 1782344

URL: http://svn.apache.org/viewvc?rev=1782344&view=rev
Log:
TOBAGO-1515 Offsets for SegementLayout
* add a <tc:segmentLayoutContraint/> tag with the attributes
'offsetExtraSmall', 'offsetSmall', 'offsetMedium' and 'offsetLarge'
[developed by hnoeth]

Added:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/SegmentLayoutConstraintHandler.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutConstraintTagDeclaration.java
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/16-layout/30-segment/segment-layout.xhtml

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java?rev=1782344&r1=1782343&r2=1782344&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/component/Attributes.java Thu Feb  9 15:23:14 2017
@@ -144,6 +144,22 @@ public enum Attributes {
   name,
   navigate,
   numberStyle,
+  /**
+   * Used by a layout manager
+   */
+  offsetExtraSmall,
+  /**
+   * Used by a layout manager
+   */
+  offsetLarge,
+  /**
+   * Used by a layout manager
+   */
+  offsetMedium,
+  /**
+   * Used by a layout manager
+   */
+  offsetSmall,
   omit,
   /** @deprecated */
   @Deprecated

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/SegmentLayoutConstraintHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/SegmentLayoutConstraintHandler.java?rev=1782344&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/SegmentLayoutConstraintHandler.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/SegmentLayoutConstraintHandler.java Thu Feb  9 15:23:14 2017
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.apache.myfaces.tobago.facelets;
+
+import org.apache.myfaces.tobago.component.Attributes;
+
+import javax.faces.component.UIComponent;
+import javax.faces.view.facelets.FaceletContext;
+import javax.faces.view.facelets.TagAttribute;
+import javax.faces.view.facelets.TagConfig;
+import javax.faces.view.facelets.TagHandler;
+import java.io.IOException;
+import java.util.Map;
+
+public class SegmentLayoutConstraintHandler extends TagHandler {
+
+  private final TagAttribute offsetExtraSmall;
+  private final TagAttribute offsetSmall;
+  private final TagAttribute offsetMedium;
+  private final TagAttribute offsetLarge;
+
+  public SegmentLayoutConstraintHandler(TagConfig config) {
+    super(config);
+    offsetExtraSmall = getAttribute(Attributes.offsetExtraSmall.getName());
+    offsetSmall = getAttribute(Attributes.offsetSmall.getName());
+    offsetMedium = getAttribute(Attributes.offsetMedium.getName());
+    offsetLarge = getAttribute(Attributes.offsetLarge.getName());
+  }
+
+  @Override
+  public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException {
+    final Map<String, Object> attributes = parent.getAttributes();
+
+    if (offsetExtraSmall != null) {
+      if (offsetExtraSmall.isLiteral()) {
+        attributes.put(Attributes.offsetExtraSmall.getName(), offsetExtraSmall.getValue());
+      } else {
+        parent.setValueExpression(Attributes.offsetExtraSmall.getName(),
+            offsetExtraSmall.getValueExpression(faceletContext, Integer.TYPE));
+      }
+    }
+
+    if (offsetSmall != null) {
+      if (offsetSmall.isLiteral()) {
+        attributes.put(Attributes.offsetSmall.getName(), offsetSmall.getValue());
+      } else {
+        parent.setValueExpression(Attributes.offsetSmall.getName(),
+            offsetSmall.getValueExpression(faceletContext, Integer.TYPE));
+      }
+    }
+
+    if (offsetMedium != null) {
+      if (offsetMedium.isLiteral()) {
+        attributes.put(Attributes.offsetMedium.getName(), offsetMedium.getValue());
+      } else {
+        parent.setValueExpression(Attributes.offsetMedium.getName(),
+            offsetMedium.getValueExpression(faceletContext, Integer.TYPE));
+      }
+    }
+
+    if (offsetLarge != null) {
+      if (offsetLarge.isLiteral()) {
+        attributes.put(Attributes.offsetLarge.getName(), offsetLarge.getValue());
+      } else {
+        parent.setValueExpression(Attributes.offsetLarge.getName(),
+            offsetLarge.getValueExpression(faceletContext, Integer.TYPE));
+      }
+    }
+  }
+}

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java?rev=1782344&r1=1782343&r2=1782344&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SegmentLayoutRenderer.java Thu Feb  9 15:23:14 2017
@@ -23,11 +23,11 @@ import org.apache.myfaces.tobago.compone
 import org.apache.myfaces.tobago.component.SupportsLabelLayout;
 import org.apache.myfaces.tobago.component.UISegmentLayout;
 import org.apache.myfaces.tobago.internal.component.AbstractUISegmentLayout;
+import org.apache.myfaces.tobago.internal.util.RenderUtils;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
 import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
 import org.apache.myfaces.tobago.renderkit.css.Classes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
-import org.apache.myfaces.tobago.internal.util.RenderUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -111,7 +111,7 @@ public class SegmentLayoutRenderer exten
       FacesContext facesContext, TobagoResponseWriter writer, BootstrapClass.Generator generator, UIComponent child)
       throws IOException {
     writer.startElement(HtmlElements.DIV);
-    writer.writeClassAttribute(null, null, generator.generate());
+    writer.writeClassAttribute(null, null, generator.generate(child));
     RenderUtils.encode(facesContext, child);
     writer.endElement(HtmlElements.DIV);
   }
@@ -121,5 +121,4 @@ public class SegmentLayoutRenderer exten
     final TobagoResponseWriter writer = getResponseWriter(facesContext);
     writer.endElement(HtmlElements.DIV);
   }
-
 }

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutConstraintTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutConstraintTagDeclaration.java?rev=1782344&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutConstraintTagDeclaration.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SegmentLayoutConstraintTagDeclaration.java Thu Feb  9 15:23:14 2017
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+package org.apache.myfaces.tobago.internal.taglib.component;
+
+import org.apache.myfaces.tobago.apt.annotation.SimpleTag;
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
+
+import javax.el.ValueExpression;
+
+/**
+ * Set a offset for the parent UIComponent withing a segment layout.
+ */
+@Tag(name = "segmentLayoutConstraint")
+@SimpleTag(faceletHandler = "org.apache.myfaces.tobago.facelets.SegmentLayoutConstraintHandler")
+public interface SegmentLayoutConstraintTagDeclaration {
+
+  /**
+   * The number of columns this component moves to the right for extra small devices.
+   */
+  @TagAttribute(type = "java.lang.Integer")
+  void setOffsetExtraSmall(final ValueExpression offsetExtraSmall);
+
+  /**
+   * The number of columns this component moves to the right for small devices.
+   */
+  @TagAttribute(type = "java.lang.Integer")
+  void setOffsetSmall(final ValueExpression offsetSmall);
+
+  /**
+   * The number of columns this component moves to the right for medium devices.
+   */
+  @TagAttribute(type = "java.lang.Integer")
+  void setOffsetMedium(final ValueExpression offsetMedium);
+
+  /**
+   * The number of columns this component moves to the right for large devices.
+   */
+  @TagAttribute(type = "java.lang.Integer")
+  void setOffsetLarge(final ValueExpression offsetLarge);
+}

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java?rev=1782344&r1=1782343&r2=1782344&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java Thu Feb  9 15:23:14 2017
@@ -19,6 +19,7 @@
 
 package org.apache.myfaces.tobago.renderkit.css;
 
+import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.layout.ColumnPartition;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 
@@ -26,6 +27,7 @@ import javax.faces.application.FacesMess
 import javax.faces.component.UIComponent;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * CSS classes for the Bootstrap Library.
@@ -145,6 +147,53 @@ public enum BootstrapClass implements Cs
   NAVBAR_NAV("navbar-nav"),
   NAVBAR_TOGGLEABLE_XS("navbar-toggleable-xs"),
   NAVBAR_TOGGLER("navbar-toggler"),
+  OFFSET_LG_0("offset-lg-0"),
+  OFFSET_LG_1("offset-lg-1"),
+  OFFSET_LG_2("offset-lg-2"),
+  OFFSET_LG_3("offset-lg-3"),
+  OFFSET_LG_4("offset-lg-4"),
+  OFFSET_LG_5("offset-lg-5"),
+  OFFSET_LG_6("offset-lg-6"),
+  OFFSET_LG_7("offset-lg-7"),
+  OFFSET_LG_8("offset-lg-8"),
+  OFFSET_LG_9("offset-lg-9"),
+  OFFSET_LG_10("offset-lg-10"),
+  OFFSET_LG_11("offset-lg-11"),
+  OFFSET_MD_0("offset-md-0"),
+  OFFSET_MD_1("offset-md-1"),
+  OFFSET_MD_2("offset-md-2"),
+  OFFSET_MD_3("offset-md-3"),
+  OFFSET_MD_4("offset-md-4"),
+  OFFSET_MD_5("offset-md-5"),
+  OFFSET_MD_6("offset-md-6"),
+  OFFSET_MD_7("offset-md-7"),
+  OFFSET_MD_8("offset-md-8"),
+  OFFSET_MD_9("offset-md-9"),
+  OFFSET_MD_10("offset-md-10"),
+  OFFSET_MD_11("offset-md-11"),
+  OFFSET_SM_0("offset-sm-0"),
+  OFFSET_SM_1("offset-sm-1"),
+  OFFSET_SM_2("offset-sm-2"),
+  OFFSET_SM_3("offset-sm-3"),
+  OFFSET_SM_4("offset-sm-4"),
+  OFFSET_SM_5("offset-sm-5"),
+  OFFSET_SM_6("offset-sm-6"),
+  OFFSET_SM_7("offset-sm-7"),
+  OFFSET_SM_8("offset-sm-8"),
+  OFFSET_SM_9("offset-sm-9"),
+  OFFSET_SM_10("offset-sm-10"),
+  OFFSET_SM_11("offset-sm-11"),
+  OFFSET_XS_1("offset-xs-1"),
+  OFFSET_XS_2("offset-xs-2"),
+  OFFSET_XS_3("offset-xs-3"),
+  OFFSET_XS_4("offset-xs-4"),
+  OFFSET_XS_5("offset-xs-5"),
+  OFFSET_XS_6("offset-xs-6"),
+  OFFSET_XS_7("offset-xs-7"),
+  OFFSET_XS_8("offset-xs-8"),
+  OFFSET_XS_9("offset-xs-9"),
+  OFFSET_XS_10("offset-xs-10"),
+  OFFSET_XS_11("offset-xs-11"),
   OPEN("open"),
   PAGE_ITEM("page-item"),
   PAGE_LINK("page-link"),
@@ -233,6 +282,22 @@ public enum BootstrapClass implements Cs
         COL_LG_5, COL_LG_6, COL_LG_7, COL_LG_8,
         COL_LG_9, COL_LG_10, COL_LG_11, COL_LG_12,
     };
+    private static final BootstrapClass[] OFFSET_EXTRA_SMALL = new BootstrapClass[]{
+        OFFSET_XS_1, OFFSET_XS_1, OFFSET_XS_2, OFFSET_XS_3, OFFSET_XS_4, OFFSET_XS_5,
+        OFFSET_XS_6, OFFSET_XS_7, OFFSET_XS_8, OFFSET_XS_9, OFFSET_XS_10, OFFSET_XS_11
+    };
+    private static final BootstrapClass[] OFFSET_SMALL = new BootstrapClass[]{
+        OFFSET_SM_0, OFFSET_SM_1, OFFSET_SM_2, OFFSET_SM_3, OFFSET_SM_4, OFFSET_SM_5,
+        OFFSET_SM_6, OFFSET_SM_7, OFFSET_SM_8, OFFSET_SM_9, OFFSET_SM_10, OFFSET_SM_11
+    };
+    private static final BootstrapClass[] OFFSET_MEDIUM = new BootstrapClass[]{
+        OFFSET_MD_0, OFFSET_MD_1, OFFSET_MD_2, OFFSET_MD_3, OFFSET_MD_4, OFFSET_MD_5,
+        OFFSET_MD_6, OFFSET_MD_7, OFFSET_MD_8, OFFSET_MD_9, OFFSET_MD_10, OFFSET_MD_11
+    };
+    private static final BootstrapClass[] OFFSET_LARGE = new BootstrapClass[]{
+        OFFSET_LG_0, OFFSET_LG_1, OFFSET_LG_2, OFFSET_LG_3, OFFSET_LG_4, OFFSET_LG_5,
+        OFFSET_LG_6, OFFSET_LG_7, OFFSET_LG_8, OFFSET_LG_9, OFFSET_LG_10, OFFSET_LG_11
+    };
 
     private final ColumnPartition extraSmall;
     private final ColumnPartition small;
@@ -246,7 +311,7 @@ public enum BootstrapClass implements Cs
         final ColumnPartition large) {
       if (extraSmall == null && small == null && medium == null && large == null) {
         this.extraSmall = ColumnPartition.PARTITION_12;
-      } else  {
+      } else {
         this.extraSmall = extraSmall;
       }
       this.small = small;
@@ -262,12 +327,17 @@ public enum BootstrapClass implements Cs
       index++;
     }
 
-    public BootstrapClass[] generate() {
+    public BootstrapClass[] generate(final UIComponent child) {
       ArrayList<BootstrapClass> result = new ArrayList<BootstrapClass>(4);
       generate(result, extraSmall, EXTRA_SMALL);
       generate(result, small, SMALL);
       generate(result, medium, MEDIUM);
       generate(result, large, LARGE);
+      final Map<String, Object> attributes = child.getAttributes();
+      generateOffset(result, attributes.get(Attributes.offsetExtraSmall.name()), OFFSET_EXTRA_SMALL);
+      generateOffset(result, attributes.get(Attributes.offsetSmall.name()), OFFSET_SMALL);
+      generateOffset(result, attributes.get(Attributes.offsetMedium.name()), OFFSET_MEDIUM);
+      generateOffset(result, attributes.get(Attributes.offsetLarge.name()), OFFSET_LARGE);
       return result.toArray(new BootstrapClass[result.size()]);
     }
 
@@ -277,5 +347,15 @@ public enum BootstrapClass implements Cs
         result.add(values[partition.getPart(index % partition.getSize()) - 1]);
       }
     }
+
+    private void generateOffset(final List<BootstrapClass> result, final Object offset, final BootstrapClass[] values) {
+      if (offset != null) {
+        int offsetIndex = Integer.valueOf((String) offset);
+        if (offsetIndex >= 0) {
+          offsetIndex = offsetIndex > 11 ? 11 : offsetIndex;
+          result.add(values[offsetIndex]);
+        }
+      }
+    }
   }
 }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/16-layout/30-segment/segment-layout.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/16-layout/30-segment/segment-layout.xhtml?rev=1782344&r1=1782343&r2=1782344&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/16-layout/30-segment/segment-layout.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/16-layout/30-segment/segment-layout.xhtml Thu Feb  9 15:23:14 2017
@@ -85,6 +85,40 @@
       <tc:in value="11"/>
       <tc:in value="12"/>
     </tc:segmentLayout>
+  </tc:section>
 
+  <tc:section label="Offset">
+    <p>An offset can be set for the different proportions with the
+      <code class="language-markup">&lt;tc:segmentLayoutConstraint/></code> tag which can have the attributes
+      <code>offsetExtraSmall</code>, <code>offsetSmall</code>,<code>offsetMedium</code> and
+      <code>offsetLarge</code>.</p>
+    <p>Possible values are from 1 to 11 for <code>offsetExtraSmall</code>.<br/>
+      For the other attributes possible values are from 0 to 11.<br/>
+      A <code>offsetMedium="0"</code> overwrite the offset from smaller proportions.</p>
+    <p>In the following example an offset is set for all proportions.</p>
+    <pre><code class="language-markup">&lt;tc:segmentLayout extraSmall="4;4;4" small="3;3;3;3" medium="2;2;2;2;2;2" large="1;1;1;1;1;1;1;1;1;1;1;1">
+  &lt;tc:in value="1"/>
+  &lt;tc:in value="2">
+    &lt;tc:segmentLayoutConstraint offsetExtraSmall="4" offsetSmall="6" offsetMedium="8" offsetLarge="10"/>
+  &lt;/tc:in>
+  &lt;tc:in value="3"/>
+  ...
+&lt;/tc:segmentLayout></code></pre>
+    <tc:segmentLayout extraSmall="4;4;4" small="3;3;3;3" medium="2;2;2;2;2;2" large="1;1;1;1;1;1;1;1;1;1;1;1">
+      <tc:in value="1"/>
+      <tc:in value="2">
+        <tc:segmentLayoutConstraint offsetExtraSmall="4" offsetSmall="6" offsetMedium="8" offsetLarge="10"/>
+      </tc:in>
+      <tc:in value="3"/>
+      <tc:in value="4"/>
+      <tc:in value="5"/>
+      <tc:in value="6"/>
+      <tc:in value="7"/>
+      <tc:in value="8"/>
+      <tc:in value="9"/>
+      <tc:in value="10"/>
+      <tc:in value="11"/>
+      <tc:in value="12"/>
+    </tc:segmentLayout>
   </tc:section>
 </ui:composition>