|
@@ -1,260 +1,260 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.ui; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.core.typeutils.Objects; |
5 |
|
- |
import java.util.*; |
6 |
|
- |
|
7 |
|
- |
import com.google.gwt.junit.client.*; |
8 |
|
- |
import com.google.gwt.user.client.ui.*; |
9 |
|
- |
import org.litesoft.GWT.eventbus.client.*; |
10 |
|
- |
import org.litesoft.GWT.forms.client.components.*; |
11 |
|
- |
import org.litesoft.GWT.forms.client.components.helpers.*; |
12 |
|
- |
import org.litesoft.core.util.*; |
13 |
|
- |
import org.litesoft.ui.def.*; |
14 |
|
- |
import org.litesoft.ui.def.nonpublic.*; |
15 |
|
- |
import org.litesoft.ui.def.nonpublic.support.*; |
16 |
|
- |
import org.litesoft.ui.def.nonpublic.support.components.helpers.*; |
17 |
|
- |
import org.litesoft.ui.def.nonpublic.support.components.helpers.factories.*; |
18 |
|
- |
import org.litesoft.ui.support.*; |
19 |
|
- |
|
20 |
|
- |
public class FactoryHelperTest extends GWTTestCase |
21 |
|
- |
{ |
22 |
|
- |
private static final String DESICATED_FORM = // |
23 |
|
- |
"Form(IntendedUse=Edit RootType=Test)\n" + // |
24 |
|
- |
".VerticalLayout()\n" + // |
25 |
|
- |
"..Input(AttributeName=zAname)\n" + // |
26 |
|
- |
"..Label(LabelID=Label1)\n" + // |
27 |
|
- |
"..Input(AttributeName=stupid)\n" + // |
28 |
|
- |
"..Form(RootType=SubTest)\n" + // |
29 |
|
- |
"...VerticalLayout()\n" + // |
30 |
|
- |
"....Input(AttributeName=zBname)\n" + // |
31 |
|
- |
"....Label(LabelID=Label22)\n" + // |
32 |
|
- |
""; |
33 |
|
- |
|
34 |
|
- |
private static final UiFormDef FORM_DEF; |
35 |
|
- |
private static final FormMetaData zNullMetaData; |
36 |
|
- |
private static final ActionMetaData NULL_ACTION_META_DATA = new ActionMetaData( new ActionUsage( "actionId", false), |
37 |
|
- |
false, |
38 |
|
- |
"extenrnaText", |
39 |
|
- |
"toolTipNumeroUno"); |
40 |
|
- |
|
41 |
|
- |
static { |
42 |
|
- |
FORM_DEF = (UiFormDef) UiFormDef.rehydrate( UiDefFactory.INSTANCE, |
43 |
|
- |
HierarchicalDataSimpleFactory.INSTANCE.createSource( |
44 |
|
- |
DESICATED_FORM ) ); |
45 |
|
- |
FORM_DEF.prepareToRender(); |
46 |
|
- |
zNullMetaData = buildMetaDataFromDef( FORM_DEF ); |
47 |
|
- |
} |
48 |
|
- |
|
49 |
|
- |
public void testHelperFactories() |
50 |
|
- |
throws Exception |
51 |
|
- |
{ |
52 |
|
- |
UiInputDef zUiDef = new UiInputDef( "zAttrName" ); |
53 |
|
- |
UiComponentHelper zInputHelper = new UiComponentTestableHelperFactory().newInstance( |
54 |
|
- |
new ComponentBusHelperImpl( new SimpleEventBus(), "ParentParentParent", "ServerPeerId" ), zUiDef, |
55 |
|
- |
zNullMetaData, IntendedUse.ForView ); |
56 |
|
- |
assertNotNull(zInputHelper.getFormComponent()); |
57 |
|
- |
} |
58 |
|
- |
|
59 |
|
- |
public void testFormHandler() |
60 |
|
- |
{ |
61 |
|
- |
final Widget[] zThis = new Widget[]{null}; |
62 |
|
- |
SimpleEventBus zBus = new SimpleEventBus(); |
63 |
|
- |
UiFormHandler zComponentHandler = new UiFormHandler( zBus, FORM_DEF ); |
64 |
|
- |
|
65 |
|
- |
zComponentHandler.renderWidget( new UiFormHandler.Listener() |
66 |
|
- |
{ |
67 |
|
- |
public void componentsRendered( Widget pWidget ) |
68 |
|
- |
{ |
69 |
|
- |
assertNotNull( pWidget ); |
70 |
|
- |
zThis[0] = pWidget; |
71 |
|
- |
} |
72 |
|
- |
} ); |
73 |
|
- |
assertNull( zThis[0] ); |
74 |
|
- |
zBus.publish( new FormComponentBusConstants.FormCreationResponsePackage( "thisnThat", |
75 |
|
- |
zComponentHandler.getUniqueName(), |
76 |
|
- |
zNullMetaData ) ); |
77 |
|
- |
assertNotNull( zThis[0] ); |
78 |
|
- |
|
79 |
|
- |
testComponentEvents( zComponentHandler, zBus ); |
80 |
|
- |
} |
81 |
|
- |
|
82 |
|
- |
public void testComponentEvents( UiFormHandler pFormHandler, SimpleEventBus pClientEventBus) { |
83 |
|
- |
|
84 |
|
- |
|
85 |
|
- |
UiComponentHelper zHelper = pFormHandler.getHelper( "zAname" ); |
86 |
|
- |
assertNotNull( zHelper ); |
87 |
|
- |
assertEquals (zHelper.getValue(), ""); |
88 |
|
- |
Map tmpMap = new HashMap( ); |
89 |
|
- |
tmpMap.put( "zAname", Boolean.FALSE.toString()); |
90 |
|
- |
pClientEventBus.publish( new FormComponentBusConstants.FormComponentEnabledUpdatePackage("source", pFormHandler.getUniqueName(), |
91 |
|
- |
tmpMap )); |
92 |
|
- |
|
93 |
|
- |
Map values = new HashMap( ); |
94 |
|
- |
values.put( "zAname", "newValue"); |
95 |
|
- |
pClientEventBus.publish( new FormComponentBusConstants.FormValuesUpdatePackage("source", |
96 |
|
- |
pFormHandler.getUniqueName(), |
97 |
|
- |
values |
98 |
|
- |
)); |
99 |
|
- |
|
100 |
|
- |
assertEquals( zHelper.getValue(), "newValue"); |
101 |
|
- |
} |
102 |
|
- |
|
103 |
|
- |
public void testTextFieldHelper() { |
104 |
|
- |
UiInputDef zLabelUiDef = new UiInputDef( "attribName"); |
105 |
|
- |
AttributeUsage zUsage = new AttributeUsage( zLabelUiDef.getAttributeName(), IntendedUse.ForView, false); |
106 |
|
- |
SimpleEventBus zClientEventBus = new SimpleEventBus(); |
107 |
|
- |
UiInputHelper zHelper = new UiInputHelper( new ComponentBusHelperImpl( zClientEventBus, "ppanranr", "ServerPeerId"), |
108 |
|
- |
IntendedUse.ForView, zLabelUiDef, new TextFieldMetaData(zUsage, false, "ext", "tooltip", true, 100)); |
109 |
|
- |
assertNotNull( zHelper ); |
110 |
|
- |
assertFalse( "newValue".equals(zHelper.getValue()) ); |
111 |
|
- |
assertTrue( zHelper.getFormComponent() instanceof FormTextField ); |
112 |
|
- |
zHelper.getFormComponent().setFocused( true ); |
113 |
|
- |
} |
114 |
|
- |
|
115 |
|
- |
public void testCheckBoxHelper() { |
116 |
|
- |
UiInputDef zLabelUiDef = new UiInputDef( "attribName"); |
117 |
|
- |
AttributeUsage zUsage = new AttributeUsage( zLabelUiDef.getAttributeName(), IntendedUse.ForView, false); |
118 |
|
- |
SimpleEventBus zClientEventBus = new SimpleEventBus(); |
119 |
|
- |
UiInputHelper zHelper = new UiInputHelper( new ComponentBusHelperImpl( zClientEventBus, "ppanranr", "ServerPeerId"), |
120 |
|
- |
IntendedUse.ForView, zLabelUiDef, new CheckBoxMetaData(zUsage, false, "ext", "tooltip")); |
121 |
|
- |
assertNotNull( zHelper ); |
122 |
|
- |
assertFalse( "newValue".equals(zHelper.getValue()) ); |
123 |
|
- |
assertTrue( zHelper.getFormComponent() instanceof FormCheckBox ); |
124 |
|
- |
zHelper.getFormComponent().setFocused( true ); |
125 |
|
- |
} |
126 |
|
- |
/** |
127 |
|
- |
* private builders below |
128 |
|
- |
*/ |
129 |
|
- |
private static FormMetaData buildMetaDataFromDef( UiFormDef pUiFormDef ) |
130 |
|
- |
{ |
131 |
|
- |
FormMetaData zFormMetaData = new FormMetaData( pUiFormDef.getFormUsage() ); |
132 |
|
- |
rBuildMetaDataFromDef( pUiFormDef, zFormMetaData ); |
133 |
|
- |
return zFormMetaData; |
134 |
|
- |
} |
135 |
|
- |
|
136 |
|
- |
private static void rBuildMetaDataFromDef( UiDef pUiDef, FormMetaData pFormMetaData ) |
137 |
|
- |
{ |
138 |
|
- |
addToFormMetaDataByType (pUiDef, pFormMetaData); |
139 |
|
- |
if ( pUiDef instanceof UiContainerDef ) { |
140 |
|
- |
UiDef[] zArray = ((UiContainerDef) pUiDef).getChildrenHelper().getChildren(); |
141 |
|
- |
for ( int i = 0; i < zArray.length; i++ ) { |
142 |
|
- |
UiDef zUiDef = zArray[i]; |
143 |
|
- |
rBuildMetaDataFromDef( zUiDef, pFormMetaData ); |
144 |
|
- |
} |
145 |
|
- |
} |
146 |
|
- |
} |
147 |
|
- |
|
148 |
|
- |
private static void addToFormMetaDataByType( UiDef pUiDef, FormMetaData pFormMetaData ) |
149 |
|
- |
{ |
150 |
|
- |
if (pUiDef instanceof UiLabelDef) { |
151 |
|
- |
pFormMetaData.addLabel( buildNullLabelMetaData((UiLabelDef) pUiDef) ); |
152 |
|
- |
} else if (pUiDef instanceof UiActionDef) { |
153 |
|
- |
pFormMetaData.addAction( NULL_ACTION_META_DATA ); |
154 |
|
- |
} else if (pUiDef instanceof UiAttributeNamedDef) { |
155 |
|
- |
pFormMetaData.addAttribute( buildNullAttribute(pUiDef) ); |
156 |
|
- |
} else if (pUiDef instanceof UiFormDef) { |
157 |
|
- |
// pFormMetaData.addSubForm( new FormMetaData( ((UiFormDef)pUiDef).getFormUsage() )); |
158 |
|
- |
} else { |
159 |
|
- |
pFormMetaData.addAttribute( buildNullAttribute(pUiDef) ); |
160 |
|
- |
} |
161 |
|
- |
} |
162 |
|
- |
|
163 |
|
- |
private static LabelMetaData buildNullLabelMetaData( UiLabelDef pUiDef ) |
164 |
|
- |
{ |
165 |
|
- |
return new LabelMetaData( new LabelUsage(pUiDef.getLabelID()), "extyText"); |
166 |
|
- |
} |
167 |
|
- |
|
168 |
|
- |
private static AttributeMetaData buildNullAttribute( UiDef pUiDef ) |
169 |
|
- |
{ |
170 |
|
- |
if (pUiDef instanceof UiInputDef ) { |
171 |
|
- |
UiInputDef zUiInputDef = (UiInputDef) pUiDef; |
172 |
|
- |
return getNullTextFieldMetaData(zUiInputDef); |
173 |
|
- |
} else if (pUiDef instanceof UiHorizontalLayoutDef ) { |
174 |
|
- |
return null; |
175 |
|
- |
} else if (pUiDef instanceof UiVerticalLayoutDef ) { |
176 |
|
- |
return null; |
177 |
|
- |
} else { |
178 |
|
- |
return null; |
179 |
|
- |
} |
180 |
|
- |
} |
181 |
|
- |
|
182 |
|
- |
|
183 |
|
- |
private static TextFieldMetaData getNullTextFieldMetaData( UiInputDef pIntendedUse ) |
184 |
|
- |
{ |
185 |
|
- |
return new TextFieldMetaData( pIntendedUse.getAttributeUsage( pIntendedUse.getIntendedUse()), false, "extnerna", |
186 |
|
- |
"tooltiptt", true, 100); |
187 |
|
- |
} |
188 |
|
- |
// public void testCreation() |
189 |
|
- |
// throws Exception { |
190 |
|
- |
// |
191 |
|
- |
// recurseTree( FORM_DEF); |
192 |
|
- |
// } |
193 |
|
- |
// |
194 |
|
- |
// private void recurseTree( UiDef pUiDef ) { |
195 |
|
- |
// if ( pUiDef instanceof UiContainerDef ) { |
196 |
|
- |
// UiDef[] zArray = ((UiContainerDef) pUiDef).getChildrenHelper().getChildren(); |
197 |
|
- |
// for ( int i=0; i<zArray.length; i++) |
198 |
|
- |
// { |
199 |
|
- |
// UiDef zUiDef = zArray[i]; |
200 |
|
- |
// recurseTree( zUiDef ); |
201 |
|
- |
// } |
202 |
|
- |
// } else { |
203 |
|
- |
// try { |
204 |
|
- |
// NeverToBeUsedFactoryFactory zUsedFactoryFactory = NeverToBeUsedFactoryFactory.INSTANCE; |
205 |
|
- |
//// zUsedFactoryFactory.switchToTestableFactories(); |
206 |
|
- |
// String zToolTip = "This is a toolTip"; |
207 |
|
- |
// SimpleEventBus zBus = new SimpleEventBus(); |
208 |
|
- |
// UiComponentHelper zHelper = |
209 |
|
- |
// zUsedFactoryFactory.create( zBus, pUiDef, zNullMetaData ); |
210 |
|
- |
// checkFormComponent( zBus, zHelper, zToolTip ); |
211 |
|
- |
// } catch ( Exception e ) { |
212 |
|
- |
// fail( e.getMessage() ); |
213 |
|
- |
// } |
214 |
|
- |
// } |
215 |
|
- |
// |
216 |
|
- |
// } |
217 |
|
- |
// |
218 |
|
- |
// private static final String VALUE_1 = "first value"; |
219 |
|
- |
// private static final String VALUE_2 = "changed value"; |
220 |
|
- |
// |
221 |
|
- |
// private void checkFormComponent( EventBus pBus, UiComponentHelper pHelper, String pToolTip ) { |
222 |
|
- |
// // do whatever work needed here: add to visual container or whatever |
223 |
|
- |
// MockFormComponent zMockFormComponent = (MockFormComponent) pHelper.getFormComponent(); |
224 |
|
- |
// assertNotNull( zMockFormComponent ); |
225 |
|
- |
// |
226 |
|
- |
// // check changed - from component |
227 |
|
- |
// pHelper.setValue( "something"); |
228 |
|
- |
// assertFalse( zMockFormComponent.isChanged() ); |
229 |
|
- |
// pHelper.setValue( VALUE_1); |
230 |
|
- |
// zMockFormComponent.fireChangeListeners(); |
231 |
|
- |
// assertTrue( zMockFormComponent.isChanged() ); |
232 |
|
- |
// |
233 |
|
- |
// // check changed - from change listener (server-side change) |
234 |
|
- |
// pHelper.setValue( VALUE_1); |
235 |
|
- |
// zMockFormComponent.fireChangeListeners(); |
236 |
|
- |
// assertFalse( zMockFormComponent.isChanged() ); |
237 |
|
- |
// pBus.publish( new FormComponentBusConstants.FormComponentEnabledUpdatePackage( |
238 |
|
- |
// "thisIsntUsed", |
239 |
|
- |
// pHelper.getComponentName(), |
240 |
|
- |
// null, VALUE_2 )); |
241 |
|
- |
// assertTrue( zMockFormComponent.isChanged() ); |
242 |
|
- |
// |
243 |
|
- |
// // check ability to clear changed and then through on blur |
244 |
|
- |
// pHelper.setValue( VALUE_2 ); |
245 |
|
- |
// zMockFormComponent.fireChangeListeners(); |
246 |
|
- |
// assertFalse( zMockFormComponent.isChanged() ); |
247 |
|
- |
// pHelper.setValue( "somethingsdfsdf else"); |
248 |
|
- |
// zMockFormComponent.fireBlurListeners(); |
249 |
|
- |
// assertTrue( zMockFormComponent.isChanged() ); |
250 |
|
- |
// |
251 |
|
- |
// // check focused |
252 |
|
- |
// assertFalse( zMockFormComponent.isFocused() ); |
253 |
|
- |
// zMockFormComponent.fireFocusListeners(); |
254 |
|
- |
// assertTrue( zMockFormComponent.isFocused() ); |
255 |
|
- |
// } |
256 |
|
- |
public String getModuleName() |
257 |
|
- |
{ |
258 |
|
- |
return "org.litesoft.GWT_test"; |
259 |
|
- |
} |
260 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.ui; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.core.typeutils.Objects; |
|
5 |
+ |
import java.util.*; |
|
6 |
+ |
|
|
7 |
+ |
import com.google.gwt.junit.client.*; |
|
8 |
+ |
import com.google.gwt.user.client.ui.*; |
|
9 |
+ |
import org.litesoft.GWT.eventbus.client.*; |
|
10 |
+ |
import org.litesoft.GWT.forms.client.components.*; |
|
11 |
+ |
import org.litesoft.GWT.forms.client.components.helpers.*; |
|
12 |
+ |
import org.litesoft.core.util.*; |
|
13 |
+ |
import org.litesoft.ui.def.*; |
|
14 |
+ |
import org.litesoft.ui.def.nonpublic.*; |
|
15 |
+ |
import org.litesoft.ui.def.nonpublic.support.*; |
|
16 |
+ |
import org.litesoft.ui.def.nonpublic.support.components.helpers.*; |
|
17 |
+ |
import org.litesoft.ui.def.nonpublic.support.components.helpers.factories.*; |
|
18 |
+ |
import org.litesoft.ui.support.*; |
|
19 |
+ |
|
|
20 |
+ |
public class FactoryHelperTest extends GWTTestCase |
|
21 |
+ |
{ |
|
22 |
+ |
private static final String DESICATED_FORM = // |
|
23 |
+ |
"Form(IntendedUse=Edit RootType=Test)\n" + // |
|
24 |
+ |
".VerticalLayout()\n" + // |
|
25 |
+ |
"..Input(AttributeName=zAname)\n" + // |
|
26 |
+ |
"..Label(LabelID=Label1)\n" + // |
|
27 |
+ |
"..Input(AttributeName=stupid)\n" + // |
|
28 |
+ |
"..Form(RootType=SubTest)\n" + // |
|
29 |
+ |
"...VerticalLayout()\n" + // |
|
30 |
+ |
"....Input(AttributeName=zBname)\n" + // |
|
31 |
+ |
"....Label(LabelID=Label22)\n" + // |
|
32 |
+ |
""; |
|
33 |
+ |
|
|
34 |
+ |
private static final UiFormDef FORM_DEF; |
|
35 |
+ |
private static final FormMetaData zNullMetaData; |
|
36 |
+ |
private static final ActionMetaData NULL_ACTION_META_DATA = new ActionMetaData( new ActionUsage( "actionId", false), |
|
37 |
+ |
false, |
|
38 |
+ |
"extenrnaText", |
|
39 |
+ |
"toolTipNumeroUno"); |
|
40 |
+ |
|
|
41 |
+ |
static { |
|
42 |
+ |
FORM_DEF = (UiFormDef) UiFormDef.rehydrate( UiDefFactory.INSTANCE, |
|
43 |
+ |
HierarchicalDataSimpleFactory.INSTANCE.createSource( |
|
44 |
+ |
DESICATED_FORM ) ); |
|
45 |
+ |
FORM_DEF.prepareToRender(); |
|
46 |
+ |
zNullMetaData = buildMetaDataFromDef( FORM_DEF ); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
public void testHelperFactories() |
|
50 |
+ |
throws Exception |
|
51 |
+ |
{ |
|
52 |
+ |
UiInputDef zUiDef = new UiInputDef( "zAttrName" ); |
|
53 |
+ |
UiComponentHelper zInputHelper = new UiComponentTestableHelperFactory().newInstance( |
|
54 |
+ |
new ComponentBusHelperImpl( new SimpleEventBus(), "ParentParentParent", "ServerPeerId" ), zUiDef, |
|
55 |
+ |
zNullMetaData, IntendedUse.ForView ); |
|
56 |
+ |
assertNotNull(zInputHelper.getFormComponent()); |
|
57 |
+ |
} |
|
58 |
+ |
|
|
59 |
+ |
public void testFormHandler() |
|
60 |
+ |
{ |
|
61 |
+ |
final Widget[] zThis = new Widget[]{null}; |
|
62 |
+ |
SimpleEventBus zBus = new SimpleEventBus(); |
|
63 |
+ |
UiFormHandler zComponentHandler = new UiFormHandler( zBus, FORM_DEF ); |
|
64 |
+ |
|
|
65 |
+ |
zComponentHandler.renderWidget( new UiFormHandler.Listener() |
|
66 |
+ |
{ |
|
67 |
+ |
public void componentsRendered( Widget pWidget ) |
|
68 |
+ |
{ |
|
69 |
+ |
assertNotNull( pWidget ); |
|
70 |
+ |
zThis[0] = pWidget; |
|
71 |
+ |
} |
|
72 |
+ |
} ); |
|
73 |
+ |
assertNull( zThis[0] ); |
|
74 |
+ |
zBus.publish( new FormComponentBusConstants.FormCreationResponsePackage( "thisnThat", |
|
75 |
+ |
zComponentHandler.getUniqueName(), |
|
76 |
+ |
zNullMetaData ) ); |
|
77 |
+ |
assertNotNull( zThis[0] ); |
|
78 |
+ |
|
|
79 |
+ |
testComponentEvents( zComponentHandler, zBus ); |
|
80 |
+ |
} |
|
81 |
+ |
|
|
82 |
+ |
public void testComponentEvents( UiFormHandler pFormHandler, SimpleEventBus pClientEventBus) { |
|
83 |
+ |
|
|
84 |
+ |
|
|
85 |
+ |
UiComponentHelper zHelper = pFormHandler.getHelper( "zAname" ); |
|
86 |
+ |
assertNotNull( zHelper ); |
|
87 |
+ |
assertEquals (zHelper.getValue(), ""); |
|
88 |
+ |
Map tmpMap = new HashMap( ); |
|
89 |
+ |
tmpMap.put( "zAname", Boolean.FALSE.toString()); |
|
90 |
+ |
pClientEventBus.publish( new FormComponentBusConstants.FormComponentEnabledUpdatePackage("source", pFormHandler.getUniqueName(), |
|
91 |
+ |
tmpMap )); |
|
92 |
+ |
|
|
93 |
+ |
Map values = new HashMap( ); |
|
94 |
+ |
values.put( "zAname", "newValue"); |
|
95 |
+ |
pClientEventBus.publish( new FormComponentBusConstants.FormValuesUpdatePackage("source", |
|
96 |
+ |
pFormHandler.getUniqueName(), |
|
97 |
+ |
values |
|
98 |
+ |
)); |
|
99 |
+ |
|
|
100 |
+ |
assertEquals( zHelper.getValue(), "newValue"); |
|
101 |
+ |
} |
|
102 |
+ |
|
|
103 |
+ |
public void testTextFieldHelper() { |
|
104 |
+ |
UiInputDef zLabelUiDef = new UiInputDef( "attribName"); |
|
105 |
+ |
AttributeUsage zUsage = new AttributeUsage( zLabelUiDef.getAttributeName(), IntendedUse.ForView, false); |
|
106 |
+ |
SimpleEventBus zClientEventBus = new SimpleEventBus(); |
|
107 |
+ |
UiInputHelper zHelper = new UiInputHelper( new ComponentBusHelperImpl( zClientEventBus, "ppanranr", "ServerPeerId"), |
|
108 |
+ |
IntendedUse.ForView, zLabelUiDef, new TextFieldMetaData(zUsage, false, "ext", "tooltip", true, 100)); |
|
109 |
+ |
assertNotNull( zHelper ); |
|
110 |
+ |
assertFalse( "newValue".equals(zHelper.getValue()) ); |
|
111 |
+ |
assertTrue( zHelper.getFormComponent() instanceof FormTextField ); |
|
112 |
+ |
zHelper.getFormComponent().setFocused( true ); |
|
113 |
+ |
} |
|
114 |
+ |
|
|
115 |
+ |
public void testCheckBoxHelper() { |
|
116 |
+ |
UiInputDef zLabelUiDef = new UiInputDef( "attribName"); |
|
117 |
+ |
AttributeUsage zUsage = new AttributeUsage( zLabelUiDef.getAttributeName(), IntendedUse.ForView, false); |
|
118 |
+ |
SimpleEventBus zClientEventBus = new SimpleEventBus(); |
|
119 |
+ |
UiInputHelper zHelper = new UiInputHelper( new ComponentBusHelperImpl( zClientEventBus, "ppanranr", "ServerPeerId"), |
|
120 |
+ |
IntendedUse.ForView, zLabelUiDef, new CheckBoxMetaData(zUsage, false, "ext", "tooltip")); |
|
121 |
+ |
assertNotNull( zHelper ); |
|
122 |
+ |
assertFalse( "newValue".equals(zHelper.getValue()) ); |
|
123 |
+ |
assertTrue( zHelper.getFormComponent() instanceof FormCheckBox ); |
|
124 |
+ |
zHelper.getFormComponent().setFocused( true ); |
|
125 |
+ |
} |
|
126 |
+ |
/** |
|
127 |
+ |
* private builders below |
|
128 |
+ |
*/ |
|
129 |
+ |
private static FormMetaData buildMetaDataFromDef( UiFormDef pUiFormDef ) |
|
130 |
+ |
{ |
|
131 |
+ |
FormMetaData zFormMetaData = new FormMetaData( pUiFormDef.getFormUsage() ); |
|
132 |
+ |
rBuildMetaDataFromDef( pUiFormDef, zFormMetaData ); |
|
133 |
+ |
return zFormMetaData; |
|
134 |
+ |
} |
|
135 |
+ |
|
|
136 |
+ |
private static void rBuildMetaDataFromDef( UiDef pUiDef, FormMetaData pFormMetaData ) |
|
137 |
+ |
{ |
|
138 |
+ |
addToFormMetaDataByType (pUiDef, pFormMetaData); |
|
139 |
+ |
if ( pUiDef instanceof UiContainerDef ) { |
|
140 |
+ |
UiDef[] zArray = ((UiContainerDef) pUiDef).getChildrenHelper().getChildren(); |
|
141 |
+ |
for ( int i = 0; i < zArray.length; i++ ) { |
|
142 |
+ |
UiDef zUiDef = zArray[i]; |
|
143 |
+ |
rBuildMetaDataFromDef( zUiDef, pFormMetaData ); |
|
144 |
+ |
} |
|
145 |
+ |
} |
|
146 |
+ |
} |
|
147 |
+ |
|
|
148 |
+ |
private static void addToFormMetaDataByType( UiDef pUiDef, FormMetaData pFormMetaData ) |
|
149 |
+ |
{ |
|
150 |
+ |
if (pUiDef instanceof UiLabelDef) { |
|
151 |
+ |
pFormMetaData.addLabel( buildNullLabelMetaData((UiLabelDef) pUiDef) ); |
|
152 |
+ |
} else if (pUiDef instanceof UiActionDef) { |
|
153 |
+ |
pFormMetaData.addAction( NULL_ACTION_META_DATA ); |
|
154 |
+ |
} else if (pUiDef instanceof UiAttributeNamedDef) { |
|
155 |
+ |
pFormMetaData.addAttribute( buildNullAttribute(pUiDef) ); |
|
156 |
+ |
} else if (pUiDef instanceof UiFormDef) { |
|
157 |
+ |
// pFormMetaData.addSubForm( new FormMetaData( ((UiFormDef)pUiDef).getFormUsage() )); |
|
158 |
+ |
} else { |
|
159 |
+ |
pFormMetaData.addAttribute( buildNullAttribute(pUiDef) ); |
|
160 |
+ |
} |
|
161 |
+ |
} |
|
162 |
+ |
|
|
163 |
+ |
private static LabelMetaData buildNullLabelMetaData( UiLabelDef pUiDef ) |
|
164 |
+ |
{ |
|
165 |
+ |
return new LabelMetaData( new LabelUsage(pUiDef.getLabelID()), "extyText"); |
|
166 |
+ |
} |
|
167 |
+ |
|
|
168 |
+ |
private static AttributeMetaData buildNullAttribute( UiDef pUiDef ) |
|
169 |
+ |
{ |
|
170 |
+ |
if (pUiDef instanceof UiInputDef ) { |
|
171 |
+ |
UiInputDef zUiInputDef = (UiInputDef) pUiDef; |
|
172 |
+ |
return getNullTextFieldMetaData(zUiInputDef); |
|
173 |
+ |
} else if (pUiDef instanceof UiHorizontalLayoutDef ) { |
|
174 |
+ |
return null; |
|
175 |
+ |
} else if (pUiDef instanceof UiVerticalLayoutDef ) { |
|
176 |
+ |
return null; |
|
177 |
+ |
} else { |
|
178 |
+ |
return null; |
|
179 |
+ |
} |
|
180 |
+ |
} |
|
181 |
+ |
|
|
182 |
+ |
|
|
183 |
+ |
private static TextFieldMetaData getNullTextFieldMetaData( UiInputDef pIntendedUse ) |
|
184 |
+ |
{ |
|
185 |
+ |
return new TextFieldMetaData( pIntendedUse.getAttributeUsage( pIntendedUse.getIntendedUse()), false, "extnerna", |
|
186 |
+ |
"tooltiptt", true, 100); |
|
187 |
+ |
} |
|
188 |
+ |
// public void testCreation() |
|
189 |
+ |
// throws Exception { |
|
190 |
+ |
// |
|
191 |
+ |
// recurseTree( FORM_DEF); |
|
192 |
+ |
// } |
|
193 |
+ |
// |
|
194 |
+ |
// private void recurseTree( UiDef pUiDef ) { |
|
195 |
+ |
// if ( pUiDef instanceof UiContainerDef ) { |
|
196 |
+ |
// UiDef[] zArray = ((UiContainerDef) pUiDef).getChildrenHelper().getChildren(); |
|
197 |
+ |
// for ( int i=0; i<zArray.length; i++) |
|
198 |
+ |
// { |
|
199 |
+ |
// UiDef zUiDef = zArray[i]; |
|
200 |
+ |
// recurseTree( zUiDef ); |
|
201 |
+ |
// } |
|
202 |
+ |
// } else { |
|
203 |
+ |
// try { |
|
204 |
+ |
// NeverToBeUsedFactoryFactory zUsedFactoryFactory = NeverToBeUsedFactoryFactory.INSTANCE; |
|
205 |
+ |
//// zUsedFactoryFactory.switchToTestableFactories(); |
|
206 |
+ |
// String zToolTip = "This is a toolTip"; |
|
207 |
+ |
// SimpleEventBus zBus = new SimpleEventBus(); |
|
208 |
+ |
// UiComponentHelper zHelper = |
|
209 |
+ |
// zUsedFactoryFactory.create( zBus, pUiDef, zNullMetaData ); |
|
210 |
+ |
// checkFormComponent( zBus, zHelper, zToolTip ); |
|
211 |
+ |
// } catch ( Exception e ) { |
|
212 |
+ |
// fail( e.getMessage() ); |
|
213 |
+ |
// } |
|
214 |
+ |
// } |
|
215 |
+ |
// |
|
216 |
+ |
// } |
|
217 |
+ |
// |
|
218 |
+ |
// private static final String VALUE_1 = "first value"; |
|
219 |
+ |
// private static final String VALUE_2 = "changed value"; |
|
220 |
+ |
// |
|
221 |
+ |
// private void checkFormComponent( EventBus pBus, UiComponentHelper pHelper, String pToolTip ) { |
|
222 |
+ |
// // do whatever work needed here: add to visual container or whatever |
|
223 |
+ |
// MockFormComponent zMockFormComponent = (MockFormComponent) pHelper.getFormComponent(); |
|
224 |
+ |
// assertNotNull( zMockFormComponent ); |
|
225 |
+ |
// |
|
226 |
+ |
// // check changed - from component |
|
227 |
+ |
// pHelper.setValue( "something"); |
|
228 |
+ |
// assertFalse( zMockFormComponent.isChanged() ); |
|
229 |
+ |
// pHelper.setValue( VALUE_1); |
|
230 |
+ |
// zMockFormComponent.fireChangeListeners(); |
|
231 |
+ |
// assertTrue( zMockFormComponent.isChanged() ); |
|
232 |
+ |
// |
|
233 |
+ |
// // check changed - from change listener (server-side change) |
|
234 |
+ |
// pHelper.setValue( VALUE_1); |
|
235 |
+ |
// zMockFormComponent.fireChangeListeners(); |
|
236 |
+ |
// assertFalse( zMockFormComponent.isChanged() ); |
|
237 |
+ |
// pBus.publish( new FormComponentBusConstants.FormComponentEnabledUpdatePackage( |
|
238 |
+ |
// "thisIsntUsed", |
|
239 |
+ |
// pHelper.getComponentName(), |
|
240 |
+ |
// null, VALUE_2 )); |
|
241 |
+ |
// assertTrue( zMockFormComponent.isChanged() ); |
|
242 |
+ |
// |
|
243 |
+ |
// // check ability to clear changed and then through on blur |
|
244 |
+ |
// pHelper.setValue( VALUE_2 ); |
|
245 |
+ |
// zMockFormComponent.fireChangeListeners(); |
|
246 |
+ |
// assertFalse( zMockFormComponent.isChanged() ); |
|
247 |
+ |
// pHelper.setValue( "somethingsdfsdf else"); |
|
248 |
+ |
// zMockFormComponent.fireBlurListeners(); |
|
249 |
+ |
// assertTrue( zMockFormComponent.isChanged() ); |
|
250 |
+ |
// |
|
251 |
+ |
// // check focused |
|
252 |
+ |
// assertFalse( zMockFormComponent.isFocused() ); |
|
253 |
+ |
// zMockFormComponent.fireFocusListeners(); |
|
254 |
+ |
// assertTrue( zMockFormComponent.isFocused() ); |
|
255 |
+ |
// } |
|
256 |
+ |
public String getModuleName() |
|
257 |
+ |
{ |
|
258 |
+ |
return "org.litesoft.GWT_test"; |
|
259 |
+ |
} |
|
260 |
+ |
} |