1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.eclipse.common.util;
17
18 import junit.framework.TestCase;
19
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Shell;
23
24
25
26
27
28
29 public abstract class AbstractShellTest extends TestCase {
30 protected Display display;
31
32 protected Shell shell;
33
34 private boolean useShell;
35
36 protected AbstractShellTest() {
37 this(false);
38 }
39
40 protected AbstractShellTest(final boolean useShell) {
41 super();
42 this.useShell = useShell;
43 }
44
45 @Override
46 protected void setUp() throws Exception {
47 display = Display.getCurrent();
48 if (display == null) {
49 display = new Display();
50 }
51
52 if (useShell) {
53 shell = display.getActiveShell();
54 if (shell == null) {
55 shell = new Shell(display);
56 }
57 }
58 }
59
60 @Override
61 protected void tearDown() throws Exception {
62 if (useShell) {
63 if (shell != null) {
64 shell.dispose();
65 }
66 }
67
68 if (display != null) {
69 display.dispose();
70 }
71 }
72 }