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