1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.uruma.renderer.impl;
17
18 import org.eclipse.jface.window.Window;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.graphics.Image;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.swt.widgets.Shell;
26 import org.seasar.eclipse.common.util.GeometryUtil;
27 import org.seasar.eclipse.common.util.ImageManager;
28 import org.seasar.framework.util.StringUtil;
29 import org.seasar.uruma.component.UIComponent;
30 import org.seasar.uruma.component.jface.ControlComponent;
31 import org.seasar.uruma.component.jface.WindowComponent;
32 import org.seasar.uruma.context.PartContext;
33 import org.seasar.uruma.context.WidgetHandle;
34 import org.seasar.uruma.core.UrumaConstants;
35 import org.seasar.uruma.util.PathUtil;
36
37
38
39
40
41
42 public class WindowRenderer extends
43 AbstractCompositeRenderer<WindowComponent, Composite> {
44
45
46
47
48
49
50
51 public int getShellStyle(final WindowComponent uiComponent) {
52 return getStyle(uiComponent);
53 }
54
55
56
57
58
59
60 @Override
61 public WidgetHandle render(final UIComponent uiComponent,
62 final WidgetHandle parent, final PartContext context) {
63 Shell shell = parent.<Shell> getCastWidget();
64
65 configureShell((WindowComponent) uiComponent, shell);
66 return super.render(uiComponent, parent, context);
67 }
68
69
70
71
72
73
74
75 @Override
76 protected void doRenderAfter(final Composite widget,
77 final WindowComponent uiComponent, final WidgetHandle parent,
78 final PartContext context) {
79 setDefaultButton(uiComponent, context);
80 setDefaultFocus(uiComponent, context);
81 }
82
83 protected void configureShell(final WindowComponent window,
84 final Shell shell) {
85
86 if (window.title != null) {
87 shell.setText(window.title);
88 }
89
90
91 String width = window.width;
92 String height = window.height;
93 if ((width != null) && (height != null)) {
94 shell.setSize(calcWidth(width), calcHeight(height));
95 shell.setLocation(calcX(window), calcY(window));
96 }
97
98
99 setMinimumSize(window, shell);
100
101
102 String img = window.image;
103 if (!StringUtil.isEmpty(img)) {
104 Image image = ImageManager.getImage(img);
105 if (image == null) {
106 String path = PathUtil.createPath(window.getBasePath(), img);
107 image = ImageManager.loadImage(path);
108 }
109 shell.setImage(image);
110 }
111 }
112
113 protected int calcWidth(final String width) {
114 return GeometryUtil.calcSize(width, Display.getCurrent()
115 .getClientArea().width);
116 }
117
118 protected int calcHeight(final String height) {
119 return GeometryUtil.calcSize(height, Display.getCurrent()
120 .getClientArea().height);
121 }
122
123 protected int calcX(final WindowComponent window) {
124 return GeometryUtil.calcPosition(window.x, Display.getCurrent()
125 .getClientArea().width, calcWidth(window.width));
126 }
127
128 protected int calcY(final WindowComponent window) {
129 return GeometryUtil.calcPosition(window.y, Display.getCurrent()
130 .getClientArea().height, calcHeight(window.height));
131 }
132
133 protected void setDefaultButton(final WindowComponent windowComponent,
134 final PartContext context) {
135 WidgetHandle defaultButtonHandle = context
136 .getWidgetHandle(windowComponent.defaultButtonId);
137
138 if (defaultButtonHandle != null) {
139 if (Button.class.isAssignableFrom(defaultButtonHandle
140 .getWidgetClass())) {
141 Button defaultButton = defaultButtonHandle
142 .<Button> getCastWidget();
143
144 WidgetHandle handle = context
145 .getWidgetHandle(UrumaConstants.SHELL_CID);
146 Shell shell = handle.<Shell> getCastWidget();
147 if (shell != null) {
148 shell.setDefaultButton(defaultButton);
149 defaultButton.forceFocus();
150 }
151 }
152
153 }
154 }
155
156 protected void setDefaultFocus(final WindowComponent windowComponent,
157 final PartContext context) {
158 WidgetHandle defaultFocusHandle = context
159 .getWidgetHandle(windowComponent.defaultButtonId);
160 if (defaultFocusHandle != null) {
161 if (Control.class.isAssignableFrom(defaultFocusHandle
162 .getWidgetClass())) {
163 Control control = defaultFocusHandle.<Control> getCastWidget();
164 control.setFocus();
165 }
166 }
167 }
168
169 protected void setMinimumSize(final WindowComponent windowComponent,
170 final Shell shell) {
171 String minWidth = windowComponent.minimumWidth;
172 String minHeight = windowComponent.minimumHeight;
173 if ((minWidth != null) && (minHeight != null)) {
174 shell.setMinimumSize(calcWidth(minWidth), calcHeight(minHeight));
175 }
176 }
177
178
179
180
181 @Override
182 protected Class<Composite> getWidgetType() {
183 return Composite.class;
184 }
185
186
187
188
189 @Override
190 protected int getDefaultStyle() {
191 return SWT.SHELL_TRIM;
192 }
193
194
195
196
197
198 @Override
199 protected void doRenderComposite(final WindowComponent compositeComponent,
200 final Composite composite) {
201
202 }
203
204
205
206
207
208 @Override
209 protected void setLocation(final ControlComponent controlComponent,
210 final Control control) {
211
212 }
213
214
215
216
217
218 @Override
219 protected void setSize(final ControlComponent controlComponent,
220 final Control control) {
221
222 }
223
224
225
226
227
228 @Override
229 protected void setMenu(final ControlComponent controlComponent,
230 final Control control) {
231
232 }
233 }