X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Fdialogs%2FCmsMessageDialog.java;h=eb881c6bd03cf60fb7e9b7181465f57055b24228;hb=94ec9b5a0282c8119ee9831688124bc96f3a62b8;hp=21d4792ddb9e4eff83fd02a6f3b3c3490ed10c2c;hpb=9eaf85002b003a68eea81fca417465ba52f14e4e;p=lgpl%2Fargeo-commons.git 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 index 21d4792dd..eb881c6bd 100644 --- 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 @@ -1,10 +1,12 @@ package org.argeo.cms.ui.dialogs; 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; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -15,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; @@ -33,23 +39,39 @@ public class CmsMessageDialog extends LightweightDialog { protected Control createDialogArea(Composite parent) { parent.setLayout(new GridLayout()); + TraverseListener traverseListener = new TraverseListener() { + private static final long serialVersionUID = -1158892811534971856L; + + public void keyTraversed(TraverseEvent e) { + if (e.detail == SWT.TRAVERSE_RETURN) + okPressed(); + else if (e.detail == SWT.TRAVERSE_ESCAPE) + cancelPressed(); + } + }; + // message Composite body = new Composite(parent, SWT.NONE); + body.addTraverseListener(traverseListener); 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) + 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; @@ -59,7 +81,16 @@ public class CmsMessageDialog extends LightweightDialog { 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) { + close.setFocus(); + close.addTraverseListener(traverseListener); + + buttons.setTabList(new Control[] { close }); + } else if (kind == CONFIRM || kind == QUESTION || kind == QUESTION_WITH_CANCEL) { + Control input = createInputArea(body); + if (input != null) { + input.addTraverseListener(traverseListener); + body.setTabList(new Control[] { input }); + } GridLayout layout = new GridLayout(2, true); layout.marginWidth = 0; layout.marginHeight = 0; @@ -69,16 +100,29 @@ public class CmsMessageDialog extends LightweightDialog { cancel.setText(CmsMsg.cancel.lead()); cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); cancel.addSelectionListener((Selected) (e) -> cancelPressed()); + cancel.addTraverseListener(traverseListener); 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) -> okPressed()); + ok.addTraverseListener(traverseListener); + if (input == null) + ok.setFocus(); + else + input.setFocus(); + + buttons.setTabList(new Control[] { ok, cancel }); } // pack(); + parent.setTabList(new Control[] { body, buttons }); return body; } + protected Control createInputArea(Composite parent) { + return null; + } + protected void okPressed() { closeShell(OK); } @@ -87,6 +131,10 @@ public class CmsMessageDialog extends LightweightDialog { closeShell(CANCEL); } + protected void cancel() { + closeShell(CANCEL); + } + protected Point getInitialSize() { return new Point(400, 200); } @@ -112,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); + } + }