source: java/main/src/main/java/com/framsticks/gui/TreePanel.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1package com.framsticks.gui;
2
3import static com.framsticks.structure.TreeOperations.*;
4
5import com.framsticks.gui.tree.AbstractNode;
6import com.framsticks.gui.tree.TreeNode;
7import com.framsticks.params.Access;
8import com.framsticks.params.CompositeParam;
9import com.framsticks.params.FramsClass;
10import com.framsticks.structure.Path;
11import com.framsticks.structure.Tree;
12import com.framsticks.util.lang.Casting;
13
14import org.apache.logging.log4j.Logger;
15import org.apache.logging.log4j.LogManager;
16
17@SuppressWarnings("serial")
18public 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}
Note: See TracBrowser for help on using the repository browser.