1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels.dboverview;
17
18 import java.awt.BorderLayout;
19 import java.util.List;
20 import java.util.logging.Level;
21
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTree;
25 import javax.swing.event.TreeSelectionEvent;
26 import javax.swing.event.TreeSelectionListener;
27 import javax.swing.tree.DefaultTreeModel;
28 import javax.swing.tree.TreePath;
29
30 import org.jamesii.SimSystem;
31
32 import p3j.database.DatabaseFactory;
33 import p3j.database.IP3MDatabase;
34 import p3j.gui.panels.AbstractNavigationPanel;
35 import p3j.gui.panels.projections.ProjectionTreeNode;
36 import p3j.pppm.ProjectionModel;
37
38
39
40
41
42
43
44
45 public class DatabaseOverviewPanel extends AbstractNavigationPanel {
46
47
48 private static final long serialVersionUID = 7431882091363418297L;
49
50
51 private DatabaseNode root;
52
53
54 private IP3MDatabase db;
55
56
57
58
59
60
61
62 public DatabaseOverviewPanel(JPanel contentP) {
63 super(null, contentP);
64 db = DatabaseFactory.getDatabaseSingleton();
65 initTree();
66 setLayout(new BorderLayout());
67 add(getScrollPane(), BorderLayout.CENTER);
68 }
69
70 @Override
71 protected final void initTree() {
72
73
74 if (root != null) {
75 return;
76 }
77
78 root = new DatabaseNode(DatabaseFactory.getDbConnData(), DatabaseFactory
79 .getDbConnData().getURL());
80 setTreeModel(new DefaultTreeModel(root));
81 setTree(new JTree(getTreeModel()));
82 getTree().setRootVisible(true);
83 setScrollPane(new JScrollPane(getTree()));
84
85 totalRefresh();
86
87 getTree().addTreeSelectionListener(new TreeSelectionListener() {
88 @Override
89 public void valueChanged(TreeSelectionEvent e) {
90 TreePath oldPath = e.getOldLeadSelectionPath();
91 if (oldPath != null) {
92 ((ProjectionTreeNode<?>) oldPath.getLastPathComponent()).deselected();
93 }
94 getContentPanel().removeAll();
95 TreePath newPath = e.getNewLeadSelectionPath();
96 if (newPath != null) {
97 ((ProjectionTreeNode<?>) newPath.getLastPathComponent()).selected(
98 newPath, getContentPanel(), null);
99 }
100 getContentPanel().repaint();
101 getContentPanel().updateUI();
102 }
103 });
104 }
105
106
107
108
109 public final void totalRefresh() {
110 for (ProjectionTreeNode<?> child : root.getChilds()) {
111 getTreeModel().removeNodeFromParent(child);
112 }
113
114 List<ProjectionModel> projections = null;
115
116 try {
117 projections = db.getAllProjections();
118 } catch (Exception ex) {
119 SimSystem.report(Level.SEVERE,
120 "Could not read projections list from data base.", ex);
121 projections = null;
122 }
123
124 if (projections == null) {
125 return;
126 }
127
128 for (ProjectionModel projection : projections) {
129 root.add(new OverviewProjectionNode(projection, projection.getName()));
130 }
131
132 getTreeModel().nodeStructureChanged(root);
133 getTree().repaint();
134 }
135
136 }