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

70
LINES

< > BotCompany Repo | #1027591 // Generic Multi-CRUD

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (13753L/73K).

1  
!7
2  
3  
concept ObjectType > Named {
4  
  S conceptClassName;
5  
  
6  
  toString { ret "object type " + quote(name); }
7  
}
8  
9  
concept DynamicThing > Named {
10  
  ObjectType type;
11  
  
12  
  toString { ret (type == null ? "?" : type.name) + " " + quote(name); }
13  
}
14  
15  
cmodule DynamicClassesMultiCRUD > DynVoiceMultiCRUD {
16  
  switchable S caseID;
17  
  transient S defaultCmdsSnippetID = #1027616;
18  
  
19  
  L<Table> makeTables() {
20  
    ret itemPlusList(new Table("Object Types", "object type", ObjectType), 
21  
      map(list(cc, ObjectType), type ->
22  
        new Table(plural(type.name), type.name, DynamicThing, litparams(+type))));
23  
  }
24  
    
25  
  transient NameBasedVoiceCRUD<ObjectType> typesCRUD;
26  
  
27  
  void startDB { cc = dm_handleCaseIDField(); }
28  
29  
  start {
30  
    typesCRUD = voiceCRUDs.get(idx(ObjectType));
31  
    
32  
    // Update voice CRUDs when there is a new object type
33  
    onConceptsChange(cc, rWatcher_noRunFirstTime(
34  
      () -> objectTypes(), names -> objectTypesChanged(names)));
35  
  }
36  
  
37  
  void objectTypesChanged(LS names) enter {
38  
    print("Updating voice CRUDs");
39  
    remakeVoiceCRUDs();
40  
    vmBus_send objectTypesChanged(module(), names);
41  
  }
42  
  
43  
  void startSwingCRUDs {
44  
    swingCRUDs = ll(
45  
      pair("Object Types", CRUD(cc, ObjectType)),
46  
      pair("Objects", CRUD(cc, DynamicThing)));
47  
  }
48  
  
49  
  void startFrontEnd enter {
50  
    S frontEnd = dm_showModuleWithParams("#1027602/ChatBotFrontend", backendModuleID := dm_moduleID());
51  
    if (eq(dm_call(frontEnd, 'conceptCount), 0))
52  
      dm_call(frontEnd, 'importCmdsFromSnippet, defaultCmdsSnippetID);
53  
  }
54  
  
55  
  afterVisualize {
56  
    addComponent(firstSwingCRUDButtons(), jbutton("Start front-end", rThread startFrontEnd));
57  
  }
58  
  
59  
  @Override S moreActions(S s) null {
60  
    if "stats"
61  
      ret "You have stored " + nObjects(countConcepts(cc, ObjectType))
62  
        + " of " + nTypes(countConcepts(cc, DynamicThing));
63  
  }
64  
  
65  
  // API
66  
  
67  
  LS objectTypes() {
68  
    ret itemPlus("object type", collect name(list(cc, ObjectType)));
69  
  }
70  
}

Author comment

Began life as a copy of #1027580

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: #1027591
Snippet name: Generic Multi-CRUD
Eternal ID of this version: #1027591/33
Text MD5: 4d907ba40a914cc692ce31a1d7d45b5c
Transpilation MD5: 2ed50b76fc54d7c4e6067e51f16d13ec
Author: stefan
Category: javax / voice crud
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-28 00:22:01
Source code size: 2010 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 215 / 42067
Version history: 32 change(s)
Referenced in: [show references]