source: java/main/src/main/java/com/framsticks/gui/InstanceAtFrame.java @ 88

Last change on this file since 88 was 88, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • loading f0 schema with XmlLoader?
  • use XmlLoader? to load configuration
  • introduce unified fork-join model of various entities

(Instances, Connections, GUI Frames, etc.),
all those entities clean up gracefully on
shutdown, which may be initialized by user
or by some entity

  • basing on above, simplify several organizing classes

(Observer, main class)

(to host native frams server process from Java level)

CHANGELOG:
Remove redundant Observer class.

Clean up in AbstractJoinable?.

Update ExternalProcess? class to changes in joining model.

Another sweep through code with FindBugs?.

Find bug with not joining RemoteInstance?.

Joining almost works.

Much improved joining model.

More improvement to joining model.

Add logging messages around joinable operations.

Rename methods in AbstractJoinable?.

Improve Joinable.

Rewrite of entity structure.

More simplifications with entities.

Further improve joinables.

Let Frame compose from JFrame instead of inheriting.

Add join classes.

Improvements of closing.

Add Builder interface.

Add FramsServerTest?.xml

FramsServer? may be configured through xml.

Make Framsticks main class an Observer of Entities.

Make Observer a generic type.

Remove variables regarding to removed endpoint.

Simplify observer (remove endpoints).

More changes to Observer and Endpoint.

Minor improvements.

Add OutputListener? to ExternalProcess?.

Improve testing of ExternalProcess?.

Add ExternalProcess? runner.

Rename the Program class to Framsticks.

Migrate Program to use XmlLoader? configuration.

First steps with configuration using XmlLoader?.

Fix several bugs.

Move all f0 classes to apriopriate package.

XmlLoader? is able to load Schema.

XmlLoader? is loading classes and props.

Add GroupBuilder?.

File size: 4.3 KB
Line 
1package com.framsticks.gui;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.core.Instance;
6import com.framsticks.core.InstanceListener;
7import com.framsticks.core.ListChange;
8import com.framsticks.core.Node;
9import com.framsticks.core.Path;
10import com.framsticks.params.CompositeParam;
11import com.framsticks.params.FramsClass;
12
13import java.util.*;
14
15import javax.swing.tree.TreePath;
16import com.framsticks.util.dispatching.RunAt;
17
18/**
19 * @author Piotr Sniegowski
20 */
21public class InstanceAtFrame implements InstanceListener {
22
23        private static final Logger log = Logger.getLogger(InstanceAtFrame.class);
24
25        protected final Frame frame;
26        protected final Instance instance;
27        protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>();
28        protected TreeNode rootTreeNode;
29
30        public InstanceAtFrame(Instance instance, Frame frame) {
31                this.frame = frame;
32                this.instance = instance;
33        }
34
35        public Frame getFrame() {
36                return frame;
37        }
38
39        /**
40         * @return the instance
41         */
42        public Instance getInstance() {
43                return instance;
44        }
45
46        public void registerPanel(Panel panel) {
47        }
48
49        public Panel findPanel(String accessId) {
50                assert frame.isActive();
51                return (knownPanels.containsKey(accessId) ? knownPanels.get(accessId) : null);
52        }
53
54        public final String getName() {
55                return instance.getName();
56        }
57
58        public Panel preparePanel(CompositeParam param, FramsClass framsClass) {
59                assert frame.isActive();
60                Panel panel = preparePanelImpl(param, framsClass);
61                assert panel != null;
62                String accessId = param.computeAccessId();
63                panel.uniqueName = accessId + "@" + instance.getName();
64                knownPanels.put(accessId, panel);
65                frame.cardPanel.add(panel, panel.uniqueName);
66                log.debug("prepared panel for " + panel);
67                return panel;
68        }
69
70        protected Panel preparePanelImpl(CompositeParam param, FramsClass framsClass) {
71                assert frame.isActive();
72                List<Panel> panels = new ArrayList<Panel>();
73
74                Panel.Parameters parameters = new Panel.Parameters(this, param,
75                                framsClass);
76                for (PanelProvider pp : frame.browser.panelProviders) {
77                        Panel p = pp.providePanel(parameters);
78                        if (p != null) {
79                                panels.add(p);
80                        }
81                }
82
83                if (panels.isEmpty()) {
84                        return new EmptyPanel(parameters);
85                }
86                if (panels.size() == 1) {
87                        return panels.get(0);
88                }
89                return new MultiPanel(parameters, panels);
90
91        }
92
93        @Override
94        public void onListChange(Path path, ListChange change) {
95
96        }
97
98        public TreePath getTreePath(Path path, boolean create) {
99                assert frame.isActive();
100                TreeNode t = rootTreeNode;
101                TreePath result = new TreePath(frame.rootNode).pathByAddingChild(rootTreeNode);
102                List<Node> nodes = path.getNodes();
103                Iterator<Node> i = nodes.iterator();
104                i.next();
105                // Node first = i.next();
106
107                // if (!t.path.isResolved()) {
108                //      t.path = new Path(path.getInstance(), nodes, first);
109                // }
110                while (i.hasNext()) {
111                        Node n = i.next();
112                        TreeNode r = null;
113                        for (TreeNode c : t.childrenIterable()) {
114                                if (c.paramId.equals(n.getParam().getId())) {
115                                        r = c;
116                                        break;
117                                }
118                        }
119                        if (r == null) {
120                                log.debug("missing " + n.getParam().getId() + " in " + t);
121                                if (!create) {
122                                        return result;
123                                }
124                                Path p = Path.build().instance(path.getInstance()).buildUpTo(nodes, n).finish();
125
126
127                                log.debug("forced resolution: creating treenode for " + p);
128                                TreeNode childNode = new TreeNode(InstanceAtFrame.this, p);
129
130                                frame.addNode(childNode, t);
131                                // frame.treeModel.reload();
132                                // t.add(childNode);
133                                // frame.treeModel.nodeStructureChanged(t);
134
135                                r = childNode;
136                        } else {
137                                // if (!r.path.isResolved()) {
138                                //      r.path = new Path(path.getInstance(), nodes, n);
139                                // }
140                        }
141                        result = result.pathByAddingChild(r);
142                        t = r;
143                }
144                return result;
145        }
146
147        @Override
148        public void onFetch(final Path path) {
149                assert instance.isActive();
150                log.trace("fetched " + path);
151
152                frame.invokeLater(new RunAt<Frame>() {
153                        @Override
154                        public void run() {
155
156                                TreePath treePath = getTreePath(path, true);
157                                assert treePath.getPathCount() == path.size() + 1;
158
159                                final TreeNode result = (TreeNode) treePath.getLastPathComponent();
160                                // log.trace("found " + result + " == " + path);
161                                instance.invokeLater(new RunAt<Instance>() {
162                                        @Override
163                                        public void run() {
164                                                result.reactForFetchResult(path, null);
165                                        }
166                                });
167                        }
168                });
169        }
170
171        @Override
172        public void onRun(Exception e) {
173
174        }
175
176        @Override
177        public void onStop(Exception e) {
178
179        }
180}
Note: See TracBrowser for help on using the repository browser.