1 | !include once #1027578 // Named |
2 | |
3 | asclass DynVoiceMultiCRUD extends DynModule { |
4 | srecord Table(S tabName, S name, Class<? extends Concept> conceptClass) {} |
5 | |
6 | transient L<Table> tables; |
7 | |
8 | transient L<CRUD> swingCRUDs; |
9 | transient L<NameBasedVoiceCRUD> voiceCRUDs; |
10 | |
11 | // current selections for persistence. concept name to concept id |
12 | Map<S, Long> selections = syncCIMap(); |
13 | |
14 | start { |
15 | db(); |
16 | tables = makeTables(); |
17 | startCRUDs(); |
18 | } |
19 | |
20 | // override me |
21 | L<Table> makeTables() { ret ll(); } |
22 | |
23 | void startCRUDs { |
24 | swingCRUDs = map(tables, t -> CRUD(t.conceptClass)); |
25 | voiceCRUDs = map(tables, t -> { |
26 | NameBasedVoiceCRUD crud = new(t.conceptClass, t.name); |
27 | restoreSelection(crud); |
28 | crud.onSelect(value -> saveSelection(crud)); |
29 | ret crud; |
30 | }); |
31 | } |
32 | |
33 | int idx(Class<? extends Concept> c) { ret indexOfPred(tables, t -> t.conceptClass == c); } |
34 | |
35 | !include #1027563 // Undo Manager |
36 | |
37 | S answer(S s) { |
38 | ret dm_q(() -> { |
39 | print("answering: " + s); |
40 | try answer undoActions(s); |
41 | |
42 | try answer moreActions(s); |
43 | |
44 | for (NameBasedVoiceCRUD crud : nonNulls(voiceCRUDs)) { |
45 | crud.addUndo = (IVF1<UndoableWithAnswer>) lambda1 addUndo; |
46 | try answer crud.answer(s); |
47 | } |
48 | null; |
49 | }); |
50 | } |
51 | |
52 | // override me |
53 | S moreActions(S s) { null; } |
54 | |
55 | visual { |
56 | JComponent c = jtabs(pairsToParams(mapPairsToList(zipTwoListsToPairs(tables, swingCRUDs), (t, crud) -> |
57 | pair(t.tabName, crud.visualize())))); |
58 | if (nempty(swingCRUDs)) |
59 | addComponent(first(swingCRUDs).crud.buttons, jbutton("Talk to raw backend", rThread talkToMe)); |
60 | ret c; |
61 | } |
62 | |
63 | void talkToMe enter { dm_showConversationPopupForModule(); } |
64 | |
65 | // e.g. for concept ScenarioCondition > Named { Scenario scenario; } |
66 | // c2 is the dependent concept (ScenarioCondition) |
67 | void addDependency(Class<? extends Concept> c2, S field) { |
68 | Class<? extends Concept> c1 = fieldType(c2, field); |
69 | int i1 = idx(c1), i2 = idx(c2); |
70 | NameBasedVoiceCRUD originalCRUD2 = voiceCRUDs.get(i2); |
71 | S conceptName = originalCRUD2.concept; |
72 | NameBasedVoiceCRUD crud = voiceCRUDs.get(i1); |
73 | //printVars("addDependency", +c1, +c2, +conceptName, +field, +i1, +i2); |
74 | IVF1<Concept> r = value -> { |
75 | printVars("addDependency", +i2, +field, +value); |
76 | voiceCRUDs.set(i2, value == null ? null : NameBasedVoiceCRUD(c2, conceptName, field, value)); |
77 | }; |
78 | crud.onSelect(r); |
79 | r.get(crud.selected); |
80 | } |
81 | |
82 | void restoreSelection(NameBasedVoiceCRUD crud) { |
83 | Long id = selections.get(crud.concept); |
84 | Concept c = getConcept_allowNull(id); |
85 | //printStackTrace("restoreSelection " + crud.concept + " " + id + " " + c); |
86 | crud.select(c); |
87 | } |
88 | |
89 | void saveSelection(NameBasedVoiceCRUD crud) { |
90 | Long id = conceptIDOrNull(crud.selected); |
91 | //printStackTrace("saveSelection: " + crud.concept + " " + id); |
92 | if (mapPutOrRemove_trueIfChanged(selections, crud.concept, id)) change(); |
93 | } |
94 | } |
Began life as a copy of #1027579
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027587 |
Snippet name: | DynVoiceMultiCRUD [backup v1 before dynamic concept classes] |
Eternal ID of this version: | #1027587/1 |
Text MD5: | 368c366dfc102c986200c25682d2d179 |
Author: | stefan |
Category: | javax / scenarios |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-25 12:52:09 |
Source code size: | 3044 bytes / 94 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 194 / 217 |
Referenced in: | [show references] |