Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

94
LINES

< > BotCompany Repo | #1006009 // showConceptsTable + makeConceptsTable - show table of concepts (Swing)

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (22364L/145K).

1  
// optional parameters
2  
static ThreadLocal<L<S>> showConceptsTable_dropFields = new ThreadLocal;
3  
static new ThreadLocal showConceptsTable_postProcess; // func(L) -> L
4  
static new ThreadLocal showConceptsTable_afterUpdate; // voidfunc(JTable)
5  
static new ThreadLocal<Concepts> showConceptsTable_concepts;
6  
static new ThreadLocal<Bool> showConceptsTable_latestFirst;
7  
static new ThreadLocal<O> showConceptsTable_sorter; // func(Cl<Concept>) -> Cl<Concept>
8  
9  
static int makeConceptsTable_idWidth = 50;
10  
11  
static JTable showConceptsTable(Class<? extends Concept> c) {
12  
  JTable table = makeConceptsTable(c);
13  
  showFrame(plural(shortClassName(c)), table);
14  
  ret table;
15  
}
16  
17  
static JTable makeConceptsTable(Class<? extends Concept> c) {
18  
  LS dropFields = getAndClearThreadLocal(showConceptsTable_dropFields);
19  
  O pp = getAndClearThreadLocal(showConceptsTable_postProcess);
20  
  O afterUpdate = optParam(showConceptsTable_afterUpdate);
21  
  Concepts concepts = optParam(showConceptsTable_concepts, db_mainConcepts());
22  
  bool latestFirst = boolParam(showConceptsTable_latestFirst);
23  
  O sorter = optParam(showConceptsTable_sorter);
24  
  bool useStruct = boolParam(dataToTable_useStruct);
25  
26  
  final L<S> fields = listMinusList(concatLists(ll("id"), conceptFieldsInOrder(c)), dropFields);
27  
  final JTable table = sexyTable();
28  
  tablePopupMenu(table, voidfunc(JPopupMenu menu, final int row) {
29  
    addMenuItem(menu, "Delete", r {
30  
      final long id = toLong(getTableCell(table, row, 0));
31  
      deleteConcept_sync(concepts, id);
32  
    });
33  
  });
34  
  temp tempSetTL(awtOnConceptChanges_concepts, concepts);
35  
  awtOnConceptChanges(table, r {
36  
    //print("Updating concept table");
37  
    new L<L> data;
38  
    Cl<? extends Concept> l = list(concepts, c);
39  
    if (sorter != null) l = (Cl) callF(sorter, l);
40  
    for (Concept cc : l)
41  
      data.add(map(func(S field) {
42  
        O value = cget(cc, field);
43  
        ret useStruct ? renderForTable(value)
44  
                      : renderForTable_noStruct(value);
45  
      }, fields));
46  
    if (latestFirst) reverseInPlace(data);
47  
    data = (L) postProcess(pp, data);
48  
    fillTableWithData(table, data, map humanizeFormLabel(fields));
49  
    if (table.getColumnCount() > 0)
50  
      table.getColumnModel().getColumn(0).setMaxWidth(makeConceptsTable_idWidth);
51  
    pcallF(afterUpdate, table);
52  
  }, true);
53  
  ret table;
54  
}
55  
56  
// renderer takes a concept and makes a map for display
57  
static <A extends Concept> JTable makeConceptsTable(final Class<A> cClass, final O renderer) {
58  
  if (renderer == null) ret makeConceptsTable(cClass);
59  
  fO pp = optParam(showConceptsTable_postProcess);
60  
  fO afterUpdate = optParam(showConceptsTable_afterUpdate);
61  
  final Concepts concepts = optParam(showConceptsTable_concepts, db_mainConcepts());
62  
  fbool latestFirst = boolParam(showConceptsTable_latestFirst);
63  
  O sorter = optParam(showConceptsTable_sorter);
64  
  bool useStruct = boolParam(dataToTable_useStruct);
65  
  
66  
  final JTable table = sexyTable();
67  
  temp tempSetTL(awtOnConceptChanges_concepts, concepts);
68  
  awtOnConceptChanges(table, 1000, r {
69  
    new L<Map> data;
70  
    Cl<A> l = list(concepts, cClass);
71  
    if (sorter != null) l = (Cl) callF(sorter, l);
72  
    for (A c : l)
73  
      addIfNotNull(data, (Map) pcallF(renderer, c));
74  
    if (latestFirst) reverseInPlace(data);
75  
    data = (L) postProcess(pp, data);
76  
    ifdef makeConceptsTable_debug
77  
      printVars makeConceptsTable(+useStruct);
78  
    endifdef
79  
    temp tempSetTL(dataToTable_useStruct, useStruct);
80  
    dataToTable_uneditable(data, table);
81  
    pcallF(afterUpdate, table);
82  
  });
83  
  ret table;
84  
}
85  
86  
static <A extends Concept> JTable showConceptsTable(final Class<A> c, final O f) {
87  
  JTable table = makeConceptsTable(c, f);
88  
  showFrame(plural(shortClassName(c)), table);
89  
  ret table;
90  
}
91  
92  
static <A extends Concept> JTable showConceptsTable(S title, Class<A> cClass, O f) {
93  
  ret setFrameTitle(title, showConceptsTable(cClass, f));
94  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1006009
Snippet name: showConceptsTable + makeConceptsTable - show table of concepts (Swing)
Eternal ID of this version: #1006009/47
Text MD5: d8ba1d208039ad36299f71dca05c3741
Transpilation MD5: f4e7dd9feeab541a31985695345e0939
Author: stefan
Category: javax / gui / concepts
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-12 04:36:39
Source code size: 3934 bytes / 94 lines
Pitched / IR pitched: No / No
Views / Downloads: 689 / 779
Version history: 46 change(s)
Referenced in: [show references]