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.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import javax.swing.JButton;
24 import javax.swing.JPanel;
25 import javax.swing.SwingWorker;
26 import javax.swing.tree.TreePath;
27
28 import p3j.database.DatabaseFactory;
29 import p3j.gui.P3J;
30 import p3j.gui.dialogs.execstatus.SimpleProgressDialog;
31 import p3j.gui.panels.PropertiesShowPanelFactory;
32 import p3j.gui.panels.projections.IProjectionTree;
33 import p3j.gui.panels.projections.ProjectionTreeNode;
34 import p3j.misc.IProgressObserver;
35 import p3j.misc.Misc;
36 import p3j.misc.gui.GUI;
37 import p3j.pppm.ProjectionModel;
38
39
40
41
42
43
44
45
46
47 public class OverviewProjectionNode extends ProjectionTreeNode<ProjectionModel> {
48
49
50 private static final long serialVersionUID = -7668884101075657298L;
51
52
53
54
55
56
57
58
59
60 public OverviewProjectionNode(ProjectionModel projectionModel, String name) {
61 super(projectionModel, name);
62 }
63
64 @Override
65 public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
66
67 JButton loadProjection = new JButton("<html><b>Load</b></html>");
68 loadProjection.addActionListener(new ActionListener() {
69 @Override
70 public void actionPerformed(ActionEvent e) {
71 P3J.getInstance().setCurrentProjection(getEntity());
72 }
73 });
74
75 JButton removeProjection = new JButton("Remove");
76 removeProjection.addActionListener(new ActionListener() {
77 @Override
78 public void actionPerformed(ActionEvent e) {
79 (new SwingWorker<Void, Void>() {
80 @Override
81 protected Void doInBackground() {
82 try {
83 if (GUI.printQuestion(P3J.getInstance(), "Are you sure?",
84 "Do you really want to delete the projection'"
85 + getEntity().getName() + "'? This cannot be undone!")) {
86 IProgressObserver progress = SimpleProgressDialog.showDialog(
87 P3J.getInstance(), "Deleting projection and its results",
88 "", 2, true);
89 DatabaseFactory.getDatabaseSingleton().deleteProjection(
90 getEntity(), progress);
91 progress.incrementProgress("Updating user interface...");
92 P3J.getInstance().projectionDeleted(getEntity());
93 progress.taskFinished();
94 }
95 } catch (Exception ex) {
96 GUI.printErrorMessage("Projection Deletion Failed", ex);
97 }
98 return null;
99 }
100 }).execute();
101 }
102 });
103
104 List<JButton> buttons = new ArrayList<JButton>();
105 buttons.add(removeProjection);
106 buttons.add(loadProjection);
107
108 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(buttons, 1);
109 pspf.sep("General Information");
110 pspf.app(Misc.GUI_LABEL_NAME, getEntity().getName());
111 pspf.app(Misc.GUI_LABEL_DESCRIPTION, getEntity().getDescription());
112 pspf.app(Misc.GUI_LABEL_JUMP_OFF_YEAR,
113 Integer.toString(getEntity().getJumpOffYear()));
114 pspf.app("Settypes:", getEntity().getAllSetTypes().size());
115 pspf.app("Descendant Generations:", getEntity().getGenerations() - 1);
116 pspf.app("Years to be predicted:", getEntity().getYears());
117 pspf.app("Number of age classes:", getEntity().getNumberOfAgeClasses());
118 return pspf.constructPanel();
119 }
120
121 }