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 2014/12/10 18:08:15 UTC
svn commit: r1644482 - in /myfaces/tobago/branches/tobago-3.0.x:
tobago-core/src/main/java/org/apache/myfaces/tobago/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/
tobago-core/src/main/java/org/apache/myfaces/tobago/...
Author: lofwyr
Date: Wed Dec 10 17:08:14 2014
New Revision: 1644482
URL: http://svn.apache.org/r1644482
Log:
TOBAGO-1428: New tag <tc:section> for structured flow oriented pages
Added:
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISection.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.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/SectionRenderer.java
Modified:
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java?rev=1644482&r1=1644481&r2=1644482&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/component/RendererTypes.java Wed Dec 10 17:08:14 2014
@@ -58,6 +58,7 @@ public final class RendererTypes {
public static final String POPUP = "Popup";
public static final String PROGRESS = "Progress";
public static final String SCRIPT = "Script";
+ public static final String SECTION = "Section";
public static final String SELECT_BOOLEAN_CHECKBOX = "SelectBooleanCheckbox";
public static final String SELECT_MANY_CHECKBOX = "SelectManyCheckbox";
public static final String SELECT_MANY_LISTBOX = "SelectManyListbox";
Added: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISection.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISection.java?rev=1644482&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISection.java (added)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISection.java Wed Dec 10 17:08:14 2014
@@ -0,0 +1,76 @@
+/*
+ * 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.component;
+
+import org.apache.myfaces.tobago.component.Facets;
+import org.apache.myfaces.tobago.layout.LayoutComponent;
+import org.apache.myfaces.tobago.util.ComponentUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+
+public abstract class AbstractUISection extends UIComponentBase implements LayoutComponent {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AbstractUISection.class);
+
+ private int level;
+
+ public String getLabelToRender() {
+
+ final UIComponent facet = getFacet(Facets.LABEL);
+ if (facet instanceof UIOutput) {
+ return String.valueOf(((UIOutput) facet).getValue());
+ } else if (facet != null) {
+ LOG.warn("Wrong type: " + facet.getClass().getName());
+ }
+
+ return getLabel();
+ }
+
+ public abstract String getLabel();
+
+ @Override
+ public void encodeBegin(FacesContext context) throws IOException {
+
+ if (getLevel() == 0) {
+ final AbstractUISection section = ComponentUtils.findAncestor(getParent(), AbstractUISection.class);
+ if (section != null) {
+ setLevel(section.getLevel() + 1);
+ } else {
+ setLevel(1);
+ }
+ }
+
+ super.encodeBegin(context);
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public void setLevel(int level) {
+ this.level = level;
+ }
+}
Added: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.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/SectionTagDeclaration.java?rev=1644482&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.java (added)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/SectionTagDeclaration.java Wed Dec 10 17:08:14 2014
@@ -0,0 +1,51 @@
+/*
+ * 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.Facet;
+import org.apache.myfaces.tobago.apt.annotation.Tag;
+import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
+import org.apache.myfaces.tobago.component.Facets;
+import org.apache.myfaces.tobago.component.RendererTypes;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasCurrentMarkup;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasImage;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasMarkup;
+import org.apache.myfaces.tobago.internal.taglib.declaration.IsGridLayoutComponent;
+
+/**
+ * Renders a section or subsection.
+ */
+@Tag(name = "section")
+@UIComponentTag(
+ uiComponent = "org.apache.myfaces.tobago.component.UISection",
+ uiComponentBaseClass = "org.apache.myfaces.tobago.internal.component.AbstractUISection",
+ uiComponentFacesClass = "javax.faces.component.UIComponentBase",
+ componentFamily = "org.apache.myfaces.tobago.Section",
+ rendererType = RendererTypes.SECTION,
+ facets = {
+ @Facet(name = Facets.LABEL,
+ description = "This facet contains a UILabel",
+ allowedChildComponenents = "org.apache.myfaces.tobago.Label")})
+
+public interface SectionTagDeclaration
+ extends HasIdBindingAndRendered, HasLabel, IsGridLayoutComponent, HasImage, HasMarkup, HasCurrentMarkup {
+}
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java?rev=1644482&r1=1644481&r2=1644482&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlElements.java Wed Dec 10 17:08:14 2014
@@ -33,6 +33,12 @@ public final class HtmlElements {
public static final String DIV = "div";
public static final String FIELDSET = "fieldset";
public static final String FORM = "form";
+ public static final String H1 = "h1";
+ public static final String H2 = "h2";
+ public static final String H3 = "h3";
+ public static final String H4 = "h4";
+ public static final String H5 = "h5";
+ public static final String H6 = "h6";
public static final String HEAD = "head";
public static final String HR = "hr";
public static final String HTML = "html";
Added: myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SectionRenderer.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/SectionRenderer.java?rev=1644482&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SectionRenderer.java (added)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-theme/tobago-theme-standard/src/main/java/org/apache/myfaces/tobago/renderkit/html/standard/standard/tag/SectionRenderer.java Wed Dec 10 17:08:14 2014
@@ -0,0 +1,88 @@
+/*
+ * 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.renderkit.html.standard.standard.tag;
+
+import org.apache.myfaces.tobago.component.UISection;
+import org.apache.myfaces.tobago.context.ClientProperties;
+import org.apache.myfaces.tobago.internal.util.StringUtils;
+import org.apache.myfaces.tobago.renderkit.HtmlUtils;
+import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
+import org.apache.myfaces.tobago.renderkit.css.Classes;
+import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
+import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
+import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.io.IOException;
+
+public class SectionRenderer extends LayoutComponentRendererBase {
+
+ public void encodeBegin(final FacesContext facesContext, final UIComponent component) throws IOException {
+
+ final UISection section = (UISection) component;
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+
+ writer.startElement(HtmlElements.DIV, component);
+ writer.writeIdAttribute(section.getClientId(facesContext));
+ writer.writeClassAttribute(Classes.create(component));
+ HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
+
+ String label = section.getLabelToRender();
+ if (label != null) {
+ if (ClientProperties.getInstance(facesContext).getUserAgent().isMsie()) {
+ label = StringUtils.replace(label, " ", HtmlUtils.CHAR_NON_BEAKING_SPACE);
+ }
+
+ // todo: implement a level
+
+ final String tag;
+ switch (section.getLevel()) {
+ case 1:
+ tag = HtmlElements.H1;
+ break;
+ case 2:
+ tag = HtmlElements.H2;
+ break;
+ case 3:
+ tag = HtmlElements.H3;
+ break;
+ case 4:
+ tag = HtmlElements.H4;
+ break;
+ case 5:
+ tag = HtmlElements.H5;
+ break;
+ default:
+ tag = HtmlElements.H6;
+ }
+
+ writer.startElement(tag, component);
+ writer.writeText(label);
+ writer.endElement(tag);
+ }
+ }
+
+ public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
+
+ final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
+ writer.endElement(HtmlElements.DIV);
+ }
+}