Introduce CMS Message Dialog and improve l10n
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 21 May 2018 11:22:09 +0000 (13:22 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 21 May 2018 11:22:09 +0000 (13:22 +0200)
org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsFeedback.java
org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java [new file with mode: 0644]
org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsWizardDialog.java
org.argeo.cms/OSGI-INF/l10n/bundle.properties
org.argeo.cms/OSGI-INF/l10n/bundle_de.properties
org.argeo.cms/OSGI-INF/l10n/bundle_fr.properties
org.argeo.cms/src/org/argeo/cms/CmsMsg.java
org.argeo.cms/src/org/argeo/cms/i18n/Localized.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeUserAdmin.java
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/LightweightDialog.java

index 61cce4ed3349f693fefd7715c7346d53ec49ba88..a4f3362da1d39364e7d5fa3f7593ac69744f1104 100644 (file)
@@ -13,7 +13,6 @@ import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
@@ -37,25 +36,25 @@ public class CmsFeedback extends LightweightDialog {
                if (e instanceof ThreadDeath)
                        throw (ThreadDeath) e;
 
-               new CmsFeedback(getDisplay().getActiveShell(), message, e).open();
+               new CmsFeedback(null, message, e).open();
        }
 
        public static void show(String message) {
-               new CmsFeedback(getDisplay().getActiveShell(), message, null).open();
+               new CmsFeedback(null, message, null).open();
        }
 
        /** Tries to find a display */
-       private static Display getDisplay() {
-               try {
-                       Display display = Display.getCurrent();
-                       if (display != null)
-                               return display;
-                       else
-                               return Display.getDefault();
-               } catch (Exception e) {
-                       return Display.getCurrent();
-               }
-       }
+//     private static Display getDisplay() {
+//             try {
+//                     Display display = Display.getCurrent();
+//                     if (display != null)
+//                             return display;
+//                     else
+//                             return Display.getDefault();
+//             } catch (Exception e) {
+//                     return Display.getCurrent();
+//             }
+//     }
 
        protected Control createDialogArea(Composite parent) {
                parent.setLayout(new GridLayout(2, false));
diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/dialogs/CmsMessageDialog.java
new file mode 100644 (file)
index 0000000..6e1fc26
--- /dev/null
@@ -0,0 +1,107 @@
+package org.argeo.cms.ui.dialogs;
+
+import org.argeo.cms.CmsMsg;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.eclipse.ui.Selected;
+import org.argeo.eclipse.ui.dialogs.LightweightDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+public class CmsMessageDialog extends LightweightDialog {
+       public final static int INFORMATION = 2;
+       public final static int QUESTION = 3;
+       public final static int WARNING = 4;
+       public final static int CONFIRM = 5;
+
+       private int kind;
+       private String message;
+
+       public CmsMessageDialog(Shell parentShell, String message, int kind) {
+               super(parentShell);
+               this.kind = kind;
+               this.message = message;
+       }
+
+       protected Control createDialogArea(Composite parent) {
+               parent.setLayout(new GridLayout());
+
+               // message
+               Composite body = new Composite(parent, SWT.NONE);
+               GridLayout bodyGridLayout = new GridLayout();
+               bodyGridLayout.marginHeight = 20;
+               bodyGridLayout.marginWidth = 20;
+               body.setLayout(bodyGridLayout);
+               body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+               Label messageLbl = new Label(body, SWT.WRAP);
+               messageLbl.setFont(EclipseUiUtils.getBoldFont(parent));
+               if (message != null)
+                       messageLbl.setText(message);
+
+               // buttons
+               Composite buttons = new Composite(parent, SWT.NONE);
+               buttons.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false));
+               if (kind == INFORMATION || kind == WARNING) {
+                       GridLayout layout = new GridLayout(1, true);
+                       layout.marginWidth = 0;
+                       layout.marginHeight = 0;
+                       buttons.setLayout(layout);
+
+                       Button close = new Button(buttons, SWT.FLAT);
+                       close.setText(CmsMsg.close.lead());
+                       close.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+                       close.addSelectionListener((Selected) (e) -> closeShell(OK));
+               } else if (kind == CONFIRM || kind == QUESTION) {
+                       GridLayout layout = new GridLayout(2, true);
+                       layout.marginWidth = 0;
+                       layout.marginHeight = 0;
+                       buttons.setLayout(layout);
+
+                       Button cancel = new Button(buttons, SWT.FLAT);
+                       cancel.setText(CmsMsg.cancel.lead());
+                       cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+                       cancel.addSelectionListener((Selected) (e) -> closeShell(CANCEL));
+
+                       Button ok = new Button(buttons, SWT.FLAT);
+                       ok.setText(CmsMsg.ok.lead());
+                       ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+                       ok.addSelectionListener((Selected) (e) -> closeShell(OK));
+               }
+               // pack();
+               return messageLbl;
+       }
+
+       protected Point getInitialSize() {
+               return new Point(400, 200);
+       }
+
+       public static boolean open(int kind, Shell parent, String message) {
+               CmsMessageDialog dialog = new CmsMessageDialog(parent, message, kind);
+               return dialog.open() == 0;
+       }
+
+       public static boolean openConfirm(String message) {
+               return open(CONFIRM, Display.getCurrent().getActiveShell(), message);
+       }
+
+       public static void openInformation(String message) {
+               open(INFORMATION, Display.getCurrent().getActiveShell(), message);
+       }
+
+       public static boolean openQuestion(String message) {
+               return open(QUESTION, Display.getCurrent().getActiveShell(), message);
+       }
+
+       public static void openWarning(String message) {
+               open(WARNING, Display.getCurrent().getActiveShell(), message);
+       }
+
+}
index 80fe3c85fc7b48c78be69a3b0532cf2493e5fdb8..29633cfb8366ef16030b9c97c74e204eb51517f3 100644 (file)
@@ -3,6 +3,7 @@ package org.argeo.cms.ui.dialogs;
 import java.lang.reflect.InvocationTargetException;
 
 import org.argeo.cms.CmsException;
+import org.argeo.cms.CmsMsg;
 import org.argeo.cms.util.CmsUtils;
 import org.argeo.eclipse.ui.EclipseUiUtils;
 import org.argeo.eclipse.ui.Selected;
@@ -58,7 +59,7 @@ public class CmsWizardDialog extends LightweightDialog implements IWizardContain
                        titleBar.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, true, false));
                        updateTitleBar();
                        Button cancelButton = new Button(messageArea, SWT.FLAT);
-                       cancelButton.setText("Cancel");
+                       cancelButton.setText(CmsMsg.cancel.lead());
                        cancelButton.setLayoutData(new GridData(SWT.END, SWT.TOP, false, false, 1, 3));
                        cancelButton.addSelectionListener((Selected) (e) -> closeShell(CANCEL));
                        message = new Label(messageArea, SWT.WRAP);
@@ -84,17 +85,17 @@ public class CmsWizardDialog extends LightweightDialog implements IWizardContain
 
                        if (!singlePage) {
                                back = new Button(buttons, SWT.PUSH);
-                               back.setText("Back");
+                               back.setText(CmsMsg.wizardBack.lead());
                                back.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
                                back.addSelectionListener((Selected) (e) -> backPressed());
 
                                next = new Button(buttons, SWT.PUSH);
-                               next.setText("Next");
+                               next.setText(CmsMsg.wizardNext.lead());
                                next.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
                                next.addSelectionListener((Selected) (e) -> nextPressed());
                        }
                        finish = new Button(buttons, SWT.PUSH);
-                       finish.setText("Finish");
+                       finish.setText(CmsMsg.wizardFinish.lead());
                        finish.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
                        finish.addSelectionListener((Selected) (e) -> finishPressed());
 
index 1cd1f8e12b17061e5ed6223bb6c2b83282bb52bf..20d5b10e7fe818a98b7621096b3764af6c88d8c4 100644 (file)
@@ -9,3 +9,11 @@ currentPassword=Current password
 newPassword=New password
 repeatNewPassword=Repeat new password
 passwordChanged=Password changed
+
+close=Close
+cancel=Cancel
+ok=Ok
+
+wizardBack=Back
+wizardNext=Next
+wizardFinish=Finish
index b2dc5a414f2ae5861b9d65901491dbc2dfcb38c5..93a3d7118f2f170ea7615a9c50025c66f8bf4519 100644 (file)
@@ -9,3 +9,11 @@ currentPassword=Derzeites Passwort
 newPassword=Neues passwort
 repeatNewPassword=Newes Passwort wiederholen
 passwordChanged=Passwort geändert
+
+close=Schließen
+cancel=Abbrechen
+ok=Ok
+
+wizardBack=Zurück
+wizardNext=Nächstes
+wizardFinish=Fertig
index dc25d31a12d2ffa5c7c2c0b05c76b9db3b671aa6..085ea7444e29908bc2f2fb190125c84388df797e 100644 (file)
@@ -9,3 +9,11 @@ currentPassword=mot de passe actuel
 newPassword=nouveau mot de passe
 repeatNewPassword=répéter le nouveau mot de passe
 passwordChanged=mot de passe changé
+
+close=Fermer
+cancel=Annuler
+ok=Ok
+
+wizardBack=Précédent
+wizardNext=Suivant
+wizardFinish=Terminer
index 521ceedef120417088f98b17d8f3b69ba13ba05b..718bfa48d6c51902c9957068b6b6e6ac4bcb122a 100644 (file)
@@ -3,7 +3,11 @@ package org.argeo.cms;
 import org.argeo.cms.i18n.Localized;
 
 public enum CmsMsg implements Localized {
-       username, password, login, logout, register, changePassword, currentPassword, newPassword, repeatNewPassword, passwordChanged;
-
-
+       username, password, login, logout, register,
+       // password
+       changePassword, currentPassword, newPassword, repeatNewPassword, passwordChanged,
+       // dialog
+       close, cancel, ok,
+       // wizard
+       wizardBack, wizardNext, wizardFinish;
 }
index 9378d476d402bdc7af35f38e7987e58447285d74..535b5f225d04e7cedaa150faf6a286e57ab49f09 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.cms.i18n;
 
+import java.text.MessageFormat;
 import java.util.Locale;
 
 /** Localized object. */
@@ -13,6 +14,12 @@ public interface Localized {
                return LocaleUtils.lead(this);
        }
 
+       default String format(Object[] args) {
+               Locale locale = LocaleUtils.getCurrentLocale();
+               MessageFormat format = new MessageFormat(local(locale).toString(), locale);
+               return format.format(args);
+       }
+
        default String lead(Locale locale) {
                return LocaleUtils.lead(local(locale).toString(), locale);
        }
index d1d4721389bcad5ab05acd536a6e5c60ec8ae216..dc9d33a3b5fa9bcb7751fb269c288786ba003b7e 100644 (file)
@@ -137,15 +137,15 @@ class NodeUserAdmin extends AggregatingUserAdmin implements ManagedServiceFactor
                        log.debug("User directory " + userDirectory.getBaseDn() + " [" + u.getScheme() + "] enabled."
                                        + (realm != null ? " " + realm + " realm." : ""));
 
-               if (isSystemRolesBaseDn(baseDn)) {
-                       if (userAdminReg != null)
-                               userAdminReg.unregister();
-                       // register self as main user admin
-                       Dictionary<String, Object> userAdminregProps = currentState();
-                       userAdminregProps.put(NodeConstants.CN, NodeConstants.DEFAULT);
-                       userAdminregProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
-                       userAdminReg = bc.registerService(UserAdmin.class, this, userAdminregProps);
-               }
+               // if (isSystemRolesBaseDn(baseDn)) {
+               if (userAdminReg != null)
+                       userAdminReg.unregister();
+               // register self as main user admin
+               Dictionary<String, Object> userAdminregProps = currentState();
+               userAdminregProps.put(NodeConstants.CN, NodeConstants.DEFAULT);
+               userAdminregProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+               userAdminReg = bc.registerService(UserAdmin.class, this, userAdminregProps);
+               // }
        }
 
        @Override
index 6cc80f3ddec1d1e757b668e3f313c1e9e677fb90..6e9b668bf8d6f13e588110cbe5f9fde73676ced8 100644 (file)
@@ -186,6 +186,10 @@ public class LightweightDialog {
                block = shouldBlock;
        }
 
+       public void pack() {
+               foregoundShell.pack();
+       }
+
        private void runEventLoop(Shell loopShell) {
                Display display;
                if (foregoundShell == null) {