myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1702464 - in /myfaces/tobago/branches/tobago-3.0.x: tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ tobago-core/src/main/java/org/apache/myfaces/t...
Date Fri, 11 Sep 2015 13:46:32 GMT
Author: lofwyr
Date: Fri Sep 11 13:46:30 2015
New Revision: 1702464

URL: http://svn.apache.org/r1702464
Log:
TOBAGO-1489: Optimize enums used for attributes in taglib.

Modified:
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/FlowLayoutRule.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FlowLayoutTagDeclaration.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/TextAlign.java
    myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.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/SheetRenderer.java

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/FlowLayoutRule.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/FlowLayoutRule.java?rev=1702464&r1=1702463&r2=1702464&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/FlowLayoutRule.java
(original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/facelets/FlowLayoutRule.java
Fri Sep 11 13:46:30 2015
@@ -22,7 +22,6 @@ package org.apache.myfaces.tobago.facele
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.UIFlowLayout;
 import org.apache.myfaces.tobago.layout.Measure;
-import org.apache.myfaces.tobago.layout.TextAlign;
 
 import javax.faces.view.facelets.FaceletContext;
 import javax.faces.view.facelets.MetaRule;
@@ -37,9 +36,6 @@ public class FlowLayoutRule extends Meta
   public Metadata applyRule(final String name, final TagAttribute attribute, final MetadataTarget
metadataTarget) {
     if (metadataTarget.isTargetInstanceOf(UIFlowLayout.class)) {
       if (attribute.isLiteral()) {
-        if (Attributes.TEXT_ALIGN.equals(name)) {
-          return new TextAlignMapper(attribute);
-        }
         if (Attributes.MARGIN_LEFT.equals(name)) {
           return new MarginLeftMapper(attribute);
         }
@@ -60,19 +56,6 @@ public class FlowLayoutRule extends Meta
     return null;
   }
 
-  static final class TextAlignMapper extends Metadata {
-    private final TagAttribute attribute;
-
-    TextAlignMapper(final TagAttribute attribute) {
-      this.attribute = attribute;
-    }
-
-    public void applyMetadata(final FaceletContext ctx, final Object instance) {
-      final UIFlowLayout gridLayout = (UIFlowLayout) instance;
-      gridLayout.setTextAlign(TextAlign.parse(attribute.getValue()));
-    }
-  }
-
   static final class MarginLeftMapper extends Metadata {
     private final TagAttribute attribute;
 

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FlowLayoutTagDeclaration.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FlowLayoutTagDeclaration.java?rev=1702464&r1=1702463&r2=1702464&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FlowLayoutTagDeclaration.java
(original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/FlowLayoutTagDeclaration.java
Fri Sep 11 13:46:30 2015
@@ -53,15 +53,15 @@ public interface FlowLayoutTagDeclaratio
 
   /**
    * The alignment of the elements inside of the container, possible values are:
-   * {@value TextAlign#STRING_LEFT},
-   * {@value TextAlign#STRING_RIGHT},
-   * {@value TextAlign#STRING_CENTER} und
-   * {@value TextAlign#STRING_JUSTIFY}.
+   * {@link TextAlign#left},
+   * {@link TextAlign#right},
+   * {@link TextAlign#center} und
+   * {@link TextAlign#justify}.
    */
   @TagAttribute
   @UIComponentTagAttribute(
       type = {"org.apache.myfaces.tobago.layout.TextAlign"},
-      defaultValue = "TextAlign.LEFT",
+      defaultValue = "TextAlign.left",
       allowedValues = {
           TextAlign.STRING_LEFT, TextAlign.STRING_RIGHT, TextAlign.STRING_CENTER, TextAlign.STRING_JUSTIFY})
   void setTextAlign(String textAlign);

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/TextAlign.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/TextAlign.java?rev=1702464&r1=1702463&r2=1702464&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/TextAlign.java
(original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/layout/TextAlign.java
Fri Sep 11 13:46:30 2015
@@ -19,53 +19,71 @@
 
 package org.apache.myfaces.tobago.layout;
 
-
-import java.util.HashMap;
-import java.util.Map;
-
-
+/**
+ * Values for text alignments used with CSS.
+ *
+ * Note: the enums are not capitalized, because of problems with {@link java.beans.PropertyEditor}.
+ */
 public enum TextAlign {
 
-  LEFT("left"),
-  RIGHT("right"),
-  CENTER("center"),
-  JUSTIFY("justify");
-
+  left,
+  right,
+  center,
+  justify;
+
+  /**
+   * @deprecated Since Tobago 3.0.0 Please use {@link TextAlign#left}
+   */
+  public static final TextAlign LEFT = left;
+
+  /**
+   * @deprecated Since Tobago 3.0.0 Please use {@link TextAlign#right}
+   */
+  public static final TextAlign RIGHT = right;
+
+  /**
+   * @deprecated Since Tobago 3.0.0 Please use {@link TextAlign#center}
+   */
+  public static final TextAlign CENTER = center;
+
+  /**
+   * @deprecated Since Tobago 3.0.0 Please use {@link TextAlign#justify}
+   */
+  public static final TextAlign JUSTIFY = justify;
+
+  /**
+   * Internal constant to use in annotations. Please use {@link TextAlign#left}
+   */
   public static final String STRING_LEFT = "left";
+
+  /**
+   * Internal constant to use in annotations. Please use {@link TextAlign#right}
+   */
   public static final String STRING_RIGHT = "right";
-  public static final String STRING_CENTER = "center";
-  public static final String STRING_JUSTIFY = "justify";
 
-  private final String value;
+  /**
+   * Internal constant to use in annotations. Please use {@link TextAlign#center}
+   */
+  public static final String STRING_CENTER = "center";
 
-  TextAlign(final String value) {
-    this.value = value;
-  }
+  /**
+   * Internal constant to use in annotations. Please use {@link TextAlign#justify}
+   */
+  public static final String STRING_JUSTIFY = "justify";
 
+  /**
+   * @deprecated Since Tobago 3.0.0 Please use {@link TextAlign:name}
+   */
   public String getValue() {
-    return value;
-  }
-
-  private static final Map<String, TextAlign> MAPPING;
-
-  static {
-    MAPPING = new HashMap<String, TextAlign>();
-
-    for (final TextAlign textAlign : TextAlign.values()) {
-      MAPPING.put(textAlign.getValue(), textAlign);
-    }
+    return name();
   }
 
+  /**
+   * @deprecated Since Tobago 3.0.0 Please use {@link TextAlign:valueOf}
+   */
+  @Deprecated
   public static TextAlign parse(final String string) {
-    if (string == null) {
-      return null;
-    }
-    final TextAlign value = MAPPING.get(string);
-    if (value != null) {
-      return value;
-    } else {
-      throw new IllegalArgumentException("Unknown value for TextAlign: '" + string + "'");
-    }
+    return valueOf(string);
   }
 
 }

Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.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/BootstrapClass.java?rev=1702464&r1=1702463&r2=1702464&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.java
(original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/BootstrapClass.java
Fri Sep 11 13:46:30 2015
@@ -161,13 +161,13 @@ public enum BootstrapClass implements Cs
 
   public static CssItem textAlign(final TextAlign textAlign) {
     switch (textAlign) {
-      case LEFT:
+      case left:
         return TEXT_LEFT;
-      case RIGHT:
+      case right:
         return TEXT_RIGHT;
-      case CENTER:
+      case center:
         return TEXT_CENTER;
-      case JUSTIFY:
+      case justify:
         return TEXT_JUSTIFY;
       default:
         return null;

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/SheetRenderer.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/SheetRenderer.java?rev=1702464&r1=1702463&r2=1702464&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/SheetRenderer.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/SheetRenderer.java
Fri Sep 11 13:46:30 2015
@@ -325,13 +325,21 @@ public class SheetRenderer extends Layou
         if (isPure(column)) {
           markup = markup.add(Markup.PURE);
         }
-        final TextAlign align = TextAlign.parse((String) column.getAttributes().get(Attributes.ALIGN));
-        if (align == TextAlign.RIGHT) {
-          markup = markup.add(Markup.RIGHT);
-        } else if (align == TextAlign.CENTER) {
-          markup = markup.add(Markup.CENTER);
-        } else if (align == TextAlign.JUSTIFY) {
-          markup = markup.add(Markup.JUSTIFY);
+        final String textAlign = (String) column.getAttributes().get(Attributes.ALIGN);
+        if (textAlign != null) {
+          switch (TextAlign.valueOf(textAlign)) {
+            case right:
+              markup = markup.add(Markup.RIGHT);
+              break;
+            case center:
+              markup = markup.add(Markup.CENTER);
+              break;
+            case justify:
+              markup = markup.add(Markup.JUSTIFY);
+              break;
+            default:
+              // nothing to do
+          }
         }
         writer.writeClassAttribute(Classes.create(sheet, "cell", markup));
 



Mime
View raw message