1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels.dboverview;
17
18 import james.SimSystem;
19
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import javax.swing.JButton;
26 import javax.swing.JPanel;
27 import javax.swing.tree.TreePath;
28
29 import p3j.database.DatabaseFactory;
30 import p3j.gui.P3J;
31 import p3j.gui.panels.PropertiesShowPanelFactory;
32 import p3j.gui.panels.projections.IProjectionTree;
33 import p3j.gui.panels.projections.ProjectionTreeNode;
34 import p3j.misc.Misc;
35 import p3j.misc.gui.GUI;
36 import p3j.pppm.ProjectionModel;
37
38
39
40
41
42
43
44
45
46 public class OverviewProjectionNode extends ProjectionTreeNode<ProjectionModel> {
47
48
49 private static final long serialVersionUID = -7668884101075657298L;
50
51
52
53
54
55
56
57
58
59 public OverviewProjectionNode(ProjectionModel projectionModel, String name) {
60 super(projectionModel, name);
61 }
62
63 @Override
64 public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
65
66 JButton loadProjection = new JButton("<html><b>Load</b></html>");
67 loadProjection.addActionListener(new ActionListener() {
68 @Override
69 public void actionPerformed(ActionEvent e) {
70 P3J.getInstance().setCurrentProjection(getEntity());
71 }
72 });
73
74 JButton removeProjection = new JButton("Remove");
75 removeProjection.addActionListener(new ActionListener() {
76 @Override
77 public void actionPerformed(ActionEvent e) {
78 try {
79 if (GUI.printQuestion(P3J.getInstance(), "Are you sure?",
80 "Do you really want to delete the projection'"
81 + getEntity().getName() + "'? This cannot be undone!")) {
82 DatabaseFactory.getDatabaseSingleton()
83 .deleteProjection(getEntity());
84 P3J.getInstance().projectionDeleted(getEntity());
85 }
86 } catch (Exception ex) {
87 SimSystem.report(ex);
88 }
89 }
90 });
91
92 List<JButton> buttons = new ArrayList<JButton>();
93 buttons.add(removeProjection);
94 buttons.add(loadProjection);
95
96 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(buttons, 1);
97 pspf.sep("General Information");
98 pspf.app(Misc.GUI_LABEL_NAME, getEntity().getName());
99 pspf.app(Misc.GUI_LABEL_DESCRIPTION, getEntity().getDescription());
100 pspf.app(Misc.GUI_LABEL_JUMP_OFF_YEAR,
101 Integer.toString(getEntity().getJumpOffYear()));
102 pspf.app("Settypes:", getEntity().getAllSetTypes().size());
103 pspf.app("Descendant Generations:", getEntity().getGenerations() - 1);
104 pspf.app("Years to be predicted:", getEntity().getYears());
105 pspf.app("Number of age classes:", getEntity().getNumberOfAgeClasses());
106 return pspf.constructPanel();
107 }
108
109 }