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 | 228 | public class WindowRenderer extends |
43 | |
AbstractCompositeRenderer<WindowComponent, Composite> { |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public int getShellStyle(final WindowComponent uiComponent) { |
52 | 112 | 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 | 112 | Shell shell = parent.<Shell> getCastWidget(); |
64 | |
|
65 | 112 | configureShell((WindowComponent) uiComponent, shell); |
66 | 112 | 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 | 112 | setDefaultButton(uiComponent, context); |
80 | 112 | setDefaultFocus(uiComponent, context); |
81 | 112 | } |
82 | |
|
83 | |
protected void configureShell(final WindowComponent window, |
84 | |
final Shell shell) { |
85 | |
|
86 | 112 | if (window.title != null) { |
87 | 112 | shell.setText(window.title); |
88 | |
} |
89 | |
|
90 | |
|
91 | 112 | String width = window.width; |
92 | 112 | String height = window.height; |
93 | 112 | if ((width != null) && (height != null)) { |
94 | 20 | shell.setSize(calcWidth(width), calcHeight(height)); |
95 | 20 | shell.setLocation(calcX(window), calcY(window)); |
96 | |
} |
97 | |
|
98 | |
|
99 | 112 | setMinimumSize(window, shell); |
100 | |
|
101 | |
|
102 | 112 | String img = window.image; |
103 | 112 | if (!StringUtil.isEmpty(img)) { |
104 | 12 | Image image = ImageManager.getImage(img); |
105 | 12 | if (image == null) { |
106 | 12 | String path = PathUtil.createPath(window.getBasePath(), img); |
107 | 12 | image = ImageManager.loadImage(path); |
108 | |
} |
109 | 12 | shell.setImage(image); |
110 | |
} |
111 | 112 | } |
112 | |
|
113 | |
protected int calcWidth(final String width) { |
114 | 44 | return GeometryUtil.calcSize(width, Display.getCurrent() |
115 | |
.getClientArea().width); |
116 | |
} |
117 | |
|
118 | |
protected int calcHeight(final String height) { |
119 | 44 | return GeometryUtil.calcSize(height, Display.getCurrent() |
120 | |
.getClientArea().height); |
121 | |
} |
122 | |
|
123 | |
protected int calcX(final WindowComponent window) { |
124 | 20 | return GeometryUtil.calcPosition(window.x, Display.getCurrent() |
125 | |
.getClientArea().width, calcWidth(window.width)); |
126 | |
} |
127 | |
|
128 | |
protected int calcY(final WindowComponent window) { |
129 | 20 | 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 | 112 | WidgetHandle defaultButtonHandle = context |
136 | |
.getWidgetHandle(windowComponent.defaultButtonId); |
137 | |
|
138 | 112 | if (defaultButtonHandle != null) { |
139 | 108 | if (Button.class.isAssignableFrom(defaultButtonHandle |
140 | |
.getWidgetClass())) { |
141 | 108 | Button defaultButton = defaultButtonHandle |
142 | |
.<Button> getCastWidget(); |
143 | |
|
144 | 108 | WidgetHandle handle = context |
145 | |
.getWidgetHandle(UrumaConstants.SHELL_CID); |
146 | 108 | Shell shell = handle.<Shell> getCastWidget(); |
147 | 108 | if (shell != null) { |
148 | 108 | shell.setDefaultButton(defaultButton); |
149 | 108 | defaultButton.forceFocus(); |
150 | |
} |
151 | |
} |
152 | |
|
153 | |
} |
154 | 112 | } |
155 | |
|
156 | |
protected void setDefaultFocus(final WindowComponent windowComponent, |
157 | |
final PartContext context) { |
158 | 112 | WidgetHandle defaultFocusHandle = context |
159 | |
.getWidgetHandle(windowComponent.defaultButtonId); |
160 | 112 | if (defaultFocusHandle != null) { |
161 | 108 | if (Control.class.isAssignableFrom(defaultFocusHandle |
162 | |
.getWidgetClass())) { |
163 | 108 | Control control = defaultFocusHandle.<Control> getCastWidget(); |
164 | 108 | control.setFocus(); |
165 | |
} |
166 | |
} |
167 | 112 | } |
168 | |
|
169 | |
protected void setMinimumSize(final WindowComponent windowComponent, |
170 | |
final Shell shell) { |
171 | 112 | String minWidth = windowComponent.minimumWidth; |
172 | 112 | String minHeight = windowComponent.minimumHeight; |
173 | 112 | if ((minWidth != null) && (minHeight != null)) { |
174 | 4 | shell.setMinimumSize(calcWidth(minWidth), calcHeight(minHeight)); |
175 | |
} |
176 | 112 | } |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
@Override |
182 | |
protected Class<Composite> getWidgetType() { |
183 | 336 | return Composite.class; |
184 | |
} |
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
@Override |
190 | |
protected int getDefaultStyle() { |
191 | 224 | 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 | 112 | } |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
@Override |
209 | |
protected void setLocation(final ControlComponent controlComponent, |
210 | |
final Control control) { |
211 | |
|
212 | 112 | } |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
@Override |
219 | |
protected void setSize(final ControlComponent controlComponent, |
220 | |
final Control control) { |
221 | |
|
222 | 112 | } |
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
@Override |
229 | |
protected void setMenu(final ControlComponent controlComponent, |
230 | |
final Control control) { |
231 | |
|
232 | 112 | } |
233 | |
} |