1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.util;
17
18 import org.eclipse.swt.widgets.Display;
19 import org.eclipse.swt.widgets.Shell;
20 import org.seasar.framework.container.S2Container;
21 import org.seasar.framework.container.factory.SingletonS2ContainerFactory;
22 import org.seasar.uruma.context.ApplicationContext;
23 import org.seasar.uruma.context.WidgetHandle;
24 import org.seasar.uruma.context.WindowContext;
25 import org.seasar.uruma.core.UrumaConstants;
26 import org.seasar.uruma.rcp.UrumaService;
27 import org.seasar.uruma.rcp.util.UrumaServiceUtil;
28
29
30
31
32
33
34 public class ShellUtil {
35
36
37
38
39
40 public static Shell getShell() {
41 UrumaService service = UrumaServiceUtil.getService();
42 if (service != null) {
43 return service.getWorkbench().getActiveWorkbenchWindow().getShell();
44 } else {
45 S2Container container = SingletonS2ContainerFactory.getContainer();
46 ApplicationContext context = (ApplicationContext) container
47 .getComponent(ApplicationContext.class);
48 WindowContext wContext = context.getWindowContexts().iterator()
49 .next();
50 WidgetHandle handle = wContext
51 .getWidgetHandle(UrumaConstants.SHELL_CID);
52 if (handle != null) {
53 return handle.<Shell> getCastWidget();
54 } else {
55 return Display.getCurrent().getActiveShell();
56 }
57 }
58 }
59 }