My favorites | Sign in
Project Home Wiki Issues Source
Checkout   Browse   Changes    
 
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
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
/**
* Completes the functionality of {@model SyncWire}s.
*/
package org.openiaml.model.drools.rules.sync_wires

#list any import classes here.
import org.openiaml.model.drools.*;

import org.openiaml.model.inference.*;
import org.openiaml.model.model.*;
import org.openiaml.model.model.impl.*;
import org.openiaml.model.model.wires.*;
import org.openiaml.model.model.visual.*;
import org.openiaml.model.model.operations.*;
import org.openiaml.model.model.scopes.*;
import org.openiaml.model.model.domain.*;

import org.eclipse.emf.ecore.*;

#declare any global variables here
global OverridableCreateElementsHelper handler;
global DroolsInsertionQueue queue;
global DroolsHelperFunctions functions;

/**
* @inference SyncWire,CanBeSynced
* A {@model SyncWire} connecting two objects will create sub-{@model SyncWire}s between
* every contained object within these parent objects which have matching {@model CanBeSynced#name names}.
*/
rule "Sync wires between objects should create sync wires between all elements inside each object that matches"
when
# source : SyncWire(, eval(connects(source, p1, p2)) )
source : SyncWire( overriddenNames not contains "sync" )

# we put in these to prevent multiple wires being generated for two connects
p1 : CanBeSynced ( )
p2 : CanBeSynced ( )
eval ( functions.connectsSync1( source, p1, p2 ))

eval (p1 != p2)

e1 : CanBeSynced( eContainer == p1 )
e2 : CanBeSynced( eContainer == p2 )

eval(functions.nameMatches(e1, e2))

not (sw : SyncWire( eContainer == source, eval(functions.connects( sw, e1, e2)) ))

eval ( handler.veto( source ))

then
SyncWire sw = handler.generatedSyncWire(source, source, e1, e2);
handler.setName(sw, "sync");
handler.setExecuteOnInput(sw, source.isExecuteOnInput());
queue.add(sw, drools);

end

/**
* @inference SyncWire,CanBeSynced
* A {@model SyncWire} connecting an {@model DomainIterator} to a {@model CanBeSynced} object
* will create sub-{@model SyncWire}s between every contained object within the contained {@model DomainInstance}
* to every contained {@model CanBeSynced} object which have matching {@model CanBeSynced#name names}.
*/
rule "Sync wires to Domain Iterators should be copied to the contents of the Domain Iterator"
when
# source : SyncWire(, eval(connects(source, p1, p2)) )
source : SyncWire( overriddenNames not contains "sync" )

# we put in these to prevent multiple wires being generated for two connects
p1 : CanBeSynced ( )
p2_container : DomainIterator ( )
p2 : DomainInstance ( eContainer == p2_container )
eval ( functions.connects( source, p1, p2_container )) # can no longer rely on unidirectionality

eval (p1 != p2)

e1 : CanBeSynced( eContainer == p1 )
e2 : CanBeSynced( eContainer == p2 )

eval(functions.nameMatches(e1, e2))

not (sw : SyncWire( eContainer == source, eval(functions.connects( sw, e1, e2)) ))

eval ( handler.veto( source ))

then
SyncWire sw = handler.generatedSyncWire(source, source, e1, e2);
handler.setName(sw, "sync");
handler.setExecuteOnInput(sw, source.isExecuteOnInput());
queue.add(sw, drools);

end

/**
* @inference SyncWire
* When a {@model Changeable} is connected to a {@model ContainsOperations} by a
* {@model SyncWire}, the source element will {@model ECARule call} the 'update' {@model Operation} on the
* target when the source {@model Changeable#onChange changes}.
*/
rule "Run instance wire from edit to update (onChange)"
when
sw : SyncWire( overriddenNames not contains "run" )
source : Changeable( )
target : ContainsOperations( )
eval(functions.connects(sw, source, target))

event : Event( source.onChange == event )
operation : Operation( eContainer == target, name=="update" )

not (ECARule( trigger == event, target == operation, name == "run", eContainer == sw ))

eval ( handler.veto( sw ))

then
ECARule rw = handler.generatedECARule(sw, sw, event, operation);
handler.setName(rw, "run");
queue.add(rw, drools);

end

/**
* @inference SyncWire
* When an {@model InputTextField} is connected to a {@model ContainsOperations} by a {@model SyncWire#executeOnInput instant}
* {@model SyncWire}, the source element will {@model ECARule call} the 'update' {@model Operation} on the
* target when the source {@model InputTextField#onInput input changes}.
*/
rule "Run instance wire from edit to update, instant SyncWire (onInput)"
when
sw : SyncWire( executeOnInput == true, overriddenNames not contains "run" )
source : InputTextField( )
target : ContainsOperations( )
eval(functions.connects(sw, source, target))

event : Event( source.onInput == event )
operation : Operation( eContainer == target, name=="update" )

not (ECARule( trigger == event, target == operation, name == "run", eContainer == sw ))

eval ( handler.veto( sw ))

then
ECARule rw = handler.generatedECARule(sw, sw, event, operation);
handler.setName(rw, "run");
queue.add(rw, drools);

end

/**
* TODO Ideally, these two commands would be joined together into one
*
* @inference SyncWire,CanBeSynced,Parameter
* When a {@model CanBeSynced} element is connected to an {@model CanBeSynced} element by a
* {@model SyncWire}, the {@model CanBeSynced#fieldValue value} of the source element
* will be provided as a {@model Parameter} to the updating {@model ECARule}.
*/
rule "Connect parameter wire to: run instance wire from source.edit to target.update (onChange)"
when
sw : SyncWire( overriddenNames not contains "[sync] run instance parameter (source.edit)" )
source : Changeable( )
target : ContainsOperations( )
eval( functions.connects(sw, source, target))

event : Event( source.onChange == event )
operation : Operation( eContainer == target, name=="update" )
field : Value( source.fieldValue == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not ( Parameter ( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[sync] run instance parameter (source.edit)");
queue.add(pw, drools);

end

/**
* @inference SyncWire,InputTextField,CanBeSynced,Parameter
* When an {@model InputTextField} is connected to a {@model CanBeSynced} element by an {@model SyncWire#executeOnInput instant}
* {@model SyncWire}, the {@model CanBeSynced#fieldValue value} of the source element
* will be provided as a {@model Parameter} to the updating {@model ECARule}.
*/
rule "Connect parameter wire to: run instance wire from source.edit to target.update, instant SyncWire (onInput)"
when
sw : SyncWire( executeOnInput == true, overriddenNames not contains "[sync] run instance parameter instant (source.edit)" )
source : InputTextField( )
target : ContainsOperations( )
eval( functions.connects(sw, source, target))

event : Event( source.onInput == event )
operation : Operation( eContainer == target, name=="update" )
field : Value( source.currentInput == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not ( Parameter ( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[sync] run instance parameter instant (source.edit)");
queue.add(pw, drools);

end

/**
* TODO Ideally, these two commands would be joined together into one
*
* @inference SyncWire
* When a {@model ContainsOperations} element is connected to an {@model Accessible} element by a
* {@model SyncWire}, the source element will {@model ECARule call} the 'init' {@model Operation} on the
* target when the target {@model Accessible#onAccess is accessed}.
*/
rule "Run instance wire from source.access to source.init, when we have a value to provide as a parameter (onAccess)"
when
sw : SyncWire( overriddenNames not contains "run" )
source : Accessible( )
target : ContainsOperations( )
eval ( functions.connects(sw, source, target ))

event : Event( source.onAccess == event )
operation : Operation( eContainer == source, name=="init" )
field : Value( target.fieldValue == field )

not (ECARule( trigger == event, target == operation, name == "run", eContainer == sw ))

eval ( handler.veto( sw ))

then
ECARule rw = handler.generatedECARule(sw, sw, event, operation);
handler.setName(rw, "run");
queue.add(rw, drools);

end

/**
* @inference SyncWire,SimpleCondition
* When a {@model ContainsOperations} element is connected to an {@model Accessible} element by a
* {@model SyncWire}, the target element will {@model SimpleCondition only} be initialised if the source value is set.
*/
rule "Run instance wire from source.access to source.init, adding SimpleCondition to check it is set (onAccess)"
when
sw : SyncWire()
source : Accessible( )
target : ContainsOperations( )
eval ( functions.connects(sw, source, target))

event : Event( source.onAccess == event )
operation : Operation( eContainer == source, name=="init" )
field : Value( target.fieldValue == field )

run : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

# condition check
condition : Function ( eContainer == target, name == "fieldValue is set" )

not ( SimpleCondition ( function == condition, conditioned == run ))

eval ( handler.veto( sw ))

then
SimpleCondition cw = handler.generatedSimpleCondition(sw, sw, condition, run);
queue.add(cw, drools);

end

/**
* TODO Ideally, these two commands would be joined together into one
*
* @inference SyncWire,Parameter
* When a {@model CanBeSynced} element is connected to a {@model CanBeSynced} element by a
* {@model SyncWire}, the {@model CanBeSynced#fieldValue} of the source element will be used as a
* {@model Parameter} to initialise the target through the 'init' {@model Operation}.
*/
rule "Connect parameter wire to: run instance wire from source.access to source.init"
when
sw : SyncWire( overriddenNames not contains "[sync] run instance parameter (source.access)" )
source : Accessible( )
target : ContainsOperations( )
eval ( functions.connects(sw, source, target))

event : Event( source.onAccess == event )
operation : Operation( eContainer == source, name=="init" )
field : Value( target.fieldValue == field )
wire : ECARule( trigger == event, target == operation, name == "run", eContainer == sw )

not ( Parameter ( eContainer == sw, parameterValue == field, parameterTerm == wire ))

eval ( handler.veto( sw ))

then
Parameter pw = handler.generatedParameter(sw, sw, field, wire);
handler.setName(pw, "[sync] run instance parameter (source.access)");
queue.add(pw, drools);

end

/**
* I think that chained SyncWires are generally impossible. Consider:
*
* page1 <--> page2 <--> unrelated
* condition on both SyncWires, matching (page1, page2)
*
* If we allow for chaining, then the condition
* condition[page2, unrelated]
* will be copied onto
* condition[page1, page2]
* which means the SyncWire will never satisfy all its conditions.
*
* --
*
* I think that chained SyncWires are only possible *when* each
* SyncWire has identical Conditions, so we don't have to combine
* the two conditions together into something impossible.
*
* However, trying to implement this did nothing. I think it is because
* without adding more information to the model, you cannot chain.
* The information you'd be adding is stuff like ChainedSyncWire, but
* this defeats the purpose of having it in the model, because this should
* be handled by the code generation instead.
*/

/**
* @inference SyncWire,SimpleCondition
* A sub-{@model SyncWire} generated for a parent {@model SyncWire}
* will also be restricted with all of the {@model SimpleCondition}s of the parent wire.
*/
rule "Cascaded SyncWires: Conditions from parent to child"
when

# the containing elements
sw : SyncWire ( )
source : CanBeSynced( )
// cannot use 'sw.to == target, target != source'
// can NOT use 'sw.to == target, this != source'
// can NOT use 'sw.to == this, this != source'
target : CanBeSynced( )
eval ( target != source )

eval ( functions.connectsSync1(sw, source, target ))

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SyncWire( name == "sync", eval(functions.connects(esw, e1, e2)) )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# and there isn't one on the element sync wire
not (ecw : SimpleCondition( function == condition, conditioned == esw ))

eval ( handler.veto( cw ))

then
SimpleCondition ecw = handler.generatedSimpleCondition( cw, sw, condition, esw );
handler.setName(ecw, "[copied] from: " + cw.getId());
queue.add(ecw, drools);

end

/**
* @inference SyncWire,SimpleCondition
* A sub-{@model SyncWire} generated for a parent {@model SyncWire} connected to a {@model DomainIterator}
* will also be restricted with all of the {@model SimpleCondition}s of the parent wire.
*/
rule "Cascaded SyncWires: Conditions from parent to child (Domain Instances)"
when

# the containing elements
sw : SyncWire ( )
source : CanBeSynced( )
// cannot use 'sw.to == target, target != source'
// can NOT use 'sw.to == target, this != source'
// can NOT use 'sw.to == this, this != source'
target_container : DomainIterator ( )
target : DomainInstance( eContainer == target_container )

eval ( target != source )

eval ( functions.connects(sw, source, target_container )) # can no longer rely on unidirectionality

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SyncWire( name == "sync", eval(functions.connects(esw, e1, e2)) )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# and there isn't one on the element sync wire
not (ecw : SimpleCondition( function == condition, conditioned == esw ))

eval ( handler.veto( cw ))

then
SimpleCondition ecw = handler.generatedSimpleCondition( cw, sw, condition, esw );
handler.setName(ecw, "[copied] from: " + cw.getId());
queue.add(ecw, drools);

end

/**
* @inference SyncWire,SimpleCondition
* All restrictions derived by copying the {@model SimpleCondition}s of parent {@model SyncWire}s
* to their sub-{@model SyncWire}s will also be provided with the same {@model Parameter}s.
*/
rule "Cascaded SyncWires: Parameters from parent to child"
when

# the containing elements
sw : SyncWire ( )
source : CanBeSynced( )
target : CanBeSynced( )
eval ( target != source )

eval ( functions.connectsSync1(sw, source, target ))

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SyncWire( name == "sync", eval(functions.connects(esw, e1, e2)) )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# the generated condition wire
ecw : SimpleCondition( function == condition, conditioned == esw )

# there is a parameter on the condition wire
parameter : ParameterEdgesSource( )
pw : Parameter( parameterValue == parameter, parameterTerm == cw )

# and there isn't one on the element sync wire
not (epw : Parameter( parameterValue == parameter, parameterTerm == ecw ))

eval ( handler.veto( cw ))

then
# create it
Parameter epw = handler.generatedParameter( cw, sw, parameter, ecw );
handler.setName(epw, "[copied] from: " + pw.getId());
queue.add(epw, drools);

end

/**
* @inference SyncWire,SimpleCondition
* All restrictions derived by copying the {@model SimpleCondition}s of parent {@model SyncWire}s involving a {@model DomainIterator}
* to their sub-{@model SyncWire}s will also be provided with the same {@model Parameter}s.
*/
rule "Cascaded SyncWires: Parameters from parent to child (Domain Instances)"
when

# the containing elements
sw : SyncWire ( )
source : CanBeSynced( )
// cannot use 'sw.to == target, target != source'
// can NOT use 'sw.to == target, this != source'
// can NOT use 'sw.to == this, this != source'
target_container : DomainIterator ( )
target : DomainInstance( eContainer == target_container )

eval ( target != source )

eval ( functions.connectsSync1(sw, source, target ))

# the elements contained
e1 : CanBeSynced( eContainer == source )
e2 : CanBeSynced( eContainer == target, eval(functions.nameMatches(e1, e2)) )
esw : SyncWire( name == "sync", eval(functions.connects(esw, e1, e2)) )

# there is a condition on the containing sync wire
condition : Function ( )
cw : SimpleCondition( function == condition, conditioned == sw )

# the generated condition wire
ecw : SimpleCondition( function == condition, conditioned == esw )

# there is a parameter on the condition wire
parameter : ParameterEdgesSource( )
pw : Parameter( parameterValue == parameter, parameterTerm == cw )

# and there isn't one on the element sync wire
not (epw : Parameter( parameterValue == parameter, parameterTerm == ecw ))

eval ( handler.veto( cw ))

then
# create it
Parameter epw = handler.generatedParameter( cw, sw, parameter, ecw );
handler.setName(epw, "[copied] from: " + pw.getId());
queue.add(epw, drools);

end

/**
* SyncWires do not just connect the fields together; they can _also_
* connect the Frames together.
*
* @inference SyncWire,Session
* A parent {@model SyncWire} connecting a {@model Session}-contained {@model VisibleThing} to a {@model ContainsOperations} element
* outside of that {@model Session}, will {@model ECARule call} the 'init' {@model Operation} generated by each sub-{@model SyncWire}
* when the {@model Session} is {@model Session#onInit initialised}.
*/
rule "Connect Session.init to incoming SyncWires (contained in Frames) (onChange 2)"
when
session : Session ( )
sw : SyncWire( )
sourceFrame : VisibleThing( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
eval( functions.connects(sw, sourceFrame, targetFrame ))

sw2 : SyncWire ( eContainer == sw, overriddenNames not contains "run" )
sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
eval( functions.connects(sw2, sourceElement, targetElement ))

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

not (ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" ))

eval ( handler.veto( sw2 ))

then
ECARule rw2 = handler.generatedECARule(sw2, sw2, inite, operation);
handler.setName(rw2, "run");
queue.add(rw2, drools);

end

/**
* VisibleThing != Frame
*
* @inference SyncWire,Session
* A parent {@model SyncWire} connecting a {@model Session}-contained {@model Frame} to a {@model ContainsOperations} element
* outside of that {@model Session}, will {@model ECARule call} the 'init' {@model Operation} generated by each sub-{@model SyncWire}
* when the {@model Session} is {@model Session#onInit initialised}.
*/
rule "Connect Session.init to incoming SyncWires (contained in Frames) (onChange 3)"
when
session : Session ( )
sw : SyncWire( )
sourceFrame : Frame( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
eval( functions.connects(sw, sourceFrame, targetFrame ))

sw2 : SyncWire ( eContainer == sw, overriddenNames not contains "run" )
sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
eval( functions.connects(sw2, sourceElement, targetElement ))

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

not (ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" ))

eval ( handler.veto( sw2 ))

then
ECARule rw2 = handler.generatedECARule(sw2, sw2, inite, operation);
handler.setName(rw2, "run");
queue.add(rw2, drools);

end

/**
* @inference SyncWire,Session,Parameter
* Every 'init' {@model Operation} executed when a {@model Session} is {@model Session#onInit initialised} due to
* a {@model SyncWire} between a {@model VisibleThing} within that session, to {@model ContainsOperations another element}
* outside of that session, will be provided the {@model Changeable#fieldValue} of the source element as a {@model Parameter}.
*/
rule "Connect parameter for Session.init to incoming SyncWires (contained in Frames) (onChange) (2)"
when
session : Session ( )
sw : SyncWire ( )
sourceFrame : VisibleThing( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
eval( functions.connects(sw, sourceFrame, targetFrame ))

sw2 : SyncWire ( eContainer == sw)
sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
eval( functions.connects(sw2, sourceElement, targetElement ))

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

initrw : ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" )

field : Value( sourceElement.fieldValue == field )
pw : Parameter( eContainer == sw2, parameterValue == field, parameterTerm == rw )

not( Parameter ( eContainer == sw2, parameterValue == field, parameterTerm == initrw ))

eval ( handler.veto( sw ))

then
Parameter pw2 = handler.generatedParameter(sw, sw, field, initrw);
queue.add(pw2, drools);
end

/**
* @inference SyncWire,Session,Parameter
* Every 'init' {@model Operation} executed when a {@model Session} is {@model Session#onInit initialised} due to
* a {@model SyncWire} between a {@model Frame} within that session, to {@model ContainsOperations another element}
* outside of that session, will be provided the {@model Changeable#fieldValue} of the source element as a {@model Parameter}.
*/
rule "Connect parameter for Session.init to incoming SyncWires (contained in Frames) (onChange) (3)"
when
session : Session ( )
sw : SyncWire( )
sourceFrame : Frame( eval(!functions.containingSessionEquals(sourceFrame, session)) )
targetFrame : ContainsOperations( eval(functions.containingSessionEquals(targetFrame, session)) )
eval( functions.connects(sw, sourceFrame, targetFrame ))

sw2 : SyncWire ( eContainer == sw)
sourceElement : Changeable( eContainer == sourceFrame )
targetElement : ContainsOperations( eContainer == targetFrame )
eval( functions.connects(sw2, sourceElement, targetElement ))

event : Event( sourceElement.onChange == event )
operation : Operation( eContainer == targetElement, name == "update" )

rw : ECARule( eContainer == sw2, trigger == event, target == operation, name == "run" )
inite : Event (eContainer == session, session.onInit == inite )

initrw : ECARule( eContainer == sw2, trigger == inite, target == operation, name == "run" )

field : Value( sourceElement.fieldValue == field )
pw : Parameter( eContainer == sw2, parameterValue == field, parameterTerm == rw )

not( Parameter ( eContainer == sw2, parameterValue == field, parameterTerm == initrw ))

eval ( handler.veto( sw ))

then
Parameter pw2 = handler.generatedParameter(sw, sw, field, initrw);
queue.add(pw2, drools);
end

/**
* @inference SyncWire,DomainInstance
* An empty {@model InputForm} connected to a {@model DomainIterator} with a {@model SyncWire}
* will create an {@model InputTextField} in that form for every {@model DomainAttributeInstance}
* that is not a {@model DomainAttribute#primaryKey primary key} or {@model ExtendsEdge foreign key}.
* @implementation DomainAttributeInstance
* Currently, it is not possible to modify a {@model DomainAttributeInstance}
* that is {@model ExtendsEdge derived} or directly a {@model DomainAttribute#primaryKey primary key}.
*/
rule "Refresh New Instance Object mappings (except for generated primary keys) when sync connected to Forms: create text fields"
when
sync : SyncWire( )
form : InputForm ( )
iterator : DomainIterator ( )
instance : DomainInstance ( iterator.currentInstance == instance )

eval(functions.connects(sync, form, iterator))

originalAttribute : DomainAttribute ( )
attribute : DomainAttributeInstance( eContainer == instance )
ExtendsEdge ( from == attribute, to == originalAttribute )

# at the top of the attribute inheritance heirarchy, not
# a generated primary key
eval( functions.notExtendingGeneratedPrimaryKey( originalAttribute ) )

# or ANY type of primary key
eval( functions.notExtendingPrimaryKey( originalAttribute ) )

not ( tf : VisibleThing( eContainer == form, eval(functions.nameMatches( attribute, tf )) ) )

eval ( !form.getOverriddenNames().contains(attribute.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
InputTextField text = handler.generatedInputTextField(sync, form);
handler.setName(text, attribute.getName());
handler.setType(text, attribute.getType());
queue.add(text, drools);

end

/**
* @inference SyncWire,InputForm,InputTextField
* An {@model InputForm} connected to another {@model InputForm} with a {@model SyncWire}
* will create an {@model InputTextField} in the target form for every {@model InputTextField} in the
* source form with the same {@model InputTextField#name}.
*/
rule "Refresh mappings between InputForms connected to InputForms containing InputTextFields"
when
sync : SyncWire( )
source : InputForm ( )
target : InputForm ( )

eval(functions.connects(sync, source, target))

sf : InputTextField ( eContainer == source )
not ( tf : VisibleThing ( eContainer == target, eval(functions.nameMatches( sf, tf ))) )

eval ( !target.getOverriddenNames().contains(sf.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
InputTextField tf = handler.generatedInputTextField(sync, target);
handler.setName(tf, sf.getName());
queue.add(tf, drools);

end

/**
* @inference SyncWire,InputForm,Label
* An {@model InputForm} connected to another {@model InputForm} with a {@model SyncWire}
* will create a {@model Label} in the target form for every {@model Label} in the
* source form with the same {@model Label#name}.
*/
rule "Refresh mappings between InputForms connected to InputForms containing Labels"
when
sync : SyncWire( )
source : InputForm ( )
target : InputForm ( )

eval(functions.connects(sync, source, target))

sf : Label ( eContainer == source )
not ( tf : VisibleThing ( eContainer == target, eval(functions.nameMatches( sf, tf ))) )

eval ( !target.getOverriddenNames().contains(sf.getName()) )

eval ( handler.veto( sync ))

then
# create a new one
Label tf = handler.generatedLabel(sync, target);
handler.setName(tf, sf.getName());
queue.add(tf, drools);

end

/**
* @inference SyncWire,DomainIterator
* A {@model SyncWire} connecting a {@model DomainIterator#query 'new'} {@model DomainIterator} to an {@model InputForm} should only
* execute the 'init' {@model Operation} on the created {@model Label}s when the label is {@model Label#onAccess accessed}
* if the {@model DomainInstance} is {@model Function not empty}.
*/
rule "A SyncWire between Attributes selected from a NewInstanceWire need to check that the attribute exists before initialising"
when
sync : SyncWire( )
form : InputForm ( )
iterator : DomainIterator ( query == "new" )
instance : DomainInstance ( iterator.currentInstance == instance )

eval(functions.connects(sync, form, iterator))

# contained attribute/field
attribute : DomainAttributeInstance( eContainer == instance )
tf : InputTextField ( eContainer == form )
sync2 : SyncWire ( overriddenNames not contains "check new instance exists" )

eval(functions.connects(sync2, tf, attribute))

# text field access/init events
access : Event ( tf.onAccess == access )
initOp : Operation ( eContainer == tf, name == "init" )
run : ECARule ( trigger == access, target == initOp )

attributeValue : Value ( attribute.fieldValue == attributeValue )

param : Parameter ( parameterValue == attributeValue, parameterTerm == run )

# 'not empty' condition in the iterator
# TODO this could also be part of the DomainInstance
existsCondition : Function ( eContainer == iterator, name == "not empty" )

# but not connected
not (SimpleCondition ( function == existsCondition, conditioned == run ))

eval ( handler.veto( sync2 ))

then
# connect it
SimpleCondition cw = handler.generatedSimpleCondition(sync2, sync2, existsCondition, run);
handler.setName(cw, "check new instance exists");
queue.add(cw, drools);

end

Change log

r3151 by soundasleep on Oct 13, 2011   Diff
additional model completion documentation
fixes
Go to: 
Project members, sign in to write a code review

Older revisions

r3087 by soundasleep on Sep 15, 2011   Diff
improving the grammar and structure of
the model completion rules
documentation
r2962 by soundasleep on May 23, 2011   Diff
 issue 261 : removing unused SetWire and
SyncWire rules
r2952 by soundasleep on May 22, 2011   Diff
 issue 240 : updating more rule packages
with inference modeldoc
All revisions of this file

File info

Size: 31128 bytes, 807 lines
Powered by Google Project Hosting