This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch 3808-table.page.actions
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit 0f210ca3bdd3582d8d5e43f97c3e137356f6d205
Author: andi-huber <[email protected]>
AuthorDate: Tue Aug 27 07:29:44 2024 +0200

    CAUSEWAY-3808: adds table tooltip on bulk select all
---
 .../table/head/HeadersToolbarAbstract.java         |  17 ++++
 .../table/nav/pageact/PageActionChooser.html       |  44 ++++++++
 .../table/nav/pageact/PageActionChooser.java       | 111 +++++++++++++++++++++
 3 files changed, 172 insertions(+)

diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/head/HeadersToolbarAbstract.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/head/HeadersToolbarAbstract.java
index 3a055901be..92876a8622 100644
--- 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/head/HeadersToolbarAbstract.java
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/head/HeadersToolbarAbstract.java
@@ -41,11 +41,16 @@ import org.apache.wicket.markup.repeater.RefreshingView;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.model.Model;
 
+import org.apache.causeway.applib.services.i18n.TranslationContext;
+import org.apache.causeway.applib.services.i18n.TranslationService;
 import org.apache.causeway.commons.internal.base._Casts;
 import org.apache.causeway.core.config.CausewayConfiguration;
+import org.apache.causeway.core.metamodel.context.MetaModelContext;
 import 
org.apache.causeway.viewer.wicket.ui.components.collectioncontents.ajaxtable.columns.TitleColumn;
+import 
org.apache.causeway.viewer.wicket.ui.components.collectioncontents.ajaxtable.columns.ToggleboxColumn;
 import 
org.apache.causeway.viewer.wicket.ui.components.table.CausewayAjaxDataTable;
 import org.apache.causeway.viewer.wicket.ui.util.Wkt;
+import org.apache.causeway.viewer.wicket.ui.util.WktTooltips;
 
 import de.agilecoders.wicket.core.util.Attributes;
 
@@ -132,6 +137,10 @@ abstract class HeadersToolbarAbstract<S> extends 
AbstractToolbar {
                 Component sortIcon = newSortIcon("sortIcon", column, 
stateLocator);
                 header.add(label, sortIcon);
 
+                if(column instanceof ToggleboxColumn) {
+                    WktTooltips.addTooltip(header, 
+                            translate("Toggle select/unselect all rows across 
all pages."));
+                }
                 if(column instanceof TitleColumn) {
                     Wkt.cssAppend(header, "title-column");
                 }
@@ -139,6 +148,14 @@ abstract class HeadersToolbarAbstract<S> extends 
AbstractToolbar {
                         ? "column-sortable"
                         : "column-nonsortable");
             }
+            
+            private String translate(String text) {
+                var translationService = MetaModelContext.instance()
+                    .map(MetaModelContext::getTranslationService)
+                    .orElseGet(TranslationService::identity);
+                return 
translationService.translate(TranslationContext.named("Table"), text);
+            }
+            
         };
         add(headers);
     }
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/nav/pageact/PageActionChooser.html
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/nav/pageact/PageActionChooser.html
new file mode 100644
index 0000000000..8bfdfeed90
--- /dev/null
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/nav/pageact/PageActionChooser.html
@@ -0,0 +1,44 @@
+<?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.
+-->
+<html xmlns:wicket="http://wicket.apache.org";>
+    <body>
+        <wicket:panel>
+               <div class="dropdown">
+                   <button class="btn btn-sm btn-light dropdown-toggle" 
+                                                       type="button"
+                                                       
data-bs-toggle="dropdown" 
+                                                       aria-expanded="false">
+                       <span wicket:id="entriesPerPageLabel"></span>
+                   </button>
+                   <ul class="dropdown-menu" role="menu">
+                       <li wicket:id="pagesizeChoices">
+                                               <!-- link entry -->
+                                               <a href="#" 
wicket:id="pagesizeChoice" class="dropdown-item">
+                                                   <span 
wicket:id="viewItemIcon" class="ViewLinkItem"></span>
+                                                   <span 
wicket:id="viewItemTitle" class="ViewLinkItemTitle">[link title]</span>
+                                                   <i 
wicket:id="viewItemCheckmark" class="fa-solid fa-check"></i>
+                                               </a>
+                                               
+                                       </li>
+                   </ul>
+                       </div>
+        </wicket:panel>
+    </body>
+</html>
diff --git 
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/nav/pageact/PageActionChooser.java
 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/nav/pageact/PageActionChooser.java
new file mode 100644
index 0000000000..a3f76a7d3d
--- /dev/null
+++ 
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/table/nav/pageact/PageActionChooser.java
@@ -0,0 +1,111 @@
+/*
+ *  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.causeway.viewer.wicket.ui.components.table.nav.pageact;
+
+import java.util.Optional;
+
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.Model;
+
+import org.apache.causeway.viewer.wicket.model.pagesize.PagesizeChoice;
+import 
org.apache.causeway.viewer.wicket.ui.components.table.DataTableWithPagesAndFilter;
+import 
org.apache.causeway.viewer.wicket.ui.components.widgets.links.AjaxLinkNoPropagate;
+import org.apache.causeway.viewer.wicket.ui.util.Wkt;
+import org.apache.causeway.viewer.wicket.ui.util.WktLinks;
+
+import lombok.Getter;
+import lombok.NonNull;
+
+public class PageActionChooser extends Panel {
+    private static final long serialVersionUID = 1L;
+
+    private static final String ID_ENTRIES_PER_PAGE_LABEL = 
"entriesPerPageLabel";
+    private static final String ID_PAGESIZE_CHOICE = "pagesizeChoice";
+    private static final String ID_PAGESIZE_CHOICES = "pagesizeChoices";
+
+    private static final String ID_VIEW_ITEM_TITLE = "viewItemTitle";
+    private static final String ID_VIEW_ITEM_ICON = "viewItemIcon";
+    private static final String ID_VIEW_ITEM_CHECKMARK = "viewItemCheckmark"; 
// indicator for the selected item
+
+    @Getter final DataTableWithPagesAndFilter<?, ?> table;
+
+    public PageActionChooser(final String id, final 
DataTableWithPagesAndFilter<?, ?> table) {
+        super(id);
+        this.table = table;
+    }
+
+    @Override
+    protected void onInitialize() {
+        super.onInitialize();
+        buildGui();
+    }
+
+    // -- HELPER
+
+    private void buildGui() {
+
+        Wkt.labelAdd(this, ID_ENTRIES_PER_PAGE_LABEL, 
table.getEntriesPerPageAsLiteral());
+
+        Wkt.listViewAdd(this, ID_PAGESIZE_CHOICES, table.getPagesizeChoices(), 
item->{
+            var link = Wkt.linkAdd(item, ID_PAGESIZE_CHOICE, target->{
+                var pagesizeChoice = item.getModelObject();
+                table.setItemsPerPage(pagesizeChoice.getItemsPerPage());
+                table.setPageSizeHintAndBroadcast(target);
+                target.add(table);
+            });
+            // add title and icon to the link
+            addIconAndTitle(item, link);
+            // add checkmark to the link
+            addCheckmark(item, link, table.getCurrentPagesizeChoice());
+
+            Wkt.ajaxEnable(link);
+        });
+
+    }
+
+    private static void addIconAndTitle(
+            final @NonNull ListItem<PagesizeChoice> item,
+            final @NonNull AjaxLinkNoPropagate link) {
+        WktLinks.listItemAsDropdownLink(item, link,
+                ID_VIEW_ITEM_TITLE, 
pagesizeChoice->Model.of(pagesizeChoice.getTitle()),
+                ID_VIEW_ITEM_ICON, 
pagesizeChoice->Model.of(pagesizeChoice.getCssClass()),
+                null);
+    }
+
+    private static void addCheckmark(
+            final @NonNull ListItem<PagesizeChoice> item,
+            final @NonNull AjaxLinkNoPropagate link,
+            final @NonNull Optional<PagesizeChoice> currentPagesizeChoice) {
+        var checkmarkForChoice = Wkt.labelAdd(link, ID_VIEW_ITEM_CHECKMARK, 
"");
+
+        // whether the item in this loop is also the currently selected one 
(is to receive the checkmark)
+        var isSelected = currentPagesizeChoice
+                .map(currentChoice->
+                    currentChoice.equals(item.getModelObject()))
+                .orElse(false);
+        checkmarkForChoice.setVisible(isSelected);
+
+        // disable the link when selected
+        if(isSelected) {
+            link.setEnabled(false);
+        }
+    }
+
+}

Reply via email to