1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.rcp.ui;
17
18 import java.util.ResourceBundle;
19
20 import org.eclipse.swt.widgets.Display;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.application.IWorkbenchConfigurer;
23 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
24 import org.eclipse.ui.application.WorkbenchAdvisor;
25 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
26 import org.seasar.eclipse.common.util.ImageManager;
27 import org.seasar.framework.util.StringUtil;
28 import org.seasar.uruma.component.rcp.WorkbenchComponent;
29 import org.seasar.uruma.core.UrumaConstants;
30 import org.seasar.uruma.core.UrumaMessageCodes;
31 import org.seasar.uruma.exception.NotFoundException;
32 import org.seasar.uruma.log.UrumaLogger;
33 import org.seasar.uruma.rcp.UrumaService;
34 import org.seasar.uruma.rcp.util.UrumaServiceUtil;
35 import org.seasar.uruma.ui.dialogs.UrumaErrorDialog;
36 import org.seasar.uruma.util.MessageUtil;
37
38
39
40
41
42
43 public class UrumaWorkbenchAdvisor extends WorkbenchAdvisor implements
44 UrumaMessageCodes, UrumaConstants {
45 private static final UrumaLogger logger = UrumaLogger
46 .getLogger(UrumaWorkbenchAdvisor.class);
47
48
49
50
51 @Override
52 public void initialize(final IWorkbenchConfigurer configurer) {
53 UrumaService service = UrumaServiceUtil.getService();
54
55 service.getContainer().register(configurer);
56
57
58 WorkbenchComponent workbench = service.getWorkbenchComponent();
59 boolean flg = Boolean.parseBoolean(workbench.saveAndRestore);
60 configurer.setSaveAndRestore(flg);
61
62 ResourceBundle imageBundle = service.getImageBundle();
63 if (imageBundle != null) {
64 logger.log(UrumaMessageCodes.LOADING_IMAGE_BUNDLE, imageBundle);
65 ImageManager.loadImages(imageBundle);
66 }
67 }
68
69
70
71
72 @Override
73 public boolean preShutdown() {
74 ImageManager.dispose();
75 return true;
76 }
77
78
79
80
81 @Override
82 public String getInitialWindowPerspectiveId() {
83 UrumaService service = UrumaServiceUtil.getService();
84
85 String perspectiveId = service.getWorkbenchComponent().initialPerspectiveId;
86
87 if (StringUtil.isNotBlank(perspectiveId)) {
88 WorkbenchComponent workbench = UrumaServiceUtil.getService()
89 .getWorkbenchComponent();
90 if (workbench.findPerspective(perspectiveId) != null) {
91 return service.createRcpId(perspectiveId);
92 } else {
93 throw new NotFoundException(
94 UrumaMessageCodes.PERSPECTIVE_NOT_FOUND, perspectiveId);
95 }
96 } else {
97 return service.createRcpId(UrumaConstants.DEFAULT_PERSPECTIVE_ID);
98 }
99 }
100
101
102
103
104 @Override
105 public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
106 final IWorkbenchWindowConfigurer configurer) {
107 return new UrumaWorkbenchWindowAdvisor(configurer);
108 }
109
110
111
112
113 @Override
114 public void eventLoopException(final Throwable throwable) {
115 logger.log(EXCEPTION_OCCURED_WITH_REASON, throwable, throwable
116 .getMessage());
117
118 Display display = getWorkbenchConfigurer().getWorkbench().getDisplay();
119 boolean displayCreated = false;
120 if (display == null) {
121 display = Display.getCurrent();
122
123 if (display == null) {
124 display = new Display();
125 displayCreated = true;
126 }
127 }
128 Shell shell = new Shell(display);
129 String msg = MessageUtil.getMessageWithBundleName(URUMA_MESSAGE_BASE,
130 "RCP_EXCEPTION_OCCURED");
131 UrumaErrorDialog dialog = new UrumaErrorDialog(shell, "Uruma", msg,
132 throwable);
133 dialog.open();
134 shell.dispose();
135
136 if (displayCreated) {
137 display.dispose();
138 }
139 }
140 }