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 org.eclipse.core.commands.IHandler;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.swt.graphics.Point;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.ui.IWorkbench;
24 import org.eclipse.ui.application.ActionBarAdvisor;
25 import org.eclipse.ui.application.IActionBarConfigurer;
26 import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
27 import org.eclipse.ui.application.WorkbenchWindowAdvisor;
28 import org.eclipse.ui.handlers.IHandlerService;
29 import org.seasar.eclipse.common.util.GeometryUtil;
30 import org.seasar.eclipse.common.util.ImageManager;
31 import org.seasar.framework.container.S2Container;
32 import org.seasar.framework.util.StringUtil;
33 import org.seasar.uruma.binding.enables.EnablesDependingListenerSupport;
34 import org.seasar.uruma.binding.method.MethodBindingSupport;
35 import org.seasar.uruma.component.EnablesDependableVisitor;
36 import org.seasar.uruma.component.jface.MenuComponent;
37 import org.seasar.uruma.component.rcp.WorkbenchComponent;
38 import org.seasar.uruma.context.WidgetHandle;
39 import org.seasar.uruma.context.WindowContext;
40 import org.seasar.uruma.context.impl.WidgetHandleImpl;
41 import org.seasar.uruma.core.ComponentUtil;
42 import org.seasar.uruma.core.UrumaConstants;
43 import org.seasar.uruma.rcp.binding.CommandDesc;
44 import org.seasar.uruma.rcp.binding.CommandRegistry;
45 import org.seasar.uruma.rcp.binding.GenericHandler;
46 import org.seasar.uruma.rcp.util.UrumaServiceUtil;
47 import org.seasar.uruma.rcp.util.ViewPartUtil;
48 import org.seasar.uruma.util.PathUtil;
49
50
51
52
53
54
55 public class UrumaWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
56 private WorkbenchComponent workbench;
57
58
59
60
61
62
63
64 public UrumaWorkbenchWindowAdvisor(
65 final IWorkbenchWindowConfigurer configurer) {
66 super(configurer);
67
68 registComponents(configurer);
69 }
70
71
72
73
74 @Override
75 public void createWindowContents(final Shell shell) {
76 super.createWindowContents(shell);
77
78 WindowContext windowContext = UrumaServiceUtil.getService()
79 .getWorkbenchWindowContext();
80
81
82 ComponentUtil.setupWorkbenchAction(windowContext,
83 UrumaConstants.WORKBENCH_WINDOW_CONTEXT_ID);
84 ComponentUtil.invokeInitMethodOnAction(windowContext);
85 }
86
87
88
89
90 @Override
91 public ActionBarAdvisor createActionBarAdvisor(
92 final IActionBarConfigurer configurer) {
93 return new UrumaActionBarAdvisor(configurer);
94 }
95
96 @Override
97 public void preWindowOpen() {
98 workbench = UrumaServiceUtil.getService().getWorkbenchComponent();
99
100 IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
101 configurer.setTitle(workbench.title);
102
103 configurer.setInitialSize(calcInitialSize(workbench.initWidth,
104 workbench.initHeight));
105
106 setupStatusLine(workbench, configurer);
107
108 WindowContext windowContext = UrumaServiceUtil.getService()
109 .getWorkbenchWindowContext();
110
111 setupCommandHandler(configurer, windowContext);
112 setupEnablesDependable(windowContext);
113 setupWorkbench(configurer);
114 }
115
116
117
118
119 @Override
120 public void postWindowCreate() {
121
122
123 WindowContext context = UrumaServiceUtil.getService()
124 .getWorkbenchWindowContext();
125 EnablesDependingListenerSupport.setupEnableDependingListeners(context);
126
127
128
129
130 MethodBindingSupport.createListeners(context);
131
132 ViewPartUtil.findUrumaAppViewRefs();
133 }
134
135 protected void setupWorkbench(final IWorkbenchWindowConfigurer configurer) {
136 configurer.setShowMenuBar(workbench.menuBar == null ? true : Boolean
137 .parseBoolean(workbench.menuBar));
138 configurer.setShowCoolBar(Boolean.parseBoolean(workbench.coolBar));
139 configurer.setShowFastViewBars(Boolean
140 .parseBoolean(workbench.fastViewBars));
141 configurer.setShowPerspectiveBar(Boolean
142 .parseBoolean(workbench.perspectiveBar));
143 configurer.setShowProgressIndicator(Boolean
144 .parseBoolean(workbench.progressIndicator));
145 }
146
147 protected Point calcInitialSize(final String width, final String height) {
148 String widthStr = StringUtil.isNotBlank(width) ? width
149 : UrumaConstants.DEFAULT_WORKBENCH_WIDTH;
150 String heightStr = StringUtil.isNotBlank(height) ? height
151 : UrumaConstants.DEFAULT_WORKBENCH_HEIGHT;
152
153 int xSize = GeometryUtil.calcSize(widthStr, Display.getCurrent()
154 .getClientArea().width);
155 int ySize = GeometryUtil.calcSize(heightStr, Display.getCurrent()
156 .getClientArea().height);
157 return new Point(xSize, ySize);
158 }
159
160 protected void setupImage(final WorkbenchComponent workbench) {
161 if (StringUtil.isNotBlank(workbench.image)) {
162 Image image = ImageManager.getImage(workbench.image);
163 if (image == null) {
164 String path = PathUtil.createPath(workbench.getBasePath(),
165 workbench.image);
166 image = ImageManager.loadImage(path);
167 }
168
169 if (image != null) {
170 IWorkbenchWindowConfigurer configurator = getWindowConfigurer();
171 Shell shell = configurator.getWindow().getShell();
172 shell.setImage(image);
173 }
174 }
175 }
176
177 protected void setupStatusLine(final WorkbenchComponent workbench,
178 final IWorkbenchWindowConfigurer configurer) {
179 configurer
180 .setShowStatusLine(Boolean.parseBoolean(workbench.statusLine));
181 }
182
183
184
185
186
187
188 protected void setupCommandHandler(
189 final IWorkbenchWindowConfigurer configurer,
190 final WindowContext context) {
191 IWorkbench workbench = configurer.getWorkbenchConfigurer()
192 .getWorkbench();
193 IHandlerService service = (IHandlerService) workbench
194 .getService(IHandlerService.class);
195
196 CommandRegistry registry = UrumaServiceUtil.getService()
197 .getCommandRegistry();
198 for (CommandDesc desc : registry.getCommandDescs()) {
199 GenericHandler handler = new GenericHandler();
200 service.activateHandler(desc.getCommandId(), handler);
201
202 WidgetHandle handle = new WidgetHandleImpl(handler);
203 handle.setId(desc.getUrumaId());
204 context.putWidgetHandle(handle);
205 }
206 }
207
208 protected void setupEnablesDependable(final WindowContext context) {
209 EnablesDependableVisitor visitor = new EnablesDependableVisitor(context);
210 for (MenuComponent menu : workbench.getMenus()) {
211 menu.accept(visitor);
212 }
213 }
214
215 protected void registComponents(final IWorkbenchWindowConfigurer configurer) {
216 S2Container container = UrumaServiceUtil.getService().getContainer();
217 container.register(configurer);
218 container.register(configurer.getWindow());
219 container.register(configurer.getWindow().getWorkbench());
220 }
221 }