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).

1  
srecord noeq G22DatabasesPanel(G22Utils g22utils) {
2  
  delegate GazelleDB to G22Utils.
3  
  delegate masterStuff to g22utils.
4  
  
5  
  JObjectTable<GazelleDB> table;
6  
  FileWatchService dirWatcher;
7  
  ReliableSingleThread rstUpdate = new(r _updateTable);
8  
  
9  
  cachedVisualize {
10  
    table = swing(-> new JObjectTable);
11  
    table.defaultAction(runnableToIVF1(rThread openDB));
12  
    table.itemToMap = db -> {
13  
      IG22LoadedDB loaded = db.loadedDB();
14  
      ret litorderedmap(
15  
        "Name" := db.name,
16  
        "Directory" := f2s(db.dir),
17  
        "Loaded" := loaded == null ? "No"
18  
          : (loaded.hidden() ? "Yes (hidden)" : "Yes");      };
19  
20  
    var tbl = table.visualize();
21  
    bindToComponent(tbl, -> {
22  
      dirWatcher = new FileWatchService;
23  
      dirWatcher.addNonRecursiveListener(g22utils.databasesMotherDir(), file -> {
24  
        //print("G22DatabasesPanel File change: " + file);
25  
        rstUpdate!;
26  
      });
27  
      masterStuff().onLoadedDBsChange(rstUpdate);
28  
      rstUpdate!;
29  
    }, -> {
30  
      masterStuff().removeLoadedDBsChangeListener(rstUpdate);
31  
      dispose dirWatcher;
32  
    });
33  
34  
    ret withTopAndBottomMargin(jCenteredRaisedSection("Gazelle projects on this computer",
35  
      northAndCenterWithMargins(
36  
        jline(
37  
          toolTip("Create a new Gazelle project", jbutton("New project...", rThread newDatabase))
38  
        ),
39  
        centerAndEastWithMargin(
40  
          tbl,
41  
          jscroll_vertical_borderless(vstackWithSpacing_fixed(
42  
            // BUTTONS defined here
43  
            
44  
            DefaultButtonBorder(toolTip("Open selected project, keep other projects open too",
45  
              tableDependentButton(table.table, "Open project", rThread openDB))),
46  
            toolTip("Open selected project in hidden mode [without a window]",
47  
              tableDependentButton(table.table, "Open hidden", rThread openDBHidden)),
48  
            toolTip("Open selected project, close all other projects",
49  
              tableDependentButton(table.table, "Switch to project", rThread switchToDB)),
50  
            tableDependentButton(table.table, "Close project", rThread closeDB),
51  
            tableDependentButton(table.table, "Rename project", rThread renameDB),
52  
            tableDependentButton(table.table, "Delete project...", rThread deleteDB),
53  
            tableDependentButton(table.table, "Browse files", rThread browse),
54  
            tableDependentButton(table.table, "Export project as zip...", rThread exportAsZip),
55  
            jThreadedButton("Import project from zip...", rThread importZip),
56  
            jThreadedButton("Download project from Gaz.AI...", rThread downloadProject),
57  
          )))));
58  
  }
59  
  
60  
  void newDatabase {
61  
    temp g22utils.enter();
62  
    
63  
    var tf = jtextfield();
64  
    var lblDir = jlabel(" ");
65  
    var lblStatus = jlabel(" ");
66  
    var button = jThreadedButton("Create project", -> {
67  
      temp g22utils.enter();
68  
      
69  
      S name = trim(tf.getText());
70  
      File dir = newFile(g22utils.databasesMotherDir(), name);
71  
      createEmptyConceptsFileInDir(dir);
72  
      disposeFrame(tf);
73  
      
74  
      masterStuff().openDatabase(dir);
75  
    });
76  
    disableButton(button);
77  
    onEnter(tf, button);
78  
    
79  
    onChange(tf, r {
80  
      S name = trim(tf.getText());
81  
      bool ok;
82  
      S status = " ", path = " ";
83  
      if (isValidFileName(name)) {
84  
        File dir = newFile(g22utils.databasesMotherDir(), name);
85  
        path = f2s(dir);
86  
        if (dirExists(dir))
87  
          status = "A project with that name exists";
88  
        else
89  
          ok = true;
90  
      } else if (!empty(name))
91  
        status = "Project name must be a valid file name";
92  
      setEnabled(button, ok);
93  
      setText(lblStatus, status);
94  
      setText(lblDir, path);
95  
    });
96  
    
97  
    showForm_makeFrame("New Gazelle Project",
98  
      vstackWithSpacing(
99  
        withLabel("Name for new project", tf),
100  
        lblDir,
101  
        lblStatus,
102  
        button);
103  
  }
104  
105  
  void _updateTable { table.setData_force(g22utils.gazelleDBs()); }
106  
  
107  
  void browse { desktopOpen(table.selected().dir); }
108  
  void openDB { masterStuff().openDatabase(table.selected().dir); }
109  
  void openDBHidden { masterStuff().openDatabase(table.selected().dir, true); }
110  
  void switchToDB { masterStuff().switchToDatabase(table.selected().dir); }
111  
  void closeDB { masterStuff().closeDatabase(table.selected().dir); }
112  
  
113  
  void deleteDB {
114  
    var db = table.selected();
115  
    if (db == null) ret;
116  
    
117  
    var dir = db.dir();
118  
    if (g22utils.isConceptsDir(dir))
119  
      ret with messageBox("Can't delete current project");
120  
      
121  
    // First, close the databse
122  
    masterStuff().closeDatabase(dir);
123  
    new DeleteFilesDialog("Delete Gazelle project " + db.name())
124  
      .wholeDirectory(dir).show();
125  
  }
126  
  
127  
  void exportAsZip {
128  
    // Get project directory to export
129  
    File projectDir = table.selected().dir;
130  
    
131  
    // Make up a zip name + place and let user decide where to actually put it
132  
    
133  
    new JFileChooser fileChooser;
134  
    fileChooser.setDialogTitle("Export project as zip");
135  
    fileChooser.setSelectedFile(javaxBackupDir(projectDir.getName() + "-" + ymdMinusHMS() + ".zip"));
136  
    var cbSubdirs = jcheckbox("Include subdirectories", true);
137  
    fileChooser.setAccessory(withLeftMargin(cbSubdirs));
138  
139  
    // Show dialog    
140  
    if (fileChooser.showSaveDialog(visualize()) != JFileChooser.APPROVE_OPTION) ret;
141  
    
142  
    // User has confirmed, proceed with export
143  
    File zip = fileChooser.getSelectedFile();
144  
    S prefix = projectDir.getName() + "/";
145  
    if (isChecked(cbSubdirs))
146  
      dir2zip_recurse(projectDir, zip, prefix);
147  
    else
148  
      dir2zip(projectDir, zip, prefix);
149  
    
150  
    // Show note
151  
    fileSavedInfoBox(zip);
152  
    
153  
    // Try to open in file manager
154  
    desktopOpen(dirOfFile(zip));
155  
  }
156  
  
157  
  void importZip { pcall-messagebox {
158  
    new JFileChooser fc;
159  
    fc.setDialogTitle("Import project from zip");
160  
    fc.setCurrentDirectory(javaxBackupDir());
161  
    if (fc.showOpenDialog(visualize()) == JFileChooser.APPROVE_OPTION) {
162  
      File zip = fc.getSelectedFile();
163  
      g22utils.importProjectFromZip(zip);
164  
    }
165  
  }}
166  
  
167  
  void downloadProject {
168  
    if (gazAICredentialsFromJavaXSecret() == null)
169  
      ret with messageBox("Please enter Gaz.AI credentials first");
170  
      
171  
    inputText("Project to download", projectName -> { pcall-messagebox {
172  
      var zip = g22utils.downloadProjectFromGazAI(gazAICredentialsFromJavaXSecret(), projectName);
173  
      if (swingConfirm("Install downloaded project?"))
174  
        g22utils.importProjectFromZip(zip);
175  
    }});
176  
  }
177  
  
178  
  void renameDB {
179  
    File dir = table.selected().dir;
180  
    
181  
    inputText("New name", fileName(dir), newName -> {
182  
      assertValidFileName(newName);
183  
      if (!eq(newName, fileName(dir))) {
184  
        bool open = masterStuff().isConceptDirLoaded(dir);
185  
        if (open)
186  
          masterStuff().closeDatabase(dir);
187  
        renameFileVerbose(dir, newName);
188  
        if (open)
189  
          masterStuff().openDatabase(dir);
190  
      }
191  
    });
192  
  }
193  
}

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: 566 / 1183
Version history: 92 change(s)
Referenced in: [show references]