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

63
LINES

< > BotCompany Repo | #1035496 // G22NetworksFromAllDBsPanel

JavaX fragment (include)

sclass G22NetworksFromAllDBsPanel {
  G22Utils g22utils;
  
  // Each script is registered to a non-persistent Concepts object
  // loaded temporarily but connected to the appropriate db dir
  JObjectTable<G22Network> table;
  
  ReliableSingleThread rstUpdate = new(r _updateTable);
  transient SingleComponentPanel scpDetail = singleComponentPanel();
  
  *(G22Utils *g22utils) {}
  
  visualize {
    table = new JObjectTable;
    table.itemToMap = script -> litorderedmap(
      "Network" := script.description,
      "Project" := fileName(networkToDBDir(script)),
      "ID in original project" := str(script.id),
    );

    var tbl = table.visualize();
    rstUpdate!;
    
    tablePopupMenuItem_top(table.table, "Open project", rThread {
      g22utils.masterStuff.openDatabase(table.selected()._concepts.conceptsDir());
    });
    
    tablePopupMenuItem_top(table.table, "Import network", rThread {
      var network = table.selected();
      var clonedNetwork = (G22Network) g22utils.restructure(network);
      registerConcept(g22utils.concepts(), clonedNetwork);
      g22utils.projectActions().openObjectInProject(clonedNetwork.id);
    });
    
    table.onSelect(network -> {
      if (network == null) scpDetail.clear();
      else {
        scpDetail.set(makeDetailView(network));
      }
    });
    
    ret withTopAndBottomMargin(jCenteredRaisedSection("Networks from all projects",
      jvsplit(tbl, scpDetail)));
  }
  
  JComponent makeDetailView(G22Network network) {
    ret JG22Network(g22utils, network).visualize();
  }
  
  File networkToDBDir(G22Network network) {
    ret network == null ?: network._concepts.conceptsDir();
  }
  
  void _updateTable {
    table.setData_force(concatLists(
      map_pcall(g22utils.gazelleDBs(), db -> {
        var classFinder = g22utils.masterStuff.makeClassFinder();
        var cc = newConceptsWithClassFinder(db.conceptsFile(), classFinder);
        cc.loadFromDisk();
        ret list(cc, G22Network);
      })));
  }
}

Author comment

Began life as a copy of #1034641

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035496
Snippet name: G22NetworksFromAllDBsPanel
Eternal ID of this version: #1035496/9
Text MD5: 9396823f2edbaf08648ecd0b28ae601b
Author: stefan
Category: javax / gazelle 22
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-16 16:24:49
Source code size: 2055 bytes / 63 lines
Pitched / IR pitched: No / No
Views / Downloads: 134 / 155
Version history: 8 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)