sclass G22DatabasesPanel { G22Utils g22utils; Concepts concepts; JObjectTable table; FileWatchService dirWatcher; ReliableSingleThread rstUpdate = new(r _updateTable); *(G22Utils *g22utils, Concepts *concepts) {} record GazelleDB(S name, File dir) { simplyCached bool loaded() { ret sameFile(dir, concepts.conceptsDir()); } } visualize { table = swing(-> new JObjectTable); table.defaultAction(runnableToIVF1(rThread switchDB)); table.itemToMap = db -> litorderedmap( "Name" := db.name, "Directory" := f2s(db.dir), "Loaded" := db.loaded() ? "Yes" : "No" ); var tbl = table.visualize(); //updateTable(); bindToComponent(tbl, -> { dirWatcher = new FileWatchService; dirWatcher.addNonRecursiveListener(g22utils.databasesMotherDir(), dir -> rstUpdate!); rstUpdate!; }, -> { dispose dirWatcher; }); ret withTopAndBottomMargin(jCenteredRaisedSection("Gazelle Databases", northAndCenterWithMargins( jline( toolTip("Create a new Gazelle database", jbutton("New Gazelle database...", rThread newDatabase)) ), centerAndEastWithMargins( tbl, vstackWithSpacing_fixed( tableDependentButton(table.table, "Switch to database", rThread switchDB), tableDependentButton(table.table, "Delete database (TODO)"), tableDependentButton(table.table, "Browse files", rThread browse) )))); } void newDatabase { temp g22utils.enter(); var tf = jtextfield(); var lblDir = jlabel(" "); var lblStatus = jlabel(" "); var button = jbutton("Create database", r { temp g22utils.enter(); S name = trim(tf.getText()); File dir = newFile(g22utils.databasesMotherDir(), name); createEmptyConceptsFileInDir(dir); disposeFrame(tf); //updateTable(); }); disableButton(button); onEnter(tf, button); onChange(tf, r { S name = trim(tf.getText()); bool ok; S status = " ", path = " "; if (isValidFileName(name)) { File dir = newFile(g22utils.databasesMotherDir(), name); path = f2s(dir); if (dirExists(dir)) status = "A database with that name exists"; else ok = true; } else if (!empty(name)) status = "Database name must be a valid file name"; setEnabled(button, ok); setText(lblStatus, status); setText(lblDir, path); }); showForm_makeFrame("New Gazelle Database", vstackWithSpacing( withLabel("Name for new database", tf), lblDir, lblStatus, button); } void _updateTable { new L dbs; dbs.add(new GazelleDB("Legacy DB", programDir())); for (File dir : listDirsContainingFileNamed(g22utils.databasesMotherDir(), "concepts.structure.gz")) dbs.add(new GazelleDB(fileName(dir), dir)); table.setList(dbs); } void browse { desktopOpen(table.selected().dir); } void switchDB { g22utils.masterStuff().switchDatabase(table.selected().dir); } }