1 | switchable S caseID; |
2 | switchable float tableFontSize = 0; // 0 for default |
3 | transient Concepts cc = db_mainConcepts(); |
4 | transient Class<A> conceptClass; |
5 | transient SimpleCRUD_v2<A> crud; |
6 | transient bool addCountToName = true, addCountToName_installed; |
7 | transient bool useInternalFramesForForms = true; |
8 | |
9 | void start_DynCRUD { |
10 | ifndef NoMainConcepts // set flag to save space |
11 | if (cc == db_mainConcepts()) |
12 | dbWithCase(caseID); // So we can do stuff in overridden start methods |
13 | endifndef |
14 | crud = makeCRUD(); // so we can customize early |
15 | if (addCountToName) addCountToName(); |
16 | } |
17 | |
18 | JComponent visualizeWithCountInTab() { |
19 | JComponent c = visualize(); |
20 | bindToComponent(table(), r updateTabTitle); |
21 | onConceptChange(cc, 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 | if (useInternalFramesForForms) |
32 | crud.showAForm = (title, parts) -> { |
33 | //formLayouter1_yPlus = 35; |
34 | JComponent form = makeForm_customLayout_b(true, formLayouter1b(), parts); |
35 | dm_showExtraFrame(title, withRightAndBottomMargin(form), |
36 | /*usePreferredSizeInitially := true*/); |
37 | ret form; |
38 | }; |
39 | crud.idWidth = 0; |
40 | crud.tableFontSize = zeroToNull(tableFontSize); |
41 | ret withMargin(crud.make_dontStartBots()); |
42 | } |
43 | |
44 | SimpleCRUD_v2<A> makeCRUD() { |
45 | ret SimpleCRUD_v2<A>(cc, conceptClass); |
46 | } |
47 | |
48 | JTable table() { ret crud?.table; } |
49 | |
50 | A selected() { ret crud?.selectedConcept(); } |
51 | |
52 | A getItem(int row) { ret crud?.getItem(row); } |
53 | |
54 | // call these in visualize() only (after calling super.visualize()) |
55 | |
56 | void addButton(JComponent button) { |
57 | if (crud != null) addComponent(crud.buttons, button); |
58 | } |
59 | void addButton(S name, Runnable action) { addButton(jbutton(name, action)); } |
60 | void addSelectionDependentButton(S name, O action) { |
61 | addButton(tableDependentButton(table(), name, toRunnable(action))); |
62 | } |
63 | |
64 | void makeSortable() { // broken? |
65 | addRowSorter(table()); |
66 | rowSorter_setComparatorForAllColumns(table(), alphaNumComparator()); |
67 | } |
68 | |
69 | S searchTerm() { |
70 | ret crud == null || crud.tableSearcher == null ? null : gtt(crud.tableSearcher.tfInput); |
71 | } |
72 | |
73 | void addCountToName { |
74 | if (addCountToName_installed) ret; |
75 | addCountToName_installed = true; |
76 | onConceptChangeAndNow(cc, rEnter { setModuleName(dm_originalModuleName() + " (" + nObjects(conceptCount()) + ")") }); |
77 | } |
78 | |
79 | Concepts conceptsObject() { |
80 | ret crud.concepts; |
81 | } |
82 | |
83 | // overwrite for compact modules to work |
84 | |
85 | <B extends Concept> L<B> list(Class<B> c) { |
86 | ret conceptsObject().list(c); |
87 | } |
88 | |
89 | <B extends Concept> L<B> list(Concepts cc, Class<B> c) { |
90 | ret cc.list(c); |
91 | } |
92 | // API |
93 | |
94 | L<A> concepts() enter { ret list(conceptClass); } |
95 | L<A> data() { ret concepts(); } |
96 | L<A> list() { ret concepts(); } |
97 | |
98 | L<Concept> conceptsOfType(S type) enter { ret conceptsObject().list(type); } |
99 | |
100 | // TODO: use index |
101 | L<Concept> conceptsOfTypeWhere(S type, O[] params) enter { |
102 | ret filterConcepts(conceptsOfType(type), params); |
103 | } |
104 | |
105 | int conceptCount() enter { ret countConcepts(cc, conceptClass); } |
106 | |
107 | void deleteAll() enter { |
108 | deleteConcepts(cc, conceptClass); |
109 | } |
110 | |
111 | void addDialog() enter { crud.newConcept(); } |
112 | |
113 | A uniqConcept(O... params) { |
114 | ret uniq_sync(cc, conceptClass, params); |
115 | } |
116 | |
117 | Pair<A, Bool> uniqConcept2(O... params) { |
118 | ret uniq2_sync(cc, conceptClass, params); |
119 | } |
120 | |
121 | int cset(Concept c, O... values) { |
122 | ret _cset(c, values); |
123 | } |
Began life as a copy of #1026525
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1030727 |
Snippet name: | DynCRUD Include v2 |
Eternal ID of this version: | #1030727/25 |
Text MD5: | 1b0bedcd332f4a85752194c6510aa160 |
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:07:49 |
Source code size: | 3477 bytes / 123 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 281 / 566 |
Version history: | 24 change(s) |
Referenced in: | [show references] |