set flag AllowMetaCode.
meta-postProcess { tok_crudAutoConstructor }
abstract sclass DynCRUD extends DynModule {
transient Class conceptClass;
transient SimpleCRUD crud;
S caseID;
*() {}
*(Class *conceptClass) {}
start {
dbWithCase(caseID); // So we can do stuff in overridden start methods
crud = makeCRUD(); // so we can customize early
}
visualize {
makeConceptsTable_idWidth = 0;
showConceptsTable_afterUpdate.set(voidfunc(JTable t) {
int n = tableColumnCount(t);
for i to n:
setColumnName(t, i, i == 0 ? "" : humanizeFormLabel(getColumnName(t, i)));
});
ret withMargin(crud.make());
}
SimpleCRUD makeCRUD() {
ret SimpleCRUD(db_mainConcepts(), conceptClass);
}
JTable table() { ret crud == null ? null : crud.table; }
A selected() { ret crud == null ? null : crud.selectedConcept(); }
void addButton(JComponent button) {
if (crud != null) addComponent(crud.buttons, button);
}
void addButton(S name, O action) { addButton(jbutton(name, action)); }
void makeSortable() { // broken?
addRowSorter(table());
rowSorter_setComparatorForAllColumns(table(), alphaNumComparator());
}
S searchTerm() {
ret crud == null || crud.tableSearcher == null ? null : gtt(crud.tableSearcher.tfInput);
}
void addCountToName {
onConceptChangeAndNow(r { setModuleName(programTitle() + " (" + conceptCount() + ")") });
}
Concepts conceptsObject() {
ret crud.concepts;
}
// overwrite for compact modules to work
L list(Class c) {
ret conceptsObject().list(c);
}
// API
L concepts() enter {
ret list(conceptClass);
}
int conceptCount() enter { ret countConcepts(conceptClass); }
void deleteAll() enter {
deleteConcepts(conceptClass);
}
void addDialog() enter { crud.newConcept(); }
}