!include once #1027578 // Named asclass DynVoiceMultiCRUD extends DynModule { srecord Table(S tabName, S name, Class<? extends Concept> conceptClass) {} transient L<Table> tables; transient L<CRUD> swingCRUDs; transient L<NameBasedVoiceCRUD> voiceCRUDs; // current selections for persistence. concept name to concept id Map<S, Long> selections = syncCIMap(); start { db(); tables = makeTables(); startCRUDs(); } // override me L<Table> makeTables() { ret ll(); } void startCRUDs { swingCRUDs = map(tables, t -> CRUD(t.conceptClass)); voiceCRUDs = map(tables, t -> { NameBasedVoiceCRUD crud = new(t.conceptClass, t.name); restoreSelection(crud); crud.onSelect(value -> saveSelection(crud)); ret crud; }); } int idx(Class<? extends Concept> c) { ret indexOfPred(tables, t -> t.conceptClass == c); } !include #1027563 // Undo Manager S answer(S s) { ret dm_q(() -> { print("answering: " + s); try answer undoActions(s); try answer moreActions(s); for (NameBasedVoiceCRUD crud : nonNulls(voiceCRUDs)) { crud.addUndo = (IVF1<UndoableWithAnswer>) lambda1 addUndo; try answer crud.answer(s); } null; }); } // override me S moreActions(S s) { null; } visual { JComponent c = jtabs(pairsToParams(mapPairsToList(zipTwoListsToPairs(tables, swingCRUDs), (t, crud) -> pair(t.tabName, crud.visualize())))); if (nempty(swingCRUDs)) addComponent(first(swingCRUDs).crud.buttons, jbutton("Talk to raw backend", rThread talkToMe)); ret c; } void talkToMe enter { dm_showConversationPopupForModule(); } // e.g. for concept ScenarioCondition > Named { Scenario scenario; } // c2 is the dependent concept (ScenarioCondition) void addDependency(Class<? extends Concept> c2, S field) { Class<? extends Concept> c1 = fieldType(c2, field); int i1 = idx(c1), i2 = idx(c2); NameBasedVoiceCRUD originalCRUD2 = voiceCRUDs.get(i2); S conceptName = originalCRUD2.concept; NameBasedVoiceCRUD crud = voiceCRUDs.get(i1); //printVars("addDependency", +c1, +c2, +conceptName, +field, +i1, +i2); IVF1<Concept> r = value -> { printVars("addDependency", +i2, +field, +value); voiceCRUDs.set(i2, value == null ? null : NameBasedVoiceCRUD(c2, conceptName, field, value)); }; crud.onSelect(r); r.get(crud.selected); } void restoreSelection(NameBasedVoiceCRUD crud) { Long id = selections.get(crud.concept); Concept c = getConcept_allowNull(id); //printStackTrace("restoreSelection " + crud.concept + " " + id + " " + c); crud.select(c); } void saveSelection(NameBasedVoiceCRUD crud) { Long id = conceptIDOrNull(crud.selected); //printStackTrace("saveSelection: " + crud.concept + " " + id); if (mapPutOrRemove_trueIfChanged(selections, crud.concept, id)) change(); } }
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: | 112 / 134 |
Referenced in: | [show references] |