source: java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java @ 97

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

HIGHLIGHTS:

  • add proper exception passing between communication sides:

if exception occur during handling client request, it is
automatically passed as comment to error response.

it may be used to snoop communication between peers

  • fix algorithm choosing text controls in GUI
  • allow GUI testing in virtual frame buffer (xvfb)

FEST had some problem with xvfb but workaround was found

supports tab-completion based on requests history

CHANGELOG:
Further improve handling of exceptions in GUI.

Add StatusBar? implementing ExceptionResultHandler?.

Make completion processing asynchronous.

Minor changes.

Improve completion in console.

Improve history in InteractiveConsole?.

First working version of DirectConsole?.

Minor changes.

Make Connection.address non final.

It is more suitable to use in configuration.

Improvement of consoles.

Improve PopupMenu? and closing of FrameJoinable?.

Fix BrowserTest?.

Found bug with FEST running under xvfb.

JButtonFixture.click() is not working under xvfb.
GuiTest? has wrapper which uses JButton.doClick() directly.

Store CompositeParam? param in TreeNode?.

Simplify ClientSideManagedConnection? connecting.

There is now connectedFunctor needed, ApplicationRequests? can be
send right after creation. They are buffered until the version
and features are negotiated.

Narow down interface of ClientSideManagedConnection?.

Allow that connection specialization send only
ApplicationRequests?.

Improve policy of text control choosing.

Change name of Genotype in BrowserTest?.

Make BrowserTest? change name of Genotype.

Minor change.

First working draft of TrackConsole?.

Simplify Consoles.

More improvements with gui joinables.

Unify initialization on gui joinables.

More rework of Frame based entities.

Refactorize structure of JFrames based entities.

Extract GuiTest? from BrowserBaseTest?.

Reorganize Console classes structure.

Add Collection view to JoinableCollection?.

Configure timeout in testing.

Minor changes.

Rework connections hierarchy.

Add Mode to the get operation.

Make get and set in Tree take PrimitiveParam?.

Unify naming of operations.

Make RunAt? use the given ExceptionHandler?.

It wraps the virtual runAt() method call with
try-catch passing exception to handler.

Force RunAt? to include ExceptionHandler?.

Improve ClientAtServer?.

Minor change.

Another sweep with FindBugs?.

Rename Instance to Tree.

Minor changes.

Minor changes.

Further clarify semantics of Futures.

Add FutureHandler?.

FutureHandler? is refinement of Future, that proxifies
exception handling to ExceptionResultHandler? given
at construction time.

Remove StateFunctor? (use Future<Void> instead).

Make Connection use Future<Void>.

Unparametrize *ResponseFuture?.

Remove StateCallback? not needed anymore.

Distinguish between sides of ResponseFuture?.

Base ResponseCallback? on Future (now ResponseFuture?).

Make asynchronous store taking Future for flags.

Implement storeValue in ObjectInstance?.

File size: 4.2 KB
Line 
1package com.framsticks.gui;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.core.Tree;
6import com.framsticks.core.TreeListener;
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 TreeAtFrame implements TreeListener {
22
23        private static final Logger log = Logger.getLogger(TreeAtFrame.class);
24
25        protected final Frame frame;
26        protected final Tree tree;
27        protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>();
28        protected TreeNode rootTreeNode;
29
30        public TreeAtFrame(Tree tree, Frame frame) {
31                this.frame = frame;
32                this.tree = tree;
33        }
34
35        public Frame getFrame() {
36                return frame;
37        }
38
39        /**
40         * @return the tree
41         */
42        public Tree getTree() {
43                return tree;
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 tree.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 + "@" + tree.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, framsClass);
75                for (PanelProvider pp : frame.browser.panelProviders) {
76                        Panel p = pp.providePanel(parameters);
77                        if (p != null) {
78                                panels.add(p);
79                        }
80                }
81
82                if (panels.isEmpty()) {
83                        return new EmptyPanel(parameters);
84                }
85                if (panels.size() == 1) {
86                        return panels.get(0);
87                }
88                return new MultiPanel(parameters, panels);
89
90        }
91
92        @Override
93        public void onListChange(Path path, ListChange change) {
94
95        }
96
97        public TreePath getTreePath(Path path, boolean create) {
98                assert frame.isActive();
99                TreeNode t = rootTreeNode;
100                TreePath result = new TreePath(frame.rootNode).pathByAddingChild(rootTreeNode);
101                List<Node> nodes = path.getNodes();
102                Iterator<Node> i = nodes.iterator();
103                i.next();
104                // Node first = i.next();
105
106                // if (!t.path.isResolved()) {
107                //      t.path = new Path(path.getInstance(), nodes, first);
108                // }
109                while (i.hasNext()) {
110                        Node n = i.next();
111                        TreeNode r = null;
112                        for (TreeNode c : t.childrenIterable()) {
113                                if (c.param.getId().equals(n.getParam().getId())) {
114                                        r = c;
115                                        break;
116                                }
117                        }
118                        if (r == null) {
119                                log.debug("missing " + n.getParam().getId() + " in " + t);
120                                if (!create) {
121                                        return result;
122                                }
123                                Path p = Path.build().tree(path.getTree()).buildUpTo(nodes, n).finish();
124
125
126                                log.debug("forced resolution: creating treenode for " + p);
127                                TreeNode childNode = new TreeNode(TreeAtFrame.this, p);
128
129                                frame.addNode(childNode, t);
130                                // frame.treeModel.reload();
131                                // t.add(childNode);
132                                // frame.treeModel.nodeStructureChanged(t);
133
134                                r = childNode;
135                        } else {
136                                // if (!r.path.isResolved()) {
137                                //      r.path = new Path(path.getInstance(), nodes, n);
138                                // }
139                        }
140                        result = result.pathByAddingChild(r);
141                        t = r;
142                }
143                return result;
144        }
145
146        @Override
147        public void onFetch(final Path path) {
148                assert tree.isActive();
149                log.trace("fetched " + path);
150
151                frame.dispatch(new RunAt<Frame>(frame) {
152                        @Override
153                        protected void runAt() {
154
155                                TreePath treePath = getTreePath(path, true);
156                                assert treePath.getPathCount() == path.size() + 1;
157
158                                final TreeNode result = (TreeNode) treePath.getLastPathComponent();
159                                // log.trace("found " + result + " == " + path);
160                                tree.dispatch(new RunAt<Tree>(frame) {
161                                        @Override
162                                        protected void runAt() {
163                                                result.reactForFetchResult(path, null);
164                                        }
165                                });
166                        }
167                });
168        }
169
170        @Override
171        public void onRun(Exception e) {
172
173        }
174
175        @Override
176        public void onStop(Exception e) {
177
178        }
179}
Note: See TracBrowser for help on using the repository browser.