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 2015/09/04 10:38:22 UTC

svn commit: r1701175 - in /myfaces/tobago/branches/tobago-3.0.x: tobago-core/src/main/java/org/apache/myfaces/tobago/component/ tobago-example/tobago-example-demo/src/main/webapp/ tobago-example/tobago-example-demo/src/main/webapp/content/11-layout/00/...

Author: lofwyr
Date: Fri Sep  4 08:38:22 2015
New Revision: 1701175

URL: http://svn.apache.org/r1701175
Log:
TOBAGO-1485: Label support of the tc-library, so the tx-tibrary will be unnecessary (and deprecated)
* implementation of segmentLeft and segmentRight

Modified:
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/LabelLayout.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/11-layout/00/labeled-layout.xhtml
    myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/logging-info.xhtml
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LabelLayoutRendererBase.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SegmentLayoutRenderer.java

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/LabelLayout.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/LabelLayout.java?rev=1701175&r1=1701174&r2=1701175&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/LabelLayout.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/LabelLayout.java Fri Sep  4 08:38:22 2015
@@ -19,7 +19,30 @@
 
 package org.apache.myfaces.tobago.component;
 
+import javax.faces.context.FacesContext;
+
 public enum LabelLayout {
 
-  none, flexLeft, flexRight, top, segmentLeft, segmentRight, flowLeft, flowRight
+  none, flexLeft, flexRight, top, segmentLeft, segmentRight, flowLeft, flowRight;
+
+  private static final String SEGMENT_TO_RENDER_KEY = LabelLayout.class.getName();
+
+  public static boolean isSegment(final LabelLayout labelLayout) {
+    return labelLayout == segmentLeft || labelLayout == segmentRight;
+  }
+
+  public static void setSegment(final FacesContext facesContext, final LabelLayout labelLayout) {
+    if (labelLayout != segmentLeft && labelLayout != segmentRight) {
+      throw new IllegalArgumentException("not supported: " + labelLayout);
+    }
+    facesContext.getAttributes().put(SEGMENT_TO_RENDER_KEY, labelLayout);
+  }
+
+  public static LabelLayout getSegment(final FacesContext facesContext) {
+    return (LabelLayout) facesContext.getAttributes().get(SEGMENT_TO_RENDER_KEY);
+  }
+
+  public static void removeSegment(FacesContext facesContext) {
+    facesContext.getAttributes().remove(SEGMENT_TO_RENDER_KEY);
+  }
 }

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/11-layout/00/labeled-layout.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/11-layout/00/labeled-layout.xhtml?rev=1701175&r1=1701174&r2=1701175&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/11-layout/00/labeled-layout.xhtml (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/11-layout/00/labeled-layout.xhtml Fri Sep  4 08:38:22 2015
@@ -22,53 +22,57 @@
                 xmlns:ui="http://java.sun.com/jsf/facelets">
   <ui:param name="title" value="Labeled layout - replaces the deprecated tx: library"/>
 
+  <tc:button label="Reload"/> Press "Reload" to check error style of the controls.
+
+  <tc:separator/>
+
   <tc:box label="labelLayout is not set (default is flexLeft)">
-    <tc:in label="In Label" value="some value"/>
-    <tc:date label="Date Label" />
+    <tc:in required="true" label="In Label"/>
+    <tc:date required="true" label="Date Label"/>
   </tc:box>
 
   <tc:box label="labelLayout=&quot;none&quot;">
-    <tc:in label="In Label" value="some value" labelLayout="none"/>
-    <tc:date label="Date Label" labelLayout="none"/>
+    <tc:in required="true" label="In Label" labelLayout="none"/>
+    <tc:date required="true" label="Date Label" labelLayout="none"/>
   </tc:box>
 
   <tc:box label="labelLayout=&quot;flexLeft&quot;">
-    <tc:in label="In Label" value="some value" labelLayout="flexLeft"/>
-    <tc:date label="Date Label" labelLayout="flexLeft"/>
+    <tc:in required="true" label="In Label" labelLayout="flexLeft"/>
+    <tc:date required="true" label="Date Label" labelLayout="flexLeft"/>
   </tc:box>
 
   <tc:box label="labelLayout=&quot;flexRight&quot;">
-    <tc:in label="In Label" value="some value" labelLayout="flexRight"/>
-    <tc:date label="Date Label" labelLayout="flexRight"/>
+    <tc:in required="true" label="In Label" labelLayout="flexRight"/>
+    <tc:date required="true" label="Date Label" labelLayout="flexRight"/>
   </tc:box>
 
   <tc:box label="labelLayout=&quot;top&quot;">
-    <tc:in label="In Label" value="some value" labelLayout="top"/>
-    <tc:date label="Date Label" labelLayout="top"/>
+    <tc:in required="true" label="In Label" labelLayout="top"/>
+    <tc:date required="true" label="Date Label" labelLayout="top"/>
   </tc:box>
 
-  <tc:box label="labelLayout=&quot;segmentLeft&quot; (FIXME: not impleented yet)">
-    <tc:segmentLayout large="2;10">
-      <tc:in label="In Label" value="some value" labelLayout="segmentLeft"/>
-      <tc:date label="Date Label" labelLayout="segmentLeft"/>
+  <tc:box label="labelLayout=&quot;segmentLeft&quot;">
+    <tc:segmentLayout large="3;9">
+      <tc:in required="true" label="In Label" labelLayout="segmentLeft"/>
+      <tc:date required="true" label="Date Label" labelLayout="segmentLeft"/>
     </tc:segmentLayout>
   </tc:box>
 
-  <tc:box label="labelLayout=&quot;segmentRight&quot; (FIXME: not impleented yet)">
-    <tc:segmentLayout large="2;10">
-      <tc:in label="In Label" value="some value" labelLayout="segmentRight"/>
-      <tc:date label="Date Label" labelLayout="segmentRight"/>
+  <tc:box label="labelLayout=&quot;segmentRight&quot; (FIXME: height of label breaks layout, try 6;6)">
+    <tc:segmentLayout large="9;3">
+      <tc:in required="true" label="In Label" labelLayout="segmentRight"/>
+      <tc:date required="true" label="Date Label" labelLayout="segmentRight"/>
     </tc:segmentLayout>
   </tc:box>
 
   <tc:box label="labelLayout=&quot;flowLeft&quot; (FIXME: not impleented yet)">
-    <tc:in label="In Label" value="some value" labelLayout="flowLeft"/>
-    <tc:date label="Date Label" labelLayout="flowLeft"/>
+    <tc:in required="true" label="In Label" labelLayout="flowLeft"/>
+    <tc:date required="true" label="Date Label" labelLayout="flowLeft"/>
   </tc:box>
 
   <tc:box label="labelLayout=&quot;flowRight&quot; (FIXME: not impleented yet)">
-    <tc:in label="In Label" value="some value" labelLayout="flowRight"/>
-    <tc:date label="Date Label" labelLayout="flowRight"/>
+    <tc:in required="true" label="In Label" labelLayout="flowRight"/>
+    <tc:date required="true" label="Date Label" labelLayout="flowRight"/>
   </tc:box>
 
 </ui:composition>

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/logging-info.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/logging-info.xhtml?rev=1701175&r1=1701174&r2=1701175&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/logging-info.xhtml (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/logging-info.xhtml Fri Sep  4 08:38:22 2015
@@ -29,10 +29,8 @@
       <tc:gridLayout rows="auto;auto;auto;*"/>
     </f:facet>
 
-    <tc:segmentLayout>
-      <tx:in label="Test Category" value="#{universalLoggingInfo.testCategory}"/>
-      <tc:button label="Update" action="#{universalLoggingInfo.update}"/>
-    </tc:segmentLayout>
+    <tc:in label="Test Category" value="#{universalLoggingInfo.testCategory}"/>
+    <tc:button label="Update" action="#{universalLoggingInfo.update}"/>
 
     <tc:separator/>
 

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LabelLayoutRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LabelLayoutRendererBase.java?rev=1701175&r1=1701174&r2=1701175&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LabelLayoutRendererBase.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/LabelLayoutRendererBase.java Fri Sep  4 08:38:22 2015
@@ -39,19 +39,50 @@ import java.io.IOException;
 
 /**
  * Manages the rendering of the <b>label</b> and the <b>field</b> together with different possibilities for
- * the position of the label (defined by {@link org.apache.myfaces.tobago.component.Attributes.LABEL_LAYOUT}
+ * the position of the label (defined by {@link org.apache.myfaces.tobago.component.Attributes#LABEL_LAYOUT}
  */
 public abstract class LabelLayoutRendererBase extends LayoutComponentRendererBase {
 
   @Override
   public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
+
     encodeBeginSurrounding(facesContext, component);
-    encodeBeginField(facesContext, component);
+
+    switch (((SupportsLabelLayout) component).getLabelLayout()) {
+      case segmentLeft:
+        if (LabelLayout.getSegment(facesContext) == LabelLayout.segmentRight) {
+          encodeBeginField(facesContext, component);
+        }
+        break;
+      case segmentRight:
+        if (LabelLayout.getSegment(facesContext) == LabelLayout.segmentLeft) {
+          encodeBeginField(facesContext, component);
+        }
+        break;
+      default:
+        encodeBeginField(facesContext, component);
+        break;
+    }
   }
 
   @Override
   public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
-    encodeEndField(facesContext, component);
+    switch (((SupportsLabelLayout) component).getLabelLayout()) {
+      case segmentLeft:
+        if (LabelLayout.getSegment(facesContext) == LabelLayout.segmentRight) {
+          encodeEndField(facesContext, component);
+        }
+        break;
+      case segmentRight:
+        if (LabelLayout.getSegment(facesContext) == LabelLayout.segmentLeft) {
+          encodeEndField(facesContext, component);
+        }
+        break;
+      default:
+        encodeEndField(facesContext, component);
+        break;
+    }
+
     encodeEndSurrounding(facesContext, component);
   }
 
@@ -85,13 +116,14 @@ public abstract class LabelLayoutRendere
     }
 
 //    if (labelLayout != LabelLayout.none) {
-      writer.startElement(HtmlElements.DIV, component);
+    writer.startElement(HtmlElements.DIV, component);
 //    }
 //    writer.writeClassAttribute(divClass, BootstrapClass.maximumSeverity(component));
     // todo: check if BootstrapClass.FORM_GROUP is needed, I've removed it, because of it's margin-bottom: 15px;
     // todo: so we lost too much space
     // todo: without it, e. g. an input field in the header will not be layouted correctly
     writer.writeClassAttribute(divClass, BootstrapClass.FORM_GROUP, BootstrapClass.maximumSeverity(component));
+
     switch (labelLayout) {
       case flexLeft:
         // todo: const, utils, etc.
@@ -108,9 +140,18 @@ public abstract class LabelLayoutRendere
     switch (labelLayout) {
       case none:
       case flexRight:
-      case segmentRight:
       case flowRight:
         break;
+      case segmentLeft:
+        if (LabelLayout.getSegment(facesContext) == LabelLayout.segmentLeft) {
+          encodeLabel(component, writer, labelLayout);
+        }
+        break;
+      case segmentRight:
+        if (LabelLayout.getSegment(facesContext) == LabelLayout.segmentRight) {
+          encodeLabel(component, writer, labelLayout);
+        }
+        break;
       default:
         encodeLabel(component, writer, labelLayout);
     }
@@ -123,7 +164,6 @@ public abstract class LabelLayoutRendere
 
     switch (labelLayout) {
       case flexRight:
-      case segmentRight:
       case flowRight:
         encodeLabel(component, writer, labelLayout);
         break;
@@ -132,7 +172,7 @@ public abstract class LabelLayoutRendere
     }
 
 //    if (labelLayout != LabelLayout.none) {
-      writer.endElement(HtmlElements.DIV);
+    writer.endElement(HtmlElements.DIV);
 //    }
   }
 

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SegmentLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SegmentLayoutRenderer.java?rev=1701175&r1=1701174&r2=1701175&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SegmentLayoutRenderer.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SegmentLayoutRenderer.java Fri Sep  4 08:38:22 2015
@@ -20,9 +20,11 @@
 package org.apache.myfaces.tobago.renderkit.html.standard.standard.tag;
 
 import org.apache.myfaces.tobago.component.Facets;
-import org.apache.myfaces.tobago.component.UISegmentLayout;
+import org.apache.myfaces.tobago.component.LabelLayout;
+import org.apache.myfaces.tobago.component.SupportsLabelLayout;
 import org.apache.myfaces.tobago.component.UIExtensionPanel;
 import org.apache.myfaces.tobago.component.UILabel;
+import org.apache.myfaces.tobago.component.UISegmentLayout;
 import org.apache.myfaces.tobago.internal.component.AbstractUISegmentLayout;
 import org.apache.myfaces.tobago.layout.LayoutContainer;
 import org.apache.myfaces.tobago.renderkit.RendererBase;
@@ -92,13 +94,9 @@ public class SegmentLayoutRenderer exten
     for (UIComponent child : children) {
       if (child.isRendered()) {
         if (child instanceof UIExtensionPanel) {
-//          writer.startElement(HtmlElements.DIV, null);
-//          writer.writeClassAttribute(BootstrapClass.FORM_GROUP); or
-//          writer.writeClassAttribute(BootstrapClass.ROW);
           for (UIComponent subChild : child.getChildren()) {
             encodeChild(facesContext, writer, generator, subChild);
           }
-//          writer.endElement(HtmlElements.DIV);
         } else {
           encodeChild(facesContext, writer, generator, child);
         }
@@ -118,15 +116,35 @@ public class SegmentLayoutRenderer exten
       }
       generator.generate(currentCss);
       RenderUtils.encode(facesContext, child);
-    } else {
-      writer.startElement(HtmlElements.DIV, null);
-      Css css = new Css();
-      generator.generate(css);
-      writer.writeClassAttribute(css.encode());
-      RenderUtils.encode(facesContext, child);
-      writer.endElement(HtmlElements.DIV);
+      generator.next();
+    } else if (child instanceof SupportsLabelLayout
+        && LabelLayout.isSegment(((SupportsLabelLayout) child).getLabelLayout())) {
+
+      // left part
+      LabelLayout.setSegment(facesContext, LabelLayout.segmentLeft);
+      encodeDiv(facesContext, writer, generator, child);
+      generator.next();
+
+      // right part
+      LabelLayout.setSegment(facesContext, LabelLayout.segmentRight);
+      encodeDiv(facesContext, writer, generator, child);
+      generator.next();
+
+      LabelLayout.removeSegment(facesContext);
+    } else { // normal case
+      encodeDiv(facesContext, writer, generator, child);
+      generator.next();
     }
-    generator.next();
+  }
+
+  private void encodeDiv(FacesContext facesContext, TobagoResponseWriter writer, BootstrapCssGenerator generator,
+                         UIComponent child) throws IOException {
+    writer.startElement(HtmlElements.DIV, null);
+    Css css = new Css();
+    generator.generate(css);
+    writer.writeClassAttribute(css.encode());
+    RenderUtils.encode(facesContext, child);
+    writer.endElement(HtmlElements.DIV);
   }
 
   @Override