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 2022/09/07 15:28:20 UTC
[myfaces-tobago] branch main updated: feat: bar facet in sheet (#3152) (#3153)
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/main by this push:
new 58de7a2eeb feat: bar facet in sheet (#3152) (#3153)
58de7a2eeb is described below
commit 58de7a2eeb64f0bc5c746828975cd2d6fae78b87
Author: Udo Schnurpfeil <gi...@schnurpfeil.de>
AuthorDate: Wed Sep 7 17:28:15 2022 +0200
feat: bar facet in sheet (#3152) (#3153)
Sheet - Commands in Header may help to Select, Filter, ...
issue: TOBAGO-2156
Co-authored-by: Udo Schnurpfeil <ud...@irian.eu>
Co-authored-by: Udo Schnurpfeil <ud...@irian.eu>
---
.../internal/renderkit/renderer/SheetRenderer.java | 7 ++
.../taglib/component/ColumnTagDeclaration.java | 9 ++-
.../tobago/example/demo/SheetBarController.java | 88 +++++++++++++++++++++
.../myfaces/tobago/example/demo/SolarObject.java | 9 +++
.../myfaces/tobago/example/demo/SolarType.java | 25 ++++++
.../content/080-sheet/45-bar/Column_Bar.xhtml | 90 ++++++++++++++++++++++
6 files changed, 227 insertions(+), 1 deletion(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java
index 1d43f3d86a..1218dc8687 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/SheetRenderer.java
@@ -945,6 +945,13 @@ public class SheetRenderer<T extends AbstractUISheet> extends RendererBase<T> {
cellComponent.encodeAll(facesContext);
}
+ final UIComponent bar = ComponentUtils.getFacet(column, Facets.bar);
+ if (bar != null) {
+ insideBegin(facesContext, Facets.bar);
+ bar.encodeAll(facesContext);
+ insideEnd(facesContext, Facets.bar);
+ }
+
writer.endElement(HtmlElements.SPAN);
if (!autoLayout) {
if (column.isResizable()) {
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ColumnTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ColumnTagDeclaration.java
index 1741b6dc40..be8bd5afc8 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ColumnTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/ColumnTagDeclaration.java
@@ -19,10 +19,12 @@
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.TagAttribute;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
+import org.apache.myfaces.tobago.component.Facets;
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasIdBindingAndRendered;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasLabel;
@@ -46,7 +48,12 @@ import jakarta.faces.component.UIColumn;
interfaces = {
// As long as no behavior event names are defined, ClientBehaviorHolder must be implemented for Mojarra.
"jakarta.faces.component.behavior.ClientBehaviorHolder"
- })
+ },
+ facets = {
+ @Facet(name = Facets.BAR,
+ description = "Contains some code to be placed in the header at the bar position.")
+ }
+)
public interface ColumnTagDeclaration
extends HasIdBindingAndRendered, HasLabel, HasTip, IsVisual {
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetBarController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetBarController.java
new file mode 100644
index 0000000000..351464ece6
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SheetBarController.java
@@ -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.example.demo;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.SessionScoped;
+import jakarta.inject.Inject;
+import jakarta.inject.Named;
+import org.apache.myfaces.tobago.model.SheetState;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@SessionScoped
+@Named
+public class SheetBarController implements Serializable {
+
+ @Inject
+ private AstroData astroData;
+
+ private List<SolarObject> solarList;
+
+ private SheetState state;
+
+ @PostConstruct
+ private void init() {
+ solarList = astroData.findAll().collect(Collectors.toList());
+ }
+
+ public List<SolarObject> getSolarList() {
+ return solarList;
+ }
+
+ public SheetState getState() {
+ return state;
+ }
+
+ public void setState(SheetState state) {
+ this.state = state;
+ }
+
+ public void selectAllOnServer() {
+ final List<Integer> selectedRows = state.getSelectedRows();
+ selectedRows.clear();
+ for (int i = 0; i < solarList.size(); i++) {
+ selectedRows.add(i);
+ }
+ }
+
+ public void deselectAllOnServer() {
+ final List<Integer> selectedRows = state.getSelectedRows();
+ selectedRows.clear();
+ }
+
+ public void all() {
+ init();
+ }
+
+ public void starsOnly() {
+ solarList = astroData.findAll().filter(object -> object.getType() == SolarType.STAR).collect(Collectors.toList());
+ }
+
+ public void planetsOnly() {
+ solarList = astroData.findAll().filter(object -> object.getType() == SolarType.PLANET).collect(Collectors.toList());
+ }
+
+ public void moonsOnly() {
+ solarList = astroData.findAll().filter(object -> object.getType() == SolarType.MOON).collect(Collectors.toList());
+ }
+}
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SolarObject.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SolarObject.java
index 22178aa0c4..2735493af0 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SolarObject.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SolarObject.java
@@ -55,6 +55,8 @@ public class SolarObject implements Serializable {
private List<Element> chemicalComposition;
+ private SolarType type;
+
public SolarObject(
final String name, final String number, final String orbit, final Integer distance, final Double period,
final Double incl, final Double eccen, final String discoverer, final Integer discoverYear) {
@@ -190,6 +192,13 @@ public class SolarObject implements Serializable {
this.chemicalComposition = chemicalComposition;
}
+ public SolarType getType() {
+ if (type == null) {
+ type = name.equals("Sun") ? SolarType.STAR : orbit.equals("Sun") ? SolarType.PLANET : SolarType.MOON;
+ }
+ return type;
+ }
+
public String toString() {
return name;
}
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SolarType.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SolarType.java
new file mode 100644
index 0000000000..78c2b759b2
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/SolarType.java
@@ -0,0 +1,25 @@
+/*
+ * 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.example.demo;
+
+public enum SolarType {
+
+ STAR, PLANET, MOON
+}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/45-bar/Column_Bar.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/45-bar/Column_Bar.xhtml
new file mode 100644
index 0000000000..5ceded44d4
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/45-bar/Column_Bar.xhtml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * 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.
+-->
+
+<ui:composition template="/main.xhtml"
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+ xmlns:f="http://xmlns.jcp.org/jsf/core"
+ xmlns="http://www.w3.org/1999/xhtml">
+
+ <p>With the bar-facet something can be placed in the header cell of a column.
+ </p>
+ <p>Tag Library Documentation:
+ <tc:link label="<tc:sheet/>" image="#{request.contextPath}/image/feather-leaf.png"
+ link="#{apiController.tobagoTld}/tc/sheet.html"/>
+ |
+ <tc:link label="<tc:column/>" image="#{request.contextPath}/image/feather-leaf.png"
+ link="#{apiController.tobagoTld}/tc/column.html"/></p>
+
+ <tc:section label="Bar Facet">
+ <tc:sheet id="sheet" value="#{sheetBarController.solarList}"
+ state="#{sheetBarController.state}" var="object" rows="15">
+ <tc:columnSelector>
+ <f:facet name="bar">
+ <tc:button omit="true">
+ <tc:link label="Select all on server" action="#{sheetBarController.selectAllOnServer}">
+ <f:ajax render="sheet"/>
+ </tc:link>
+ <tc:link label="Deselect all on server" action="#{sheetBarController.deselectAllOnServer}">
+ <f:ajax render="sheet"/>
+ </tc:link>
+ </tc:button>
+ </f:facet>
+ </tc:columnSelector>
+ <tc:column label="Name">
+ <f:facet name="bar">
+ <tc:button label="Filter" omit="true">
+ <tc:link label="All" action="#{sheetBarController.all}">
+ <f:ajax render="sheet"/>
+ </tc:link>
+ <tc:link label="Planets only" action="#{sheetBarController.planetsOnly}">
+ <f:ajax render="sheet"/>
+ </tc:link>
+ <tc:link label="Moons only" action="#{sheetBarController.moonsOnly}">
+ <f:ajax render="sheet"/>
+ </tc:link>
+ <tc:link label="Stars only" action="#{sheetBarController.starsOnly}">
+ <f:ajax render="sheet"/>
+ </tc:link>
+ </tc:button>
+ </f:facet>
+ <tc:out value="#{object.name}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Orbit">
+ <tc:out value="#{object.orbit}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Period (Days)">
+ <tc:out value="#{object.period}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Discoverer">
+ <tc:out value="#{object.discoverer}" labelLayout="skip"/>
+ </tc:column>
+ <tc:column label="Year">
+ <tc:out value="#{object.discoverYear}" labelLayout="skip"/>
+ </tc:column>
+ </tc:sheet>
+ </tc:section>
+
+ <p>
+ There are other possible filtering methods in the
+ <tc:link label="Sheet Filter"
+ outcome="/content/080-sheet/50-filter/Sheet_Filter.xhtml"/>
+ page.
+ </p>
+</ui:composition>