Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.GWT.forms.server;

import org.litesoft.commonfoundation.typeutils.*;

import java.util.*;

import org.litesoft.GWT.forms.server.support.*;
import org.litesoft.GWT.forms.server.support.mdconstruction.*;
import org.litesoft.GWT.forms.server.support.nonpublic.*;
import org.litesoft.commonfoundation.typeutils.Objects;
import org.litesoft.core.simpletypes.*;
import org.litesoft.orsup.base.*;
import org.litesoft.orsup.otherattributeaccessors.*;
import org.litesoft.orsup.selection.*;
import org.litesoft.orsup.transact.*;
import org.litesoft.ui.def.nonpublic.support.*;
import org.litesoft.ui.support.*;
import org.litesoft.ui_1_5.*;

public class POFormServicePeer extends AbstractFormServicePeer
{
    public static final String ERR_PO_NOT_FOUND = "PoNotFound";

    protected final NonTransactionalFinder mFinder;

    public POFormServicePeer( NonTransactionalFinder pFinder )
    {
        Objects.assertNotNull( "Finder", mFinder = pFinder );
    }

    public boolean clearToOneFilter( String pToOneAttributeName )
    {
        return ((POTypeHelper) getRootTypeHelper()).clearToOneFilter( pToOneAttributeName );
    }

    public boolean setToOneFilter( String pToOneAttributeName, String pToOnesAttribute, Object pFilterValue )
    {
        return ((POTypeHelper) getRootTypeHelper()).setToOneFilter( pToOneAttributeName, pToOnesAttribute,
                                                                    pFilterValue );
    }

    public TypeHelper createTypeHelper( FSPTypeHelperBackDoor pBackDoor, //
                                        ExternalizationInterface pExternalization, //
                                        FormAccessControl pAccessControl, //
                                        TypeHelper pParent, String pRelativeType, FormUsage pUsage )
    {
        return new POTypeHelper( pBackDoor, pExternalization, pAccessControl, pParent, pRelativeType,
                                 pUsage );
    }

    public InstanceHelper createRootInstanceHelper( TypeHelper pTypeHelper )
    {
        return new POInstanceHelper( pTypeHelper, null );
    }

    /**
     * subclasses may override this to add values to a newly created PO
     *
     * @param pPO !null
     */
    protected void onRootPoCreate( PersistentObject pPO )
    {
    }

    /**
     * subclasses may override this to fiddle with a PO that has just been loaded in
     *
     * @param pPO !null
     */
    protected void onRootPoLoad( PersistentObject pPO )
    {
    }

    public void reloadOptions( String pToThemRegisteredPOName )
    {
        if ( !isDisposed() )
        {
            updateComboBoxOptions( findAMDconvertPairsByRegisteredPOName( pToThemRegisteredPOName ) );
        }
    }

    private List<AMDconverterPair> findAMDconvertPairsByRegisteredPOName( String pRegisteredPOName )
    {
        List<AMDconverterPair> result = new ArrayList<AMDconverterPair>();

        TypeHelper zHelper = getRootTypeHelper();
        if ( zHelper != null )
        {
            AMDconverterPair[] zPairs = zHelper.getAMDconvertPairs();
            if ( zPairs != null )
            {
                for ( AMDconverterPair pair : zPairs )
                {
                    if ( pair.getDataConverter() instanceof POKeyValuePairConverter )
                    {
                        POKeyValuePairConverter converter = (POKeyValuePairConverter) pair.getDataConverter();

                        if ( pRegisteredPOName.equals( converter.getRegisteredPOName() ) )
                        {
                            result.add( pair );
                        }
                    }
                }
            }
        }

        return result;
    }

    public void reloadOptionsByAttributeReference( String pAttributeReference )
    {
        updateComboBoxOptions( findAMDconvertPairsByAttributeReference( pAttributeReference ) );
    }

    private List<AMDconverterPair> findAMDconvertPairsByAttributeReference( String pAttributeReference )
    {
        List<AMDconverterPair> result = new ArrayList<AMDconverterPair>();

        TypeHelper zHelper = getRootTypeHelper();
        if ( zHelper != null )
        {
            AMDconverterPair[] zPairs = zHelper.getAMDconvertPairs();
            if ( zPairs != null )
            {
                for ( AMDconverterPair pair : zPairs )
                {
                    if ( pAttributeReference.equals( pair.getAttributeMetaData().getAttributeReference() ) )
                    {
                        result.add( pair );
                    }
                }
            }
        }

        return result;
    }

    private void updateComboBoxOptions( List<AMDconverterPair> pPairs )
    {
        boolean updated = false;
        if ( pPairs != null )
        {
            for ( AMDconverterPair pair : pPairs )
            {
                FormSendableDataConverter zDataConverter = pair.getDataConverter();
                if ( zDataConverter instanceof POKeyValuePairConverter )
                {
                    POKeyValuePairConverter dataConverter = (POKeyValuePairConverter) zDataConverter;
                    AttributeMetaData zAttributeMD = pair.getAttributeMetaData();
                    POTypeHelper helper = (POTypeHelper) getRootTypeHelper();
                    if ( helper != null )
                    {
                        SimpleKeyValuePair[] options =
                                helper.getValidOptions( zAttributeMD.getAttributeReference(), dataConverter );
                        if ( Objects.isNotNullOrEmpty( options ) )
                        {
                            ComboBoxAttributeUpdateFormData update =
                                    new ComboBoxAttributeUpdateFormData( null, zAttributeMD, options );

                            getCollectorProxy().add( update );
                            updated = true;
                        }
                    }
                }
            }
        }
        if ( updated )
        {
            sendUnsolicitedData();
        }
    }

    public PersistentObject getRootPO()
    {
        return ((POInstanceHelper) getRootInstanceHelper()).getPO();
    }

    public void setRootPO( PersistentObject pPO )
    {
        ((POInstanceHelper) getRootInstanceHelper()).setPO( pPO );
    }

    protected boolean hasRootObject()
    {
        if ( getRootPO() == null )
        {
            addError( ERR_PO_NOT_FOUND );
            return false;
        }
        return true;
    }

    protected String LLsharedNewRootObject( PersistentObject pPO )
    {
        RuntimeException zProblem;
        if ( pPO != null )
        {
            try
            {
                setRootPO( pPO );
                onRootPoCreate( pPO ); // hook to let subclasses fiddle with the new PO
                return pPO.getPersistentObjectUniqueKey().toString();
            }
            catch ( RuntimeException e )
            {
                zProblem = e;
            }
        }
        else
        {
            zProblem = new RuntimeException( "No New Root Object" );
        }
        setRootPO( null );
        LOGGER.error.log( zProblem );
        addError( ERR_PO_NOT_FOUND, zProblem.getMessage() );
        return null;
    }

    protected Transaction createTransaction()
    {
        return mFinder.createTransaction().setTransactionSource( FormServicePeer.class );
    }

    /**
     * @return new Root Objects Key
     */
    protected String LLnewRootObject()
    {
        PersistentObject<?> zPersistentObject = LLnewRootPO();
        return LLsharedNewRootObject( zPersistentObject );
    }

    /**
     * @return true if succeeded
     */
    protected boolean LLloadExistingRootObject( String pNewRootObjectKey )
    {
        PersistentObject<?> zPO = null;
        RuntimeException zProblem = null;
        try
        {
            PersistentObjectUniqueKey zPOUK =
                    mFinder.createPersistentObjectUniqueKeyFrom( getRootType(), pNewRootObjectKey );
            zPO = LLloadExistingRootPO( zPOUK );
        }
        catch ( RuntimeException e )
        {
            zProblem = e;
        }
        return LLsharedLoadingExistingRootObject( zPO, zProblem );
    }

    /**
     * @return true if succeeded
     */
    protected boolean LLreloadExistingRootObject()
    {
        PersistentObject zPO = null;
        RuntimeException zProblem = null;
        try
        {
            zPO = LLreloadExistingRootPO();
        }
        catch ( RuntimeException e )
        {
            zProblem = e;
        }
        return LLsharedLoadingExistingRootObject( zPO, zProblem );
    }

    protected PersistentObject<?> LLnewRootPO()
    {
        return createTransaction().create( getRootType() );
    }

    protected PersistentObject<?> LLloadExistingRootPO( PersistentObjectUniqueKey pPOUK )
    {
        return createTransaction().findOne( getRootType(), pPOUK );
    }

    protected PersistentObject<?> LLloadExistingRootPO( PersistentObjectURL pURL )
    {
        return createTransaction().findOne( pURL );
    }

    protected PersistentObject<?> LLreloadExistingRootPO()
    {
        return getRootPO().refreshInto( createTransaction() );
    }

    protected boolean LLsharedLoadingExistingRootObject( PersistentObject pPO, RuntimeException pProblem )
    {
        if ( pPO != null )
        {
            try
            {
                setRootPO( pPO );
                onRootPoLoad( pPO );
                return true;
            }
            catch ( RuntimeException e )
            {
                pProblem = e;
            }
        }
        setRootPO( null );
        LOGGER.error.log( pProblem );
        if ( pProblem == null )
        {
            addError( ERR_PO_NOT_FOUND );
        }
        else
        {
            addError( ERR_PO_NOT_FOUND, pProblem.getMessage() );
        }
        return false;
    }

    protected void LLcommit()
    {
        LLcommitPo( getRootPO().getTransaction() ); // commit what we've got
        mIsNewRootObject = false; // if it was new, not it's not!
        // start a new transaction
        Transaction transaction = createTransaction();
        setRootPO( getRootPO().copyInto( transaction ) );
    }

    protected void LLcommitPo( Transaction pTransaction )
    {
        pTransaction.setTransactionSource( FormServicePeer.class );
        pTransaction.commit();
    }

    public class POInstanceHelper extends InstanceHelper
    {
        protected PersistentObject mPO;

        public POInstanceHelper( TypeHelper pTypeHelper, PersistentObject pPO )
        {
            super( pTypeHelper, (pPO != null) ? pPO.getPersistentObjectUniqueKey().toString() : null );
            mPO = pPO;
        }

        public synchronized PersistentObject getPO()
        {
            return mPO;
        }

        public synchronized void setPO( PersistentObject pPO )
        {
            mPO = pPO;
        }

        /**
         * Only called for Non-BaseForms
         *
         * @return true if successful
         */
        protected boolean removeRow()
        {
            PersistentObject zPO = getPO();
            if ( zPO != null )
            {
                if ( zPO.isImmortal() )
                {
                    MetaDataForPO zMetaDataForPO = zPO.getMetaDataForPO();
                    String zImmortalAttributeName = zMetaDataForPO.getInstanceImmortalImmortalAttributeName();
                    if ( Strings.isNullOrEmpty( zImmortalAttributeName ) )
                    {
                        mTypeHelper.getCollectorProxy().addError(
                                mTypeHelper.resolveError( "MayNotRemoveImmortals" ) );
                        return true;
                    }
                    zPO.setAttributeValue( zImmortalAttributeName, Boolean.FALSE );
                }
                zPO.requestDelete();
            }
            return true;
        }

        public boolean valueUpdated( String pAttributeReference, Object pValueForAttribute )
        {
            if ( hasRootObject() )
            {
                setRawAttributeValue( pAttributeReference, pValueForAttribute );
            }
            return true;
        }

        @SuppressWarnings({"unchecked"})
        protected Object getRawAttributeValue( String pAttributeRef )
        {
            PersistentObject zPO = getPO();
            if ( zPO == null )
            {
                return "No PO";
            }

            if ( !zPO.getMetaDataForPO().hasAttribute( pAttributeRef ) )
            {
                return "Field is missing";
            }

            return zPO.getAttributeValue( pAttributeRef );
        }

        protected void setRawAttributeValue( String pAttributeRef, Object pValueForAttribute )
        {
            getPO().setAttributeValue( pAttributeRef, pValueForAttribute );
        }

        protected List<String> getRowKeysFor( String pRelSubFormRef )
        {
            List<PersistentObject> zRelPOs = getRelatedPOs( pRelSubFormRef );
            if ( zRelPOs.isEmpty() )
            {
                return Collections.emptyList();
            }
            List<String> zRowKeys = new ArrayList<String>( zRelPOs.size() );
            for ( PersistentObject zPO : zRelPOs )
            {
                zRowKeys.add( zPO.getPersistentObjectUniqueKey().toString() );
            }
            return zRowKeys;
        }

        @SuppressWarnings({"unchecked"})
        protected List<PersistentObject> getRelatedPOs( String pRelSubFormRef )
        {
            Object zValue = getRawAttributeValue( pRelSubFormRef );
            if ( zValue instanceof List )
            {
                return (List<PersistentObject>) zValue;
            }
            LOGGER.error.log( "getRelatedPOs( '", pRelSubFormRef, "' ) on '", getPO(), "' resulted in: ",
                              zValue );
            return Collections.emptyList();
        }
    }

    protected class POTypeHelper extends TypeHelper
    {
        protected MetaDataForPO mMetaDataForPO;

        public POTypeHelper( FSPTypeHelperBackDoor pBackDoor, //
                             ExternalizationInterface pExternalization, //
                             FormAccessControl pAccessControl, //
                             TypeHelper pParent, String pRelativeType, FormUsage pUsage )
        {
            super( pBackDoor, pExternalization, pAccessControl, pParent, pRelativeType, pUsage );
            mMetaDataForPO = mFinder.getMetaDataRequired( pRelativeType );
        }

        public MetaDataForPO getMetaDataForPO()
        {
            return mMetaDataForPO;
        }

        /**
         * Only called for Non-BaseForms
         *
         * @param pParentInstanceHelper
         *
         * @return true if successful
         */
        protected boolean createNewRow( InstanceHelper pParentInstanceHelper )
        {
            if ( !(pParentInstanceHelper instanceof POInstanceHelper) )
            {
                throw new IllegalStateException( "No Parent or Unacceptable Instance" );
            }
            PersistentObject zPO = ((POInstanceHelper) pParentInstanceHelper).getPO();
            String zRelToThisSubForm = getRelToThisSubForm(); // Where to add
            PersistentObject zPOtoAdd = createNewRow( zPO.getTransaction() );
            if ( zPOtoAdd != null )
            {
                zPO.addToAttributeSet( zRelToThisSubForm, zPOtoAdd );
                return true;
            }
            return false;
        }

        protected PersistentObject createNewRow( Transaction pTransaction )
        {
            return mMetaDataForPO.createNew( pTransaction );
        }

        protected String cleanUpRelativeTypeForToolTip( String pRelativeType )
        {
            String s = "." + pRelativeType;
            return s.substring( s.lastIndexOf( '.' ) + 1 );
        }

        protected InstanceHelper LLcreateRelSubInstanceHelper( InstanceHelper pParent, String pRowKey )
        {
            Transaction zTrans = ((POInstanceHelper) pParent).getPO().getTransaction();
            PersistentObject zPO;
            if ( pRowKey == null )
            {
                zPO = createNewRow( zTrans );
            }
            else
            {
                PersistentObjectUniqueKey zPOUK = mMetaDataForPO.createUniqueKeyFrom( pRowKey );
                zPO = zTrans.findOne( mMetaDataForPO.getPOregistrationName(), zPOUK );
            }
            return LLcreateRelSubInstanceHelper( zPO );
        }

        protected InstanceHelper LLcreateRelSubInstanceHelper( PersistentObject pPO )
        {
            return new POInstanceHelper( this, pPO );
        }

        protected String determineRelSubFormRootType( String pRelAttributeRef )
        {
            AttributeAccessorSCD scd = mMetaDataForPO.getAccessorSCDoptional( pRelAttributeRef );
            if ( scd == null )
            {
                throw new IllegalArgumentException( mMetaDataForPO.getPOregistrationName() +
                                                    " does not have an Attribute for: '" + pRelAttributeRef +
                                                    "'" );
            }
            switch ( scd.getForm() )
            {
                default:
                case Local:
                    throw new IllegalArgumentException( mMetaDataForPO.getPOregistrationName() +
                                                        " does not have a Foreign Attribute for: '" +
                                                        pRelAttributeRef + "'" );
                case ToMany:
                    return ((AbstractAttributeAccessorSCDtoMany) scd).getToThemName();
                case ToOne:
                    if ( scd instanceof AttributeAccessorSCDtoOneRegular )
                    {
                        return ((AttributeAccessorSCDtoOneRegular) scd).getToThemName();
                    }
                    throw new IllegalArgumentException(
                            "Variable, Blobs, & Virtual ToOnes are Not supported: '" + pRelAttributeRef +
                            "' on: " + mMetaDataForPO.getPOregistrationName() );
            }
        }

        protected boolean validAttributeReference( String pLocalReference )
        {
            return (null != mMetaDataForPO.getAccessorSCDoptional( pLocalReference ));
        }

        protected AMDconverterPair createAttributeMetaData( CreateAMDParams pParams )
        {
            AttributeAccessorSCD scd = mMetaDataForPO.getAccessorSCDrequired( pParams.getLocalReference() );
            switch ( scd.getForm() )
            {
                case Local:
                    return createSimpleAMDpair( (AbstractAttributeAccessorSCDlocal) scd, pParams );
                case ToOne:
                    return createToOneAMDpair( (AbstractAttributeAccessorSCDtoOne) scd, pParams );
                case ToMany:
                    throw new UnsupportedOperationException( "createAttributeMetaData: ToManys" );
                default:
                    throw new UnsupportedOperationException( "createAttributeMetaData: ???" );
            }
        }

        protected AMDconverterPair createSimpleAMDpair( AbstractAttributeAccessorSCDlocal pSCD,
                                                        CreateAMDParams pParams )
        {
            return createAttributeMetaData( new CreateAMDParamsPlus( pParams, pSCD ), //
                                            pSCD.getValidOptions(), false, pSCD.getColumnType() );
        }

        protected POQueryIterator getValidOptionsPOsOfType( String pToThemName, WhereClause pWhereClause )
        {
            return mFinder.findAllCursored( pToThemName, pWhereClause );
        }

        protected AMDconverterPair createToOneAMDpair( AbstractAttributeAccessorSCDtoOne pSCD,
                                                       CreateAMDParams pParams )
        {
            POKeyValuePairConverter dataConverter = createToOneDataConverter( pSCD.getToThemName() );

            return createAttributeMetaData( new CreateAMDParamsPlus( pParams, pSCD ), //
                                            getValidOptions( pSCD.getName(), dataConverter ), //
                                            true, POAttributeMetaDataFactory.INSTANCE, //
                                            dataConverter );
        }

        protected POKeyValuePairConverter createToOneDataConverter( String pToThemName )
        {
            return new POKeyValuePairConverter( pToThemName );
        }

        protected SimpleKeyValuePair[] getValidOptions( String pToOneAttributeName,
                                                        POKeyValuePairConverter pDataConverter )
        {
            return getValidOptions( pToOneAttributeName, pDataConverter, null );
        }

        protected SimpleKeyValuePair[] getValidOptions( String pToOneAttributeName,
                                                        POKeyValuePairConverter pDataConverter,
                                                        WhereClause pWhereClause )
        {
            ValidOptionsFieldFilter zFieldFilter = mValidOptionsFieldFilters.get( pToOneAttributeName );
            if ( zFieldFilter != null )
            {
                WhereClauseFactory f = WhereClauseFactory.INSTANCE;
                WhereClause zWhereClause = f.isEqual( zFieldFilter.getSCDtoFilterOn(), //
                                                      zFieldFilter.getFilterValue() );
                pWhereClause = pWhereClause == null ? zWhereClause : f.and( pWhereClause, zWhereClause );
            }
            POQueryIterator it = getValidOptionsPOsOfType( pDataConverter.getRegisteredPOName(), //
                                                           pWhereClause );
            try
            {
                if ( !it.hasNext() )
                {
                    return null;
                }
                List<SimpleKeyValuePair> options = new ArrayList<SimpleKeyValuePair>();
                while ( it.hasNext() )
                {
                    PersistentObject po = it.next();
                    options.add( pDataConverter.createSimpleKeyValuePair( po ) );
                }
                return options.toArray( new SimpleKeyValuePair[options.size()] );
            }
            finally
            {
                it.releaseResources();
            }
        }

        private AMDconverterPair find1stPOKeyAMDconvertPairByAttributeReference( String pAttributeReference )
        {
            for ( AMDconverterPair pair : getRootTypeHelper().getAMDconvertPairs() )
            {
                if ( pAttributeReference.equals( pair.getAttributeMetaData().getAttributeReference() ) &&
                     (pair.getDataConverter() instanceof POKeyValuePairConverter) )
                {
                    return pair;
                }
            }

            return null;
        }

        public boolean clearToOneFilter( String pToOneAttributeName )
        {
            if ( null != mValidOptionsFieldFilters.remove( pToOneAttributeName ) )
            {
                reloadOptionsByAttributeReference( pToOneAttributeName );
                return true;
            }
            return false;
        }

        public boolean setToOneFilter( String pToOneAttributeName, String pToOnesAttribute,
                                       Object pFilterValue )
        {
            AMDconverterPair zPair = find1stPOKeyAMDconvertPairByAttributeReference( pToOneAttributeName );
            if ( zPair != null )
            {
                MetaDataForPO zMDtoOnePO = mFinder.getMetaDataOptional(
                        ((POKeyValuePairConverter) zPair.getDataConverter()).getRegisteredPOName() );
                if ( zMDtoOnePO != null )
                {
                    AttributeAccessorSCD zSCD = zMDtoOnePO.getAccessorSCDoptional( pToOnesAttribute );
                    if ( zSCD != null )
                    {
                        mValidOptionsFieldFilters.put( pToOneAttributeName, //
                                                       new ValidOptionsFieldFilter( zSCD, pFilterValue ) );
                        reloadOptionsByAttributeReference( pToOneAttributeName );
                        return true;
                    }
                }
            }
            return false;
        }

        private Map<String, ValidOptionsFieldFilter> mValidOptionsFieldFilters =
                new HashMap<String, ValidOptionsFieldFilter>();
    }

    protected static class ValidOptionsFieldFilter
    {
        private SimpleColumnDefinition mSCDtoFilterOn; // !null
        private Object mFilterValue; // Null Allowed...

        public ValidOptionsFieldFilter( SimpleColumnDefinition pSCDtoFilterOn, Object pFilterValue )
        {
            mSCDtoFilterOn = pSCDtoFilterOn;
            mFilterValue = pFilterValue;
        }

        public SimpleColumnDefinition getSCDtoFilterOn()
        {
            return mSCDtoFilterOn;
        }

        public Object getFilterValue()
        {
            return mFilterValue;
        }
    }

    protected static class POAttributeMetaDataFactory implements FormAttributeMetaDataFactory
    {
        public static final FormAttributeMetaDataFactory INSTANCE = new POAttributeMetaDataFactory();

        public AMDconverterPair createAttributeMetaData( CreateAMDParamsPlus pParams )
        {
            return TextFieldFormAMD.INSTANCE.create( pParams );
        }
    }

    protected class POKeyValuePairConverter extends AbstractSendableKeyValuePairConverter
    {
        private String mRegisteredPOname;

        public POKeyValuePairConverter( String pRegisteredPOname )
        {
            mRegisteredPOname = pRegisteredPOname;
        }

        public String getRegisteredPOName()
        {
            return mRegisteredPOname;
        }

        public SimpleKeyValuePair createSimpleKeyValuePair( Object pOption )
        {
            if ( pOption == null )
            {
                return new StringKeyValuePair( "" );
            }
            if ( pOption instanceof SimpleKeyValuePair )
            {
                return (SimpleKeyValuePair) pOption;
            }
            if ( pOption instanceof ResourceKeyNameURLaccessor )
            {
                return ((ResourceKeyNameURLaccessor) pOption).getResourceKeyNameURL();
            }
            if ( pOption instanceof PersistentObject )
            {
                PersistentObject po = (PersistentObject) pOption;
                return new DataStoreKeyValuePair( po.getPersistentObjectUniqueKey().toString(),
                                                  po.getDisplayValue() );
            }
            String zOptionAsString = pOption.toString();
            return new StringKeyValuePair( zOptionAsString );
        }

        protected Object convertSimpleKeyValuePairKey( Object pKey )
        {
            if ( pKey instanceof String )
            {
                try
                {
                    return mFinder.createPersistentObjectUniqueKeyFrom( mRegisteredPOname, pKey.toString() );
                }
                catch ( IllegalArgumentException e )
                {
                    // Fall thru...
                }
            }
            return super.convertSimpleKeyValuePairKey( pKey );
        }
    }
}

Commits for litesoft/trunk/Java/GWT/OldServer/src/org/litesoft/GWT/forms/server/POFormServicePeer.java

Diff revisions: vs.
Revision Author Commited Message
939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
804 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 12:48:51 +0000
802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
60 Diff Diff GeorgeS picture GeorgeS Tue 24 Aug, 2010 00:37:36 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000