1 package org
.argeo
.cms
.ui
.dialogs
;
3 import org
.argeo
.cms
.CmsMsg
;
4 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
5 import org
.argeo
.eclipse
.ui
.Selected
;
6 import org
.argeo
.eclipse
.ui
.dialogs
.LightweightDialog
;
7 import org
.eclipse
.swt
.SWT
;
8 import org
.eclipse
.swt
.graphics
.Point
;
9 import org
.eclipse
.swt
.layout
.GridData
;
10 import org
.eclipse
.swt
.layout
.GridLayout
;
11 import org
.eclipse
.swt
.widgets
.Button
;
12 import org
.eclipse
.swt
.widgets
.Composite
;
13 import org
.eclipse
.swt
.widgets
.Control
;
14 import org
.eclipse
.swt
.widgets
.Display
;
15 import org
.eclipse
.swt
.widgets
.Label
;
16 import org
.eclipse
.swt
.widgets
.Shell
;
18 public class CmsMessageDialog
extends LightweightDialog
{
19 public final static int INFORMATION
= 2;
20 public final static int QUESTION
= 3;
21 public final static int WARNING
= 4;
22 public final static int CONFIRM
= 5;
25 private String message
;
27 public CmsMessageDialog(Shell parentShell
, String message
, int kind
) {
30 this.message
= message
;
33 protected Control
createDialogArea(Composite parent
) {
34 parent
.setLayout(new GridLayout());
37 Composite body
= new Composite(parent
, SWT
.NONE
);
38 GridLayout bodyGridLayout
= new GridLayout();
39 bodyGridLayout
.marginHeight
= 20;
40 bodyGridLayout
.marginWidth
= 20;
41 body
.setLayout(bodyGridLayout
);
42 body
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
44 Label messageLbl
= new Label(body
, SWT
.WRAP
);
45 messageLbl
.setFont(EclipseUiUtils
.getBoldFont(parent
));
47 messageLbl
.setText(message
);
50 Composite buttons
= new Composite(parent
, SWT
.NONE
);
51 buttons
.setLayoutData(new GridData(SWT
.END
, SWT
.FILL
, true, false));
52 if (kind
== INFORMATION
|| kind
== WARNING
) {
53 GridLayout layout
= new GridLayout(1, true);
54 layout
.marginWidth
= 0;
55 layout
.marginHeight
= 0;
56 buttons
.setLayout(layout
);
58 Button close
= new Button(buttons
, SWT
.FLAT
);
59 close
.setText(CmsMsg
.close
.lead());
60 close
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
61 close
.addSelectionListener((Selected
) (e
) -> closeShell(OK
));
62 } else if (kind
== CONFIRM
|| kind
== QUESTION
) {
63 GridLayout layout
= new GridLayout(2, true);
64 layout
.marginWidth
= 0;
65 layout
.marginHeight
= 0;
66 buttons
.setLayout(layout
);
68 Button cancel
= new Button(buttons
, SWT
.FLAT
);
69 cancel
.setText(CmsMsg
.cancel
.lead());
70 cancel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
71 cancel
.addSelectionListener((Selected
) (e
) -> closeShell(CANCEL
));
73 Button ok
= new Button(buttons
, SWT
.FLAT
);
74 ok
.setText(CmsMsg
.ok
.lead());
75 ok
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
76 ok
.addSelectionListener((Selected
) (e
) -> closeShell(OK
));
82 protected Point
getInitialSize() {
83 return new Point(400, 200);
86 public static boolean open(int kind
, Shell parent
, String message
) {
87 CmsMessageDialog dialog
= new CmsMessageDialog(parent
, message
, kind
);
88 return dialog
.open() == 0;
91 public static boolean openConfirm(String message
) {
92 return open(CONFIRM
, Display
.getCurrent().getActiveShell(), message
);
95 public static void openInformation(String message
) {
96 open(INFORMATION
, Display
.getCurrent().getActiveShell(), message
);
99 public static boolean openQuestion(String message
) {
100 return open(QUESTION
, Display
.getCurrent().getActiveShell(), message
);
103 public static void openWarning(String message
) {
104 open(WARNING
, Display
.getCurrent().getActiveShell(), message
);