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.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.pppm.ProjectionModel;
36  
37  /**
38   * This node delivers an overview of a projections and options to remove or load
39   * it.
40   * 
41   * @author Christina Bohk
42   * @author Roland Ewald
43   * 
44   */
45  public class OverviewProjectionNode extends ProjectionTreeNode<ProjectionModel> {
46  
47  	/** Serialization ID. */
48  	private static final long serialVersionUID = -7668884101075657298L;
49  
50  	/**
51  	 * Instantiates a new overview projection node.
52  	 * 
53  	 * @param projectionModel
54  	 *          the projection model
55  	 * @param name
56  	 *          the name of the node
57  	 */
58  	public OverviewProjectionNode(ProjectionModel projectionModel, String name) {
59  		super(projectionModel, name);
60  	}
61  
62  	@Override
63  	public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
64  
65  		JButton loadProjection = new JButton("<html><b>Load</b></html>");
66  		loadProjection.addActionListener(new ActionListener() {
67  			@Override
68  			public void actionPerformed(ActionEvent e) {
69  				P3J.getInstance().setCurrentProjection(getEntity());
70  			}
71  		});
72  
73  		JButton removeProjection = new JButton("Remove");
74  		removeProjection.addActionListener(new ActionListener() {
75  			@Override
76  			public void actionPerformed(ActionEvent e) {
77  				try {
78  					DatabaseFactory.getDatabaseSingleton().deleteProjection(getEntity());
79  					P3J.getInstance().projectionDeleted(getEntity());
80  				} catch (Exception ex) {
81  					SimSystem.report(ex);
82  				}
83  			}
84  		});
85  
86  		List<JButton> buttons = new ArrayList<JButton>();
87  		buttons.add(removeProjection);
88  		buttons.add(loadProjection);
89  
90  		PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(buttons, 1);
91  		pspf.sep("General Information");
92  		pspf.app(Misc.GUI_LABEL_NAME, getEntity().getName());
93  		pspf.app(Misc.GUI_LABEL_DESCRIPTION, getEntity().getDescription());
94  		pspf.app(Misc.GUI_LABEL_JUMP_OFF_YEAR,
95  		    Integer.toString(getEntity().getJumpOffYear()));
96  		pspf.app("Settypes:", getEntity().getAllSetTypes().size());
97  		pspf.app("Descendant Generations:", getEntity().getGenerations() - 1);
98  		pspf.app("Years to be predicted:", getEntity().getYears());
99  		pspf.app("Number of age classes:", getEntity().getNumberOfAgeClasses());
100 		return pspf.constructPanel();
101 	}
102 
103 }