-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDBConnDerby.java
More file actions
113 lines (99 loc) · 4.69 KB
/
DBConnDerby.java
File metadata and controls
113 lines (99 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************************
* PathVisio, a tool for data visualization and analysis using biological pathways
* Copyright 2006-2022 BiGCaT Bioinformatics, WikiPathways
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package org.pathvisio.desktop.data;
import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.bridgedb.gui.SimpleFileFilter;
import org.bridgedb.rdb.construct.DataDerby;
import org.pathvisio.core.preferences.GlobalPreference;
import org.pathvisio.core.preferences.PreferenceManager;
import org.pathvisio.core.util.DiskSpaceValidator;
/**
* user interface functions for single-file Derby databases.
*/
public class DBConnDerby extends DataDerby implements DBConnectorSwing {
static final String DB_EXT_NAME_GEX = "Expression datasets";
static final String DB_EXT_NAME_GDB = "Synonym databases";
// TODO: reduce redundancy between openChooseDbDialog and openNewDbDialog,
public String openChooseDbDialog(Component parent) {
JFileChooser jfc = new JFileChooser();
jfc.setDialogType(JFileChooser.OPEN_DIALOG);
if (getDbType() == TYPE_GDB) {
jfc.setCurrentDirectory(PreferenceManager.getCurrent().getFile(GlobalPreference.DIR_LAST_USED_PGDB));
jfc.addChoosableFileFilter(new SimpleFileFilter(DB_EXT_NAME_GDB, "*.bridge|*.pgdb", true));
} else {
jfc.setCurrentDirectory(PreferenceManager.getCurrent().getFile(GlobalPreference.DIR_LAST_USED_PGEX));
jfc.addChoosableFileFilter(new SimpleFileFilter(DB_EXT_NAME_GEX, "*." + DB_FILE_EXT_GEX, true));
}
int status = jfc.showDialog(parent, "Open database");
if (status == JFileChooser.APPROVE_OPTION) {
if (getDbType() == TYPE_GDB) {
PreferenceManager.getCurrent().setFile(GlobalPreference.DIR_LAST_USED_PGDB, jfc.getCurrentDirectory());
} else {
PreferenceManager.getCurrent().setFile(GlobalPreference.DIR_LAST_USED_PGEX, jfc.getCurrentDirectory());
}
return jfc.getSelectedFile().toString();
}
return null;
}
public String openNewDbDialog(Component parent, String defaultName) {
JFileChooser jfc = new JFileChooser();
jfc.setDialogType(JFileChooser.SAVE_DIALOG);
if (getDbType() == TYPE_GDB) {
jfc.setCurrentDirectory(PreferenceManager.getCurrent().getFile(GlobalPreference.DIR_LAST_USED_PGDB));
jfc.addChoosableFileFilter(new SimpleFileFilter(DB_EXT_NAME_GDB, "*." + DB_FILE_EXT_GDB, true));
} else {
jfc.setCurrentDirectory(PreferenceManager.getCurrent().getFile(GlobalPreference.DIR_LAST_USED_PGEX));
jfc.addChoosableFileFilter(new SimpleFileFilter(DB_EXT_NAME_GEX, "*." + DB_FILE_EXT_GEX, true));
}
int status = jfc.showDialog(parent, "Choose filename for database");
if (status == JFileChooser.APPROVE_OPTION) {
File file = jfc.getSelectedFile();
// Issue #13: Check for disk space in pgex files before creating new database
// files
// Using conservative size estimates. TO DO: calculate from actual data by
// creating a getSourceDataSize() method
long requiredSize;
if (getDbType() == TYPE_GDB) {
requiredSize = 100L * 1024 * 1024; // default values before change is made
} else {
requiredSize = 50L * 1024 * 1024; // default values before change is made
}
if (!DiskSpaceValidator.hasEnoughSpace(file, requiredSize)) {
String dbType = (getDbType() == TYPE_GDB) ? "synonym database" : "expression dataset";
String spaceInfo = DiskSpaceValidator.getReadableSpaceInfo(file);
JOptionPane.showMessageDialog(parent,
"Not enough free disk space to create the " + dbType + ".\n" +
"Required: approx. " + (requiredSize / (1024 * 1024)) + " MB (plus safety buffer)\n" +
spaceInfo + "\n\n" +
"Please choose a different location or free up some space.",
"Insufficient Disk Space",
JOptionPane.ERROR_MESSAGE);
return null;
}
if (getDbType() == TYPE_GDB) {
PreferenceManager.getCurrent().setFile(GlobalPreference.DIR_LAST_USED_PGDB, jfc.getCurrentDirectory());
} else {
PreferenceManager.getCurrent().setFile(GlobalPreference.DIR_LAST_USED_PGEX, jfc.getCurrentDirectory());
}
return file.toString();
}
return null;
}
}