Libraryless. Click here for Pure Java version (21947L/159K).
1 | !include once #1027578 // Named |
2 | |
3 | asclass DynVoiceMultiCRUD extends DynModule { |
4 | srecord Table(S tabName, S name, Class<? extends Concept> conceptClass, O[] scope) { |
5 | Table(S tabName, S name, Class<? extends Concept> conceptClass) { |
6 | this(tabName, name, conceptClass, null); |
7 | } |
8 | } |
9 | |
10 | transient Concepts cc; |
11 | transient L<Table> tables; |
12 | |
13 | transient LPair<S, CRUD> swingCRUDs; // pair(tab name, crud) |
14 | transient L<NameBasedVoiceCRUD> voiceCRUDs; |
15 | |
16 | // current selections for persistence. concept name to concept id |
17 | Map<S, Long> selections = syncCIMap(); |
18 | |
19 | start { |
20 | startDB(); |
21 | tables = makeTables(); |
22 | startCRUDs(); |
23 | } |
24 | |
25 | void startDB { db(); cc = db_mainConcepts(); } |
26 | |
27 | // override me |
28 | L<Table> makeTables() { ret ll(); } |
29 | |
30 | void startCRUDs { |
31 | startSwingCRUDs(); |
32 | makeVoiceCRUDs(); |
33 | } |
34 | |
35 | // idempotent |
36 | void makeVoiceCRUDs { |
37 | voiceCRUDs = map(tables, t -> { |
38 | NameBasedVoiceCRUD crud = new(cc, t.conceptClass, t.name, t.scope); |
39 | restoreSelection(crud); |
40 | crud.onSelect(value -> saveSelection(crud)); |
41 | ret crud; |
42 | }); |
43 | } |
44 | |
45 | void remakeVoiceCRUDs { |
46 | tables = makeTables(); |
47 | makeVoiceCRUDs(); |
48 | } |
49 | |
50 | void startSwingCRUDs { |
51 | swingCRUDs = map(tables, t -> pair(t.tabName, CRUD(cc, t.conceptClass))); |
52 | } |
53 | |
54 | int idx(Class<? extends Concept> c) { ret indexOfPred(tables, t -> t.conceptClass == c); } |
55 | |
56 | !include #1027563 // Undo Manager |
57 | |
58 | S answer(S s) { |
59 | ret dm_q(() -> { |
60 | print("answering: " + s); |
61 | try answer undoActions(s); |
62 | |
63 | try answer moreActions(s); |
64 | |
65 | for (NameBasedVoiceCRUD crud : nonNulls(voiceCRUDs)) { |
66 | crud.addUndo = (IVF1<UndoableWithAnswer>) lambda1 addUndo; |
67 | try answer crud.answer(s); |
68 | } |
69 | null; |
70 | }); |
71 | } |
72 | |
73 | // override me |
74 | S moreActions(S s) { null; } |
75 | |
76 | visual { |
77 | JComponent c = jtabs(pairsToParams(mapPairsB(swingCRUDs, crud -> crud.visualize()))); |
78 | if (nempty(swingCRUDs)) |
79 | addComponent(firstSwingCRUDButtons(), jbutton("Talk to raw backend", rThread talkToMe)); |
80 | ret c; |
81 | } |
82 | |
83 | void talkToMe enter { dm_showConversationPopupForModule(); } |
84 | |
85 | // e.g. for concept ScenarioCondition > Named { Scenario scenario; } |
86 | // c2 is the dependent concept (ScenarioCondition) |
87 | void addDependency(Class<? extends Concept> c2, S field) { |
88 | Class<? extends Concept> c1 = fieldType(c2, field); |
89 | int i1 = idx(c1), i2 = idx(c2); |
90 | NameBasedVoiceCRUD originalCRUD2 = voiceCRUDs.get(i2); |
91 | S conceptName = originalCRUD2.concept; |
92 | NameBasedVoiceCRUD crud = voiceCRUDs.get(i1); |
93 | //printVars("addDependency", +c1, +c2, +conceptName, +field, +i1, +i2); |
94 | IVF1<Concept> r = value -> { |
95 | printVars("addDependency", +i2, +field, +value); |
96 | voiceCRUDs.set(i2, value == null ? null : NameBasedVoiceCRUD(c2, conceptName, field, value)); |
97 | }; |
98 | crud.onSelect(r); |
99 | r.get(crud.selected); |
100 | } |
101 | |
102 | void restoreSelection(NameBasedVoiceCRUD crud) { |
103 | Long id = selections.get(crud.concept); |
104 | Concept c = getConcept_allowNull(cc, id); |
105 | //printStackTrace("restoreSelection " + crud.concept + " " + id + " " + c); |
106 | crud.select(c); |
107 | } |
108 | |
109 | void saveSelection(NameBasedVoiceCRUD crud) { |
110 | Long id = conceptIDOrNull(crud.selected); |
111 | //printStackTrace("saveSelection: " + crud.concept + " " + id); |
112 | if (mapPutOrRemove_trueIfChanged(selections, crud.concept, id)) change(); |
113 | } |
114 | |
115 | JPanel firstSwingCRUDButtons() { |
116 | if (empty(swingCRUDs)) null; |
117 | ret first(swingCRUDs).b.crud.buttons; |
118 | } |
119 | } |
Began life as a copy of #1027565
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: | #1027579 |
Snippet name: | DynVoiceMultiCRUD |
Eternal ID of this version: | #1027579/47 |
Text MD5: | 2a8aadae63077cb8895c497ec8352e26 |
Transpilation MD5: | f1301994847abc0490aab5b93632fe6e |
Author: | stefan |
Category: | javax / scenarios |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-03-27 15:19:05 |
Source code size: | 3610 bytes / 119 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 362 / 883 |
Version history: | 46 change(s) |
Referenced in: | [show references] |