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
);
48 createInputArea(body
);
51 Composite buttons
= new Composite(parent
, SWT
.NONE
);
52 buttons
.setLayoutData(new GridData(SWT
.END
, SWT
.FILL
, true, false));
53 if (kind
== INFORMATION
|| kind
== WARNING
) {
54 GridLayout layout
= new GridLayout(1, true);
55 layout
.marginWidth
= 0;
56 layout
.marginHeight
= 0;
57 buttons
.setLayout(layout
);
59 Button close
= new Button(buttons
, SWT
.FLAT
);
60 close
.setText(CmsMsg
.close
.lead());
61 close
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
62 close
.addSelectionListener((Selected
) (e
) -> closeShell(OK
));
63 } else if (kind
== CONFIRM
|| kind
== QUESTION
) {
64 GridLayout layout
= new GridLayout(2, true);
65 layout
.marginWidth
= 0;
66 layout
.marginHeight
= 0;
67 buttons
.setLayout(layout
);
69 Button cancel
= new Button(buttons
, SWT
.FLAT
);
70 cancel
.setText(CmsMsg
.cancel
.lead());
71 cancel
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
72 cancel
.addSelectionListener((Selected
) (e
) -> cancelPressed());
74 Button ok
= new Button(buttons
, SWT
.FLAT
);
75 ok
.setText(CmsMsg
.ok
.lead());
76 ok
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false));
77 ok
.addSelectionListener((Selected
) (e
) -> okPressed());
83 protected Control
createInputArea(Composite parent
) {
87 protected void okPressed() {
91 protected void cancelPressed() {
95 protected Point
getInitialSize() {
96 return new Point(400, 200);
99 public static boolean open(int kind
, Shell parent
, String message
) {
100 CmsMessageDialog dialog
= new CmsMessageDialog(parent
, message
, kind
);
101 return dialog
.open() == 0;
104 public static boolean openConfirm(String message
) {
105 return open(CONFIRM
, Display
.getCurrent().getActiveShell(), message
);
108 public static void openInformation(String message
) {
109 open(INFORMATION
, Display
.getCurrent().getActiveShell(), message
);
112 public static boolean openQuestion(String message
) {
113 return open(QUESTION
, Display
.getCurrent().getActiveShell(), message
);
116 public static void openWarning(String message
) {
117 open(WARNING
, Display
.getCurrent().getActiveShell(), message
);