1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels.results;
17
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import javax.swing.JButton;
25 import javax.swing.JFileChooser;
26 import javax.swing.JPanel;
27 import javax.swing.tree.TreePath;
28
29 import p3j.database.DatabaseFactory;
30 import p3j.experiment.results.ResultExport;
31 import p3j.experiment.results.ResultsOfTrial;
32 import p3j.gui.P3J;
33 import p3j.gui.dialogs.ConfigureResultFilterDialog;
34 import p3j.gui.misc.SubNodeSummary;
35 import p3j.gui.panels.PropertiesShowPanelFactory;
36 import p3j.gui.panels.projections.IProjectionTree;
37 import p3j.gui.panels.projections.ProjectionTreeNode;
38 import p3j.misc.gui.GUI;
39 import p3j.pppm.ProjectionModel;
40
41
42
43
44
45
46
47
48 public class ResultTreeRoot extends ProjectionTreeNode<ProjectionModel> {
49
50
51 private static final int PANEL_KEY_WIDTH = 50;
52
53
54 private static final long serialVersionUID = -425870180408032392L;
55
56
57
58
59
60
61
62 public ResultTreeRoot(ProjectionModel projectionModel) {
63 super(projectionModel, "Overall Results");
64 }
65
66 @Override
67 public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
68
69 JButton generateReport = new JButton("<html><b>Generate Report</b></html>");
70 generateReport.addActionListener(new ActionListener() {
71 @Override
72 public void actionPerformed(ActionEvent e) {
73 JFileChooser fileChooser = GUI
74 .getDirectoryChooser("Determine in which directory to store the report");
75 if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
76 ResultExport resultExport = configureResultExport(getEntity(),
77 fileChooser.getSelectedFile());
78 if (resultExport == null) {
79 return;
80 }
81 try {
82 resultExport.createResultReport();
83 } catch (Exception ex) {
84 GUI.printErrorMessage("Report Generation Failed", ex);
85 }
86 }
87 }
88 });
89
90 JButton exportAggregatedData = new JButton("Aggregate");
91 exportAggregatedData.addActionListener(new ActionListener() {
92 @Override
93 public void actionPerformed(ActionEvent e) {
94 JFileChooser fileChooser = GUI
95 .getDirectoryChooser("Select directory for aggregated data");
96 if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
97 ResultExport resultExport = configureResultExport(getEntity(),
98 fileChooser.getSelectedFile());
99
100 if (resultExport == null) {
101 return;
102 }
103 try {
104 resultExport.exportAggregatedResults();
105 } catch (Exception ex) {
106 GUI.printErrorMessage("Aggregated Data Export Failed", ex);
107 }
108 }
109 }
110 });
111
112 JButton exportData = new JButton("Export");
113 exportData.addActionListener(new ActionListener() {
114 @Override
115 public void actionPerformed(ActionEvent e) {
116 JFileChooser fileChooser = GUI
117 .getDirectoryChooser("Select directory for export");
118 if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
119 ResultExport resultExport = configureResultExport(getEntity(),
120 fileChooser.getSelectedFile());
121 if (resultExport == null) {
122 return;
123 }
124 try {
125 resultExport.exportAllResults();
126 } catch (Exception ex) {
127 GUI.printErrorMessage("Data Export Failed", ex);
128 }
129 }
130 }
131 });
132
133 JButton clearResults = new JButton("Clear Results");
134 clearResults.addActionListener(new ActionListener() {
135 @Override
136 public void actionPerformed(ActionEvent e) {
137 if (GUI.printQuestion(P3J.getInstance(), "Really delete all results?",
138 "Approving this will delete ALL results associated with this projection.")) {
139 try {
140 DatabaseFactory.getDatabaseSingleton()
141 .deleteAllResults(getEntity());
142 } catch (Exception ex) {
143 GUI.printErrorMessage("Result Deletion Failed", ex);
144 }
145 }
146 P3J.getInstance().refreshNavigationTree();
147 }
148 });
149
150 List<JButton> buttons = new ArrayList<JButton>();
151 buttons.add(clearResults);
152 buttons.add(exportData);
153 buttons.add(exportAggregatedData);
154 buttons.add(generateReport);
155
156 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(
157 PANEL_KEY_WIDTH, buttons, 0);
158 pspf.sep("General Information");
159 pspf.app("Projection:", getEntity().getName());
160 pspf.app("#Trials:", getChildCount());
161 pspf.appPreview(new SubNodeSummary<ResultsOfTrial>(this, projTree,
162 ResultsOfTrial.class));
163 return pspf.constructPanel();
164 }
165
166
167
168
169
170
171
172
173
174
175
176 protected ResultExport configureResultExport(ProjectionModel projection,
177 File targetDir) {
178 ConfigureResultFilterDialog resultFilterDialog = new ConfigureResultFilterDialog(
179 null, getEntity());
180 resultFilterDialog.setVisible(true);
181 return resultFilterDialog.isCancelled() ? null : new ResultExport(
182 projection, targetDir, resultFilterDialog.getConfiguredResultFilter());
183 }
184
185 @Override
186 public void deselected() {
187 }
188
189 }