1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.ui.util;
19
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.MessageBox;
23
24
25
26
27
28
29
30
31 public class MsgBoxHelper implements IMsgBoxHelper {
32
33 private Composite parent;
34
35
36
37
38
39
40
41
42 public static final MsgBoxHelper createInstanceFor(Composite parent) {
43 return new MsgBoxHelper(parent);
44 }
45
46
47
48
49
50
51
52 public MsgBoxHelper(Composite parent) {
53 if (parent == null) {
54 throw new IllegalArgumentException();
55 }
56 this.parent = parent;
57 }
58
59
60
61
62
63
64
65 @Override
66 public int showErrorBox(String title, String msg) {
67 return showErrorBox(parent, title, msg);
68 }
69
70
71
72
73
74
75
76 @Override
77 public int showInfoBox(String title, String msg) {
78 return showInfoBox(parent, title, msg);
79
80 }
81
82
83
84
85
86
87
88 @Override
89 public int showQuestionBox(String title, String msg) {
90 return showQuestionBox(parent, title, msg);
91 }
92
93
94
95
96
97
98
99 @Override
100 public int showWarningBox(String title, String msg) {
101 return showWarningBox(parent, title, msg);
102 }
103
104
105
106
107
108
109
110 @Override
111 public int showWarningQuestionBox(String title, String msg) {
112 return showWarningQuestionBox(parent, title, msg);
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126 public static int showQuestionBox(Composite parent, String title, String msg) {
127 int style = SWT.ICON_QUESTION | SWT.YES | SWT.NO;
128 return showBox(parent, title, msg, style);
129 }
130
131
132
133
134
135
136
137
138
139
140
141
142 public static int showWarningBox(Composite parent, String title, String msg) {
143 int style = SWT.ICON_WARNING | SWT.OK;
144 return showBox(parent, title, msg, style);
145 }
146
147
148
149
150
151
152
153
154
155
156
157
158 public static int showWarningQuestionBox(Composite parent, String title, String msg) {
159 int style = SWT.ICON_WARNING | SWT.YES | SWT.NO;
160 return showBox(parent, title, msg, style);
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174 public static int showErrorBox(Composite parent, String title, String msg) {
175 int style = SWT.ICON_ERROR | SWT.OK;
176 return showBox(parent, title, msg, style);
177 }
178
179
180
181
182
183
184
185
186
187
188
189
190 public static int showInfoBox(Composite parent, String title, String msg) {
191 int style = SWT.ICON_INFORMATION | SWT.OK;
192 return showBox(parent, title, msg, style);
193 }
194
195 private static int showBox(Composite parent, String title, String msg, int style) {
196 MessageBox messageBox = new MessageBox(parent.getShell(), style);
197 messageBox.setText(title);
198 messageBox.setMessage(msg);
199 return messageBox.open();
200 }
201
202 }