/
MoleculeArchiveOpenDialog.java
79 lines (65 loc) · 2.85 KB
/
MoleculeArchiveOpenDialog.java
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
package de.mpg.biochem.mars.swingUI.MoleculeArchiveSelector;
import de.mpg.biochem.mars.io.MoleculeArchiveSource;
import de.mpg.biochem.mars.molecule.commands.ImportCloudArchiveCommand;
import org.scijava.Context;
import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
public class MoleculeArchiveOpenDialog extends AbstractMoleculeArchiveDialog {
public MoleculeArchiveOpenDialog(String url, Context context) {
super(url, context);
}
public MoleculeArchiveOpenDialog(Context context) {
super(context);
}
protected JFrame buildDialog() {
super.buildDialog();
dialog.setTitle("Open Molecule Archive");
recentURLs = prefService.getList(MoleculeArchiveOpenDialog.class, "recentOpenURLs");
recentList.setListData(recentURLs.toArray(new String[0]));
okBtn.setText("Open");
containerTree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
ok();
}
}
});
return dialog;
}
public void clearRecent() {
this.recentURLs = new ArrayList<>();
recentList.setListData(new String[0]);
recentList.repaint();
prefService.remove(MoleculeArchiveOpenDialog.class, "recentOpenURLs");
}
public void ok() {
String url;
// check if we can skip explicit dataset detection
if (containerTree.getSelectionCount() == 0) {
containerPathUpdateCallback.accept(getPath());
url = getPath();
} else {
// archive was selected by the user
String fullPath = ((MoleculeArchiveSwingTreeNode)containerTree.getLastSelectedPathComponent()).getPath();
if (fullPath.startsWith("//")) fullPath = fullPath.substring(1, fullPath.length());
if (fullPath.startsWith(getPath())) url = fullPath;
else {
String uri = (getPath().endsWith(source.getGroupSeparator())) ? getPath().substring(0, getPath().length()-1) : getPath();
if (uri.endsWith("." + MoleculeArchiveSource.MOLECULE_ARCHIVE_ENDING) || uri.endsWith("." + MoleculeArchiveSource.MOLECULE_ARCHIVE_STORE_ENDING))
url = uri;
else
url = uri + fullPath;
}
}
if (url.endsWith("." + MoleculeArchiveSource.MOLECULE_ARCHIVE_ENDING) || url.endsWith("." + MoleculeArchiveSource.MOLECULE_ARCHIVE_STORE_ENDING)) {
okCallback.accept(new MoleculeArchiveSelection(url));
if (recentURLs.contains(url))
recentURLs.remove(recentURLs.indexOf(url));
recentURLs.add(0, url);
prefService.put(MoleculeArchiveOpenDialog.class, "recentOpenURLs", recentURLs);
close();
}
}
}