myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bom...@apache.org
Subject svn commit: r491816 - in /myfaces/tobago/trunk: contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/ core/src/main/java/org/apache/myfaces/tobago/component/
Date Tue, 02 Jan 2007 15:31:04 GMT
Author: bommel
Date: Tue Jan  2 07:31:03 2007
New Revision: 491816

URL: http://svn.apache.org/viewvc?view=rev&rev=491816
Log:
(TOBAGO-107) tc:page should use a reasonable default width+height and state

Added:
    myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/UIPageRule.java
Modified:
    myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java

Modified: myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java?view=diff&rev=491816&r1=491815&r2=491816
==============================================================================
--- myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java
(original)
+++ myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/TobagoComponentHandler.java
Tue Jan  2 07:31:03 2007
@@ -25,6 +25,7 @@
 import org.apache.myfaces.tobago.event.TabChangeSource;
 import org.apache.myfaces.tobago.event.SheetStateChangeSource;
 import org.apache.myfaces.tobago.component.OnComponentCreated;
+import org.apache.myfaces.tobago.component.UIPage;
 import static org.apache.myfaces.tobago.TobagoConstants.TOBAGO_COMPONENT_CREATED;
 
 import javax.faces.component.UIComponent;
@@ -45,6 +46,9 @@
     MetaRuleset metaRuleset = super.createMetaRuleset(aClass);
     if (SortActionSource.class.isAssignableFrom(aClass)) {
       metaRuleset.addRule(SortActionSourceRule.INSTANCE);
+    }
+    if (UIPage.class.isAssignableFrom(aClass)) {
+      metaRuleset.addRule(UIPageRule.INSTANCE);
     }
     if (TabChangeSource.class.isAssignableFrom(aClass)) {
       metaRuleset.addRule(TabChangeSourceRule.INSTANCE);

Added: myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/UIPageRule.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/UIPageRule.java?view=auto&rev=491816
==============================================================================
--- myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/UIPageRule.java
(added)
+++ myfaces/tobago/trunk/contrib/facelets/src/main/java/org/apache/myfaces/tobago/facelets/UIPageRule.java
Tue Jan  2 07:31:03 2007
@@ -0,0 +1,102 @@
+package org.apache.myfaces.tobago.facelets;
+
+/*
+ * 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.
+ */
+
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.el.LegacyValueBinding;
+import org.apache.myfaces.tobago.component.UIPage;
+import org.apache.myfaces.tobago.component.ComponentUtil;
+
+import javax.faces.component.UIComponent;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: bommel
+ * Date: Jan 2, 2007
+ * Time: 3:35:58 PM
+ */
+public class UIPageRule extends MetaRule {
+  public static final UIPageRule INSTANCE = new UIPageRule();
+
+  public Metadata applyRule(String name, TagAttribute attribute,
+      MetadataTarget metadataTarget) {
+    if (metadataTarget.isTargetInstanceOf(UIPage.class)) {
+      if (!attribute.isLiteral()) {
+        Class type = metadataTarget.getPropertyType(name);
+        if (type == null) {
+          type = Object.class;
+        }
+        return new UIPageDimensionExpression(name, type, attribute);
+      } else {
+        if ("width".equals(name)) {
+          return new UIPageWidthMapper(attribute);
+        }
+        if ("height".equals(name)) {
+          return new UIPageHeightMapper(attribute);
+        }
+      }
+    }
+    return null;
+  }
+
+  static final class UIPageDimensionExpression extends Metadata {
+    private final String name;
+    private final TagAttribute attr;
+    private final Class type;
+
+    public UIPageDimensionExpression(String name, Class type, TagAttribute attr) {
+      this.name = name;
+      this.attr = attr;
+      this.type = type;
+    }
+
+    public void applyMetadata(FaceletContext ctx, Object instance) {
+      ((UIComponent) instance).setValueBinding(name, new LegacyValueBinding(attr.getValueExpression(ctx,
type)));
+    }
+  }
+
+  static final class UIPageWidthMapper extends Metadata {
+    private final TagAttribute attribute;
+
+    public UIPageWidthMapper(TagAttribute attribute) {
+      this.attribute = attribute;
+    }
+
+    public void applyMetadata(FaceletContext ctx, Object instance) {
+      UIPage page = (UIPage) instance;
+      page.setWidth(new Integer(ComponentUtil.removePx(attribute.getValue())));
+    }
+  }
+
+  static final class UIPageHeightMapper extends Metadata {
+    private final TagAttribute attribute;
+
+    public UIPageHeightMapper(TagAttribute attribute) {
+      this.attribute = attribute;
+    }
+
+    public void applyMetadata(FaceletContext ctx, Object instance) {
+      UIPage page = (UIPage) instance;
+      page.setHeight(new Integer(ComponentUtil.removePx(attribute.getValue())));
+    }
+  }
+}

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java?view=diff&rev=491816&r1=491815&r2=491816
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
(original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/ComponentUtil.java
Tue Jan  2 07:31:03 2007
@@ -644,7 +644,7 @@
     }
   }
 
-  private static String removePx(String value) {
+  public static String removePx(String value) {
     if (value!=null&&value.endsWith("px")) {
       value = value.substring(0, value.length() - 2);
     }



Mime
View raw message