1 | package com.framsticks.gui; |
---|
2 | |
---|
3 | import static com.framsticks.structure.TreeOperations.*; |
---|
4 | |
---|
5 | import com.framsticks.gui.tree.AbstractNode; |
---|
6 | import com.framsticks.gui.tree.TreeNode; |
---|
7 | import com.framsticks.params.Access; |
---|
8 | import com.framsticks.params.CompositeParam; |
---|
9 | import com.framsticks.params.FramsClass; |
---|
10 | import com.framsticks.structure.Path; |
---|
11 | import com.framsticks.structure.Tree; |
---|
12 | import com.framsticks.util.lang.Casting; |
---|
13 | |
---|
14 | import org.apache.logging.log4j.Logger; |
---|
15 | import org.apache.logging.log4j.LogManager; |
---|
16 | |
---|
17 | @SuppressWarnings("serial") |
---|
18 | public abstract class TreePanel extends AbstractPanel { |
---|
19 | |
---|
20 | private static final Logger log = LogManager.getLogger(TreePanel.class); |
---|
21 | |
---|
22 | @Override |
---|
23 | public void fillPanelWith(AbstractNode node) { |
---|
24 | TreeNode treeNode = Casting.throwCast(TreeNode.class, node); |
---|
25 | |
---|
26 | Path path = Path.to(treeNode.getTree(), treeNode.getTextual()); |
---|
27 | if (!path.isResolved()) { |
---|
28 | log.error("path is not resolved: {}", path); |
---|
29 | return; |
---|
30 | } |
---|
31 | setCurrentPath(path); |
---|
32 | pullValuesFromLocalToUser(bindAccess(path)); |
---|
33 | } |
---|
34 | |
---|
35 | public static class Parameters { |
---|
36 | public final TreeAtFrame treeAtFrame; |
---|
37 | public final CompositeParam param; |
---|
38 | |
---|
39 | /** Contained type FramsClass. */ |
---|
40 | public final FramsClass framsClass; |
---|
41 | |
---|
42 | public Parameters(TreeAtFrame treeAtFrame, CompositeParam param, FramsClass framsClass) { |
---|
43 | this.treeAtFrame = treeAtFrame; |
---|
44 | this.param = param; |
---|
45 | this.framsClass = framsClass; |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | protected final TreeAtFrame treeAtFrame; |
---|
50 | protected final String className; |
---|
51 | protected final FramsClass framsClass; |
---|
52 | protected final CompositeParam param; |
---|
53 | protected Path currentPath; |
---|
54 | |
---|
55 | public TreePanel(Parameters parameters) { |
---|
56 | super(parameters.treeAtFrame.getFrame()); |
---|
57 | this.treeAtFrame = parameters.treeAtFrame; |
---|
58 | this.framsClass = parameters.framsClass; |
---|
59 | this.param = parameters.param; |
---|
60 | this.className = parameters.param.getContainedTypeName(); |
---|
61 | this.setName(parameters.param.getFramsTypeName()); |
---|
62 | log.debug("created panel: {}", this); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * @return the currentTreePath |
---|
67 | */ |
---|
68 | public Path getCurrentPath() { |
---|
69 | return currentPath; |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * @param currentTreePath the currentTreePath to set |
---|
74 | */ |
---|
75 | public void setCurrentPath(Path path) { |
---|
76 | path.assureResolved(); |
---|
77 | this.currentPath = path; |
---|
78 | } |
---|
79 | |
---|
80 | public final TreeAtFrame getTreeAtFrame() { |
---|
81 | return treeAtFrame; |
---|
82 | } |
---|
83 | public final Object getCurrentObject() { |
---|
84 | assert currentPath != null; |
---|
85 | return currentPath.getTopObject(); |
---|
86 | } |
---|
87 | public final Tree getTree() { |
---|
88 | assert currentPath != null; |
---|
89 | return currentPath.getTree(); |
---|
90 | } |
---|
91 | |
---|
92 | public final String getClassName() { |
---|
93 | return className; |
---|
94 | } |
---|
95 | |
---|
96 | public abstract void pullValuesFromLocalToUser(Access access); |
---|
97 | |
---|
98 | @Override |
---|
99 | public String toString() { |
---|
100 | return param.getFramsTypeName() + "(" + uniqueName + ")"; |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|