View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.gui.panels.results;
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.tree.TreePath;
26  
27  import p3j.database.DatabaseFactory;
28  import p3j.experiment.results.ResultsOfTrial;
29  import p3j.gui.P3J;
30  import p3j.gui.panels.PropertiesShowPanelFactory;
31  import p3j.gui.panels.projections.IProjectionTree;
32  import p3j.gui.panels.projections.ProjectionTreeNode;
33  import p3j.misc.gui.GUI;
34  
35  /**
36   * Represents a node for a single predicted trajectory.
37   * 
38   * @author Christina Bohk
39   * @author Roland Ewald
40   * 
41   */
42  public class ResultTreeNode extends ProjectionTreeNode<ResultsOfTrial> {
43  
44  	/**
45  	 * Instantiates a new result tree node.
46  	 * 
47  	 * @param trialResult
48  	 *          the trial result
49  	 * @param number
50  	 *          the number
51  	 */
52  	public ResultTreeNode(ResultsOfTrial trialResult, int number) {
53  		super(trialResult, "Trial #" + number);
54  	}
55  
56  	/** Serialization ID. */
57  	private static final long serialVersionUID = 6093408747499597813L;
58  
59  	@Override
60  	public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
61  		JButton generateReport = new JButton("<html><b>Generate Report</b></html>");
62  		generateReport.setEnabled(false);
63  		generateReport.addActionListener(new ActionListener() {
64  			@Override
65  			public void actionPerformed(ActionEvent e) {
66  				GUI.printMessage(P3J.getInstance(), "Feature not implemented yet",
67  				    "A trial-specific report generation is not implemented yet.");
68  			}
69  		});
70  
71  		JButton exportData = new JButton("Export Data");
72  		exportData.setEnabled(false);
73  		exportData.addActionListener(new ActionListener() {
74  			@Override
75  			public void actionPerformed(ActionEvent e) {
76  				// TODO: Add trial-specific data-export.
77  				GUI.printMessage(P3J.getInstance(), "Feature not implemented yet",
78  				    "A trial-specific data export is not implemented yet.");
79  			}
80  		});
81  
82  		JButton clearData = new JButton("Clear Result");
83  		clearData.addActionListener(new ActionListener() {
84  			@Override
85  			public void actionPerformed(ActionEvent e) {
86  				if (GUI.printQuestion(P3J.getInstance(), "Really delete this result?",
87  				    "Approving this will delete the results of this trial.")) {
88  					try {
89  						DatabaseFactory.getDatabaseSingleton().deleteResult(getEntity());
90  					} catch (Exception ex) {
91  						GUI.printErrorMessage("Result Deletion Failed", ex);
92  					}
93  				}
94  				P3J.getInstance().refreshNavigationTree();
95  			}
96  		});
97  
98  		List<JButton> buttons = new ArrayList<JButton>();
99  		buttons.add(clearData);
100 		buttons.add(exportData);
101 		buttons.add(generateReport);
102 
103 		PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(buttons, 1);
104 		pspf.sep("General Information");
105 		pspf.app("Name:", getEntityLabel());
106 		pspf.app("Assignment Probability:", this.getEntity()
107 		    .getAssignmentProbability());
108 		pspf.app("Set Combination Probability:", this.getEntity()
109 		    .getSetCombinationProbability());
110 		return pspf.constructPanel();
111 	}
112 
113 	@Override
114 	public void deselected() {
115 	}
116 
117 	@Override
118 	public String getEntityLabel() {
119 		return userObject.toString();
120 	}
121 
122 }