// now a concept to allow for persistence of selected item
abstract concept G22CRUDAndDetailPanel extends ConceptWithChangeListeners is Swingable, IUnstructured {
new Ref selected;
CollapsibleNorthPanel collapsiblePanel = new(true);
transient settable G22Utils g22utils;
transient SimpleCRUD_v2 crud;
transient SingleComponentPanel scpDetail;
abstract SimpleCRUD_v2 makeCRUD();
// create detail view in background thread
transient RSTVar handleSelectionVar = new(l1 handleSelection_impl);
// a is not null
// override me
JComponent makeDetailView(A a) {
ret jTodo();
}
{ _doneLoading2(); }
public void _doneLoading2 :: after {
// Save vertical space
collapsiblePanel.wrappedSideComponent = -> centerAndEastWithMargin(collapsiblePanel.sideComponent(), vstack(collapsiblePanel.collapseButton()));
}
cachedVisualize {
crud = makeCRUD();
putCRUDButtonsNextToSearchBar(crud);
scpDetail = singleComponentPanel();
if (collapsiblePanel.expanded)
selectAfterUpdate(selected!);
var crudVis = crud.visualize();
crudVisualized();
handleSelectionVar.forceUpdate();
crud.onSelectionChanged(-> {
var selected = crud.selected();
this.selected.set(selected);
handleSelectionVar.set(selected);
});
/*ret jvsplit(
jCenteredSection(crud.entityNamePlural(), crudVis),
scpDetail);*/
collapsiblePanel.defaultSplitPoint(0.3);
collapsiblePanel.init(
crud.entityName() + " List",
jCenteredSection(crud.entityNamePlural(), crudVis),
scpDetail);
collapsiblePanel.onChange(l0 change);
ret collapsiblePanel.visualize();
}
void handleSelection_impl(A selected) {
if (selected == null)
scpDetail.set(emptyDetailView());
else {
var view = makeDetailView(selected);
var lvTitle = liveValue_hasChangeListeners(
selected,
-> detailTitle(selected));
scpDetail.set(jCenteredRaisedBoldLiveValueSection(lvTitle, view));
}
}
// item is not null
swappable S detailTitle(A item) {
ret appendPrefix(crud.entityName() + " " + item.id + ": ", str(item));
}
JComponent emptyDetailView() {
ret jGazelleLogo();
}
// override me
void crudVisualized {}
void addCountToEnclosingTab(bool b) {
crud.addCountToEnclosingTab(b);
}
void updateCount {
crud.update();
}
void edit aka setSelected(A A) {
var searcher = crud().tableSearcher();
searcher?.clearSearchField();
crud().setSelected(A);
}
void selectAfterUpdate(A A) {
crud.selectAfterUpdate(A);
}
SimpleCRUD_v2 crud() {
visualize();
ret crud;
}
}