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