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 2020/04/01 11:54:19 UTC
[isis] branch master updated: ISIS-2338: tiny code refactoring
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new db18ffe ISIS-2338: tiny code refactoring
db18ffe is described below
commit db18ffec7d646ae0687b8199be47e28b14e509c9
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Apr 1 13:54:09 2020 +0200
ISIS-2338: tiny code refactoring
---
.../isis/viewer/wicket/ui/util/Confirmations.java | 50 ++++++++++++++--------
1 file changed, 32 insertions(+), 18 deletions(-)
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/util/Confirmations.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/util/Confirmations.java
index fc19e73..873f2b5 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/util/Confirmations.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/util/Confirmations.java
@@ -18,12 +18,15 @@
*/
package org.apache.isis.viewer.wicket.ui.util;
+import javax.annotation.Nullable;
+
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.form.Button;
import org.apache.isis.applib.services.i18n.TranslationService;
import org.apache.isis.core.config.messages.MessageRegistry;
+import lombok.NonNull;
import lombok.val;
import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
@@ -33,15 +36,30 @@ import de.agilecoders.wicket.extensions.markup.html.bootstrap.confirmation.Confi
public class Confirmations {
public static void addConfirmationDialog(
- final TranslationService translationService,
- final Component component) {
+ @Nullable final TranslationService translationService,
+ @NonNull final Component component) {
+ if(component instanceof Button) {
+ // ensure dialog ok buttons receive the danger style as well
+ // don't care if expressed twice
+ addConfirmationStyle(component);
+ }
+
+ val confirmationConfig = getConfirmationConfig(translationService);
+ component.add(new ConfirmationBehavior(confirmationConfig));
+ }
+
+ public static void addConfirmationStyle(final Component component) {
+ component.add(new CssClassAppender("btn-danger"));
+ }
+
+ private static ConfirmationConfig getConfirmationConfig(
+ @Nullable final TranslationService translationService) {
+
val confirmationConfig = new ConfirmationConfig();
-
- final String context = MessageRegistry.class.getName();
- final String areYouSure = translationService.translate(context, MessageRegistry.MSG_ARE_YOU_SURE);
- final String confirm = translationService.translate(context, MessageRegistry.MSG_CONFIRM);
- final String cancel = translationService.translate(context, MessageRegistry.MSG_CANCEL);
+ final String areYouSure = translate(translationService, MessageRegistry.MSG_ARE_YOU_SURE);
+ final String confirm = translate(translationService, MessageRegistry.MSG_CONFIRM);
+ final String cancel = translate(translationService, MessageRegistry.MSG_CANCEL);
confirmationConfig
.withTitle(areYouSure)
@@ -50,19 +68,15 @@ public class Confirmations {
.withPlacement(TooltipConfig.Placement.right)
.withBtnOkClass("btn btn-danger")
.withBtnCancelClass("btn btn-default");
-
- component.add(new ConfirmationBehavior(confirmationConfig));
-
- if(component instanceof Button) {
- // ensure dialog ok buttons receive the danger style as well
- // don't care if expressed twice
- addConfirmationStyle(component);
- }
+ return confirmationConfig;
}
-
- public static void addConfirmationStyle(final Component component) {
- component.add(new CssClassAppender("btn-danger"));
+
+ private static String translate(TranslationService translationService, String msg) {
+ if(translationService!=null) {
+ return translationService.translate(MessageRegistry.class.getName(), msg);
+ }
+ return msg;
}
}