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

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

HIGHLIGHTS:

CHANGELOG:
Get data also on tree expansion.

Use nice framstick icon for empty nodes.

Update panel after reload if it is current.

Add shallow reload procedure.

Cut Gui prefix from several tree classes.

Bring back counter of GuiTreeNode?.

Use IdentityHashMap? were it is more appriopriate.

Remove TreeListener?.

Do not use TreeListener? in GUI.

Minor change.

Done migration to GuiTreeModel?.

BrowserTest? in that version always crashes frams.linux.

Move rendering implementation into GuiAbstractNode?.

Use hand-crafted list in GuiTreeNode?.

Generally, it would be a great place for WeakIdentityHashMap?
(but there is none in Java Collection Framework).

Remove superfluous logging.

Fix bug in GuiTreeNode?.

Use IdentityHashMap? instead of HashMap?.

Improve structure update.

Filter out invalid uids in UniqueListAccess?.

Improve TreeCellRenderer?.

Add filtering in TrackConsole?.

Improve TreeModel?.

More changes.

More improvements.

More changes.

Remove TreeNode?.

Support MetaNode? in the GuiTreeModel?.

Implement more in GuiTreeModel?.

Add CompositeParam? interface to FramsClass? and AccessInterface?.

Allow access by number to UniqueList?.

Add UidComparator?.

Use TreeMap? as a default accessee in unique list.

It keeps order of keys.

Introduce classes to use with new TreeModel?.

Another step.

Migrate from TreeNode? to Node in many places.

Remove some uses of TreeNode? as DefaultMutableTreeNode?.

Remove Path from TreeNode? interface.

Remove Path from TreeNode?.

Add Path recration from node feature.

Reworking TreeCellRenderer?.

Minor change of TreeOperations? interface.

Remove last methods from TreeNode?.

Another minor step.

Do not store reference to TreeAtFrame? in TreeNode?.

Add proxy exceptionHandler to StatusBar?.

Move panels management to TreeAtFrame?.

Store localChanges in the NodeAtFrame?.

More cleanup.

Move name computing to TreeCellRenderer?.

Move tooltip and icon computations to TreeCellRenderer?.

More dispatches removed.

Remove most dispatching from TreeNode?.

TreeNode? does not actually redispatch tasks.

Make Tree embedded in Browser use SwingDispatcher?.

Make lazy binding of Tree with Dispatcher.

Minor changes.

Organizational change in AbstractTree?.

Make AbstractTree? compose from Thread instead of inherit from it.

Make SwingDispatcher? and AtOnceDispatcher? Joinable compatible.

Add ListPanelProvider?.

Improve Controls readonly and enabled handling.

Properly pass ExceptionHandlers? in more places.

Make Tree.get accept ValueParam?.

  • This is to allow access number of list elements.

Remove not needed get redirection in ClientAtServer?.

Rename tryResolve to tryGet.

Unify tryResolveAndGet into tryResolve.

Remove resolveTop from Tree interface.

Make Tree.get accept Future<Path>.

Use get to implement resolveTop also in ObjectTree?.

Unify resolveTop and get in RemoteTree?.

Another minor step.

More minor changes in tree operations.

Minor organizational changes.

In RemoteTree? first fetch info for root.

Reworking resolving.

Minor changes.

Make ListAccess? return proxy iterators (instead of creating temporary collection).

Let AccessInterface? return Iterable<Param>.

Improve resolving.

More improvements.

First working completion in ManagedConsole?.

Rename resolve to resolveTop.

This reflects the actuall functionality.

Change semantic of tryResolve and tryResolveAndGet.

File size: 4.7 KB
Line 
1package com.framsticks.gui;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.core.Tree;
6import com.framsticks.core.Node;
7import com.framsticks.core.Path;
8import com.framsticks.core.TreeOperations;
9import com.framsticks.gui.controls.ValueControl;
10import com.framsticks.params.CompositeParam;
11import com.framsticks.params.FramsClass;
12
13import java.util.*;
14
15import javax.swing.tree.TreePath;
16
17
18import com.framsticks.util.dispatching.FutureHandler;
19import com.framsticks.util.lang.Casting;
20
21/**
22 * @author Piotr Sniegowski
23 */
24public class TreeAtFrame {
25
26        private static final Logger log = Logger.getLogger(TreeAtFrame.class);
27
28        protected final Frame frame;
29        protected final Tree tree;
30        protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>();
31        protected Node rootNode;
32
33        protected Map<TreeNode, NodeAtFrame> nodesStorage = new WeakHashMap<>();
34
35        public TreeAtFrame(Tree tree, Frame frame) {
36                this.frame = frame;
37                this.tree = tree;
38        }
39
40        public Frame getFrame() {
41                return frame;
42        }
43
44        /**
45         * @return the tree
46         */
47        public Tree getTree() {
48                return tree;
49        }
50
51        public void registerPanel(Panel panel) {
52        }
53
54        public Panel findPanel(String accessId) {
55                assert frame.isActive();
56                return (knownPanels.containsKey(accessId) ? knownPanels.get(accessId) : null);
57        }
58
59        public final String getName() {
60                return tree.getName();
61        }
62
63        public Panel preparePanel(CompositeParam param, FramsClass framsClass) {
64                assert frame.isActive();
65                Panel panel = preparePanelImpl(param, framsClass);
66                assert panel != null;
67                String accessId = param.computeAccessId();
68                panel.uniqueName = accessId + "@" + tree.getName();
69                knownPanels.put(accessId, panel);
70                frame.cardPanel.add(panel, panel.uniqueName);
71                log.debug("prepared panel for " + panel);
72                return panel;
73        }
74
75        protected Panel preparePanelImpl(CompositeParam param, FramsClass framsClass) {
76                assert frame.isActive();
77                List<Panel> panels = new ArrayList<Panel>();
78
79                Panel.Parameters parameters = new Panel.Parameters(this, param, framsClass);
80                for (PanelProvider pp : frame.browser.panelProviders) {
81                        Panel p = pp.providePanel(parameters);
82                        if (p != null) {
83                                panels.add(p);
84                        }
85                }
86
87                if (panels.isEmpty()) {
88                        return new EmptyPanel(parameters);
89                }
90                if (panels.size() == 1) {
91                        return panels.get(0);
92                }
93                return new MultiPanel(parameters, panels);
94
95        }
96
97        public boolean hasLocalChanges(TreePath treePath) {
98                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
99                if (nodeAtFrame == null) {
100                        return false;
101                }
102                return !nodeAtFrame.localChanges.isEmpty();
103        }
104
105        public NodeAtFrame assureLocalInfo(TreePath treePath) {
106                assert frame.isActive();
107                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
108
109                if (nodeAtFrame == null) {
110                        nodeAtFrame = new NodeAtFrame();
111                        nodesStorage.put(Casting.throwCast(TreeNode.class, treePath.getLastPathComponent()), nodeAtFrame);
112                }
113                return nodeAtFrame;
114        }
115
116        public NodeAtFrame getLocalInfo(TreePath treePath) {
117                return nodesStorage.get(treePath.getLastPathComponent());
118        }
119
120        public boolean changeValue(TreePath treePath, ValueControl component, Object newValue) {
121                log.debug("changing value of " + component + " to '" + newValue + "'");
122
123                assureLocalInfo(treePath).localChanges.put(component, newValue);
124
125                return true;
126        }
127
128        public void pushLocalChanges(TreePath treePath) {
129                assert frame.isActive();
130
131                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
132                if (nodeAtFrame == null) {
133                        return;
134                }
135                Path path = frame.treeModel.convertToPath(treePath);
136
137                for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) {
138                        TreeOperations.set(path, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(frame) {
139                                @Override
140                                protected void result(Integer flag) {
141                                }
142                        });
143                }
144        }
145
146        public void fillPanelWithValues(TreePath treePath) {
147                NodeAtFrame nodeAtFrame = assureLocalInfo(treePath);
148                if (nodeAtFrame == null) {
149                        return;
150                }
151
152                if (nodeAtFrame.panel == null) {
153                        return;
154                }
155                Node node = TreeNode.tryGetNode(treePath);
156                if (node == null) {
157                        return;
158                }
159                nodeAtFrame.panel.setCurrentTreePath(treePath);
160                nodeAtFrame.panel.pullValuesFromLocalToUser(TreeOperations.bindAccess(node));
161
162                frame.showPanel(nodeAtFrame.panel);
163
164        }
165
166        public void useOrCreatePanel(TreePath treePath) {
167                // node.assureResolved();
168                Node node = TreeNode.tryGetNode(treePath);
169
170                NodeAtFrame nodeAtFrame = assureLocalInfo(treePath);
171
172                if (nodeAtFrame.panel == null) {
173                        CompositeParam param = node.getParam();
174                        nodeAtFrame.panel = findPanel(param.computeAccessId());
175                        if (nodeAtFrame.panel == null) {
176                                FramsClass framsClass = node.getTree().getInfoFromCache(param.getContainedTypeName());
177                                nodeAtFrame.panel = preparePanel(param, framsClass);
178                        }
179                }
180                fillPanelWithValues(treePath);
181        }
182}
Note: See TracBrowser for help on using the repository browser.