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.action.IAction; |
19 | |
import org.eclipse.jface.action.MenuManager; |
20 | |
import org.eclipse.jface.resource.ImageDescriptor; |
21 | |
import org.eclipse.swt.widgets.MenuItem; |
22 | |
import org.seasar.framework.util.StringUtil; |
23 | |
import org.seasar.uruma.binding.method.GenericAction; |
24 | |
import org.seasar.uruma.component.EnablesDependable; |
25 | |
import org.seasar.uruma.component.UIComponent; |
26 | |
import org.seasar.uruma.component.jface.MenuItemComponent; |
27 | |
import org.seasar.uruma.context.PartContext; |
28 | |
import org.seasar.uruma.context.WidgetHandle; |
29 | |
import org.seasar.uruma.context.WindowContext; |
30 | |
import org.seasar.uruma.renderer.RendererSupportUtil; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 4 | public class MenuItemRenderer extends AbstractRenderer { |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
@Override |
45 | |
public WidgetHandle preRender(final UIComponent uiComponent, |
46 | |
final WidgetHandle parent, final WindowContext context) { |
47 | 108 | setWindowContext(context); |
48 | |
|
49 | 108 | MenuItemComponent menuItemComponent = (MenuItemComponent) uiComponent; |
50 | 108 | IAction action = new GenericAction(null, getStyle(menuItemComponent)); |
51 | |
|
52 | 108 | setText(action, menuItemComponent); |
53 | 108 | setAccelerator(action, menuItemComponent); |
54 | 108 | setChecked(action, menuItemComponent); |
55 | 108 | setEnabled(action, menuItemComponent); |
56 | 108 | setImageDescriptor(action, menuItemComponent); |
57 | 108 | setDisabledImageDescriptor(action, menuItemComponent); |
58 | |
|
59 | 108 | MenuManager parentMenuManager = parent.<MenuManager> getCastWidget(); |
60 | 108 | parentMenuManager.add(action); |
61 | |
|
62 | 108 | WidgetHandle handle = createWidgetHandle(uiComponent, action); |
63 | |
|
64 | 108 | if (uiComponent instanceof EnablesDependable) { |
65 | 108 | setupEnablesDependingDef(handle, (EnablesDependable) uiComponent); |
66 | |
} |
67 | |
|
68 | 108 | return handle; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public WidgetHandle render(final UIComponent uiComponent, |
77 | |
final WidgetHandle parent, final PartContext context) { |
78 | |
|
79 | 0 | return null; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void renderAfter(final WidgetHandle widget, |
89 | |
final UIComponent uiComponent, final WidgetHandle parent, |
90 | |
final PartContext context) { |
91 | |
|
92 | 0 | } |
93 | |
|
94 | |
protected int getStyle(final MenuItemComponent menuItemComponent) { |
95 | 108 | String style = menuItemComponent.getStyle(); |
96 | 108 | if (MenuItemComponent.PUSH.equals(style)) { |
97 | 0 | return IAction.AS_PUSH_BUTTON; |
98 | 108 | } else if (MenuItemComponent.RADIO.equals(style)) { |
99 | 12 | return IAction.AS_RADIO_BUTTON; |
100 | 96 | } else if (MenuItemComponent.CHECK.equals(style)) { |
101 | 16 | return IAction.AS_CHECK_BOX; |
102 | |
} else { |
103 | 80 | return IAction.AS_PUSH_BUTTON; |
104 | |
} |
105 | |
} |
106 | |
|
107 | |
protected void setText(final IAction action, |
108 | |
final MenuItemComponent menuItemComponent) { |
109 | 108 | String text = menuItemComponent.text; |
110 | 108 | if (!StringUtil.isEmpty(text)) { |
111 | 108 | action.setText(RendererSupportUtil.convertText(text)); |
112 | |
} |
113 | 108 | } |
114 | |
|
115 | |
protected void setAccelerator(final IAction action, |
116 | |
final MenuItemComponent menuItemComponent) { |
117 | 108 | String accelStr = menuItemComponent.accelerator; |
118 | 108 | if (accelStr != null) { |
119 | 8 | action.setAccelerator(RendererSupportUtil |
120 | |
.convertAccelerator(accelStr)); |
121 | |
} |
122 | 108 | } |
123 | |
|
124 | |
protected void setChecked(final IAction action, |
125 | |
final MenuItemComponent menuItemComponent) { |
126 | 108 | String selection = menuItemComponent.selection; |
127 | 108 | if (selection != null) { |
128 | 12 | action.setChecked(RendererSupportUtil.convertBoolean(selection)); |
129 | |
} |
130 | 108 | } |
131 | |
|
132 | |
protected void setDescription(final IAction action, |
133 | |
final MenuItemComponent menuItemComponent) { |
134 | 0 | if (menuItemComponent.description != null) { |
135 | 0 | action.setDescription(RendererSupportUtil |
136 | |
.convertText(menuItemComponent.description)); |
137 | |
} |
138 | 0 | } |
139 | |
|
140 | |
protected void setEnabled(final IAction action, |
141 | |
final MenuItemComponent menuItemComponent) { |
142 | 108 | String checked = menuItemComponent.enabled; |
143 | 108 | if (checked != null) { |
144 | 8 | action.setEnabled(RendererSupportUtil.convertBoolean(checked)); |
145 | |
} |
146 | 108 | } |
147 | |
|
148 | |
protected void setImageDescriptor(final IAction action, |
149 | |
final MenuItemComponent menuItemComponent) { |
150 | 108 | String path = menuItemComponent.image; |
151 | 108 | if (!StringUtil.isEmpty(path)) { |
152 | 4 | ImageDescriptor desc = RendererSupportUtil.convertImageDescriptor( |
153 | |
path, menuItemComponent.getBasePath()); |
154 | 4 | action.setImageDescriptor(desc); |
155 | |
} |
156 | 108 | } |
157 | |
|
158 | |
protected void setDisabledImageDescriptor(final IAction action, |
159 | |
final MenuItemComponent menuItemComponent) { |
160 | 108 | String path = menuItemComponent.disabledImage; |
161 | 108 | if (!StringUtil.isEmpty(path)) { |
162 | 4 | ImageDescriptor desc = RendererSupportUtil.convertImageDescriptor( |
163 | |
path, menuItemComponent.getBasePath()); |
164 | 4 | action.setDisabledImageDescriptor(desc); |
165 | |
} |
166 | 108 | } |
167 | |
|
168 | |
protected void setHoverImageDescriptor(final IAction action, |
169 | |
final MenuItemComponent menuItemComponent) { |
170 | 0 | String path = menuItemComponent.disabledImage; |
171 | 0 | if (!StringUtil.isEmpty(path)) { |
172 | 0 | ImageDescriptor desc = RendererSupportUtil.convertImageDescriptor( |
173 | |
path, menuItemComponent.getBasePath()); |
174 | 0 | action.setHoverImageDescriptor(desc); |
175 | |
} |
176 | 0 | } |
177 | |
|
178 | |
} |