!include once #1027578 // Named
asclass DynVoiceMultiCRUD extends DynModule {
srecord Table(S tabName, S name, Class extends Concept> conceptClass) {}
transient L
tables;
transient L swingCRUDs;
transient L voiceCRUDs;
start {
tables = makeTables();
startCRUDs();
}
// override me
L makeTables() { ret ll(); }
void startCRUDs {
swingCRUDs = map(tables, t -> CRUD(t.conceptClass));
voiceCRUDs = map(tables, t -> NameBasedVoiceCRUD(t.conceptClass, t.name));
}
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) 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(); }
}