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.misc.gui.GUI;
36  import p3j.pppm.ProjectionModel;
37  
38  /**
39   * This node delivers an overview of a projections and options to remove or load
40   * it.
41   * 
42   * @author Christina Bohk
43   * @author Roland Ewald
44   * 
45   */
46  public class OverviewProjectionNode extends ProjectionTreeNode<ProjectionModel> {
47  
48    /** Serialization ID. */
49    private static final long serialVersionUID = -7668884101075657298L;
50  
51    /**
52     * Instantiates a new overview projection node.
53     * 
54     * @param projectionModel
55     *          the projection model
56     * @param name
57     *          the name of the node
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 }