You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/11/09 15:10:31 UTC

[isis] branch v2 updated: ISIS-2032: introduces IsisTotalRecordsToolbar which displays 'Showing all of 123' at the bottom of data tables

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

ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/v2 by this push:
     new 51913b8  ISIS-2032: introduces IsisTotalRecordsToolbar which displays 'Showing all of 123' at the bottom of data tables
51913b8 is described below

commit 51913b8de108227c39237502dc0c5f7ab24ea0e3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Nov 9 16:10:25 2018 +0100

    ISIS-2032: introduces IsisTotalRecordsToolbar which displays 'Showing
    all of 123' at the bottom of data tables
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-2032
---
 .../wicket/model/models/EntityCollectionModel.java |  2 +-
 .../CollectionContentsAsAjaxTablePanel.java        | 17 ++--
 .../ajaxtable/IsisAjaxFallbackDataTable.java       |  8 +-
 .../ajaxtable/IsisAjaxNavigationToolbar.java       |  4 +-
 .../ajaxtable/IsisTotalRecordsToolbar.html         | 26 ++++++
 .../ajaxtable/IsisTotalRecordsToolbar.java         | 96 ++++++++++++++++++++++
 6 files changed, 141 insertions(+), 12 deletions(-)

diff --git a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
index 17c0fba..0b3c2ca 100644
--- a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
+++ b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/EntityCollectionModel.java
@@ -254,7 +254,7 @@ UiHintContainer {
 
         final ObjectSpecification elementSpec = lowestCommonSuperclassFinder.getLowestCommonSuperclass()
                 .map(sessionFactory.getSpecificationLoader()::loadSpecification)
-                .orElse(collectionAsAdapter.getElementSpecification());
+                .orElse(collectionAsAdapter.getSpecification().getElementSpecification());
 
         final Class<?> elementType;
         int pageSize = PAGE_SIZE_DEFAULT_FOR_STANDALONE;
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
index feefca0..0a6e226 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
@@ -19,8 +19,6 @@
 
 package org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable;
 
-import static org.apache.isis.commons.internal.base._With.mapIfPresentElse;
-
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
@@ -63,6 +61,8 @@ import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.
 import org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable.columns.ObjectAdapterToggleboxColumn;
 import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
 
+import static org.apache.isis.commons.internal.base._With.mapIfPresentElse;
+
 /**
  * {@link PanelAbstract Panel} that represents a {@link EntityCollectionModel
  * collection of entity}s rendered using {@link AjaxFallbackDefaultDataTable}.
@@ -86,12 +86,12 @@ extends PanelAbstract<EntityCollectionModel> implements CollectionCountProvider
         super.onInitialize();
         buildGui();
     }
-
+    
     private void buildGui() {
 
         final List<IColumn<ObjectAdapter,String>> columns = _Lists.newArrayList();
 
-        // bulkactions
+        // bulk actions
         final BulkActionsProvider bulkActionsProvider = getBulkActionsProvider();
 
         ObjectAdapterToggleboxColumn toggleboxColumn = null;
@@ -105,14 +105,19 @@ extends PanelAbstract<EntityCollectionModel> implements CollectionCountProvider
         }
 
         final EntityCollectionModel model = getModel();
-        addTitleColumn(columns, model.getParentObjectAdapterMemento(), getSettings().getMaxTitleLengthInStandaloneTables(), getSettings().getMaxTitleLengthInStandaloneTables());
+        addTitleColumn(
+                columns, 
+                model.getParentObjectAdapterMemento(), 
+                getSettings().getMaxTitleLengthInParentedTables(), 
+                getSettings().getMaxTitleLengthInStandaloneTables());
+        
         addPropertyColumnsIfRequired(columns);
 
         final CollectionContentsSortableDataProvider dataProvider = new CollectionContentsSortableDataProvider(model);
         dataTable = new IsisAjaxFallbackDataTable<>(ID_TABLE, columns, dataProvider, model.getPageSize(), toggleboxColumn);
         addOrReplace(dataTable);
         dataTable.honourHints();
-
+        
         if(toggleboxColumn != null) {
             final OnConcurrencyExceptionHandler handler2 = new OnConcurrencyExceptionHandler() {
 
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java
index a22c48c..b293de5 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxFallbackDataTable.java
@@ -81,9 +81,11 @@ public class IsisAjaxFallbackDataTable<T, S> extends DataTable<T, S> {
         addTopToolbar(headersToolbar);
 
         navigationToolbar = new IsisAjaxNavigationToolbar(this, this.toggleboxColumn);
-        addBottomToolbar(navigationToolbar);
-
+        
+        // implementation note: toolbars do decide for themselves, whether they are visible
+        addBottomToolbar(navigationToolbar); 
         addBottomToolbar(new NoRecordsToolbar(this));
+        addBottomToolbar(new IsisTotalRecordsToolbar(this));
     }
 
     @Override
@@ -171,7 +173,7 @@ public class IsisAjaxFallbackDataTable<T, S> extends DataTable<T, S> {
 
     public void honourHints() {
         headersToolbar.honourSortOrderHints();
-        navigationToolbar.honourSortOrderHints();
+        navigationToolbar.honourHints();
         honourPageNumberHint();
     }
 
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java
index c248b63..502ca5d 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisAjaxNavigationToolbar.java
@@ -76,7 +76,7 @@ public class IsisAjaxNavigationToolbar extends AjaxNavigationToolbar {
         return new IsisAjaxPagingNavigator(navigatorId, table);
     }
 
-    void honourSortOrderHints() {
+    void honourHints() {
         UiHintContainer uiHintContainer = getUiHintContainer();
         if(uiHintContainer == null) {
             return;
@@ -89,7 +89,7 @@ public class IsisAjaxNavigationToolbar extends AjaxNavigationToolbar {
         }
     }
 
-    private void showAllItemsOn(final DataTable<?, ?> table) {
+    static void showAllItemsOn(final DataTable<?, ?> table) {
         table.setItemsPerPage(Long.MAX_VALUE);
     }
 
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.html b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.html
new file mode 100644
index 0000000..fa094bc
--- /dev/null
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.html
@@ -0,0 +1,26 @@
+<?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.
+-->
+<wicket:panel xmlns:wicket="http://wicket.apache.org">
+	<tr class="totalrecords-tr">
+		<td wicket:id="td" class="totalrecords-td">
+			<div class="navigatorLabel">
+				<span wicket:id="msg">[total records message]</span>
+            </div>
+		</td>
+	</tr>
+</wicket:panel>
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.java
new file mode 100644
index 0000000..93ea169
--- /dev/null
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/IsisTotalRecordsToolbar.java
@@ -0,0 +1,96 @@
+/*
+ *  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.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable;
+
+import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractToolbar;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+/**
+ * Responsibility: Display 'Showing all of 123' at the bottom of data tables.
+ * <p>
+ * Implementation Note: this is almost a copy of {@link NoRecordsToolbar}
+ * 
+ * @since 2.0.0-M2
+ */
+public class IsisTotalRecordsToolbar extends AbstractToolbar {
+
+    private static final long serialVersionUID = 1L;
+
+    public IsisTotalRecordsToolbar(final DataTable<?, ?> table) {
+        
+        this(table, new Model<String>() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public String getObject() {
+                return String.format("Showing all of %d", table.getRowCount());
+            }
+            
+        });
+        
+    }
+    
+    /**
+     * @param table
+     *            data table this toolbar will be attached to
+     * @param messageModel
+     *            model that will be used to display the "total records" message
+     */
+    protected IsisTotalRecordsToolbar(final DataTable<?, ?> table, final IModel<String> messageModel) {
+        super(table);
+
+        WebMarkupContainer td = new WebMarkupContainer("td");
+        add(td);
+
+        td.add(AttributeModifier.replace("colspan", new IModel<String>()
+        {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public String getObject()
+            {
+                return String.valueOf(table.getColumns().size()).intern();
+            }
+        }));
+        td.add(new Label("msg", messageModel));
+    }
+
+    /**
+     * Only shows this toolbar when there is only one pages (when there is no page navigation)
+     */
+    @Override
+    protected void onConfigure() {
+        super.onConfigure();
+
+        if(getTable().getRowCount() == 0) {
+            setVisible(false);
+            return;
+        }
+        
+        setVisible(getTable().getPageCount() == 1);
+    }
+
+}