sclass G22DatabasesPanel { delegate GazelleDB to G22Utils. G22Utils g22utils; Concepts concepts; JObjectTable table; FileWatchService dirWatcher; ReliableSingleThread rstUpdate = new(r _updateTable); *(G22Utils *g22utils, Concepts *concepts) {} visualize { 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(); //updateTable(); 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 Databases", northAndCenterWithMargins( jline( toolTip("Create a new Gazelle database", jbutton("New Gazelle database...", rThread newDatabase)) ), centerAndEastWithMargin( tbl, vstackWithSpacing_fixed( tableDependentButton(table.table, "Open database", rThread openDB), tableDependentButton(table.table, "Close database", rThread closeDB), 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 { table.setList(g22utils.gazelleDBs()); } void browse { desktopOpen(table.selected().dir); } void openDB { g22utils.masterStuff().openDatabase(table.selected().dir); } void closeDB { g22utils.masterStuff().closeDatabase(table.selected().dir); } }