Libraryless. Click here for Pure Java version (21947L/159K).
!include once #1027578 // Named asclass DynVoiceMultiCRUD extends DynModule { srecord Table(S tabName, S name, Class<? extends Concept> conceptClass, O[] scope) { Table(S tabName, S name, Class<? extends Concept> conceptClass) { this(tabName, name, conceptClass, null); } } transient Concepts cc; transient L<Table> tables; transient LPair<S, CRUD> swingCRUDs; // pair(tab name, crud) transient L<NameBasedVoiceCRUD> voiceCRUDs; // current selections for persistence. concept name to concept id Map<S, Long> selections = syncCIMap(); start { startDB(); tables = makeTables(); startCRUDs(); } void startDB { db(); cc = db_mainConcepts(); } // override me L<Table> makeTables() { ret ll(); } void startCRUDs { startSwingCRUDs(); makeVoiceCRUDs(); } // idempotent void makeVoiceCRUDs { voiceCRUDs = map(tables, t -> { NameBasedVoiceCRUD crud = new(cc, t.conceptClass, t.name, t.scope); restoreSelection(crud); crud.onSelect(value -> saveSelection(crud)); ret crud; }); } void remakeVoiceCRUDs { tables = makeTables(); makeVoiceCRUDs(); } void startSwingCRUDs { swingCRUDs = map(tables, t -> pair(t.tabName, CRUD(cc, t.conceptClass))); } 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(mapPairsB(swingCRUDs, crud -> crud.visualize()))); if (nempty(swingCRUDs)) addComponent(firstSwingCRUDButtons(), 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(cc, 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(); } JPanel firstSwingCRUDButtons() { if (empty(swingCRUDs)) null; ret first(swingCRUDs).b.crud.buttons; } }
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: | 361 / 881 |
Version history: | 46 change(s) |
Referenced in: | [show references] |