1 | switchable S caseID; |
2 | transient Concepts cc = db_mainConcepts(); |
3 | transient Class<A> conceptClass; |
4 | transient SimpleCRUD<A> crud; |
5 | transient bool addCountToName = true, addCountToName_installed; |
6 | transient bool ensureIndexed; |
7 | |
8 | void start_DynCRUD { |
9 | ifndef NoMainConcepts // set flag to save space |
10 | if (cc == db_mainConcepts()) |
11 | dbWithCase(caseID); // So we can do stuff in overridden start methods |
12 | endifndef |
13 | crud = makeCRUD(); // so we can customize early |
14 | if (addCountToName) addCountToName(); |
15 | } |
16 | |
17 | JComponent visualizeWithCountInTab() { |
18 | JComponent c = visualize(); |
19 | bindToComponent(table(), r updateTabTitle); |
20 | temp tempSetTL(awtOnConceptChanges_concepts, cc); |
21 | awtOnConceptChanges(table(), r updateTabTitle); |
22 | ret c; |
23 | } |
24 | |
25 | void updateTabTitle { |
26 | updateEnclosingTabTitleWithCount(table(), conceptCount()); |
27 | } |
28 | |
29 | visualize { |
30 | if (crud == null) start_DynCRUD(); |
31 | makeConceptsTable_idWidth = 0; |
32 | showConceptsTable_afterUpdate.set(voidfunc(JTable t) { |
33 | int n = tableColumnCount(t); |
34 | for i to n: |
35 | setColumnName(t, i, i == 0 ? "" : humanizeFormLabel(getColumnName(t, i))); |
36 | }); |
37 | ret withMargin(crud.make_dontStartBots()); |
38 | } |
39 | |
40 | SimpleCRUD<A> makeCRUD() { |
41 | var crud = SimpleCRUD<A>(cc, conceptClass); |
42 | crud.ensureIndexed = ensureIndexed; |
43 | ret crud; |
44 | } |
45 | |
46 | JTable table() { ret crud == null ? null : crud.table; } |
47 | |
48 | A selected() { ret crud == null ? null : crud.selectedConcept(); } |
49 | |
50 | void addButton(JComponent button) { |
51 | if (crud != null) addComponent(crud.buttons, button); |
52 | } |
53 | void addButton(S name, O action) { addButton(jbutton(name, action)); } |
54 | void addSelectionDependentButton(S name, O action) { |
55 | addButton(tableDependentButton(table(), name, toRunnable(action))); |
56 | } |
57 | |
58 | void makeSortable() { // broken? |
59 | addRowSorter(table()); |
60 | rowSorter_setComparatorForAllColumns(table(), alphaNumComparator()); |
61 | } |
62 | |
63 | S searchTerm() { |
64 | ret crud == null || crud.tableSearcher == null ? null : gtt(crud.tableSearcher.tfInput); |
65 | } |
66 | |
67 | void addCountToName { |
68 | if (addCountToName_installed) ret; |
69 | addCountToName_installed = true; |
70 | onConceptChangeAndNow(cc, rEnter { setModuleName(dm_originalModuleName() + " (" + conceptCount() + ")") }); |
71 | } |
72 | |
73 | Concepts conceptsObject() { |
74 | ret crud.concepts; |
75 | } |
76 | |
77 | // overwrite for compact modules to work |
78 | |
79 | <B extends Concept> L<B> list(Class<B> c) { |
80 | ret conceptsObject().list(c); |
81 | } |
82 | |
83 | // API |
84 | |
85 | L<A> concepts() enter { ret list(conceptClass); } |
86 | L<A> data() { ret concepts(); } |
87 | L<A> list() { ret concepts(); } |
88 | |
89 | L<Concept> conceptsOfType(S type) enter { ret conceptsObject().list(type); } |
90 | |
91 | // TODO: use index |
92 | L<Concept> conceptsOfTypeWhere(S type, O[] params) enter { |
93 | ret filterConcepts(conceptsOfType(type), params); |
94 | } |
95 | |
96 | int conceptCount() enter { ret countConcepts(cc, conceptClass); } |
97 | |
98 | void deleteAll() enter { |
99 | deleteConcepts(cc, conceptClass); |
100 | } |
101 | |
102 | void addDialog() enter { crud.newConcept(); } |
103 | |
104 | A uniqConcept(O... params) { |
105 | ret uniq_sync(cc, conceptClass, params); |
106 | } |
107 | |
108 | Pair<A, Bool> uniqConcept2(O... params) { |
109 | ret uniq2_sync(cc, conceptClass, params); |
110 | } |
111 | |
112 | int cset(Concept c, O... values) { |
113 | ret _cset(c, values); |
114 | } |
Began life as a copy of #1019282
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, gjtlkbvenryc, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, qsqiayxyrbia, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1026525 |
Snippet name: | DynCRUD Include |
Eternal ID of this version: | #1026525/18 |
Text MD5: | 8eafe09e7e602927c6072aa72a372527 |
Author: | stefan |
Category: | javax / db / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-07 17:08:31 |
Source code size: | 3156 bytes / 114 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 355 / 1447 |
Version history: | 17 change(s) |
Referenced in: | [show references] |