switchable S caseID;
transient Concepts cc = db_mainConcepts();
transient Class conceptClass;
transient SimpleCRUD crud;
transient bool addCountToName = true, addCountToName_installed;
transient bool ensureIndexed;
void start_DynCRUD {
ifndef NoMainConcepts // set flag to save space
if (cc == db_mainConcepts())
dbWithCase(caseID); // So we can do stuff in overridden start methods
endifndef
crud = makeCRUD(); // so we can customize early
if (addCountToName) addCountToName();
}
JComponent visualizeWithCountInTab() {
JComponent c = visualize();
bindToComponent(table(), r updateTabTitle);
temp tempSetTL(awtOnConceptChanges_concepts, cc);
awtOnConceptChanges(table(), r updateTabTitle);
ret c;
}
void updateTabTitle {
updateEnclosingTabTitleWithCount(table(), conceptCount());
}
visualize {
if (crud == null) start_DynCRUD();
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_dontStartBots());
}
SimpleCRUD makeCRUD() {
var crud = SimpleCRUD(cc, conceptClass);
crud.ensureIndexed = ensureIndexed;
ret crud;
}
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 addSelectionDependentButton(S name, O action) {
addButton(tableDependentButton(table(), name, toRunnable(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 {
if (addCountToName_installed) ret;
addCountToName_installed = true;
onConceptChangeAndNow(cc, rEnter { setModuleName(dm_originalModuleName() + " (" + 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); }
L data() { ret concepts(); }
L list() { ret concepts(); }
L conceptsOfType(S type) enter { ret conceptsObject().list(type); }
// TODO: use index
L conceptsOfTypeWhere(S type, O[] params) enter {
ret filterConcepts(conceptsOfType(type), params);
}
int conceptCount() enter { ret countConcepts(cc, conceptClass); }
void deleteAll() enter {
deleteConcepts(cc, conceptClass);
}
void addDialog() enter { crud.newConcept(); }
A uniqConcept(O... params) {
ret uniq_sync(cc, conceptClass, params);
}
Pair uniqConcept2(O... params) {
ret uniq2_sync(cc, conceptClass, params);
}
int cset(Concept c, O... values) {
ret _cset(c, values);
}