|
@@ -1,633 +1,632 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.server; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.forms.server.support.*; |
5 |
|
- |
import org.litesoft.GWT.forms.server.support.mdconstruction.*; |
6 |
|
- |
import org.litesoft.GWT.forms.server.support.nonpublic.*; |
7 |
|
- |
import org.litesoft.commonfoundation.typeutils.Objects; |
8 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
9 |
|
- |
import org.litesoft.core.simpletypes.*; |
10 |
|
- |
import org.litesoft.orsup.base.*; |
11 |
|
- |
import org.litesoft.orsup.otherattributeaccessors.*; |
12 |
|
- |
import org.litesoft.orsup.selection.*; |
13 |
|
- |
import org.litesoft.orsup.transact.*; |
14 |
|
- |
import org.litesoft.ui.def.nonpublic.support.*; |
15 |
|
- |
import org.litesoft.ui.support.*; |
16 |
|
- |
import org.litesoft.ui_1_5.*; |
17 |
|
- |
|
18 |
|
- |
import java.util.*; |
19 |
|
- |
|
20 |
|
- |
public class POFormServicePeer extends AbstractFormServicePeer { |
21 |
|
- |
public static final String ERR_PO_NOT_FOUND = "PoNotFound"; |
22 |
|
- |
|
23 |
|
- |
protected final NonTransactionalFinder mFinder; |
24 |
|
- |
|
25 |
|
- |
public POFormServicePeer( NonTransactionalFinder pFinder ) { |
26 |
|
- |
Objects.assertNotNull( "Finder", mFinder = pFinder ); |
27 |
|
- |
} |
28 |
|
- |
|
29 |
|
- |
public boolean clearToOneFilter( String pToOneAttributeName ) { |
30 |
|
- |
return ((POTypeHelper) getRootTypeHelper()).clearToOneFilter( pToOneAttributeName ); |
31 |
|
- |
} |
32 |
|
- |
|
33 |
|
- |
public boolean setToOneFilter( String pToOneAttributeName, String pToOnesAttribute, Object pFilterValue ) { |
34 |
|
- |
return ((POTypeHelper) getRootTypeHelper()).setToOneFilter( pToOneAttributeName, pToOnesAttribute, |
35 |
|
- |
pFilterValue ); |
36 |
|
- |
} |
37 |
|
- |
|
38 |
|
- |
public TypeHelper createTypeHelper( FSPTypeHelperBackDoor pBackDoor, // |
39 |
|
- |
ExternalizationInterface pExternalization, // |
40 |
|
- |
FormAccessControl pAccessControl, // |
41 |
|
- |
TypeHelper pParent, String pRelativeType, FormUsage pUsage ) { |
42 |
|
- |
return new POTypeHelper( pBackDoor, pExternalization, pAccessControl, pParent, pRelativeType, |
43 |
|
- |
pUsage ); |
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
public InstanceHelper createRootInstanceHelper( TypeHelper pTypeHelper ) { |
47 |
|
- |
return new POInstanceHelper( pTypeHelper, null ); |
48 |
|
- |
} |
49 |
|
- |
|
50 |
|
- |
/** |
51 |
|
- |
* subclasses may override this to add values to a newly created PO |
52 |
|
- |
* |
53 |
|
- |
* @param pPO !null |
54 |
|
- |
*/ |
55 |
|
- |
protected void onRootPoCreate( PersistentObject pPO ) { |
56 |
|
- |
} |
57 |
|
- |
|
58 |
|
- |
/** |
59 |
|
- |
* subclasses may override this to fiddle with a PO that has just been loaded in |
60 |
|
- |
* |
61 |
|
- |
* @param pPO !null |
62 |
|
- |
*/ |
63 |
|
- |
protected void onRootPoLoad( PersistentObject pPO ) { |
64 |
|
- |
} |
65 |
|
- |
|
66 |
|
- |
public void reloadOptions( String pToThemRegisteredPOName ) { |
67 |
|
- |
if ( !isDisposed() ) { |
68 |
|
- |
updateComboBoxOptions( findAMDconvertPairsByRegisteredPOName( pToThemRegisteredPOName ) ); |
69 |
|
- |
} |
70 |
|
- |
} |
71 |
|
- |
|
72 |
|
- |
private List<AMDconverterPair> findAMDconvertPairsByRegisteredPOName( String pRegisteredPOName ) { |
73 |
|
- |
List<AMDconverterPair> result = new ArrayList<AMDconverterPair>(); |
74 |
|
- |
|
75 |
|
- |
TypeHelper zHelper = getRootTypeHelper(); |
76 |
|
- |
if ( zHelper != null ) { |
77 |
|
- |
AMDconverterPair[] zPairs = zHelper.getAMDconvertPairs(); |
78 |
|
- |
if ( zPairs != null ) { |
79 |
|
- |
for ( AMDconverterPair pair : zPairs ) { |
80 |
|
- |
if ( pair.getDataConverter() instanceof POKeyValuePairConverter ) { |
81 |
|
- |
POKeyValuePairConverter converter = (POKeyValuePairConverter) pair.getDataConverter(); |
82 |
|
- |
|
83 |
|
- |
if ( pRegisteredPOName.equals( converter.getRegisteredPOName() ) ) { |
84 |
|
- |
result.add( pair ); |
85 |
|
- |
} |
86 |
|
- |
} |
87 |
|
- |
} |
88 |
|
- |
} |
89 |
|
- |
} |
90 |
|
- |
|
91 |
|
- |
return result; |
92 |
|
- |
} |
93 |
|
- |
|
94 |
|
- |
public void reloadOptionsByAttributeReference( String pAttributeReference ) { |
95 |
|
- |
updateComboBoxOptions( findAMDconvertPairsByAttributeReference( pAttributeReference ) ); |
96 |
|
- |
} |
97 |
|
- |
|
98 |
|
- |
private List<AMDconverterPair> findAMDconvertPairsByAttributeReference( String pAttributeReference ) { |
99 |
|
- |
List<AMDconverterPair> result = new ArrayList<AMDconverterPair>(); |
100 |
|
- |
|
101 |
|
- |
TypeHelper zHelper = getRootTypeHelper(); |
102 |
|
- |
if ( zHelper != null ) { |
103 |
|
- |
AMDconverterPair[] zPairs = zHelper.getAMDconvertPairs(); |
104 |
|
- |
if ( zPairs != null ) { |
105 |
|
- |
for ( AMDconverterPair pair : zPairs ) { |
106 |
|
- |
if ( pAttributeReference.equals( pair.getAttributeMetaData().getAttributeReference() ) ) { |
107 |
|
- |
result.add( pair ); |
108 |
|
- |
} |
109 |
|
- |
} |
110 |
|
- |
} |
111 |
|
- |
} |
112 |
|
- |
|
113 |
|
- |
return result; |
114 |
|
- |
} |
115 |
|
- |
|
116 |
|
- |
private void updateComboBoxOptions( List<AMDconverterPair> pPairs ) { |
117 |
|
- |
boolean updated = false; |
118 |
|
- |
if ( pPairs != null ) { |
119 |
|
- |
for ( AMDconverterPair pair : pPairs ) { |
120 |
|
- |
FormSendableDataConverter zDataConverter = pair.getDataConverter(); |
121 |
|
- |
if ( zDataConverter instanceof POKeyValuePairConverter ) { |
122 |
|
- |
POKeyValuePairConverter dataConverter = (POKeyValuePairConverter) zDataConverter; |
123 |
|
- |
AttributeMetaData zAttributeMD = pair.getAttributeMetaData(); |
124 |
|
- |
POTypeHelper helper = (POTypeHelper) getRootTypeHelper(); |
125 |
|
- |
if ( helper != null ) { |
126 |
|
- |
SimpleKeyValuePair[] options = |
127 |
|
- |
helper.getValidOptions( zAttributeMD.getAttributeReference(), dataConverter ); |
128 |
|
- |
if ( Objects.isNotNullOrEmpty( options ) ) { |
129 |
|
- |
ComboBoxAttributeUpdateFormData update = |
130 |
|
- |
new ComboBoxAttributeUpdateFormData( null, zAttributeMD, options ); |
131 |
|
- |
|
132 |
|
- |
getCollectorProxy().add( update ); |
133 |
|
- |
updated = true; |
134 |
|
- |
} |
135 |
|
- |
} |
136 |
|
- |
} |
137 |
|
- |
} |
138 |
|
- |
} |
139 |
|
- |
if ( updated ) { |
140 |
|
- |
sendUnsolicitedData(); |
141 |
|
- |
} |
142 |
|
- |
} |
143 |
|
- |
|
144 |
|
- |
public PersistentObject getRootPO() { |
145 |
|
- |
return ((POInstanceHelper) getRootInstanceHelper()).getPO(); |
146 |
|
- |
} |
147 |
|
- |
|
148 |
|
- |
public void setRootPO( PersistentObject pPO ) { |
149 |
|
- |
((POInstanceHelper) getRootInstanceHelper()).setPO( pPO ); |
150 |
|
- |
} |
151 |
|
- |
|
152 |
|
- |
protected boolean hasRootObject() { |
153 |
|
- |
if ( getRootPO() == null ) { |
154 |
|
- |
addError( ERR_PO_NOT_FOUND ); |
155 |
|
- |
return false; |
156 |
|
- |
} |
157 |
|
- |
return true; |
158 |
|
- |
} |
159 |
|
- |
|
160 |
|
- |
protected String LLsharedNewRootObject( PersistentObject pPO ) { |
161 |
|
- |
RuntimeException zProblem; |
162 |
|
- |
if ( pPO != null ) { |
163 |
|
- |
try { |
164 |
|
- |
setRootPO( pPO ); |
165 |
|
- |
onRootPoCreate( pPO ); // hook to let subclasses fiddle with the new PO |
166 |
|
- |
return pPO.getPersistentObjectUniqueKey().toString(); |
167 |
|
- |
} |
168 |
|
- |
catch ( RuntimeException e ) { |
169 |
|
- |
zProblem = e; |
170 |
|
- |
} |
171 |
|
- |
} else { |
172 |
|
- |
zProblem = new RuntimeException( "No New Root Object" ); |
173 |
|
- |
} |
174 |
|
- |
setRootPO( null ); |
175 |
|
- |
LOGGER.error.log( zProblem ); |
176 |
|
- |
addError( ERR_PO_NOT_FOUND, zProblem.getMessage() ); |
177 |
|
- |
return null; |
178 |
|
- |
} |
179 |
|
- |
|
180 |
|
- |
protected Transaction createTransaction() { |
181 |
|
- |
return mFinder.createTransaction().setTransactionSource( FormServicePeer.class ); |
182 |
|
- |
} |
183 |
|
- |
|
184 |
|
- |
/** |
185 |
|
- |
* @return new Root Objects Key |
186 |
|
- |
*/ |
187 |
|
- |
protected String LLnewRootObject() { |
188 |
|
- |
PersistentObject<?> zPersistentObject = LLnewRootPO(); |
189 |
|
- |
return LLsharedNewRootObject( zPersistentObject ); |
190 |
|
- |
} |
191 |
|
- |
|
192 |
|
- |
/** |
193 |
|
- |
* @return true if succeeded |
194 |
|
- |
*/ |
195 |
|
- |
protected boolean LLloadExistingRootObject( String pNewRootObjectKey ) { |
196 |
|
- |
PersistentObject<?> zPO = null; |
197 |
|
- |
RuntimeException zProblem = null; |
198 |
|
- |
try { |
199 |
|
- |
PersistentObjectUniqueKey zPOUK = |
200 |
|
- |
mFinder.createPersistentObjectUniqueKeyFrom( getRootType(), pNewRootObjectKey ); |
201 |
|
- |
zPO = LLloadExistingRootPO( zPOUK ); |
202 |
|
- |
} |
203 |
|
- |
catch ( RuntimeException e ) { |
204 |
|
- |
zProblem = e; |
205 |
|
- |
} |
206 |
|
- |
return LLsharedLoadingExistingRootObject( zPO, zProblem ); |
207 |
|
- |
} |
208 |
|
- |
|
209 |
|
- |
/** |
210 |
|
- |
* @return true if succeeded |
211 |
|
- |
*/ |
212 |
|
- |
protected boolean LLreloadExistingRootObject() { |
213 |
|
- |
PersistentObject zPO = null; |
214 |
|
- |
RuntimeException zProblem = null; |
215 |
|
- |
try { |
216 |
|
- |
zPO = LLreloadExistingRootPO(); |
217 |
|
- |
} |
218 |
|
- |
catch ( RuntimeException e ) { |
219 |
|
- |
zProblem = e; |
220 |
|
- |
} |
221 |
|
- |
return LLsharedLoadingExistingRootObject( zPO, zProblem ); |
222 |
|
- |
} |
223 |
|
- |
|
224 |
|
- |
protected PersistentObject<?> LLnewRootPO() { |
225 |
|
- |
return createTransaction().create( getRootType() ); |
226 |
|
- |
} |
227 |
|
- |
|
228 |
|
- |
protected PersistentObject<?> LLloadExistingRootPO( PersistentObjectUniqueKey pPOUK ) { |
229 |
|
- |
return createTransaction().findOne( getRootType(), pPOUK ); |
230 |
|
- |
} |
231 |
|
- |
|
232 |
|
- |
protected PersistentObject<?> LLloadExistingRootPO( PersistentObjectURL pURL ) { |
233 |
|
- |
return createTransaction().findOne( pURL ); |
234 |
|
- |
} |
235 |
|
- |
|
236 |
|
- |
protected PersistentObject<?> LLreloadExistingRootPO() { |
237 |
|
- |
return getRootPO().refreshInto( createTransaction() ); |
238 |
|
- |
} |
239 |
|
- |
|
240 |
|
- |
protected boolean LLsharedLoadingExistingRootObject( PersistentObject pPO, RuntimeException pProblem ) { |
241 |
|
- |
if ( pPO != null ) { |
242 |
|
- |
try { |
243 |
|
- |
setRootPO( pPO ); |
244 |
|
- |
onRootPoLoad( pPO ); |
245 |
|
- |
return true; |
246 |
|
- |
} |
247 |
|
- |
catch ( RuntimeException e ) { |
248 |
|
- |
pProblem = e; |
249 |
|
- |
} |
250 |
|
- |
} |
251 |
|
- |
setRootPO( null ); |
252 |
|
- |
LOGGER.error.log( pProblem ); |
253 |
|
- |
if ( pProblem == null ) { |
254 |
|
- |
addError( ERR_PO_NOT_FOUND ); |
255 |
|
- |
} else { |
256 |
|
- |
addError( ERR_PO_NOT_FOUND, pProblem.getMessage() ); |
257 |
|
- |
} |
258 |
|
- |
return false; |
259 |
|
- |
} |
260 |
|
- |
|
261 |
|
- |
protected void LLcommit() { |
262 |
|
- |
LLcommitPo( getRootPO().getTransaction() ); // commit what we've got |
263 |
|
- |
mIsNewRootObject = false; // if it was new, not it's not! |
264 |
|
- |
// start a new transaction |
265 |
|
- |
Transaction transaction = createTransaction(); |
266 |
|
- |
setRootPO( getRootPO().copyInto( transaction ) ); |
267 |
|
- |
} |
268 |
|
- |
|
269 |
|
- |
protected void LLcommitPo( Transaction pTransaction ) { |
270 |
|
- |
pTransaction.setTransactionSource( FormServicePeer.class ); |
271 |
|
- |
pTransaction.commit(); |
272 |
|
- |
} |
273 |
|
- |
|
274 |
|
- |
public class POInstanceHelper extends InstanceHelper { |
275 |
|
- |
protected PersistentObject mPO; |
276 |
|
- |
|
277 |
|
- |
public POInstanceHelper( TypeHelper pTypeHelper, PersistentObject pPO ) { |
278 |
|
- |
super( pTypeHelper, (pPO != null) ? pPO.getPersistentObjectUniqueKey().toString() : null ); |
279 |
|
- |
mPO = pPO; |
280 |
|
- |
} |
281 |
|
- |
|
282 |
|
- |
public synchronized PersistentObject getPO() { |
283 |
|
- |
return mPO; |
284 |
|
- |
} |
285 |
|
- |
|
286 |
|
- |
public synchronized void setPO( PersistentObject pPO ) { |
287 |
|
- |
mPO = pPO; |
288 |
|
- |
} |
289 |
|
- |
|
290 |
|
- |
/** |
291 |
|
- |
* Only called for Non-BaseForms |
292 |
|
- |
* |
293 |
|
- |
* @return true if successful |
294 |
|
- |
*/ |
295 |
|
- |
protected boolean removeRow() { |
296 |
|
- |
PersistentObject zPO = getPO(); |
297 |
|
- |
if ( zPO != null ) { |
298 |
|
- |
if ( zPO.isImmortal() ) { |
299 |
|
- |
MetaDataForPO zMetaDataForPO = zPO.getMetaDataForPO(); |
300 |
|
- |
String zImmortalAttributeName = zMetaDataForPO.getInstanceImmortalImmortalAttributeName(); |
301 |
|
- |
if ( Strings.isNullOrEmpty( zImmortalAttributeName ) ) { |
302 |
|
- |
mTypeHelper.getCollectorProxy().addError( |
303 |
|
- |
mTypeHelper.resolveError( "MayNotRemoveImmortals" ) ); |
304 |
|
- |
return true; |
305 |
|
- |
} |
306 |
|
- |
zPO.setAttributeValue( zImmortalAttributeName, Boolean.FALSE ); |
307 |
|
- |
} |
308 |
|
- |
zPO.requestDelete(); |
309 |
|
- |
} |
310 |
|
- |
return true; |
311 |
|
- |
} |
312 |
|
- |
|
313 |
|
- |
public boolean valueUpdated( String pAttributeReference, Object pValueForAttribute ) { |
314 |
|
- |
if ( hasRootObject() ) { |
315 |
|
- |
setRawAttributeValue( pAttributeReference, pValueForAttribute ); |
316 |
|
- |
} |
317 |
|
- |
return true; |
318 |
|
- |
} |
319 |
|
- |
|
320 |
|
- |
@SuppressWarnings({"unchecked"}) |
321 |
|
- |
protected Object getRawAttributeValue( String pAttributeRef ) { |
322 |
|
- |
PersistentObject zPO = getPO(); |
323 |
|
- |
if ( zPO == null ) { |
324 |
|
- |
return "No PO"; |
325 |
|
- |
} |
326 |
|
- |
|
327 |
|
- |
if ( !zPO.getMetaDataForPO().hasAttribute( pAttributeRef ) ) { |
328 |
|
- |
return "Field is missing"; |
329 |
|
- |
} |
330 |
|
- |
|
331 |
|
- |
return zPO.getAttributeValue( pAttributeRef ); |
332 |
|
- |
} |
333 |
|
- |
|
334 |
|
- |
protected void setRawAttributeValue( String pAttributeRef, Object pValueForAttribute ) { |
335 |
|
- |
getPO().setAttributeValue( pAttributeRef, pValueForAttribute ); |
336 |
|
- |
} |
337 |
|
- |
|
338 |
|
- |
protected List<String> getRowKeysFor( String pRelSubFormRef ) { |
339 |
|
- |
List<PersistentObject> zRelPOs = getRelatedPOs( pRelSubFormRef ); |
340 |
|
- |
if ( zRelPOs.isEmpty() ) { |
341 |
|
- |
return Collections.emptyList(); |
342 |
|
- |
} |
343 |
|
- |
List<String> zRowKeys = new ArrayList<String>( zRelPOs.size() ); |
344 |
|
- |
for ( PersistentObject zPO : zRelPOs ) { |
345 |
|
- |
zRowKeys.add( zPO.getPersistentObjectUniqueKey().toString() ); |
346 |
|
- |
} |
347 |
|
- |
return zRowKeys; |
348 |
|
- |
} |
349 |
|
- |
|
350 |
|
- |
@SuppressWarnings({"unchecked"}) |
351 |
|
- |
protected List<PersistentObject> getRelatedPOs( String pRelSubFormRef ) { |
352 |
|
- |
Object zValue = getRawAttributeValue( pRelSubFormRef ); |
353 |
|
- |
if ( zValue instanceof List ) { |
354 |
|
- |
return (List<PersistentObject>) zValue; |
355 |
|
- |
} |
356 |
|
- |
LOGGER.error.log( "getRelatedPOs( '", pRelSubFormRef, "' ) on '", getPO(), "' resulted in: ", |
357 |
|
- |
zValue ); |
358 |
|
- |
return Collections.emptyList(); |
359 |
|
- |
} |
360 |
|
- |
} |
361 |
|
- |
|
362 |
|
- |
protected class POTypeHelper extends TypeHelper { |
363 |
|
- |
protected MetaDataForPO mMetaDataForPO; |
364 |
|
- |
|
365 |
|
- |
public POTypeHelper( FSPTypeHelperBackDoor pBackDoor, // |
366 |
|
- |
ExternalizationInterface pExternalization, // |
367 |
|
- |
FormAccessControl pAccessControl, // |
368 |
|
- |
TypeHelper pParent, String pRelativeType, FormUsage pUsage ) { |
369 |
|
- |
super( pBackDoor, pExternalization, pAccessControl, pParent, pRelativeType, pUsage ); |
370 |
|
- |
mMetaDataForPO = mFinder.getMetaDataRequired( pRelativeType ); |
371 |
|
- |
} |
372 |
|
- |
|
373 |
|
- |
public MetaDataForPO getMetaDataForPO() { |
374 |
|
- |
return mMetaDataForPO; |
375 |
|
- |
} |
376 |
|
- |
|
377 |
|
- |
/** |
378 |
|
- |
* Only called for Non-BaseForms |
379 |
|
- |
* |
380 |
|
- |
* @param pParentInstanceHelper |
381 |
|
- |
* |
382 |
|
- |
* @return true if successful |
383 |
|
- |
*/ |
384 |
|
- |
protected boolean createNewRow( InstanceHelper pParentInstanceHelper ) { |
385 |
|
- |
if ( !(pParentInstanceHelper instanceof POInstanceHelper) ) { |
386 |
|
- |
throw new IllegalStateException( "No Parent or Unacceptable Instance" ); |
387 |
|
- |
} |
388 |
|
- |
PersistentObject zPO = ((POInstanceHelper) pParentInstanceHelper).getPO(); |
389 |
|
- |
String zRelToThisSubForm = getRelToThisSubForm(); // Where to add |
390 |
|
- |
PersistentObject zPOtoAdd = createNewRow( zPO.getTransaction() ); |
391 |
|
- |
if ( zPOtoAdd != null ) { |
392 |
|
- |
zPO.addToAttributeSet( zRelToThisSubForm, zPOtoAdd ); |
393 |
|
- |
return true; |
394 |
|
- |
} |
395 |
|
- |
return false; |
396 |
|
- |
} |
397 |
|
- |
|
398 |
|
- |
protected PersistentObject createNewRow( Transaction pTransaction ) { |
399 |
|
- |
return mMetaDataForPO.createNew( pTransaction ); |
400 |
|
- |
} |
401 |
|
- |
|
402 |
|
- |
protected String cleanUpRelativeTypeForToolTip( String pRelativeType ) { |
403 |
|
- |
String s = "." + pRelativeType; |
404 |
|
- |
return s.substring( s.lastIndexOf( '.' ) + 1 ); |
405 |
|
- |
} |
406 |
|
- |
|
407 |
|
- |
protected InstanceHelper LLcreateRelSubInstanceHelper( InstanceHelper pParent, String pRowKey ) { |
408 |
|
- |
Transaction zTrans = ((POInstanceHelper) pParent).getPO().getTransaction(); |
409 |
|
- |
PersistentObject zPO; |
410 |
|
- |
if ( pRowKey == null ) { |
411 |
|
- |
zPO = createNewRow( zTrans ); |
412 |
|
- |
} else { |
413 |
|
- |
PersistentObjectUniqueKey zPOUK = mMetaDataForPO.createUniqueKeyFrom( pRowKey ); |
414 |
|
- |
zPO = zTrans.findOne( mMetaDataForPO.getPOregistrationName(), zPOUK ); |
415 |
|
- |
} |
416 |
|
- |
return LLcreateRelSubInstanceHelper( zPO ); |
417 |
|
- |
} |
418 |
|
- |
|
419 |
|
- |
protected InstanceHelper LLcreateRelSubInstanceHelper( PersistentObject pPO ) { |
420 |
|
- |
return new POInstanceHelper( this, pPO ); |
421 |
|
- |
} |
422 |
|
- |
|
423 |
|
- |
protected String determineRelSubFormRootType( String pRelAttributeRef ) { |
424 |
|
- |
AttributeAccessorSCD scd = mMetaDataForPO.getAccessorSCDoptional( pRelAttributeRef ); |
425 |
|
- |
if ( scd == null ) { |
426 |
|
- |
throw new IllegalArgumentException( mMetaDataForPO.getPOregistrationName() + |
427 |
|
- |
" does not have an Attribute for: '" + pRelAttributeRef + |
428 |
|
- |
"'" ); |
429 |
|
- |
} |
430 |
|
- |
switch ( scd.getForm() ) { |
431 |
|
- |
default: |
432 |
|
- |
case Local: |
433 |
|
- |
throw new IllegalArgumentException( mMetaDataForPO.getPOregistrationName() + |
434 |
|
- |
" does not have a Foreign Attribute for: '" + |
435 |
|
- |
pRelAttributeRef + "'" ); |
436 |
|
- |
case ToMany: |
437 |
|
- |
return ((AbstractAttributeAccessorSCDtoMany) scd).getToThemName(); |
438 |
|
- |
case ToOne: |
439 |
|
- |
if ( scd instanceof AttributeAccessorSCDtoOneRegular ) { |
440 |
|
- |
return ((AttributeAccessorSCDtoOneRegular) scd).getToThemName(); |
441 |
|
- |
} |
442 |
|
- |
throw new IllegalArgumentException( |
443 |
|
- |
"Variable, Blobs, & Virtual ToOnes are Not supported: '" + pRelAttributeRef + |
444 |
|
- |
"' on: " + mMetaDataForPO.getPOregistrationName() ); |
445 |
|
- |
} |
446 |
|
- |
} |
447 |
|
- |
|
448 |
|
- |
protected boolean validAttributeReference( String pLocalReference ) { |
449 |
|
- |
return (null != mMetaDataForPO.getAccessorSCDoptional( pLocalReference )); |
450 |
|
- |
} |
451 |
|
- |
|
452 |
|
- |
protected AMDconverterPair createAttributeMetaData( CreateAMDParams pParams ) { |
453 |
|
- |
AttributeAccessorSCD scd = mMetaDataForPO.getAccessorSCDrequired( pParams.getLocalReference() ); |
454 |
|
- |
switch ( scd.getForm() ) { |
455 |
|
- |
case Local: |
456 |
|
- |
return createSimpleAMDpair( (AbstractAttributeAccessorSCDlocal) scd, pParams ); |
457 |
|
- |
case ToOne: |
458 |
|
- |
return createToOneAMDpair( (AbstractAttributeAccessorSCDtoOne) scd, pParams ); |
459 |
|
- |
case ToMany: |
460 |
|
- |
throw new UnsupportedOperationException( "createAttributeMetaData: ToManys" ); |
461 |
|
- |
default: |
462 |
|
- |
throw new UnsupportedOperationException( "createAttributeMetaData: ???" ); |
463 |
|
- |
} |
464 |
|
- |
} |
465 |
|
- |
|
466 |
|
- |
protected AMDconverterPair createSimpleAMDpair( AbstractAttributeAccessorSCDlocal pSCD, |
467 |
|
- |
CreateAMDParams pParams ) { |
468 |
|
- |
return createAttributeMetaData( new CreateAMDParamsPlus( pParams, pSCD ), // |
469 |
|
- |
pSCD.getValidOptions(), false, pSCD.getColumnType() ); |
470 |
|
- |
} |
471 |
|
- |
|
472 |
|
- |
protected POQueryIterator getValidOptionsPOsOfType( String pToThemName, WhereClause pWhereClause ) { |
473 |
|
- |
return mFinder.findAllCursored( pToThemName, pWhereClause ); |
474 |
|
- |
} |
475 |
|
- |
|
476 |
|
- |
protected AMDconverterPair createToOneAMDpair( AbstractAttributeAccessorSCDtoOne pSCD, |
477 |
|
- |
CreateAMDParams pParams ) { |
478 |
|
- |
POKeyValuePairConverter dataConverter = createToOneDataConverter( pSCD.getToThemName() ); |
479 |
|
- |
|
480 |
|
- |
return createAttributeMetaData( new CreateAMDParamsPlus( pParams, pSCD ), // |
481 |
|
- |
getValidOptions( pSCD.getName(), dataConverter ), // |
482 |
|
- |
true, POAttributeMetaDataFactory.INSTANCE, // |
483 |
|
- |
dataConverter ); |
484 |
|
- |
} |
485 |
|
- |
|
486 |
|
- |
protected POKeyValuePairConverter createToOneDataConverter( String pToThemName ) { |
487 |
|
- |
return new POKeyValuePairConverter( pToThemName ); |
488 |
|
- |
} |
489 |
|
- |
|
490 |
|
- |
protected SimpleKeyValuePair[] getValidOptions( String pToOneAttributeName, |
491 |
|
- |
POKeyValuePairConverter pDataConverter ) { |
492 |
|
- |
return getValidOptions( pToOneAttributeName, pDataConverter, null ); |
493 |
|
- |
} |
494 |
|
- |
|
495 |
|
- |
protected SimpleKeyValuePair[] getValidOptions( String pToOneAttributeName, |
496 |
|
- |
POKeyValuePairConverter pDataConverter, |
497 |
|
- |
WhereClause pWhereClause ) { |
498 |
|
- |
ValidOptionsFieldFilter zFieldFilter = mValidOptionsFieldFilters.get( pToOneAttributeName ); |
499 |
|
- |
if ( zFieldFilter != null ) { |
500 |
|
- |
WhereClauseFactory f = WhereClauseFactory.INSTANCE; |
501 |
|
- |
WhereClause zWhereClause = f.isEqual( zFieldFilter.getSCDtoFilterOn(), // |
502 |
|
- |
zFieldFilter.getFilterValue() ); |
503 |
|
- |
pWhereClause = pWhereClause == null ? zWhereClause : f.and( pWhereClause, zWhereClause ); |
504 |
|
- |
} |
505 |
|
- |
POQueryIterator it = getValidOptionsPOsOfType( pDataConverter.getRegisteredPOName(), // |
506 |
|
- |
pWhereClause ); |
507 |
|
- |
try { |
508 |
|
- |
if ( !it.hasNext() ) { |
509 |
|
- |
return null; |
510 |
|
- |
} |
511 |
|
- |
List<SimpleKeyValuePair> options = new ArrayList<SimpleKeyValuePair>(); |
512 |
|
- |
while ( it.hasNext() ) { |
513 |
|
- |
PersistentObject po = it.next(); |
514 |
|
- |
options.add( pDataConverter.createSimpleKeyValuePair( po ) ); |
515 |
|
- |
} |
516 |
|
- |
return options.toArray( new SimpleKeyValuePair[options.size()] ); |
517 |
|
- |
} |
518 |
|
- |
finally { |
519 |
|
- |
it.releaseResources(); |
520 |
|
- |
} |
521 |
|
- |
} |
522 |
|
- |
|
523 |
|
- |
private AMDconverterPair find1stPOKeyAMDconvertPairByAttributeReference( String pAttributeReference ) { |
524 |
|
- |
for ( AMDconverterPair pair : getRootTypeHelper().getAMDconvertPairs() ) { |
525 |
|
- |
if ( pAttributeReference.equals( pair.getAttributeMetaData().getAttributeReference() ) && |
526 |
|
- |
(pair.getDataConverter() instanceof POKeyValuePairConverter) ) { |
527 |
|
- |
return pair; |
528 |
|
- |
} |
529 |
|
- |
} |
530 |
|
- |
|
531 |
|
- |
return null; |
532 |
|
- |
} |
533 |
|
- |
|
534 |
|
- |
public boolean clearToOneFilter( String pToOneAttributeName ) { |
535 |
|
- |
if ( null != mValidOptionsFieldFilters.remove( pToOneAttributeName ) ) { |
536 |
|
- |
reloadOptionsByAttributeReference( pToOneAttributeName ); |
537 |
|
- |
return true; |
538 |
|
- |
} |
539 |
|
- |
return false; |
540 |
|
- |
} |
541 |
|
- |
|
542 |
|
- |
public boolean setToOneFilter( String pToOneAttributeName, String pToOnesAttribute, |
543 |
|
- |
Object pFilterValue ) { |
544 |
|
- |
AMDconverterPair zPair = find1stPOKeyAMDconvertPairByAttributeReference( pToOneAttributeName ); |
545 |
|
- |
if ( zPair != null ) { |
546 |
|
- |
MetaDataForPO zMDtoOnePO = mFinder.getMetaDataOptional( |
547 |
|
- |
((POKeyValuePairConverter) zPair.getDataConverter()).getRegisteredPOName() ); |
548 |
|
- |
if ( zMDtoOnePO != null ) { |
549 |
|
- |
AttributeAccessorSCD zSCD = zMDtoOnePO.getAccessorSCDoptional( pToOnesAttribute ); |
550 |
|
- |
if ( zSCD != null ) { |
551 |
|
- |
mValidOptionsFieldFilters.put( pToOneAttributeName, // |
552 |
|
- |
new ValidOptionsFieldFilter( zSCD, pFilterValue ) ); |
553 |
|
- |
reloadOptionsByAttributeReference( pToOneAttributeName ); |
554 |
|
- |
return true; |
555 |
|
- |
} |
556 |
|
- |
} |
557 |
|
- |
} |
558 |
|
- |
return false; |
559 |
|
- |
} |
560 |
|
- |
|
561 |
|
- |
private Map<String, ValidOptionsFieldFilter> mValidOptionsFieldFilters = |
562 |
|
- |
new HashMap<String, ValidOptionsFieldFilter>(); |
563 |
|
- |
} |
564 |
|
- |
|
565 |
|
- |
protected static class ValidOptionsFieldFilter { |
566 |
|
- |
private SimpleColumnDefinition mSCDtoFilterOn; // !null |
567 |
|
- |
private Object mFilterValue; // Null Allowed... |
568 |
|
- |
|
569 |
|
- |
public ValidOptionsFieldFilter( SimpleColumnDefinition pSCDtoFilterOn, Object pFilterValue ) { |
570 |
|
- |
mSCDtoFilterOn = pSCDtoFilterOn; |
571 |
|
- |
mFilterValue = pFilterValue; |
572 |
|
- |
} |
573 |
|
- |
|
574 |
|
- |
public SimpleColumnDefinition getSCDtoFilterOn() { |
575 |
|
- |
return mSCDtoFilterOn; |
576 |
|
- |
} |
577 |
|
- |
|
578 |
|
- |
public Object getFilterValue() { |
579 |
|
- |
return mFilterValue; |
580 |
|
- |
} |
581 |
|
- |
} |
582 |
|
- |
|
583 |
|
- |
protected static class POAttributeMetaDataFactory implements FormAttributeMetaDataFactory { |
584 |
|
- |
public static final FormAttributeMetaDataFactory INSTANCE = new POAttributeMetaDataFactory(); |
585 |
|
- |
|
586 |
|
- |
public AMDconverterPair createAttributeMetaData( CreateAMDParamsPlus pParams ) { |
587 |
|
- |
return TextFieldFormAMD.INSTANCE.create( pParams ); |
588 |
|
- |
} |
589 |
|
- |
} |
590 |
|
- |
|
591 |
|
- |
protected class POKeyValuePairConverter extends AbstractSendableKeyValuePairConverter { |
592 |
|
- |
private String mRegisteredPOname; |
593 |
|
- |
|
594 |
|
- |
public POKeyValuePairConverter( String pRegisteredPOname ) { |
595 |
|
- |
mRegisteredPOname = pRegisteredPOname; |
596 |
|
- |
} |
597 |
|
- |
|
598 |
|
- |
public String getRegisteredPOName() { |
599 |
|
- |
return mRegisteredPOname; |
600 |
|
- |
} |
601 |
|
- |
|
602 |
|
- |
public SimpleKeyValuePair createSimpleKeyValuePair( Object pOption ) { |
603 |
|
- |
if ( pOption == null ) { |
604 |
|
- |
return new StringKeyValuePair( "" ); |
605 |
|
- |
} |
606 |
|
- |
if ( pOption instanceof SimpleKeyValuePair ) { |
607 |
|
- |
return (SimpleKeyValuePair) pOption; |
608 |
|
- |
} |
609 |
|
- |
if ( pOption instanceof ResourceKeyNameURLaccessor ) { |
610 |
|
- |
return ((ResourceKeyNameURLaccessor) pOption).getResourceKeyNameURL(); |
611 |
|
- |
} |
612 |
|
- |
if ( pOption instanceof PersistentObject ) { |
613 |
|
- |
PersistentObject po = (PersistentObject) pOption; |
614 |
|
- |
return new DataStoreKeyValuePair( po.getPersistentObjectUniqueKey().toString(), |
615 |
|
- |
po.getDisplayValue() ); |
616 |
|
- |
} |
617 |
|
- |
String zOptionAsString = pOption.toString(); |
618 |
|
- |
return new StringKeyValuePair( zOptionAsString ); |
619 |
|
- |
} |
620 |
|
- |
|
621 |
|
- |
protected Object convertSimpleKeyValuePairKey( Object pKey ) { |
622 |
|
- |
if ( pKey instanceof String ) { |
623 |
|
- |
try { |
624 |
|
- |
return mFinder.createPersistentObjectUniqueKeyFrom( mRegisteredPOname, pKey.toString() ); |
625 |
|
- |
} |
626 |
|
- |
catch ( IllegalArgumentException e ) { |
627 |
|
- |
// Fall thru... |
628 |
|
- |
} |
629 |
|
- |
} |
630 |
|
- |
return super.convertSimpleKeyValuePairKey( pKey ); |
631 |
|
- |
} |
632 |
|
- |
} |
633 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.server; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.forms.server.support.*; |
|
5 |
+ |
import org.litesoft.GWT.forms.server.support.mdconstruction.*; |
|
6 |
+ |
import org.litesoft.GWT.forms.server.support.nonpublic.*; |
|
7 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
8 |
+ |
import org.litesoft.core.simpletypes.*; |
|
9 |
+ |
import org.litesoft.orsup.base.*; |
|
10 |
+ |
import org.litesoft.orsup.otherattributeaccessors.*; |
|
11 |
+ |
import org.litesoft.orsup.selection.*; |
|
12 |
+ |
import org.litesoft.orsup.transact.*; |
|
13 |
+ |
import org.litesoft.ui.def.nonpublic.support.*; |
|
14 |
+ |
import org.litesoft.ui.support.*; |
|
15 |
+ |
import org.litesoft.ui_1_5.*; |
|
16 |
+ |
|
|
17 |
+ |
import java.util.*; |
|
18 |
+ |
|
|
19 |
+ |
public class POFormServicePeer extends AbstractFormServicePeer { |
|
20 |
+ |
public static final String ERR_PO_NOT_FOUND = "PoNotFound"; |
|
21 |
+ |
|
|
22 |
+ |
protected final NonTransactionalFinder mFinder; |
|
23 |
+ |
|
|
24 |
+ |
public POFormServicePeer( NonTransactionalFinder pFinder ) { |
|
25 |
+ |
Confirm.isNotNull( "Finder", mFinder = pFinder ); |
|
26 |
+ |
} |
|
27 |
+ |
|
|
28 |
+ |
public boolean clearToOneFilter( String pToOneAttributeName ) { |
|
29 |
+ |
return ((POTypeHelper) getRootTypeHelper()).clearToOneFilter( pToOneAttributeName ); |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
public boolean setToOneFilter( String pToOneAttributeName, String pToOnesAttribute, Object pFilterValue ) { |
|
33 |
+ |
return ((POTypeHelper) getRootTypeHelper()).setToOneFilter( pToOneAttributeName, pToOnesAttribute, |
|
34 |
+ |
pFilterValue ); |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
public TypeHelper createTypeHelper( FSPTypeHelperBackDoor pBackDoor, // |
|
38 |
+ |
ExternalizationInterface pExternalization, // |
|
39 |
+ |
FormAccessControl pAccessControl, // |
|
40 |
+ |
TypeHelper pParent, String pRelativeType, FormUsage pUsage ) { |
|
41 |
+ |
return new POTypeHelper( pBackDoor, pExternalization, pAccessControl, pParent, pRelativeType, |
|
42 |
+ |
pUsage ); |
|
43 |
+ |
} |
|
44 |
+ |
|
|
45 |
+ |
public InstanceHelper createRootInstanceHelper( TypeHelper pTypeHelper ) { |
|
46 |
+ |
return new POInstanceHelper( pTypeHelper, null ); |
|
47 |
+ |
} |
|
48 |
+ |
|
|
49 |
+ |
/** |
|
50 |
+ |
* subclasses may override this to add values to a newly created PO |
|
51 |
+ |
* |
|
52 |
+ |
* @param pPO !null |
|
53 |
+ |
*/ |
|
54 |
+ |
protected void onRootPoCreate( PersistentObject pPO ) { |
|
55 |
+ |
} |
|
56 |
+ |
|
|
57 |
+ |
/** |
|
58 |
+ |
* subclasses may override this to fiddle with a PO that has just been loaded in |
|
59 |
+ |
* |
|
60 |
+ |
* @param pPO !null |
|
61 |
+ |
*/ |
|
62 |
+ |
protected void onRootPoLoad( PersistentObject pPO ) { |
|
63 |
+ |
} |
|
64 |
+ |
|
|
65 |
+ |
public void reloadOptions( String pToThemRegisteredPOName ) { |
|
66 |
+ |
if ( !isDisposed() ) { |
|
67 |
+ |
updateComboBoxOptions( findAMDconvertPairsByRegisteredPOName( pToThemRegisteredPOName ) ); |
|
68 |
+ |
} |
|
69 |
+ |
} |
|
70 |
+ |
|
|
71 |
+ |
private List<AMDconverterPair> findAMDconvertPairsByRegisteredPOName( String pRegisteredPOName ) { |
|
72 |
+ |
List<AMDconverterPair> result = new ArrayList<AMDconverterPair>(); |
|
73 |
+ |
|
|
74 |
+ |
TypeHelper zHelper = getRootTypeHelper(); |
|
75 |
+ |
if ( zHelper != null ) { |
|
76 |
+ |
AMDconverterPair[] zPairs = zHelper.getAMDconvertPairs(); |
|
77 |
+ |
if ( zPairs != null ) { |
|
78 |
+ |
for ( AMDconverterPair pair : zPairs ) { |
|
79 |
+ |
if ( pair.getDataConverter() instanceof POKeyValuePairConverter ) { |
|
80 |
+ |
POKeyValuePairConverter converter = (POKeyValuePairConverter) pair.getDataConverter(); |
|
81 |
+ |
|
|
82 |
+ |
if ( pRegisteredPOName.equals( converter.getRegisteredPOName() ) ) { |
|
83 |
+ |
result.add( pair ); |
|
84 |
+ |
} |
|
85 |
+ |
} |
|
86 |
+ |
} |
|
87 |
+ |
} |
|
88 |
+ |
} |
|
89 |
+ |
|
|
90 |
+ |
return result; |
|
91 |
+ |
} |
|
92 |
+ |
|
|
93 |
+ |
public void reloadOptionsByAttributeReference( String pAttributeReference ) { |
|
94 |
+ |
updateComboBoxOptions( findAMDconvertPairsByAttributeReference( pAttributeReference ) ); |
|
95 |
+ |
} |
|
96 |
+ |
|
|
97 |
+ |
private List<AMDconverterPair> findAMDconvertPairsByAttributeReference( String pAttributeReference ) { |
|
98 |
+ |
List<AMDconverterPair> result = new ArrayList<AMDconverterPair>(); |
|
99 |
+ |
|
|
100 |
+ |
TypeHelper zHelper = getRootTypeHelper(); |
|
101 |
+ |
if ( zHelper != null ) { |
|
102 |
+ |
AMDconverterPair[] zPairs = zHelper.getAMDconvertPairs(); |
|
103 |
+ |
if ( zPairs != null ) { |
|
104 |
+ |
for ( AMDconverterPair pair : zPairs ) { |
|
105 |
+ |
if ( pAttributeReference.equals( pair.getAttributeMetaData().getAttributeReference() ) ) { |
|
106 |
+ |
result.add( pair ); |
|
107 |
+ |
} |
|
108 |
+ |
} |
|
109 |
+ |
} |
|
110 |
+ |
} |
|
111 |
+ |
|
|
112 |
+ |
return result; |
|
113 |
+ |
} |
|
114 |
+ |
|
|
115 |
+ |
private void updateComboBoxOptions( List<AMDconverterPair> pPairs ) { |
|
116 |
+ |
boolean updated = false; |
|
117 |
+ |
if ( pPairs != null ) { |
|
118 |
+ |
for ( AMDconverterPair pair : pPairs ) { |
|
119 |
+ |
FormSendableDataConverter zDataConverter = pair.getDataConverter(); |
|
120 |
+ |
if ( zDataConverter instanceof POKeyValuePairConverter ) { |
|
121 |
+ |
POKeyValuePairConverter dataConverter = (POKeyValuePairConverter) zDataConverter; |
|
122 |
+ |
AttributeMetaData zAttributeMD = pair.getAttributeMetaData(); |
|
123 |
+ |
POTypeHelper helper = (POTypeHelper) getRootTypeHelper(); |
|
124 |
+ |
if ( helper != null ) { |
|
125 |
+ |
SimpleKeyValuePair[] options = |
|
126 |
+ |
helper.getValidOptions( zAttributeMD.getAttributeReference(), dataConverter ); |
|
127 |
+ |
if ( Currently.isNotNullOrEmpty( options ) ) { |
|
128 |
+ |
ComboBoxAttributeUpdateFormData update = |
|
129 |
+ |
new ComboBoxAttributeUpdateFormData( null, zAttributeMD, options ); |
|
130 |
+ |
|
|
131 |
+ |
getCollectorProxy().add( update ); |
|
132 |
+ |
updated = true; |
|
133 |
+ |
} |
|
134 |
+ |
} |
|
135 |
+ |
} |
|
136 |
+ |
} |
|
137 |
+ |
} |
|
138 |
+ |
if ( updated ) { |
|
139 |
+ |
sendUnsolicitedData(); |
|
140 |
+ |
} |
|
141 |
+ |
} |
|
142 |
+ |
|
|
143 |
+ |
public PersistentObject getRootPO() { |
|
144 |
+ |
return ((POInstanceHelper) getRootInstanceHelper()).getPO(); |
|
145 |
+ |
} |
|
146 |
+ |
|
|
147 |
+ |
public void setRootPO( PersistentObject pPO ) { |
|
148 |
+ |
((POInstanceHelper) getRootInstanceHelper()).setPO( pPO ); |
|
149 |
+ |
} |
|
150 |
+ |
|
|
151 |
+ |
protected boolean hasRootObject() { |
|
152 |
+ |
if ( getRootPO() == null ) { |
|
153 |
+ |
addError( ERR_PO_NOT_FOUND ); |
|
154 |
+ |
return false; |
|
155 |
+ |
} |
|
156 |
+ |
return true; |
|
157 |
+ |
} |
|
158 |
+ |
|
|
159 |
+ |
protected String LLsharedNewRootObject( PersistentObject pPO ) { |
|
160 |
+ |
RuntimeException zProblem; |
|
161 |
+ |
if ( pPO != null ) { |
|
162 |
+ |
try { |
|
163 |
+ |
setRootPO( pPO ); |
|
164 |
+ |
onRootPoCreate( pPO ); // hook to let subclasses fiddle with the new PO |
|
165 |
+ |
return pPO.getPersistentObjectUniqueKey().toString(); |
|
166 |
+ |
} |
|
167 |
+ |
catch ( RuntimeException e ) { |
|
168 |
+ |
zProblem = e; |
|
169 |
+ |
} |
|
170 |
+ |
} else { |
|
171 |
+ |
zProblem = new RuntimeException( "No New Root Object" ); |
|
172 |
+ |
} |
|
173 |
+ |
setRootPO( null ); |
|
174 |
+ |
LOGGER.error.log( zProblem ); |
|
175 |
+ |
addError( ERR_PO_NOT_FOUND, zProblem.getMessage() ); |
|
176 |
+ |
return null; |
|
177 |
+ |
} |
|
178 |
+ |
|
|
179 |
+ |
protected Transaction createTransaction() { |
|
180 |
+ |
return mFinder.createTransaction().setTransactionSource( FormServicePeer.class ); |
|
181 |
+ |
} |
|
182 |
+ |
|
|
183 |
+ |
/** |
|
184 |
+ |
* @return new Root Objects Key |
|
185 |
+ |
*/ |
|
186 |
+ |
protected String LLnewRootObject() { |
|
187 |
+ |
PersistentObject<?> zPersistentObject = LLnewRootPO(); |
|
188 |
+ |
return LLsharedNewRootObject( zPersistentObject ); |
|
189 |
+ |
} |
|
190 |
+ |
|
|
191 |
+ |
/** |
|
192 |
+ |
* @return true if succeeded |
|
193 |
+ |
*/ |
|
194 |
+ |
protected boolean LLloadExistingRootObject( String pNewRootObjectKey ) { |
|
195 |
+ |
PersistentObject<?> zPO = null; |
|
196 |
+ |
RuntimeException zProblem = null; |
|
197 |
+ |
try { |
|
198 |
+ |
PersistentObjectUniqueKey zPOUK = |
|
199 |
+ |
mFinder.createPersistentObjectUniqueKeyFrom( getRootType(), pNewRootObjectKey ); |
|
200 |
+ |
zPO = LLloadExistingRootPO( zPOUK ); |
|
201 |
+ |
} |
|
202 |
+ |
catch ( RuntimeException e ) { |
|
203 |
+ |
zProblem = e; |
|
204 |
+ |
} |
|
205 |
+ |
return LLsharedLoadingExistingRootObject( zPO, zProblem ); |
|
206 |
+ |
} |
|
207 |
+ |
|
|
208 |
+ |
/** |
|
209 |
+ |
* @return true if succeeded |
|
210 |
+ |
*/ |
|
211 |
+ |
protected boolean LLreloadExistingRootObject() { |
|
212 |
+ |
PersistentObject zPO = null; |
|
213 |
+ |
RuntimeException zProblem = null; |
|
214 |
+ |
try { |
|
215 |
+ |
zPO = LLreloadExistingRootPO(); |
|
216 |
+ |
} |
|
217 |
+ |
catch ( RuntimeException e ) { |
|
218 |
+ |
zProblem = e; |
|
219 |
+ |
} |
|
220 |
+ |
return LLsharedLoadingExistingRootObject( zPO, zProblem ); |
|
221 |
+ |
} |
|
222 |
+ |
|
|
223 |
+ |
protected PersistentObject<?> LLnewRootPO() { |
|
224 |
+ |
return createTransaction().create( getRootType() ); |
|
225 |
+ |
} |
|
226 |
+ |
|
|
227 |
+ |
protected PersistentObject<?> LLloadExistingRootPO( PersistentObjectUniqueKey pPOUK ) { |
|
228 |
+ |
return createTransaction().findOne( getRootType(), pPOUK ); |
|
229 |
+ |
} |
|
230 |
+ |
|
|
231 |
+ |
protected PersistentObject<?> LLloadExistingRootPO( PersistentObjectURL pURL ) { |
|
232 |
+ |
return createTransaction().findOne( pURL ); |
|
233 |
+ |
} |
|
234 |
+ |
|
|
235 |
+ |
protected PersistentObject<?> LLreloadExistingRootPO() { |
|
236 |
+ |
return getRootPO().refreshInto( createTransaction() ); |
|
237 |
+ |
} |
|
238 |
+ |
|
|
239 |
+ |
protected boolean LLsharedLoadingExistingRootObject( PersistentObject pPO, RuntimeException pProblem ) { |
|
240 |
+ |
if ( pPO != null ) { |
|
241 |
+ |
try { |
|
242 |
+ |
setRootPO( pPO ); |
|
243 |
+ |
onRootPoLoad( pPO ); |
|
244 |
+ |
return true; |
|
245 |
+ |
} |
|
246 |
+ |
catch ( RuntimeException e ) { |
|
247 |
+ |
pProblem = e; |
|
248 |
+ |
} |
|
249 |
+ |
} |
|
250 |
+ |
setRootPO( null ); |
|
251 |
+ |
LOGGER.error.log( pProblem ); |
|
252 |
+ |
if ( pProblem == null ) { |
|
253 |
+ |
addError( ERR_PO_NOT_FOUND ); |
|
254 |
+ |
} else { |
|
255 |
+ |
addError( ERR_PO_NOT_FOUND, pProblem.getMessage() ); |
|
256 |
+ |
} |
|
257 |
+ |
return false; |
|
258 |
+ |
} |
|
259 |
+ |
|
|
260 |
+ |
protected void LLcommit() { |
|
261 |
+ |
LLcommitPo( getRootPO().getTransaction() ); // commit what we've got |
|
262 |
+ |
mIsNewRootObject = false; // if it was new, not it's not! |
|
263 |
+ |
// start a new transaction |
|
264 |
+ |
Transaction transaction = createTransaction(); |
|
265 |
+ |
setRootPO( getRootPO().copyInto( transaction ) ); |
|
266 |
+ |
} |
|
267 |
+ |
|
|
268 |
+ |
protected void LLcommitPo( Transaction pTransaction ) { |
|
269 |
+ |
pTransaction.setTransactionSource( FormServicePeer.class ); |
|
270 |
+ |
pTransaction.commit(); |
|
271 |
+ |
} |
|
272 |
+ |
|
|
273 |
+ |
public class POInstanceHelper extends InstanceHelper { |
|
274 |
+ |
protected PersistentObject mPO; |
|
275 |
+ |
|
|
276 |
+ |
public POInstanceHelper( TypeHelper pTypeHelper, PersistentObject pPO ) { |
|
277 |
+ |
super( pTypeHelper, (pPO != null) ? pPO.getPersistentObjectUniqueKey().toString() : null ); |
|
278 |
+ |
mPO = pPO; |
|
279 |
+ |
} |
|
280 |
+ |
|
|
281 |
+ |
public synchronized PersistentObject getPO() { |
|
282 |
+ |
return mPO; |
|
283 |
+ |
} |
|
284 |
+ |
|
|
285 |
+ |
public synchronized void setPO( PersistentObject pPO ) { |
|
286 |
+ |
mPO = pPO; |
|
287 |
+ |
} |
|
288 |
+ |
|
|
289 |
+ |
/** |
|
290 |
+ |
* Only called for Non-BaseForms |
|
291 |
+ |
* |
|
292 |
+ |
* @return true if successful |
|
293 |
+ |
*/ |
|
294 |
+ |
protected boolean removeRow() { |
|
295 |
+ |
PersistentObject zPO = getPO(); |
|
296 |
+ |
if ( zPO != null ) { |
|
297 |
+ |
if ( zPO.isImmortal() ) { |
|
298 |
+ |
MetaDataForPO zMetaDataForPO = zPO.getMetaDataForPO(); |
|
299 |
+ |
String zImmortalAttributeName = zMetaDataForPO.getInstanceImmortalImmortalAttributeName(); |
|
300 |
+ |
if ( Currently.isNullOrEmpty( zImmortalAttributeName ) ) { |
|
301 |
+ |
mTypeHelper.getCollectorProxy().addError( |
|
302 |
+ |
mTypeHelper.resolveError( "MayNotRemoveImmortals" ) ); |
|
303 |
+ |
return true; |
|
304 |
+ |
} |
|
305 |
+ |
zPO.setAttributeValue( zImmortalAttributeName, Boolean.FALSE ); |
|
306 |
+ |
} |
|
307 |
+ |
zPO.requestDelete(); |
|
308 |
+ |
} |
|
309 |
+ |
return true; |
|
310 |
+ |
} |
|
311 |
+ |
|
|
312 |
+ |
public boolean valueUpdated( String pAttributeReference, Object pValueForAttribute ) { |
|
313 |
+ |
if ( hasRootObject() ) { |
|
314 |
+ |
setRawAttributeValue( pAttributeReference, pValueForAttribute ); |
|
315 |
+ |
} |
|
316 |
+ |
return true; |
|
317 |
+ |
} |
|
318 |
+ |
|
|
319 |
+ |
@SuppressWarnings({"unchecked"}) |
|
320 |
+ |
protected Object getRawAttributeValue( String pAttributeRef ) { |
|
321 |
+ |
PersistentObject zPO = getPO(); |
|
322 |
+ |
if ( zPO == null ) { |
|
323 |
+ |
return "No PO"; |
|
324 |
+ |
} |
|
325 |
+ |
|
|
326 |
+ |
if ( !zPO.getMetaDataForPO().hasAttribute( pAttributeRef ) ) { |
|
327 |
+ |
return "Field is missing"; |
|
328 |
+ |
} |
|
329 |
+ |
|
|
330 |
+ |
return zPO.getAttributeValue( pAttributeRef ); |
|
331 |
+ |
} |
|
332 |
+ |
|
|
333 |
+ |
protected void setRawAttributeValue( String pAttributeRef, Object pValueForAttribute ) { |
|
334 |
+ |
getPO().setAttributeValue( pAttributeRef, pValueForAttribute ); |
|
335 |
+ |
} |
|
336 |
+ |
|
|
337 |
+ |
protected List<String> getRowKeysFor( String pRelSubFormRef ) { |
|
338 |
+ |
List<PersistentObject> zRelPOs = getRelatedPOs( pRelSubFormRef ); |
|
339 |
+ |
if ( zRelPOs.isEmpty() ) { |
|
340 |
+ |
return Collections.emptyList(); |
|
341 |
+ |
} |
|
342 |
+ |
List<String> zRowKeys = new ArrayList<String>( zRelPOs.size() ); |
|
343 |
+ |
for ( PersistentObject zPO : zRelPOs ) { |
|
344 |
+ |
zRowKeys.add( zPO.getPersistentObjectUniqueKey().toString() ); |
|
345 |
+ |
} |
|
346 |
+ |
return zRowKeys; |
|
347 |
+ |
} |
|
348 |
+ |
|
|
349 |
+ |
@SuppressWarnings({"unchecked"}) |
|
350 |
+ |
protected List<PersistentObject> getRelatedPOs( String pRelSubFormRef ) { |
|
351 |
+ |
Object zValue = getRawAttributeValue( pRelSubFormRef ); |
|
352 |
+ |
if ( zValue instanceof List ) { |
|
353 |
+ |
return (List<PersistentObject>) zValue; |
|
354 |
+ |
} |
|
355 |
+ |
LOGGER.error.log( "getRelatedPOs( '", pRelSubFormRef, "' ) on '", getPO(), "' resulted in: ", |
|
356 |
+ |
zValue ); |
|
357 |
+ |
return Collections.emptyList(); |
|
358 |
+ |
} |
|
359 |
+ |
} |
|
360 |
+ |
|
|
361 |
+ |
protected class POTypeHelper extends TypeHelper { |
|
362 |
+ |
protected MetaDataForPO mMetaDataForPO; |
|
363 |
+ |
|
|
364 |
+ |
public POTypeHelper( FSPTypeHelperBackDoor pBackDoor, // |
|
365 |
+ |
ExternalizationInterface pExternalization, // |
|
366 |
+ |
FormAccessControl pAccessControl, // |
|
367 |
+ |
TypeHelper pParent, String pRelativeType, FormUsage pUsage ) { |
|
368 |
+ |
super( pBackDoor, pExternalization, pAccessControl, pParent, pRelativeType, pUsage ); |
|
369 |
+ |
mMetaDataForPO = mFinder.getMetaDataRequired( pRelativeType ); |
|
370 |
+ |
} |
|
371 |
+ |
|
|
372 |
+ |
public MetaDataForPO getMetaDataForPO() { |
|
373 |
+ |
return mMetaDataForPO; |
|
374 |
+ |
} |
|
375 |
+ |
|
|
376 |
+ |
/** |
|
377 |
+ |
* Only called for Non-BaseForms |
|
378 |
+ |
* |
|
379 |
+ |
* @param pParentInstanceHelper |
|
380 |
+ |
* |
|
381 |
+ |
* @return true if successful |
|
382 |
+ |
*/ |
|
383 |
+ |
protected boolean createNewRow( InstanceHelper pParentInstanceHelper ) { |
|
384 |
+ |
if ( !(pParentInstanceHelper instanceof POInstanceHelper) ) { |
|
385 |
+ |
throw new IllegalStateException( "No Parent or Unacceptable Instance" ); |
|
386 |
+ |
} |
|
387 |
+ |
PersistentObject zPO = ((POInstanceHelper) pParentInstanceHelper).getPO(); |
|
388 |
+ |
String zRelToThisSubForm = getRelToThisSubForm(); // Where to add |
|
389 |
+ |
PersistentObject zPOtoAdd = createNewRow( zPO.getTransaction() ); |
|
390 |
+ |
if ( zPOtoAdd != null ) { |
|
391 |
+ |
zPO.addToAttributeSet( zRelToThisSubForm, zPOtoAdd ); |
|
392 |
+ |
return true; |
|
393 |
+ |
} |
|
394 |
+ |
return false; |
|
395 |
+ |
} |
|
396 |
+ |
|
|
397 |
+ |
protected PersistentObject createNewRow( Transaction pTransaction ) { |
|
398 |
+ |
return mMetaDataForPO.createNew( pTransaction ); |
|
399 |
+ |
} |
|
400 |
+ |
|
|
401 |
+ |
protected String cleanUpRelativeTypeForToolTip( String pRelativeType ) { |
|
402 |
+ |
String s = "." + pRelativeType; |
|
403 |
+ |
return s.substring( s.lastIndexOf( '.' ) + 1 ); |
|
404 |
+ |
} |
|
405 |
+ |
|
|
406 |
+ |
protected InstanceHelper LLcreateRelSubInstanceHelper( InstanceHelper pParent, String pRowKey ) { |
|
407 |
+ |
Transaction zTrans = ((POInstanceHelper) pParent).getPO().getTransaction(); |
|
408 |
+ |
PersistentObject zPO; |
|
409 |
+ |
if ( pRowKey == null ) { |
|
410 |
+ |
zPO = createNewRow( zTrans ); |
|
411 |
+ |
} else { |
|
412 |
+ |
PersistentObjectUniqueKey zPOUK = mMetaDataForPO.createUniqueKeyFrom( pRowKey ); |
|
413 |
+ |
zPO = zTrans.findOne( mMetaDataForPO.getPOregistrationName(), zPOUK ); |
|
414 |
+ |
} |
|
415 |
+ |
return LLcreateRelSubInstanceHelper( zPO ); |
|
416 |
+ |
} |
|
417 |
+ |
|
|
418 |
+ |
protected InstanceHelper LLcreateRelSubInstanceHelper( PersistentObject pPO ) { |
|
419 |
+ |
return new POInstanceHelper( this, pPO ); |
|
420 |
+ |
} |
|
421 |
+ |
|
|
422 |
+ |
protected String determineRelSubFormRootType( String pRelAttributeRef ) { |
|
423 |
+ |
AttributeAccessorSCD scd = mMetaDataForPO.getAccessorSCDoptional( pRelAttributeRef ); |
|
424 |
+ |
if ( scd == null ) { |
|
425 |
+ |
throw new IllegalArgumentException( mMetaDataForPO.getPOregistrationName() + |
|
426 |
+ |
" does not have an Attribute for: '" + pRelAttributeRef + |
|
427 |
+ |
"'" ); |
|
428 |
+ |
} |
|
429 |
+ |
switch ( scd.getForm() ) { |
|
430 |
+ |
default: |
|
431 |
+ |
case Local: |
|
432 |
+ |
throw new IllegalArgumentException( mMetaDataForPO.getPOregistrationName() + |
|
433 |
+ |
" does not have a Foreign Attribute for: '" + |
|
434 |
+ |
pRelAttributeRef + "'" ); |
|
435 |
+ |
case ToMany: |
|
436 |
+ |
return ((AbstractAttributeAccessorSCDtoMany) scd).getToThemName(); |
|
437 |
+ |
case ToOne: |
|
438 |
+ |
if ( scd instanceof AttributeAccessorSCDtoOneRegular ) { |
|
439 |
+ |
return ((AttributeAccessorSCDtoOneRegular) scd).getToThemName(); |
|
440 |
+ |
} |
|
441 |
+ |
throw new IllegalArgumentException( |
|
442 |
+ |
"Variable, Blobs, & Virtual ToOnes are Not supported: '" + pRelAttributeRef + |
|
443 |
+ |
"' on: " + mMetaDataForPO.getPOregistrationName() ); |
|
444 |
+ |
} |
|
445 |
+ |
} |
|
446 |
+ |
|
|
447 |
+ |
protected boolean validAttributeReference( String pLocalReference ) { |
|
448 |
+ |
return (null != mMetaDataForPO.getAccessorSCDoptional( pLocalReference )); |
|
449 |
+ |
} |
|
450 |
+ |
|
|
451 |
+ |
protected AMDconverterPair createAttributeMetaData( CreateAMDParams pParams ) { |
|
452 |
+ |
AttributeAccessorSCD scd = mMetaDataForPO.getAccessorSCDrequired( pParams.getLocalReference() ); |
|
453 |
+ |
switch ( scd.getForm() ) { |
|
454 |
+ |
case Local: |
|
455 |
+ |
return createSimpleAMDpair( (AbstractAttributeAccessorSCDlocal) scd, pParams ); |
|
456 |
+ |
case ToOne: |
|
457 |
+ |
return createToOneAMDpair( (AbstractAttributeAccessorSCDtoOne) scd, pParams ); |
|
458 |
+ |
case ToMany: |
|
459 |
+ |
throw new UnsupportedOperationException( "createAttributeMetaData: ToManys" ); |
|
460 |
+ |
default: |
|
461 |
+ |
throw new UnsupportedOperationException( "createAttributeMetaData: ???" ); |
|
462 |
+ |
} |
|
463 |
+ |
} |
|
464 |
+ |
|
|
465 |
+ |
protected AMDconverterPair createSimpleAMDpair( AbstractAttributeAccessorSCDlocal pSCD, |
|
466 |
+ |
CreateAMDParams pParams ) { |
|
467 |
+ |
return createAttributeMetaData( new CreateAMDParamsPlus( pParams, pSCD ), // |
|
468 |
+ |
pSCD.getValidOptions(), false, pSCD.getColumnType() ); |
|
469 |
+ |
} |
|
470 |
+ |
|
|
471 |
+ |
protected POQueryIterator getValidOptionsPOsOfType( String pToThemName, WhereClause pWhereClause ) { |
|
472 |
+ |
return mFinder.findAllCursored( pToThemName, pWhereClause ); |
|
473 |
+ |
} |
|
474 |
+ |
|
|
475 |
+ |
protected AMDconverterPair createToOneAMDpair( AbstractAttributeAccessorSCDtoOne pSCD, |
|
476 |
+ |
CreateAMDParams pParams ) { |
|
477 |
+ |
POKeyValuePairConverter dataConverter = createToOneDataConverter( pSCD.getToThemName() ); |
|
478 |
+ |
|
|
479 |
+ |
return createAttributeMetaData( new CreateAMDParamsPlus( pParams, pSCD ), // |
|
480 |
+ |
getValidOptions( pSCD.getName(), dataConverter ), // |
|
481 |
+ |
true, POAttributeMetaDataFactory.INSTANCE, // |
|
482 |
+ |
dataConverter ); |
|
483 |
+ |
} |
|
484 |
+ |
|
|
485 |
+ |
protected POKeyValuePairConverter createToOneDataConverter( String pToThemName ) { |
|
486 |
+ |
return new POKeyValuePairConverter( pToThemName ); |
|
487 |
+ |
} |
|
488 |
+ |
|
|
489 |
+ |
protected SimpleKeyValuePair[] getValidOptions( String pToOneAttributeName, |
|
490 |
+ |
POKeyValuePairConverter pDataConverter ) { |
|
491 |
+ |
return getValidOptions( pToOneAttributeName, pDataConverter, null ); |
|
492 |
+ |
} |
|
493 |
+ |
|
|
494 |
+ |
protected SimpleKeyValuePair[] getValidOptions( String pToOneAttributeName, |
|
495 |
+ |
POKeyValuePairConverter pDataConverter, |
|
496 |
+ |
WhereClause pWhereClause ) { |
|
497 |
+ |
ValidOptionsFieldFilter zFieldFilter = mValidOptionsFieldFilters.get( pToOneAttributeName ); |
|
498 |
+ |
if ( zFieldFilter != null ) { |
|
499 |
+ |
WhereClauseFactory f = WhereClauseFactory.INSTANCE; |
|
500 |
+ |
WhereClause zWhereClause = f.isEqual( zFieldFilter.getSCDtoFilterOn(), // |
|
501 |
+ |
zFieldFilter.getFilterValue() ); |
|
502 |
+ |
pWhereClause = pWhereClause == null ? zWhereClause : f.and( pWhereClause, zWhereClause ); |
|
503 |
+ |
} |
|
504 |
+ |
POQueryIterator it = getValidOptionsPOsOfType( pDataConverter.getRegisteredPOName(), // |
|
505 |
+ |
pWhereClause ); |
|
506 |
+ |
try { |
|
507 |
+ |
if ( !it.hasNext() ) { |
|
508 |
+ |
return null; |
|
509 |
+ |
} |
|
510 |
+ |
List<SimpleKeyValuePair> options = new ArrayList<SimpleKeyValuePair>(); |
|
511 |
+ |
while ( it.hasNext() ) { |
|
512 |
+ |
PersistentObject po = it.next(); |
|
513 |
+ |
options.add( pDataConverter.createSimpleKeyValuePair( po ) ); |
|
514 |
+ |
} |
|
515 |
+ |
return options.toArray( new SimpleKeyValuePair[options.size()] ); |
|
516 |
+ |
} |
|
517 |
+ |
finally { |
|
518 |
+ |
it.releaseResources(); |
|
519 |
+ |
} |
|
520 |
+ |
} |
|
521 |
+ |
|
|
522 |
+ |
private AMDconverterPair find1stPOKeyAMDconvertPairByAttributeReference( String pAttributeReference ) { |
|
523 |
+ |
for ( AMDconverterPair pair : getRootTypeHelper().getAMDconvertPairs() ) { |
|
524 |
+ |
if ( pAttributeReference.equals( pair.getAttributeMetaData().getAttributeReference() ) && |
|
525 |
+ |
(pair.getDataConverter() instanceof POKeyValuePairConverter) ) { |
|
526 |
+ |
return pair; |
|
527 |
+ |
} |
|
528 |
+ |
} |
|
529 |
+ |
|
|
530 |
+ |
return null; |
|
531 |
+ |
} |
|
532 |
+ |
|
|
533 |
+ |
public boolean clearToOneFilter( String pToOneAttributeName ) { |
|
534 |
+ |
if ( null != mValidOptionsFieldFilters.remove( pToOneAttributeName ) ) { |
|
535 |
+ |
reloadOptionsByAttributeReference( pToOneAttributeName ); |
|
536 |
+ |
return true; |
|
537 |
+ |
} |
|
538 |
+ |
return false; |
|
539 |
+ |
} |
|
540 |
+ |
|
|
541 |
+ |
public boolean setToOneFilter( String pToOneAttributeName, String pToOnesAttribute, |
|
542 |
+ |
Object pFilterValue ) { |
|
543 |
+ |
AMDconverterPair zPair = find1stPOKeyAMDconvertPairByAttributeReference( pToOneAttributeName ); |
|
544 |
+ |
if ( zPair != null ) { |
|
545 |
+ |
MetaDataForPO zMDtoOnePO = mFinder.getMetaDataOptional( |
|
546 |
+ |
((POKeyValuePairConverter) zPair.getDataConverter()).getRegisteredPOName() ); |
|
547 |
+ |
if ( zMDtoOnePO != null ) { |
|
548 |
+ |
AttributeAccessorSCD zSCD = zMDtoOnePO.getAccessorSCDoptional( pToOnesAttribute ); |
|
549 |
+ |
if ( zSCD != null ) { |
|
550 |
+ |
mValidOptionsFieldFilters.put( pToOneAttributeName, // |
|
551 |
+ |
new ValidOptionsFieldFilter( zSCD, pFilterValue ) ); |
|
552 |
+ |
reloadOptionsByAttributeReference( pToOneAttributeName ); |
|
553 |
+ |
return true; |
|
554 |
+ |
} |
|
555 |
+ |
} |
|
556 |
+ |
} |
|
557 |
+ |
return false; |
|
558 |
+ |
} |
|
559 |
+ |
|
|
560 |
+ |
private Map<String, ValidOptionsFieldFilter> mValidOptionsFieldFilters = |
|
561 |
+ |
new HashMap<String, ValidOptionsFieldFilter>(); |
|
562 |
+ |
} |
|
563 |
+ |
|
|
564 |
+ |
protected static class ValidOptionsFieldFilter { |
|
565 |
+ |
private SimpleColumnDefinition mSCDtoFilterOn; // !null |
|
566 |
+ |
private Object mFilterValue; // Null Allowed... |
|
567 |
+ |
|
|
568 |
+ |
public ValidOptionsFieldFilter( SimpleColumnDefinition pSCDtoFilterOn, Object pFilterValue ) { |
|
569 |
+ |
mSCDtoFilterOn = pSCDtoFilterOn; |
|
570 |
+ |
mFilterValue = pFilterValue; |
|
571 |
+ |
} |
|
572 |
+ |
|
|
573 |
+ |
public SimpleColumnDefinition getSCDtoFilterOn() { |
|
574 |
+ |
return mSCDtoFilterOn; |
|
575 |
+ |
} |
|
576 |
+ |
|
|
577 |
+ |
public Object getFilterValue() { |
|
578 |
+ |
return mFilterValue; |
|
579 |
+ |
} |
|
580 |
+ |
} |
|
581 |
+ |
|
|
582 |
+ |
protected static class POAttributeMetaDataFactory implements FormAttributeMetaDataFactory { |
|
583 |
+ |
public static final FormAttributeMetaDataFactory INSTANCE = new POAttributeMetaDataFactory(); |
|
584 |
+ |
|
|
585 |
+ |
public AMDconverterPair createAttributeMetaData( CreateAMDParamsPlus pParams ) { |
|
586 |
+ |
return TextFieldFormAMD.INSTANCE.create( pParams ); |
|
587 |
+ |
} |
|
588 |
+ |
} |
|
589 |
+ |
|
|
590 |
+ |
protected class POKeyValuePairConverter extends AbstractSendableKeyValuePairConverter { |
|
591 |
+ |
private String mRegisteredPOname; |
|
592 |
+ |
|
|
593 |
+ |
public POKeyValuePairConverter( String pRegisteredPOname ) { |
|
594 |
+ |
mRegisteredPOname = pRegisteredPOname; |
|
595 |
+ |
} |
|
596 |
+ |
|
|
597 |
+ |
public String getRegisteredPOName() { |
|
598 |
+ |
return mRegisteredPOname; |
|
599 |
+ |
} |
|
600 |
+ |
|
|
601 |
+ |
public SimpleKeyValuePair createSimpleKeyValuePair( Object pOption ) { |
|
602 |
+ |
if ( pOption == null ) { |
|
603 |
+ |
return new StringKeyValuePair( "" ); |
|
604 |
+ |
} |
|
605 |
+ |
if ( pOption instanceof SimpleKeyValuePair ) { |
|
606 |
+ |
return (SimpleKeyValuePair) pOption; |
|
607 |
+ |
} |
|
608 |
+ |
if ( pOption instanceof ResourceKeyNameURLaccessor ) { |
|
609 |
+ |
return ((ResourceKeyNameURLaccessor) pOption).getResourceKeyNameURL(); |
|
610 |
+ |
} |
|
611 |
+ |
if ( pOption instanceof PersistentObject ) { |
|
612 |
+ |
PersistentObject po = (PersistentObject) pOption; |
|
613 |
+ |
return new DataStoreKeyValuePair( po.getPersistentObjectUniqueKey().toString(), |
|
614 |
+ |
po.getDisplayValue() ); |
|
615 |
+ |
} |
|
616 |
+ |
String zOptionAsString = pOption.toString(); |
|
617 |
+ |
return new StringKeyValuePair( zOptionAsString ); |
|
618 |
+ |
} |
|
619 |
+ |
|
|
620 |
+ |
protected Object convertSimpleKeyValuePairKey( Object pKey ) { |
|
621 |
+ |
if ( pKey instanceof String ) { |
|
622 |
+ |
try { |
|
623 |
+ |
return mFinder.createPersistentObjectUniqueKeyFrom( mRegisteredPOname, pKey.toString() ); |
|
624 |
+ |
} |
|
625 |
+ |
catch ( IllegalArgumentException e ) { |
|
626 |
+ |
// Fall thru... |
|
627 |
+ |
} |
|
628 |
+ |
} |
|
629 |
+ |
return super.convertSimpleKeyValuePairKey( pKey ); |
|
630 |
+ |
} |
|
631 |
+ |
} |
|
632 |
+ |
} |