You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/05/27 07:59:59 UTC

[isis] branch ISIS-2705 created (now 4aa8465)

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

danhaywood pushed a change to branch ISIS-2705
in repository https://gitbox.apache.org/repos/asf/isis.git.


      at 4aa8465  ISIS-2705: adds the ability to position Wicket viewer messages more accurately.

This branch includes the following new commits:

     new 4aa8465  ISIS-2705: adds the ability to position Wicket viewer messages more accurately.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[isis] 01/01: ISIS-2705: adds the ability to position Wicket viewer messages more accurately.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-2705
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 4aa84657265472f8ed08f4a270b9e067ea38b76e
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Thu May 27 08:54:22 2021 +0100

    ISIS-2705: adds the ability to position Wicket viewer messages more accurately.
---
 .../apache/isis/core/config/IsisConfiguration.java | 72 ++++++++++++++++++++++
 .../widgets/breadcrumbs/BreadcrumbPanel.java       |  5 +-
 .../viewer/wicket/ui/errors/JGrowlBehaviour.java   |  8 ++-
 .../isis/viewer/wicket/ui/errors/JGrowlUtil.java   | 39 ++++++++----
 .../wicket/ui/panels/FormExecutorDefault.java      |  3 +-
 5 files changed, 112 insertions(+), 15 deletions(-)

diff --git a/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java b/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
index d6bb853..3e23bdb 100644
--- a/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
+++ b/core/config/src/main/java/org/apache/isis/core/config/IsisConfiguration.java
@@ -21,6 +21,8 @@ package org.apache.isis.core.config;
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -48,6 +50,7 @@ import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 
 import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.convert.DurationUnit;
 import org.springframework.core.env.ConfigurableEnvironment;
 import org.springframework.validation.annotation.Validated;
 
@@ -2445,6 +2448,75 @@ public class IsisConfiguration {
                  */
                 private String text;
             }
+
+            private final MessagePopups messagePopups = new MessagePopups();
+            @Data
+            public static class MessagePopups {
+
+                /**
+                 * How long the info popup should display before disappearing.
+                 *
+                 * <p>
+                 *     A value of 0 means do not disappear automatically.
+                 * </p>
+                 */
+                Duration infoDelay = Duration.ofMillis(3500);
+
+                /**
+                 * How long the warning popup should display before disappearing.
+                 *
+                 * <p>
+                 *     A value of 0 (the default) means do not disappear automatically.
+                 * </p>
+                 */
+                Duration warningDelay = Duration.ofMillis(0);
+
+                /**
+                 * How long the error popup should display before disappearing.
+                 *
+                 * <p>
+                 *     A value of 0 (the default) means do not disappear automatically.
+                 * </p>
+                 */
+                Duration errorDelay = Duration.ofMillis(0);
+
+                /**
+                 * How far in from the edge the popup should display
+                 */
+                int offset = 100;
+
+                private final Placement placement = new Placement();
+                @Data
+                public static class Placement {
+
+                    public static enum Vertical {
+                        TOP, BOTTOM
+                    }
+
+                    public static enum Horizontal {
+                        LEFT, RIGHT
+                    }
+
+                    /**
+                     * Whether to display popups at the top or the bottom of the page.
+                     *
+                     * <p>
+                     * The default is to show them at the top.
+                     * </p>
+                     */
+                    Vertical vertical = Vertical.TOP;
+
+                    /**
+                     * Whether to display popups aligned ot the left or right of the page.
+                     *
+                     * <p>
+                     * The default is to show them aligned to the right
+                     * </p>
+                     */
+                    Horizontal horizontal = Horizontal.RIGHT;
+                }
+            }
+
         }
     }
 
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/breadcrumbs/BreadcrumbPanel.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/breadcrumbs/BreadcrumbPanel.java
index 502170f..e1e3318 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/breadcrumbs/BreadcrumbPanel.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/breadcrumbs/BreadcrumbPanel.java
@@ -42,6 +42,8 @@ import org.apache.isis.viewer.wicket.ui.errors.JGrowlUtil;
 import org.apache.isis.viewer.wicket.ui.pages.entity.EntityPage;
 import org.apache.isis.viewer.wicket.ui.panels.PanelAbstract;
 
+import lombok.val;
+
 public class BreadcrumbPanel
 extends PanelAbstract<Void, IModel<Void>> {
 
@@ -129,10 +131,11 @@ extends PanelAbstract<Void, IModel<Void>> {
                         final String oidStr = breadcrumbChoice.getInput();
                         final EntityModel selectedModel = breadcrumbModel.lookup(oidStr);
                         if(selectedModel == null) {
+                            val configuration = getCommonContext().getConfiguration();
                             getCommonContext().getMessageBroker()
                             .ifPresent(messageBroker->{
                                 messageBroker.addWarning("Cannot find object");
-                                String feedbackMsg = JGrowlUtil.asJGrowlCalls(messageBroker);
+                                String feedbackMsg = JGrowlUtil.asJGrowlCalls(messageBroker, configuration);
                                 target.appendJavaScript(feedbackMsg);
                             });
                             breadcrumbModel.remove(oidStr);
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlBehaviour.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlBehaviour.java
index 456e06d..a3e9649 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlBehaviour.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlBehaviour.java
@@ -32,6 +32,8 @@ import org.apache.isis.core.interaction.session.MessageBroker;
 import org.apache.isis.core.runtime.context.IsisAppCommonContext;
 import org.apache.isis.viewer.wicket.model.common.CommonContextUtils;
 
+import lombok.val;
+
 /**
  * Attach to any Ajax button that might trigger a notification (ie calls
  * {@link MessageBroker#addMessage(String)}, {@link MessageBroker#addWarning(String)},
@@ -56,8 +58,9 @@ public class JGrowlBehaviour extends AbstractDefaultAjaxBehavior {
     @Override
     protected void respond(AjaxRequestTarget target) {
 
+        val configuration = getCommonContext().getConfiguration();
         getCommonContext().getMessageBroker().ifPresent(messageBroker->{
-            String feedbackMsg = JGrowlUtil.asJGrowlCalls(messageBroker);
+            String feedbackMsg = JGrowlUtil.asJGrowlCalls(messageBroker, configuration);
             if(!_Strings.isNullOrEmpty(feedbackMsg)) {
                 target.appendJavaScript(feedbackMsg);
             }
@@ -76,9 +79,10 @@ public class JGrowlBehaviour extends AbstractDefaultAjaxBehavior {
                 JavaScriptHeaderItem
                 .forReference(new JavaScriptResourceReference(JGrowlBehaviour.class, "js/bootstrap-growl.js")));
 
+        val configuration = getCommonContext().getConfiguration();
         getCommonContext().getMessageBroker().ifPresent(messageBroker->{
 
-            String feedbackMsg = JGrowlUtil.asJGrowlCalls(messageBroker);
+            String feedbackMsg = JGrowlUtil.asJGrowlCalls(messageBroker, configuration);
             if(_Strings.isNotEmpty(feedbackMsg)) {
                 response.render(OnDomReadyHeaderItem.forScript(feedbackMsg));
             }
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlUtil.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlUtil.java
index 24a3f3f..0702440 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlUtil.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/errors/JGrowlUtil.java
@@ -20,6 +20,7 @@ package org.apache.isis.viewer.wicket.ui.errors;
 
 import org.apache.wicket.util.string.Strings;
 
+import org.apache.isis.core.config.IsisConfiguration;
 import org.apache.isis.core.interaction.session.MessageBroker;
 
 import lombok.Getter;
@@ -32,9 +33,21 @@ public class JGrowlUtil {
 
     @RequiredArgsConstructor @Getter
     static enum MessageSeverity {
-        INFO(3500),
-        WARNING(0), // sticky
-        DANGER(0) // sticky
+        INFO(3500) {
+            @Override long delay(IsisConfiguration.Viewer.Wicket.MessagePopups messagePopups) {
+                return messagePopups.getInfoDelay().toMillis();
+            }
+        },
+        WARNING(0) {
+            @Override long delay(IsisConfiguration.Viewer.Wicket.MessagePopups messagePopups) {
+                return messagePopups.getWarningDelay().toMillis();
+            }
+        }, // sticky
+        DANGER(0){
+            @Override long delay(IsisConfiguration.Viewer.Wicket.MessagePopups messagePopups) {
+                return messagePopups.getErrorDelay().toMillis();
+            }
+        } // sticky
         ;
 
         private final int delayMillis;
@@ -42,29 +55,33 @@ public class JGrowlUtil {
         public String cssClassSuffix() {
             return name().toLowerCase();
         }
+
+        abstract long delay(IsisConfiguration.Viewer.Wicket.MessagePopups messagePopups);
     }
 
-    public static String asJGrowlCalls(final MessageBroker messageBroker) {
+    public static String asJGrowlCalls(final MessageBroker messageBroker, IsisConfiguration configuration) {
         val buf = new StringBuilder();
 
+        val messagePopups = configuration.getViewer().getWicket().getMessagePopups();
         for (String info : messageBroker.drainMessages()) {
-            addJGrowlCall(info, JGrowlUtil.MessageSeverity.INFO, buf);
+            addJGrowlCall(info, JGrowlUtil.MessageSeverity.INFO, messagePopups, buf);
         }
 
         for (String warning : messageBroker.drainWarnings()) {
-            addJGrowlCall(warning, JGrowlUtil.MessageSeverity.WARNING, buf);
+            addJGrowlCall(warning, JGrowlUtil.MessageSeverity.WARNING, messagePopups, buf);
         }
 
         messageBroker.drainApplicationError()
         .ifPresent(error->
-            addJGrowlCall(error, MessageSeverity.DANGER, buf));
+            addJGrowlCall(error, MessageSeverity.DANGER, messagePopups, buf));
 
         return buf.toString();
     }
 
-    public static void addJGrowlCall(
+    private static void addJGrowlCall(
             final String origMsg,
             final MessageSeverity severity,
+            final IsisConfiguration.Viewer.Wicket.MessagePopups messagePopups,
             final StringBuilder buf) {
 
         final CharSequence escapedMsg = escape(origMsg);
@@ -74,9 +91,9 @@ public class JGrowlUtil {
         .append('"');
         buf.append(", {");
         buf.append("type: \"").append(severity.cssClassSuffix()).append('"');
-        buf.append(", delay: " + severity.delayMillis);
-        buf.append(", placement: { from: 'top', align: 'right' }");
-        buf.append(", offset: 50");
+        buf.append(String.format(", delay: %d", severity.delay(messagePopups)));
+        buf.append(String.format(", placement: { from: '%s', align: '%s' }", messagePopups.getPlacement().getVertical().name().toLowerCase(), messagePopups.getPlacement().getHorizontal().name().toLowerCase()));
+        buf.append(String.format(", offset: %d", messagePopups.getOffset()));
         buf.append('}');
         buf.append(");\n");
     }
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java
index 0116eee..dd73ede 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/panels/FormExecutorDefault.java
@@ -174,8 +174,9 @@ implements FormExecutor {
                 // also in this branch we also know that there *is* an ajax target to use
                 addComponentsToRedraw(targetIfAny);
 
+                val configuration = getCommonContext().getConfiguration();
                 currentMessageBroker().ifPresent(messageBorker->{
-                    final String jGrowlCalls = JGrowlUtil.asJGrowlCalls(messageBorker);
+                    final String jGrowlCalls = JGrowlUtil.asJGrowlCalls(messageBorker, configuration);
                     targetIfAny.appendJavaScript(jGrowlCalls);
                 });