Improve CMS dialogs and localisation.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / dialogs / CmsMessageDialog.java
index eb50ef2f31ba1e3384217d8a1e30565b66de3873..eb881c6bd03cf60fb7e9b7181465f57055b24228 100644 (file)
@@ -4,7 +4,6 @@ import org.argeo.cms.CmsMsg;
 import org.argeo.cms.ui.util.CmsUiUtils;
 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.events.TraverseEvent;
 import org.eclipse.swt.events.TraverseListener;
@@ -18,11 +17,15 @@ import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Shell;
 
+/** Base class for dialogs displaying messages or small forms. */
 public class CmsMessageDialog extends LightweightDialog {
+       public final static int NONE = 0;
+       public final static int ERROR = 1;
        public final static int INFORMATION = 2;
        public final static int QUESTION = 3;
        public final static int WARNING = 4;
        public final static int CONFIRM = 5;
+       public final static int QUESTION_WITH_CANCEL = 6;
 
        private int kind;
        private String message;
@@ -56,18 +59,19 @@ public class CmsMessageDialog extends LightweightDialog {
                body.setLayout(bodyGridLayout);
                body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
 
-               Label messageLbl = new Label(body, SWT.WRAP);
-               CmsUiUtils.markup(messageLbl);
-               messageLbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               messageLbl.setFont(EclipseUiUtils.getBoldFont(parent));
-               if (message != null)
+               if (message != null) {
+                       Label messageLbl = new Label(body, SWT.WRAP);
+                       CmsUiUtils.markup(messageLbl);
+                       messageLbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+                       messageLbl.setFont(EclipseUiUtils.getBoldFont(parent));
                        messageLbl.setText(message);
+               }
 
                // buttons
                Composite buttons = new Composite(parent, SWT.NONE);
                buttons.addTraverseListener(traverseListener);
                buttons.setLayoutData(new GridData(SWT.END, SWT.FILL, true, false));
-               if (kind == INFORMATION || kind == WARNING) {
+               if (kind == INFORMATION || kind == WARNING || kind == ERROR || kind == ERROR) {
                        GridLayout layout = new GridLayout(1, true);
                        layout.marginWidth = 0;
                        layout.marginHeight = 0;
@@ -81,7 +85,7 @@ public class CmsMessageDialog extends LightweightDialog {
                        close.addTraverseListener(traverseListener);
 
                        buttons.setTabList(new Control[] { close });
-               } else if (kind == CONFIRM || kind == QUESTION) {
+               } else if (kind == CONFIRM || kind == QUESTION || kind == QUESTION_WITH_CANCEL) {
                        Control input = createInputArea(body);
                        if (input != null) {
                                input.addTraverseListener(traverseListener);
@@ -127,6 +131,10 @@ public class CmsMessageDialog extends LightweightDialog {
                closeShell(CANCEL);
        }
 
+       protected void cancel() {
+               closeShell(CANCEL);
+       }
+
        protected Point getInitialSize() {
                return new Point(400, 200);
        }
@@ -152,4 +160,8 @@ public class CmsMessageDialog extends LightweightDialog {
                open(WARNING, Display.getCurrent().getActiveShell(), message);
        }
 
+       public static void openError(String message) {
+               open(ERROR, Display.getCurrent().getActiveShell(), message);
+       }
+
 }