// optional parameters static ThreadLocal> showConceptsTable_dropFields = new ThreadLocal; static new ThreadLocal showConceptsTable_postProcess; // func(L) -> L static new ThreadLocal showConceptsTable_afterUpdate; // voidfunc(JTable) static new ThreadLocal showConceptsTable_concepts; static int makeConceptsTable_idWidth = 50; static JTable showConceptsTable(Class c) { JTable table = makeConceptsTable(c); showFrame(plural(shortClassName(c)), table); ret table; } static JTable makeConceptsTable(final Class c) { L dropFields = getAndClearThreadLocal(showConceptsTable_dropFields); fO pp = getAndClearThreadLocal(showConceptsTable_postProcess); fO afterUpdate = optParam(showConceptsTable_afterUpdate); final Concepts concepts = optParam(showConceptsTable_concepts, db_mainConcepts()); final L fields = listMinusList(concatLists(ll("id"), conceptFieldsInOrder(c)), dropFields); final JTable table = sexyTable(); tablePopupMenu(table, voidfunc(JPopupMenu menu, final int row) { addMenuItem(menu, "Delete", r { final long id = toLong(getTableCell(table, row, 0)); withDBLock(r { deleteConcept(id) }); }); }); temp tempSetTL(awtOnConceptChanges_concepts, concepts); awtOnConceptChanges(table, r { //print("Updating concept table"); new L data; for (final Concept cc : list(concepts, c)) data.add(map(func(S field) { renderForTable(cget(cc, field)) }, fields)); data = (L) postProcess(pp, data); fillTableWithData(table, data, map humanizeFormLabel(fields)); if (table.getColumnCount() > 0) table.getColumnModel().getColumn(0).setMaxWidth(makeConceptsTable_idWidth); pcallF(afterUpdate, table); }, true); ret table; } // renderer takes a concept and makes a map for display static JTable makeConceptsTable(final Class cClass, final O renderer) { if (renderer == null) ret makeConceptsTable(cClass); fO pp = optParam(showConceptsTable_postProcess); fO afterUpdate = optParam(showConceptsTable_afterUpdate); final Concepts concepts = optParam(showConceptsTable_concepts); final JTable table = sexyTable(); awtOnConceptChanges(table, 1000, r { new L data; for (A c : list(concepts, cClass)) addIfNotNull(data, (Map) pcallF(renderer, c)); data = (L) postProcess(pp, data); dataToTable_uneditable(data, table); pcallF(afterUpdate, table); }); ret table; } static JTable showConceptsTable(final Class c, final O f) { JTable table = makeConceptsTable(c, f); showFrame(plural(shortClassName(c)), table); ret table; } static JTable showConceptsTable(S title, Class cClass, O f) { ret setFrameTitle(title, showConceptsTable(cClass, f)); }