1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package p3j.gui.panels.projections;
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.JTextArea;
26 import javax.swing.JTextField;
27 import javax.swing.tree.TreePath;
28
29 import p3j.database.DatabaseFactory;
30 import p3j.gui.P3J;
31 import p3j.gui.misc.SubNodeSummary;
32 import p3j.gui.panels.PropertiesShowPanelFactory;
33 import p3j.misc.Misc;
34 import p3j.misc.gui.GUI;
35 import p3j.pppm.ProjectionModel;
36 import p3j.pppm.parameters.ParameterInstance;
37 import p3j.pppm.sets.Set;
38 import p3j.pppm.sets.SetType;
39
40
41
42
43
44
45
46
47
48
49 public class SetNode extends ProjectionTreeNode<Set> {
50
51
52
53
54 private static final long serialVersionUID = -6441130209061752819L;
55
56
57
58
59
60
61
62 public SetNode(Set set) {
63 super(set, set.getName());
64 }
65
66 @Override
67 public JPanel selected(TreePath selectionPath, final IProjectionTree projTree) {
68
69
70
71 final ProjectionTreeNode<?> node = this;
72 final SetTypeNode stNode = (SetTypeNode) selectionPath.getParentPath()
73 .getLastPathComponent();
74 final JTextField name = new JTextField(getEntity().getName());
75 final JTextArea description = new JTextArea(getEntity().getDescription());
76 final JTextField probability = new JTextField(getEntity().getProbability()
77 + "");
78
79 JButton removeButton = new JButton("Remove");
80 removeButton.addActionListener(new ActionListener() {
81 @Override
82 public void actionPerformed(ActionEvent e) {
83 if (!GUI.printQuestion(P3J.getInstance(), "Really remove set?",
84 "Do you really want to remove the set '" + getEntity().getName()
85 + "'? All associated data will be lost!")) {
86 return;
87 }
88 SetType sType = stNode.getEntity();
89 sType.removeSet(getEntity());
90 DatabaseFactory.getDatabaseSingleton().saveSetType(sType);
91 projTree.removeNode(node);
92 }
93 });
94
95 JButton applyButton = new JButton("Apply");
96 applyButton.addActionListener(new ActionListener() {
97 @Override
98 public void actionPerformed(ActionEvent e) {
99 Set set = getEntity();
100 set.setName(name.getText());
101 set.setDescription(description.getText());
102 set.setProbability(Double.parseDouble(probability.getText()));
103 setUserObject(set.getName());
104 DatabaseFactory.getDatabaseSingleton().saveSet(set);
105 projTree.refreshNode(node);
106 }
107 });
108
109 List<JButton> buttons = new ArrayList<JButton>();
110 buttons.add(removeButton);
111 buttons.add(applyButton);
112
113 PropertiesShowPanelFactory pspf = new PropertiesShowPanelFactory(buttons, 1);
114 pspf.sep("General Information");
115 pspf.app(Misc.GUI_LABEL_NAME, name);
116 pspf.app(Misc.GUI_LABEL_DESCRIPTION, description, 2);
117 pspf.app(Misc.GUI_LABEL_PROBABILITY, probability);
118
119
120
121 SetType mySetType = getProjectionEntity(SetType.class);
122 ProjectionModel projection = getProjectionEntity(ProjectionModel.class);
123 boolean isDefault = (mySetType != null && projection != null && mySetType == projection
124 .getDefaultSetType());
125 probability.setEditable(!isDefault);
126 removeButton.setEnabled(!isDefault);
127 pspf.app("Default set?", isDefault ? "Yes" : "No");
128 pspf.appPreview(new SubNodeSummary<ParameterInstance>(this, projTree,
129 ParameterInstance.class));
130
131 return pspf.constructPanel();
132 }
133 }