srecord noeq G22DatabasesPanel(G22Utils g22utils) { delegate GazelleDB 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!); g22utils.masterStuff.onLoadedDBsChange(rstUpdate); rstUpdate!; }, -> { g22utils.masterStuff.removeLoadedDBsChangeListener(rstUpdate); dispose dirWatcher; }); ret withTopAndBottomMargin(jCenteredRaisedSection("Gazelle projects on this computer", northAndCenterWithMargins( jline( toolTip("Create a new Gazelle project", jbutton("New Gazelle project...", rThread newDatabase)) ), centerAndEastWithMargin( tbl, vstackWithSpacing_fixed( toolTip("Close current project, open selected project", tableDependentButton(table.table, "Switch to project", rThread switchToDB)), toolTip("Open selected project and keep current project open too", tableDependentButton(table.table, "Open project", rThread openDB)=, 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); }); 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 { g22utils.masterStuff().openDatabase(table.selected().dir); } void switchToDB { g22utils.masterStuff().switchToDatabase(table.selected().dir); } void closeDB { g22utils.masterStuff().closeDatabase(table.selected().dir); } }