srecord noeq G22DatabasesPanel(G22Utils g22utils) { delegate GazelleDB to G22Utils. delegate masterStuff to g22utils. JObjectTable table; FileWatchService dirWatcher; ReliableSingleThread rstUpdate = new(r _updateTable); cachedVisualize { table = swing(-> new JObjectTable); table.defaultAction(runnableToIVF1(rThread openDB)); table.itemToMap = db -> litorderedmap( "Name" := db.name, "Directory" := f2s(db.dir), "Loaded" := db.loaded() ? "Yes" : "No" ); var tbl = table.visualize(); bindToComponent(tbl, -> { dirWatcher = new FileWatchService; dirWatcher.addNonRecursiveListener(g22utils.databasesMotherDir(), dir -> rstUpdate!); masterStuff().onLoadedDBsChange(rstUpdate); rstUpdate!; }, -> { masterStuff().removeLoadedDBsChangeListener(rstUpdate); dispose dirWatcher; }); ret withTopAndBottomMargin(jCenteredRaisedSection("Gazelle projects on this computer", northAndCenterWithMargins( jline( toolTip("Create a new Gazelle project", jbutton("New project...", rThread newDatabase)) ), centerAndEastWithMargin( tbl, vstackWithSpacing_fixed( toolTip("Open selected project, keep other projects open too", selectButton(tableDependentButton(table.table, "Open project", rThread openDB))), toolTip("Open selected project, close all other projects", tableDependentButton(table.table, "Switch to project", rThread switchToDB)), tableDependentButton(table.table, "Close project", rThread closeDB), tableDependentButton(table.table, "Delete project (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 project", r { temp g22utils.enter(); S name = trim(tf.getText()); File dir = newFile(g22utils.databasesMotherDir(), name); createEmptyConceptsFileInDir(dir); disposeFrame(tf); masterStuff().openDatabase(dir); }); 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 project with that name exists"; else ok = true; } else if (!empty(name)) status = "Project name must be a valid file name"; setEnabled(button, ok); setText(lblStatus, status); setText(lblDir, path); }); showForm_makeFrame("New Gazelle Project", vstackWithSpacing( withLabel("Name for new project", tf), lblDir, lblStatus, button); } void _updateTable { table.setData_force(g22utils.gazelleDBs()); } void browse { desktopOpen(table.selected().dir); } void openDB { masterStuff().openDatabase(table.selected().dir); } void switchToDB { masterStuff().switchToDatabase(table.selected().dir); } void closeDB { masterStuff().closeDatabase(table.selected().dir); } }