|
@@ -1,292 +1,292 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.client.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.widgets.*; |
5 |
|
- |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
6 |
|
- |
import org.litesoft.GWT.forms.client.components.factories.*; |
7 |
|
- |
import org.litesoft.GWT.forms.client.components.factories.others.*; |
8 |
|
- |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
9 |
|
- |
import org.litesoft.commonfoundation.typeutils.Objects; |
10 |
|
- |
import org.litesoft.ui.def.*; |
11 |
|
- |
import org.litesoft.ui.def.nonpublic.*; |
12 |
|
- |
import org.litesoft.ui.def.nonpublic.support.*; |
13 |
|
- |
|
14 |
|
- |
import com.google.gwt.user.client.ui.*; |
15 |
|
- |
|
16 |
|
- |
import java.util.*; |
17 |
|
- |
|
18 |
|
- |
public abstract class AbstractFormComponentRenderer { |
19 |
|
- |
private static final String SUB_FORM_ONLY_CONTAINER = "litesoft-SubFormOnlyContainer"; |
20 |
|
- |
private static final String SUB_FORM_OUTER_CONTAINER = "litesoft-SubFormOuterContainer"; |
21 |
|
- |
private static final String SUB_FORM_INNER_CONTAINER = "litesoft-SubFormInnerContainer"; |
22 |
|
- |
protected static final String SUB_FORM_ROW_ONLY_CONTAINER = "litesoft-SubFormRowOnlyContainer"; |
23 |
|
- |
protected static final String SUB_FORM_ROW_OUTER_CONTAINER = "litesoft-SubFormRowOuterContainer"; |
24 |
|
- |
protected static final String SUB_FORM_ROW_INNER_CONTAINER = "litesoft-SubFormRowInnerContainer"; |
25 |
|
- |
protected static final String SUB_FORM_ADD_ROW_BUTTON = "litesoft-SubFormAddRowButton"; |
26 |
|
- |
protected static final String SUB_FORM_REMOVE_ROW_BUTTON = "litesoft-SubFormRemoveRowButton"; |
27 |
|
- |
|
28 |
|
- |
protected FormComponentFactory mFormComponentFactory; |
29 |
|
- |
protected FormMetaData mFormMetaData; |
30 |
|
- |
protected FormInstanceComponentHandler mComponentFormHandler; |
31 |
|
- |
|
32 |
|
- |
public AbstractFormComponentRenderer( FormComponentFactory pFormComponentFactory, |
33 |
|
- |
FormMetaData pFormMetaData, |
34 |
|
- |
FormInstanceComponentHandler pComponentHandler ) { |
35 |
|
- |
Objects.assertNotNull( "FormComponentFactory", mFormComponentFactory = pFormComponentFactory ); |
36 |
|
- |
Objects.assertNotNull( "FormMetaData", mFormMetaData = pFormMetaData ); |
37 |
|
- |
Objects.assertNotNull( "FormInstanceComponentHandler", mComponentFormHandler = pComponentHandler ); |
38 |
|
- |
} |
39 |
|
- |
|
40 |
|
- |
protected DefWidgetStruct[] renderChildren( UiContainerMarker pUiDef ) { |
41 |
|
- |
HorizontalPeerDeterminer zHPD = createHorizontalPeerDeterminer( pUiDef ); |
42 |
|
- |
List zChildDefWidgetStructs = new ArrayList(); |
43 |
|
- |
while ( zHPD.hasNext() ) { |
44 |
|
- |
UiDef zUiDef = (UiDef) zHPD.next(); |
45 |
|
- |
Widget widget = recursiveRender( zUiDef, zHPD.hasHorizontalPeer() ); |
46 |
|
- |
if ( widget != null ) { |
47 |
|
- |
zChildDefWidgetStructs.add( new DefWidgetStruct( zUiDef, widget ) ); |
48 |
|
- |
} |
49 |
|
- |
} |
50 |
|
- |
return DefWidgetStruct.toArray( zChildDefWidgetStructs ); |
51 |
|
- |
} |
52 |
|
- |
|
53 |
|
- |
protected Widget renderContainer( UiContainerDef pUiDef ) { |
54 |
|
- |
DefWidgetStruct[] zChildren; |
55 |
|
- |
switch ( pUiDef.getType().getCaseIndex() ) { |
56 |
|
- |
case UiDef.CI_TABS: |
57 |
|
- |
zChildren = renderTabs( (UiTabsDef) pUiDef ); |
58 |
|
- |
break; |
59 |
|
- |
case UiDef.CI_CARDS: |
60 |
|
- |
zChildren = renderCards( (UiCardsDef) pUiDef ); |
61 |
|
- |
break; |
62 |
|
- |
default: |
63 |
|
- |
zChildren = renderChildren( pUiDef ); |
64 |
|
- |
} |
65 |
|
- |
return createContainerWidget( pUiDef, zChildren ); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
private DefWidgetStruct[] renderCards( UiCardsDef pUiDef ) { |
69 |
|
- |
List zWidgets = new ArrayList(); |
70 |
|
- |
UiDef[] zChildren = pUiDef.getChildrenHelper().getChildren(); |
71 |
|
- |
boolean anyFloodX = false; |
72 |
|
- |
boolean anyFloodY = false; |
73 |
|
- |
for ( int i = 0; i < zChildren.length; i++ ) { |
74 |
|
- |
Widget zWidget = renderCard( (UiCardDef) zChildren[i] ); |
75 |
|
- |
if ( !anyFloodX ) { |
76 |
|
- |
anyFloodX = WidthStretchableAdjustor.isStretchable( zWidget ); |
77 |
|
- |
} |
78 |
|
- |
if ( !anyFloodY ) { |
79 |
|
- |
anyFloodY = HeightStretchableAdjustor.isStretchable( zWidget ); |
80 |
|
- |
} |
81 |
|
- |
zWidgets.add( zWidget ); |
82 |
|
- |
} |
83 |
|
- |
StretchabilityAdjustor zAdjustor; |
84 |
|
- |
switch ( (anyFloodX ? 1 : 0) + (anyFloodY ? 2 : 0) ) { |
85 |
|
- |
default: |
86 |
|
- |
case 0: |
87 |
|
- |
zAdjustor = NoStretchabilityAdjustor.INSTANCE; |
88 |
|
- |
break; |
89 |
|
- |
case 1: |
90 |
|
- |
zAdjustor = WidthStretchableAdjustor.INSTANCE; |
91 |
|
- |
break; |
92 |
|
- |
case 2: |
93 |
|
- |
zAdjustor = HeightStretchableAdjustor.INSTANCE; |
94 |
|
- |
break; |
95 |
|
- |
case 3: |
96 |
|
- |
zAdjustor = BothStretchableAdjustor.INSTANCE; |
97 |
|
- |
break; |
98 |
|
- |
} |
99 |
|
- |
DefWidgetStruct[] rv = new DefWidgetStruct[zChildren.length]; |
100 |
|
- |
for ( int i = 0; i < zChildren.length; i++ ) { |
101 |
|
- |
rv[i] = new DefWidgetStruct( zChildren[i], |
102 |
|
- |
zAdjustor.adjustStretchability( (Widget) zWidgets.get( i ) ) ); |
103 |
|
- |
} |
104 |
|
- |
return rv; |
105 |
|
- |
} |
106 |
|
- |
|
107 |
|
- |
private Widget renderCard( UiCardDef pUiDef ) { |
108 |
|
- |
UiDef zChild = pUiDef.getChildrenHelper().getFirstChild(); |
109 |
|
- |
Widget zWidget = (zChild != null) ? recursiveRender( zChild, false ) : null; |
110 |
|
- |
return (zWidget != null) ? zWidget : new Label( "No Card Widget" ); |
111 |
|
- |
} |
112 |
|
- |
|
113 |
|
- |
private DefWidgetStruct[] renderTabs( UiTabsDef pUiDef ) { |
114 |
|
- |
List zChildDefWidgetStructs = new ArrayList(); |
115 |
|
- |
UiDef[] zChildren = pUiDef.getChildrenHelper().getChildren(); |
116 |
|
- |
for ( int i = 0; i < zChildren.length; i++ ) { |
117 |
|
- |
zChildDefWidgetStructs.add( renderTab( (UiTabDef) zChildren[i] ) ); |
118 |
|
- |
} |
119 |
|
- |
return DefWidgetStruct.toArray( zChildDefWidgetStructs ); |
120 |
|
- |
} |
121 |
|
- |
|
122 |
|
- |
private DefWidgetStruct renderTab( UiTabDef pUiDef ) { |
123 |
|
- |
UiDef zChild = pUiDef.getChildrenHelper().getFirstChild(); |
124 |
|
- |
Widget zWidget = (zChild != null) ? recursiveRender( zChild, false ) : null; |
125 |
|
- |
if ( zWidget == null ) { |
126 |
|
- |
zWidget = new Label( "No Tab Widget" ); |
127 |
|
- |
} |
128 |
|
- |
return new DefWidgetStruct( pUiDef, |
129 |
|
- |
BothStretchableAdjustor.INSTANCE.adjustStretchability( zWidget ) ); |
130 |
|
- |
} |
131 |
|
- |
|
132 |
|
- |
protected HorizontalPeerDeterminer createHorizontalPeerDeterminer( UiContainerMarker pUiDef ) { |
133 |
|
- |
if ( pUiDef instanceof UiLayoutTwoDimensionalDef ) { |
134 |
|
- |
return new TwoDimensionalHorizontalPeerDeterminer( (UiLayoutTwoDimensionalDef) pUiDef ); |
135 |
|
- |
} |
136 |
|
- |
return new HorizontalPeerDeterminer( pUiDef, pUiDef instanceof UiHorizontalLayoutDef ); |
137 |
|
- |
} |
138 |
|
- |
|
139 |
|
- |
protected Widget recursiveRender( UiDef pUiDef, boolean pHasHorizontalPeer ) { |
140 |
|
- |
if ( UiRelSubFormDef.TYPE.equals( pUiDef.getType() ) ) { |
141 |
|
- |
return createSubFormWidget( (UiRelSubFormDef) pUiDef ); |
142 |
|
- |
} |
143 |
|
- |
if ( pUiDef instanceof UiContainerDef ) { |
144 |
|
- |
return renderContainer( (UiContainerDef) pUiDef ); |
145 |
|
- |
} |
146 |
|
- |
//noinspection UnnecessaryLocalVariable |
147 |
|
- |
Widget widget = mFormComponentFactory.create( mComponentFormHandler, // |
148 |
|
- |
pUiDef, mFormMetaData, // |
149 |
|
- |
pHasHorizontalPeer ); |
150 |
|
- |
return widget; |
151 |
|
- |
} |
152 |
|
- |
|
153 |
|
- |
abstract protected RelSubFormInstanceRenderer createRelSubFormInstanceRenderer( |
154 |
|
- |
UiRelSubFormDef pSubFormDef, FormMetaData pSubFormMetaData, boolean pNoRemoveRow, |
155 |
|
- |
SubFormRowCarrier pRowCarrier ); |
156 |
|
- |
|
157 |
|
- |
protected Widget createSubFormWidget( UiRelSubFormDef pSubFormDef ) { |
158 |
|
- |
FormMetaData zSubFormMetaData = mFormMetaData.getRelSubForm( pSubFormDef ); |
159 |
|
- |
String zTabAttributeName = pSubFormDef.getTabAttributeName(); |
160 |
|
- |
return (zTabAttributeName != null) ? // |
161 |
|
- |
createTabSubForms( pSubFormDef, zSubFormMetaData, zTabAttributeName ) : // |
162 |
|
- |
createVerticalSubForms( pSubFormDef, zSubFormMetaData, pSubFormDef.isDisabled() || |
163 |
|
- |
zSubFormMetaData.getIntendedUse().isDisabled() ); |
164 |
|
- |
} |
165 |
|
- |
|
166 |
|
- |
private Widget createTabSubForms( UiRelSubFormDef pSubFormDef, FormMetaData pSubFormMetaData, |
167 |
|
- |
String pTabAttributeName ) { |
168 |
|
- |
SizeableSelectorPanel zSelectorPanel = new SizeableSelectorPanel( true ); |
169 |
|
- |
createRelSubFormInstanceRenderer( pSubFormDef, pSubFormMetaData, true, |
170 |
|
- |
new TabSubFormRowCarrier( zSelectorPanel ) ); |
171 |
|
- |
return wrapSubForm( pSubFormDef, true, zSelectorPanel ); |
172 |
|
- |
} |
173 |
|
- |
|
174 |
|
- |
private Widget wrapSubForm( UiRelSubFormDef pSubFormDef, boolean pOverflowHidden, Widget pWidget ) { |
175 |
|
- |
String zExtTitle = pSubFormDef.getExtTitle(); |
176 |
|
- |
if ( zExtTitle != null ) { |
177 |
|
- |
LabelMetaData md = mFormMetaData.getLabel( pSubFormDef ); |
178 |
|
- |
String zTitle = md.getExternalText(); |
179 |
|
- |
AbstractSizeableSimplePanel zPanel = new SizeableTitledBorderedSimplePanel( pOverflowHidden, |
180 |
|
- |
zTitle, |
181 |
|
- |
pSubFormDef.getTitleFont() ).stretchable(); |
182 |
|
- |
zPanel.setWidget( pWidget ); |
183 |
|
- |
return zPanel; |
184 |
|
- |
} |
185 |
|
- |
if ( pSubFormDef.isBordered() ) { |
186 |
|
- |
AbstractSizeableSimplePanel zPanel = |
187 |
|
- |
new SizeableBorderedSimplePanel( pOverflowHidden ).stretchable(); |
188 |
|
- |
zPanel.setWidget( pWidget ); |
189 |
|
- |
return zPanel; |
190 |
|
- |
} |
191 |
|
- |
return pWidget; |
192 |
|
- |
} |
193 |
|
- |
|
194 |
|
- |
private Widget createVerticalSubForms( UiRelSubFormDef pSubFormDef, FormMetaData pSubFormMetaData, |
195 |
|
- |
boolean pDisabled ) { |
196 |
|
- |
AbstractSizeableVerticalRegularPanel zFormVerticalPanel, zRowVerticalPanel; |
197 |
|
- |
if ( pDisabled ) { |
198 |
|
- |
AbstractSizeableVerticalRegularPanel zOnlyContainer = |
199 |
|
- |
createSubFormContainer( pSubFormDef, false ); |
200 |
|
- |
zOnlyContainer.addStyleName( SUB_FORM_ONLY_CONTAINER ); |
201 |
|
- |
zFormVerticalPanel = zRowVerticalPanel = zOnlyContainer; |
202 |
|
- |
} else { |
203 |
|
- |
zFormVerticalPanel = createSubFormContainer( pSubFormDef, true ); |
204 |
|
- |
zFormVerticalPanel.addStyleName( SUB_FORM_OUTER_CONTAINER ); |
205 |
|
- |
zRowVerticalPanel = new SizeableVerticalPanel( false ).stretchable(); |
206 |
|
- |
zRowVerticalPanel.addStyleName( SUB_FORM_INNER_CONTAINER ); |
207 |
|
- |
} |
208 |
|
- |
RelSubFormInstanceRenderer zRenderer = createRelSubFormInstanceRenderer( pSubFormDef, |
209 |
|
- |
pSubFormMetaData, pDisabled, |
210 |
|
- |
new VerticalSubFormRowCarrier( |
211 |
|
- |
zRowVerticalPanel ) ); |
212 |
|
- |
if ( !pDisabled ) { |
213 |
|
- |
zFormVerticalPanel.add( zRowVerticalPanel ); |
214 |
|
- |
Widget zAddButton = zRenderer.createRowAddButton( "AddRow" ); |
215 |
|
- |
zFormVerticalPanel.add( zAddButton ); |
216 |
|
- |
zFormVerticalPanel.setCellHorizontalAlignment( zAddButton, HasHorizontalAlignment.ALIGN_CENTER ); |
217 |
|
- |
} |
218 |
|
- |
return zFormVerticalPanel; |
219 |
|
- |
} |
220 |
|
- |
|
221 |
|
- |
private AbstractSizeableVerticalRegularPanel createSubFormContainer( UiRelSubFormDef pSubFormDef, |
222 |
|
- |
boolean pOverflowHidden ) { |
223 |
|
- |
String zExtTitle = pSubFormDef.getExtTitle(); |
224 |
|
- |
if ( zExtTitle != null ) { |
225 |
|
- |
LabelMetaData md = mFormMetaData.getLabel( pSubFormDef ); |
226 |
|
- |
String zTitle = md.getExternalText(); |
227 |
|
- |
return new SizeableTitledBorderedVerticalPanel( pOverflowHidden, zTitle, |
228 |
|
- |
pSubFormDef.getTitleFont() ).stretchable(); |
229 |
|
- |
} |
230 |
|
- |
if ( pSubFormDef.isBordered() ) { |
231 |
|
- |
return new SizeableBorderedVerticalPanel( pOverflowHidden ).stretchable(); |
232 |
|
- |
} |
233 |
|
- |
return new SizeableVerticalPanel( pOverflowHidden ).stretchable(); |
234 |
|
- |
} |
235 |
|
- |
|
236 |
|
- |
protected Widget createImageFormButton( String pActionID, String pStyleName ) { |
237 |
|
- |
ActionMetaData zMD = mFormMetaData.getAction( pActionID ); |
238 |
|
- |
if ( zMD == null ) { |
239 |
|
- |
throw new IllegalStateException( "Metadata required for a " + pActionID ); |
240 |
|
- |
} |
241 |
|
- |
String zImageButtonPath = "common/images/formcomponents/imageButton" + pActionID + ".gif"; |
242 |
|
- |
Widget widget = new FormButtonAdapter( mComponentFormHandler, pActionID, zMD, null, null, |
243 |
|
- |
new PushButton( new Image( zImageButtonPath ) ) ).init(); |
244 |
|
- |
widget.setStylePrimaryName( pStyleName ); |
245 |
|
- |
return widget; |
246 |
|
- |
} |
247 |
|
- |
|
248 |
|
- |
/** |
249 |
|
- |
* @param pUiDef - !null |
250 |
|
- |
* @param pChildWidgets - !null & No Nulls |
251 |
|
- |
* |
252 |
|
- |
* @return null OK |
253 |
|
- |
*/ |
254 |
|
- |
protected Widget createContainerWidget( UiDef pUiDef, DefWidgetStruct[] pChildWidgets ) { |
255 |
|
- |
ContainerFactory factory = getContainerFactory( pUiDef ); |
256 |
|
- |
//noinspection UnnecessaryLocalVariable |
257 |
|
- |
Widget widget = factory.createContainerWidget( mComponentFormHandler, // |
258 |
|
- |
pUiDef, mFormMetaData, // |
259 |
|
- |
pChildWidgets ); |
260 |
|
- |
return widget; |
261 |
|
- |
} |
262 |
|
- |
|
263 |
|
- |
protected ContainerFactory getContainerFactory( UiDef pUiDef ) { |
264 |
|
- |
if ( pUiDef != null ) { |
265 |
|
- |
ContainerFactory zCF = (ContainerFactory) mUiDefTypeToContainerFactory.get( pUiDef.getType() ); |
266 |
|
- |
if ( zCF != null ) { |
267 |
|
- |
return zCF; |
268 |
|
- |
} |
269 |
|
- |
} |
270 |
|
- |
throw new IllegalStateException( "No Container Factory for:" + pUiDef ); |
271 |
|
- |
} |
272 |
|
- |
|
273 |
|
- |
private static Map mUiDefTypeToContainerFactory = new HashMap(); |
274 |
|
- |
|
275 |
|
- |
private static void put( UiD_Type pType, ContainerFactory pFactory ) { |
276 |
|
- |
mUiDefTypeToContainerFactory.put( pType, pFactory ); |
277 |
|
- |
} |
278 |
|
- |
|
279 |
|
- |
static { |
280 |
|
- |
put( UiButtonBarDef.TYPE, /* */ new ButtonBarWidgetFactory() ); |
281 |
|
- |
put( UiCardsOfActionsDef.TYPE, /* */ new CardsOfActionsWidgetFactory() ); |
282 |
|
- |
put( UiCardsDef.TYPE, /* */ new CardsWidgetFactory() ); |
283 |
|
- |
put( UiFormDef.TYPE, /* */ new FormWidgetFactory() ); |
284 |
|
- |
put( UiGridLayoutDef.TYPE, /* */ new GridLayoutWidgetFactory() ); |
285 |
|
- |
put( UiGridOfActionsDef.TYPE, /* */ new GridOfActionsWidgetFactory() ); |
286 |
|
- |
put( UiHorizontalLayoutDef.TYPE, /* */ new HorizontalLayoutWidgetFactory() ); |
287 |
|
- |
put( UiSingleLayoutDef.TYPE, /* */ new SingleLayoutWidgetFactory() ); |
288 |
|
- |
put( UiTableDef.TYPE, /* */ new TableWidgetFactory() ); |
289 |
|
- |
put( UiTabsDef.TYPE, /* */ new TabsWidgetFactory() ); |
290 |
|
- |
put( UiVerticalLayoutDef.TYPE, /* */ new VerticalLayoutWidgetFactory() ); |
291 |
|
- |
} |
292 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.client.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.widgets.*; |
|
5 |
+ |
import org.litesoft.GWT.client.widgets.nonpublic.*; |
|
6 |
+ |
import org.litesoft.GWT.forms.client.components.factories.*; |
|
7 |
+ |
import org.litesoft.GWT.forms.client.components.factories.others.*; |
|
8 |
+ |
import org.litesoft.GWT.forms.client.components.nonpublic.*; |
|
9 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
10 |
+ |
import org.litesoft.ui.def.*; |
|
11 |
+ |
import org.litesoft.ui.def.nonpublic.*; |
|
12 |
+ |
import org.litesoft.ui.def.nonpublic.support.*; |
|
13 |
+ |
|
|
14 |
+ |
import com.google.gwt.user.client.ui.*; |
|
15 |
+ |
|
|
16 |
+ |
import java.util.*; |
|
17 |
+ |
|
|
18 |
+ |
public abstract class AbstractFormComponentRenderer { |
|
19 |
+ |
private static final String SUB_FORM_ONLY_CONTAINER = "litesoft-SubFormOnlyContainer"; |
|
20 |
+ |
private static final String SUB_FORM_OUTER_CONTAINER = "litesoft-SubFormOuterContainer"; |
|
21 |
+ |
private static final String SUB_FORM_INNER_CONTAINER = "litesoft-SubFormInnerContainer"; |
|
22 |
+ |
protected static final String SUB_FORM_ROW_ONLY_CONTAINER = "litesoft-SubFormRowOnlyContainer"; |
|
23 |
+ |
protected static final String SUB_FORM_ROW_OUTER_CONTAINER = "litesoft-SubFormRowOuterContainer"; |
|
24 |
+ |
protected static final String SUB_FORM_ROW_INNER_CONTAINER = "litesoft-SubFormRowInnerContainer"; |
|
25 |
+ |
protected static final String SUB_FORM_ADD_ROW_BUTTON = "litesoft-SubFormAddRowButton"; |
|
26 |
+ |
protected static final String SUB_FORM_REMOVE_ROW_BUTTON = "litesoft-SubFormRemoveRowButton"; |
|
27 |
+ |
|
|
28 |
+ |
protected FormComponentFactory mFormComponentFactory; |
|
29 |
+ |
protected FormMetaData mFormMetaData; |
|
30 |
+ |
protected FormInstanceComponentHandler mComponentFormHandler; |
|
31 |
+ |
|
|
32 |
+ |
public AbstractFormComponentRenderer( FormComponentFactory pFormComponentFactory, |
|
33 |
+ |
FormMetaData pFormMetaData, |
|
34 |
+ |
FormInstanceComponentHandler pComponentHandler ) { |
|
35 |
+ |
Confirm.isNotNull( "FormComponentFactory", mFormComponentFactory = pFormComponentFactory ); |
|
36 |
+ |
Confirm.isNotNull( "FormMetaData", mFormMetaData = pFormMetaData ); |
|
37 |
+ |
Confirm.isNotNull( "FormInstanceComponentHandler", mComponentFormHandler = pComponentHandler ); |
|
38 |
+ |
} |
|
39 |
+ |
|
|
40 |
+ |
protected DefWidgetStruct[] renderChildren( UiContainerMarker pUiDef ) { |
|
41 |
+ |
HorizontalPeerDeterminer zHPD = createHorizontalPeerDeterminer( pUiDef ); |
|
42 |
+ |
List zChildDefWidgetStructs = new ArrayList(); |
|
43 |
+ |
while ( zHPD.hasNext() ) { |
|
44 |
+ |
UiDef zUiDef = (UiDef) zHPD.next(); |
|
45 |
+ |
Widget widget = recursiveRender( zUiDef, zHPD.hasHorizontalPeer() ); |
|
46 |
+ |
if ( widget != null ) { |
|
47 |
+ |
zChildDefWidgetStructs.add( new DefWidgetStruct( zUiDef, widget ) ); |
|
48 |
+ |
} |
|
49 |
+ |
} |
|
50 |
+ |
return DefWidgetStruct.toArray( zChildDefWidgetStructs ); |
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
protected Widget renderContainer( UiContainerDef pUiDef ) { |
|
54 |
+ |
DefWidgetStruct[] zChildren; |
|
55 |
+ |
switch ( pUiDef.getType().getCaseIndex() ) { |
|
56 |
+ |
case UiDef.CI_TABS: |
|
57 |
+ |
zChildren = renderTabs( (UiTabsDef) pUiDef ); |
|
58 |
+ |
break; |
|
59 |
+ |
case UiDef.CI_CARDS: |
|
60 |
+ |
zChildren = renderCards( (UiCardsDef) pUiDef ); |
|
61 |
+ |
break; |
|
62 |
+ |
default: |
|
63 |
+ |
zChildren = renderChildren( pUiDef ); |
|
64 |
+ |
} |
|
65 |
+ |
return createContainerWidget( pUiDef, zChildren ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
private DefWidgetStruct[] renderCards( UiCardsDef pUiDef ) { |
|
69 |
+ |
List zWidgets = new ArrayList(); |
|
70 |
+ |
UiDef[] zChildren = pUiDef.getChildrenHelper().getChildren(); |
|
71 |
+ |
boolean anyFloodX = false; |
|
72 |
+ |
boolean anyFloodY = false; |
|
73 |
+ |
for ( int i = 0; i < zChildren.length; i++ ) { |
|
74 |
+ |
Widget zWidget = renderCard( (UiCardDef) zChildren[i] ); |
|
75 |
+ |
if ( !anyFloodX ) { |
|
76 |
+ |
anyFloodX = WidthStretchableAdjustor.isStretchable( zWidget ); |
|
77 |
+ |
} |
|
78 |
+ |
if ( !anyFloodY ) { |
|
79 |
+ |
anyFloodY = HeightStretchableAdjustor.isStretchable( zWidget ); |
|
80 |
+ |
} |
|
81 |
+ |
zWidgets.add( zWidget ); |
|
82 |
+ |
} |
|
83 |
+ |
StretchabilityAdjustor zAdjustor; |
|
84 |
+ |
switch ( (anyFloodX ? 1 : 0) + (anyFloodY ? 2 : 0) ) { |
|
85 |
+ |
default: |
|
86 |
+ |
case 0: |
|
87 |
+ |
zAdjustor = NoStretchabilityAdjustor.INSTANCE; |
|
88 |
+ |
break; |
|
89 |
+ |
case 1: |
|
90 |
+ |
zAdjustor = WidthStretchableAdjustor.INSTANCE; |
|
91 |
+ |
break; |
|
92 |
+ |
case 2: |
|
93 |
+ |
zAdjustor = HeightStretchableAdjustor.INSTANCE; |
|
94 |
+ |
break; |
|
95 |
+ |
case 3: |
|
96 |
+ |
zAdjustor = BothStretchableAdjustor.INSTANCE; |
|
97 |
+ |
break; |
|
98 |
+ |
} |
|
99 |
+ |
DefWidgetStruct[] rv = new DefWidgetStruct[zChildren.length]; |
|
100 |
+ |
for ( int i = 0; i < zChildren.length; i++ ) { |
|
101 |
+ |
rv[i] = new DefWidgetStruct( zChildren[i], |
|
102 |
+ |
zAdjustor.adjustStretchability( (Widget) zWidgets.get( i ) ) ); |
|
103 |
+ |
} |
|
104 |
+ |
return rv; |
|
105 |
+ |
} |
|
106 |
+ |
|
|
107 |
+ |
private Widget renderCard( UiCardDef pUiDef ) { |
|
108 |
+ |
UiDef zChild = pUiDef.getChildrenHelper().getFirstChild(); |
|
109 |
+ |
Widget zWidget = (zChild != null) ? recursiveRender( zChild, false ) : null; |
|
110 |
+ |
return (zWidget != null) ? zWidget : new Label( "No Card Widget" ); |
|
111 |
+ |
} |
|
112 |
+ |
|
|
113 |
+ |
private DefWidgetStruct[] renderTabs( UiTabsDef pUiDef ) { |
|
114 |
+ |
List zChildDefWidgetStructs = new ArrayList(); |
|
115 |
+ |
UiDef[] zChildren = pUiDef.getChildrenHelper().getChildren(); |
|
116 |
+ |
for ( int i = 0; i < zChildren.length; i++ ) { |
|
117 |
+ |
zChildDefWidgetStructs.add( renderTab( (UiTabDef) zChildren[i] ) ); |
|
118 |
+ |
} |
|
119 |
+ |
return DefWidgetStruct.toArray( zChildDefWidgetStructs ); |
|
120 |
+ |
} |
|
121 |
+ |
|
|
122 |
+ |
private DefWidgetStruct renderTab( UiTabDef pUiDef ) { |
|
123 |
+ |
UiDef zChild = pUiDef.getChildrenHelper().getFirstChild(); |
|
124 |
+ |
Widget zWidget = (zChild != null) ? recursiveRender( zChild, false ) : null; |
|
125 |
+ |
if ( zWidget == null ) { |
|
126 |
+ |
zWidget = new Label( "No Tab Widget" ); |
|
127 |
+ |
} |
|
128 |
+ |
return new DefWidgetStruct( pUiDef, |
|
129 |
+ |
BothStretchableAdjustor.INSTANCE.adjustStretchability( zWidget ) ); |
|
130 |
+ |
} |
|
131 |
+ |
|
|
132 |
+ |
protected HorizontalPeerDeterminer createHorizontalPeerDeterminer( UiContainerMarker pUiDef ) { |
|
133 |
+ |
if ( pUiDef instanceof UiLayoutTwoDimensionalDef ) { |
|
134 |
+ |
return new TwoDimensionalHorizontalPeerDeterminer( (UiLayoutTwoDimensionalDef) pUiDef ); |
|
135 |
+ |
} |
|
136 |
+ |
return new HorizontalPeerDeterminer( pUiDef, pUiDef instanceof UiHorizontalLayoutDef ); |
|
137 |
+ |
} |
|
138 |
+ |
|
|
139 |
+ |
protected Widget recursiveRender( UiDef pUiDef, boolean pHasHorizontalPeer ) { |
|
140 |
+ |
if ( UiRelSubFormDef.TYPE.equals( pUiDef.getType() ) ) { |
|
141 |
+ |
return createSubFormWidget( (UiRelSubFormDef) pUiDef ); |
|
142 |
+ |
} |
|
143 |
+ |
if ( pUiDef instanceof UiContainerDef ) { |
|
144 |
+ |
return renderContainer( (UiContainerDef) pUiDef ); |
|
145 |
+ |
} |
|
146 |
+ |
//noinspection UnnecessaryLocalVariable |
|
147 |
+ |
Widget widget = mFormComponentFactory.create( mComponentFormHandler, // |
|
148 |
+ |
pUiDef, mFormMetaData, // |
|
149 |
+ |
pHasHorizontalPeer ); |
|
150 |
+ |
return widget; |
|
151 |
+ |
} |
|
152 |
+ |
|
|
153 |
+ |
abstract protected RelSubFormInstanceRenderer createRelSubFormInstanceRenderer( |
|
154 |
+ |
UiRelSubFormDef pSubFormDef, FormMetaData pSubFormMetaData, boolean pNoRemoveRow, |
|
155 |
+ |
SubFormRowCarrier pRowCarrier ); |
|
156 |
+ |
|
|
157 |
+ |
protected Widget createSubFormWidget( UiRelSubFormDef pSubFormDef ) { |
|
158 |
+ |
FormMetaData zSubFormMetaData = mFormMetaData.getRelSubForm( pSubFormDef ); |
|
159 |
+ |
String zTabAttributeName = pSubFormDef.getTabAttributeName(); |
|
160 |
+ |
return (zTabAttributeName != null) ? // |
|
161 |
+ |
createTabSubForms( pSubFormDef, zSubFormMetaData, zTabAttributeName ) : // |
|
162 |
+ |
createVerticalSubForms( pSubFormDef, zSubFormMetaData, pSubFormDef.isDisabled() || |
|
163 |
+ |
zSubFormMetaData.getIntendedUse().isDisabled() ); |
|
164 |
+ |
} |
|
165 |
+ |
|
|
166 |
+ |
private Widget createTabSubForms( UiRelSubFormDef pSubFormDef, FormMetaData pSubFormMetaData, |
|
167 |
+ |
String pTabAttributeName ) { |
|
168 |
+ |
SizeableSelectorPanel zSelectorPanel = new SizeableSelectorPanel( true ); |
|
169 |
+ |
createRelSubFormInstanceRenderer( pSubFormDef, pSubFormMetaData, true, |
|
170 |
+ |
new TabSubFormRowCarrier( zSelectorPanel ) ); |
|
171 |
+ |
return wrapSubForm( pSubFormDef, true, zSelectorPanel ); |
|
172 |
+ |
} |
|
173 |
+ |
|
|
174 |
+ |
private Widget wrapSubForm( UiRelSubFormDef pSubFormDef, boolean pOverflowHidden, Widget pWidget ) { |
|
175 |
+ |
String zExtTitle = pSubFormDef.getExtTitle(); |
|
176 |
+ |
if ( zExtTitle != null ) { |
|
177 |
+ |
LabelMetaData md = mFormMetaData.getLabel( pSubFormDef ); |
|
178 |
+ |
String zTitle = md.getExternalText(); |
|
179 |
+ |
AbstractSizeableSimplePanel zPanel = new SizeableTitledBorderedSimplePanel( pOverflowHidden, |
|
180 |
+ |
zTitle, |
|
181 |
+ |
pSubFormDef.getTitleFont() ).stretchable(); |
|
182 |
+ |
zPanel.setWidget( pWidget ); |
|
183 |
+ |
return zPanel; |
|
184 |
+ |
} |
|
185 |
+ |
if ( pSubFormDef.isBordered() ) { |
|
186 |
+ |
AbstractSizeableSimplePanel zPanel = |
|
187 |
+ |
new SizeableBorderedSimplePanel( pOverflowHidden ).stretchable(); |
|
188 |
+ |
zPanel.setWidget( pWidget ); |
|
189 |
+ |
return zPanel; |
|
190 |
+ |
} |
|
191 |
+ |
return pWidget; |
|
192 |
+ |
} |
|
193 |
+ |
|
|
194 |
+ |
private Widget createVerticalSubForms( UiRelSubFormDef pSubFormDef, FormMetaData pSubFormMetaData, |
|
195 |
+ |
boolean pDisabled ) { |
|
196 |
+ |
AbstractSizeableVerticalRegularPanel zFormVerticalPanel, zRowVerticalPanel; |
|
197 |
+ |
if ( pDisabled ) { |
|
198 |
+ |
AbstractSizeableVerticalRegularPanel zOnlyContainer = |
|
199 |
+ |
createSubFormContainer( pSubFormDef, false ); |
|
200 |
+ |
zOnlyContainer.addStyleName( SUB_FORM_ONLY_CONTAINER ); |
|
201 |
+ |
zFormVerticalPanel = zRowVerticalPanel = zOnlyContainer; |
|
202 |
+ |
} else { |
|
203 |
+ |
zFormVerticalPanel = createSubFormContainer( pSubFormDef, true ); |
|
204 |
+ |
zFormVerticalPanel.addStyleName( SUB_FORM_OUTER_CONTAINER ); |
|
205 |
+ |
zRowVerticalPanel = new SizeableVerticalPanel( false ).stretchable(); |
|
206 |
+ |
zRowVerticalPanel.addStyleName( SUB_FORM_INNER_CONTAINER ); |
|
207 |
+ |
} |
|
208 |
+ |
RelSubFormInstanceRenderer zRenderer = createRelSubFormInstanceRenderer( pSubFormDef, |
|
209 |
+ |
pSubFormMetaData, pDisabled, |
|
210 |
+ |
new VerticalSubFormRowCarrier( |
|
211 |
+ |
zRowVerticalPanel ) ); |
|
212 |
+ |
if ( !pDisabled ) { |
|
213 |
+ |
zFormVerticalPanel.add( zRowVerticalPanel ); |
|
214 |
+ |
Widget zAddButton = zRenderer.createRowAddButton( "AddRow" ); |
|
215 |
+ |
zFormVerticalPanel.add( zAddButton ); |
|
216 |
+ |
zFormVerticalPanel.setCellHorizontalAlignment( zAddButton, HasHorizontalAlignment.ALIGN_CENTER ); |
|
217 |
+ |
} |
|
218 |
+ |
return zFormVerticalPanel; |
|
219 |
+ |
} |
|
220 |
+ |
|
|
221 |
+ |
private AbstractSizeableVerticalRegularPanel createSubFormContainer( UiRelSubFormDef pSubFormDef, |
|
222 |
+ |
boolean pOverflowHidden ) { |
|
223 |
+ |
String zExtTitle = pSubFormDef.getExtTitle(); |
|
224 |
+ |
if ( zExtTitle != null ) { |
|
225 |
+ |
LabelMetaData md = mFormMetaData.getLabel( pSubFormDef ); |
|
226 |
+ |
String zTitle = md.getExternalText(); |
|
227 |
+ |
return new SizeableTitledBorderedVerticalPanel( pOverflowHidden, zTitle, |
|
228 |
+ |
pSubFormDef.getTitleFont() ).stretchable(); |
|
229 |
+ |
} |
|
230 |
+ |
if ( pSubFormDef.isBordered() ) { |
|
231 |
+ |
return new SizeableBorderedVerticalPanel( pOverflowHidden ).stretchable(); |
|
232 |
+ |
} |
|
233 |
+ |
return new SizeableVerticalPanel( pOverflowHidden ).stretchable(); |
|
234 |
+ |
} |
|
235 |
+ |
|
|
236 |
+ |
protected Widget createImageFormButton( String pActionID, String pStyleName ) { |
|
237 |
+ |
ActionMetaData zMD = mFormMetaData.getAction( pActionID ); |
|
238 |
+ |
if ( zMD == null ) { |
|
239 |
+ |
throw new IllegalStateException( "Metadata required for a " + pActionID ); |
|
240 |
+ |
} |
|
241 |
+ |
String zImageButtonPath = "common/images/formcomponents/imageButton" + pActionID + ".gif"; |
|
242 |
+ |
Widget widget = new FormButtonAdapter( mComponentFormHandler, pActionID, zMD, null, null, |
|
243 |
+ |
new PushButton( new Image( zImageButtonPath ) ) ).init(); |
|
244 |
+ |
widget.setStylePrimaryName( pStyleName ); |
|
245 |
+ |
return widget; |
|
246 |
+ |
} |
|
247 |
+ |
|
|
248 |
+ |
/** |
|
249 |
+ |
* @param pUiDef - !null |
|
250 |
+ |
* @param pChildWidgets - !null & No Nulls |
|
251 |
+ |
* |
|
252 |
+ |
* @return null OK |
|
253 |
+ |
*/ |
|
254 |
+ |
protected Widget createContainerWidget( UiDef pUiDef, DefWidgetStruct[] pChildWidgets ) { |
|
255 |
+ |
ContainerFactory factory = getContainerFactory( pUiDef ); |
|
256 |
+ |
//noinspection UnnecessaryLocalVariable |
|
257 |
+ |
Widget widget = factory.createContainerWidget( mComponentFormHandler, // |
|
258 |
+ |
pUiDef, mFormMetaData, // |
|
259 |
+ |
pChildWidgets ); |
|
260 |
+ |
return widget; |
|
261 |
+ |
} |
|
262 |
+ |
|
|
263 |
+ |
protected ContainerFactory getContainerFactory( UiDef pUiDef ) { |
|
264 |
+ |
if ( pUiDef != null ) { |
|
265 |
+ |
ContainerFactory zCF = (ContainerFactory) mUiDefTypeToContainerFactory.get( pUiDef.getType() ); |
|
266 |
+ |
if ( zCF != null ) { |
|
267 |
+ |
return zCF; |
|
268 |
+ |
} |
|
269 |
+ |
} |
|
270 |
+ |
throw new IllegalStateException( "No Container Factory for:" + pUiDef ); |
|
271 |
+ |
} |
|
272 |
+ |
|
|
273 |
+ |
private static Map mUiDefTypeToContainerFactory = new HashMap(); |
|
274 |
+ |
|
|
275 |
+ |
private static void put( UiD_Type pType, ContainerFactory pFactory ) { |
|
276 |
+ |
mUiDefTypeToContainerFactory.put( pType, pFactory ); |
|
277 |
+ |
} |
|
278 |
+ |
|
|
279 |
+ |
static { |
|
280 |
+ |
put( UiButtonBarDef.TYPE, /* */ new ButtonBarWidgetFactory() ); |
|
281 |
+ |
put( UiCardsOfActionsDef.TYPE, /* */ new CardsOfActionsWidgetFactory() ); |
|
282 |
+ |
put( UiCardsDef.TYPE, /* */ new CardsWidgetFactory() ); |
|
283 |
+ |
put( UiFormDef.TYPE, /* */ new FormWidgetFactory() ); |
|
284 |
+ |
put( UiGridLayoutDef.TYPE, /* */ new GridLayoutWidgetFactory() ); |
|
285 |
+ |
put( UiGridOfActionsDef.TYPE, /* */ new GridOfActionsWidgetFactory() ); |
|
286 |
+ |
put( UiHorizontalLayoutDef.TYPE, /* */ new HorizontalLayoutWidgetFactory() ); |
|
287 |
+ |
put( UiSingleLayoutDef.TYPE, /* */ new SingleLayoutWidgetFactory() ); |
|
288 |
+ |
put( UiTableDef.TYPE, /* */ new TableWidgetFactory() ); |
|
289 |
+ |
put( UiTabsDef.TYPE, /* */ new TabsWidgetFactory() ); |
|
290 |
+ |
put( UiVerticalLayoutDef.TYPE, /* */ new VerticalLayoutWidgetFactory() ); |
|
291 |
+ |
} |
|
292 |
+ |
} |