Uses 2164K of libraries. Click here for Pure Java version (67854L/359K).
1 | // now a concept to allow for persistence of selected item |
2 | abstract concept G22CRUDAndDetailPanel<A extends ConceptWithChangeListeners> extends ConceptWithChangeListeners is Swingable, IUnstructured { |
3 | new Ref<A> selected; |
4 | |
5 | CollapsibleNorthPanel collapsiblePanel = new(true); |
6 | |
7 | transient settable G22Utils g22utils; |
8 | |
9 | transient SimpleCRUD_v2<A> crud; |
10 | transient SingleComponentPanel scpDetail; |
11 | |
12 | abstract SimpleCRUD_v2<A> makeCRUD(); |
13 | |
14 | // create detail view in background thread |
15 | transient RSTVar<A> handleSelectionVar = new(l1 handleSelection_impl); |
16 | |
17 | // a is not null |
18 | // override me |
19 | JComponent makeDetailView(A a) { |
20 | ret jTodo(); |
21 | } |
22 | |
23 | { _doneLoading2(); } |
24 | |
25 | public void _doneLoading2 :: after { |
26 | // Save vertical space |
27 | collapsiblePanel.wrappedSideComponent = -> centerAndEastWithMargin(collapsiblePanel.sideComponent(), vstack(collapsiblePanel.collapseButton())); |
28 | } |
29 | |
30 | cachedVisualize { |
31 | crud = makeCRUD(); |
32 | putCRUDButtonsNextToSearchBar(crud); |
33 | |
34 | scpDetail = singleComponentPanel(); |
35 | if (collapsiblePanel.expanded) |
36 | selectAfterUpdate(selected!); |
37 | |
38 | var crudVis = crud.visualize(); |
39 | crudVisualized(); |
40 | |
41 | handleSelectionVar.forceUpdate(); |
42 | crud.onSelectionChanged(-> { |
43 | var selected = crud.selected(); |
44 | this.selected.set(selected); |
45 | handleSelectionVar.set(selected); |
46 | }); |
47 | |
48 | /*ret jvsplit( |
49 | jCenteredSection(crud.entityNamePlural(), crudVis), |
50 | scpDetail);*/ |
51 | |
52 | collapsiblePanel.defaultSplitPoint(0.3); |
53 | |
54 | collapsiblePanel.init( |
55 | crud.entityName() + " List", |
56 | jCenteredSection(crud.entityNamePlural(), crudVis), |
57 | scpDetail); |
58 | |
59 | collapsiblePanel.onChange(l0 change); |
60 | |
61 | ret collapsiblePanel.visualize(); |
62 | } |
63 | |
64 | void handleSelection_impl(A selected) { |
65 | if (selected == null) |
66 | scpDetail.set(emptyDetailView()); |
67 | else { |
68 | var view = makeDetailView(selected); |
69 | var lvTitle = liveValue_hasChangeListeners( |
70 | selected, |
71 | -> detailTitle(selected)); |
72 | scpDetail.set(jCenteredRaisedBoldLiveValueSection(lvTitle, view)); |
73 | } |
74 | } |
75 | |
76 | // item is not null |
77 | swappable S detailTitle(A item) { |
78 | ret appendPrefix(crud.entityName() + " " + item.id + ": ", str(item)); |
79 | } |
80 | |
81 | JComponent emptyDetailView() { |
82 | ret jGazelleLogo(); |
83 | } |
84 | |
85 | // override me |
86 | void crudVisualized {} |
87 | |
88 | void addCountToEnclosingTab(bool b) { |
89 | crud.addCountToEnclosingTab(b); |
90 | } |
91 | |
92 | void updateCount { |
93 | crud.update(); |
94 | } |
95 | |
96 | void edit aka setSelected(A A) { |
97 | var searcher = crud().tableSearcher(); |
98 | searcher?.clearSearchField(); |
99 | crud().setSelected(A); |
100 | } |
101 | |
102 | void selectAfterUpdate(A A) { |
103 | crud.selectAfterUpdate(A); |
104 | } |
105 | |
106 | SimpleCRUD_v2<A> crud() { |
107 | visualize(); |
108 | ret crud; |
109 | } |
110 | } |
Began life as a copy of #1034599
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034944 |
Snippet name: | G22CRUDAndDetailPanel |
Eternal ID of this version: | #1034944/52 |
Text MD5: | 38868aac76663eedae6165357ba91e9f |
Transpilation MD5: | b9ff34b7211d2be4be43c830d921800b |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-12-11 15:01:22 |
Source code size: | 2872 bytes / 110 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 310 / 573 |
Version history: | 51 change(s) |
Referenced in: | [show references] |