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

94
LINES

< > BotCompany Repo | #1027592 // DynCRUD Include [backup before scope]

JavaX fragment (include)

transient Class<A> conceptClass;
transient SimpleCRUD<A> crud;
transient Concepts cc = db_mainConcepts();
S caseID;
transient bool addCountToName = true, addCountToName_installed;

void start_DynCRUD {
  dbWithCase(caseID); // So we can do stuff in overridden start methods
  crud = makeCRUD(); // so we can customize early
  if (addCountToName) addCountToName();
}

visualize {
  if (crud == null) start_DynCRUD();
  makeConceptsTable_idWidth = 0;
  showConceptsTable_afterUpdate.set(voidfunc(JTable t) {
    int n = tableColumnCount(t);
    for i to n:
      setColumnName(t, i, i == 0 ? "" : humanizeFormLabel(getColumnName(t, i)));
  });
  ret withMargin(crud.make_dontStartBots());
}

SimpleCRUD<A> makeCRUD() {
  ret SimpleCRUD<A>(db_mainConcepts(), conceptClass);
}

JTable table() { ret crud == null ? null : crud.table; }

A selected() { ret crud == null ? null : crud.selectedConcept(); }

void addButton(JComponent button) {
  if (crud != null) addComponent(crud.buttons, button);
}
void addButton(S name, O action) { addButton(jbutton(name, action)); }
void addSelectionDependentButton(S name, O action) {
  addButton(tableDependentButton(table(), name, action));
}

void makeSortable() { // broken?
  addRowSorter(table());
  rowSorter_setComparatorForAllColumns(table(), alphaNumComparator());
}

S searchTerm() {
  ret crud == null || crud.tableSearcher == null ? null : gtt(crud.tableSearcher.tfInput);
}

void addCountToName {
  if (addCountToName_installed) ret;
  addCountToName_installed = true;
  onConceptChangeAndNow(rEnter { setModuleName(dm_originalModuleName() + " (" + conceptCount() + ")") });
}

Concepts conceptsObject() { ret cc; }

// overwrite for compact modules to work

<B extends Concept> L<B> list(Class<B> c) {
  ret conceptsObject().list(c);
}

// API

L<A> concepts() enter { ret list(cc, conceptClass); }
L<A> data() { ret concepts(); }
L<A> list() { ret concepts(); }

L<Concept> conceptsOfType(S type) enter { ret conceptsObject().list(type); }

// TODO: use index
L<Concept> conceptsOfTypeWhere(S type, O[] params) enter {
  ret filterConcepts(conceptsOfType(type), params);
}

int conceptCount() enter { ret countConcepts(cc, conceptClass); }

void deleteAll() enter {
  deleteConcepts(cc, conceptClass);
}

void addDialog() enter { crud.newConcept(); }

A uniqConcept(O... params) {
  ret uniq_sync(cc, conceptClass, params);
}

Pair<A, Bool> uniqConcept2(O... params) {
  ret uniq2_sync(cc, conceptClass, params);
}

int cset(Concept c, O... values) {
  ret _cset(c, values);
}

Author comment

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: 175 / 210
Version history: 2 change(s)
Referenced in: [show references]