source: java/main/src/main/java/com/framsticks/core/TreeOperations.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: 6.0 KB
Line 
1package com.framsticks.core;
2
3
4import java.util.List;
5
6import javax.annotation.Nonnull;
7
8import org.apache.log4j.Logger;
9
10import com.framsticks.communication.File;
11import com.framsticks.params.AccessInterface;
12import com.framsticks.params.CompositeParam;
13import com.framsticks.params.FramsClass;
14import com.framsticks.params.ListAccess;
15import com.framsticks.params.Param;
16import com.framsticks.params.PrimitiveParam;
17import com.framsticks.params.types.ObjectParam;
18import com.framsticks.params.types.ProcedureParam;
19import com.framsticks.parsers.Loaders;
20import com.framsticks.parsers.MultiParamLoader;
21import com.framsticks.util.FramsticksException;
22import com.framsticks.util.dispatching.Future;
23import com.framsticks.util.dispatching.FutureHandler;
24import com.framsticks.util.dispatching.RunAt;
25
26import static com.framsticks.util.dispatching.Dispatching.*;
27
28public final class TreeOperations {
29
30        private static final Logger log = Logger.getLogger(TreeOperations.class);
31
32        private TreeOperations() {
33        }
34
35        public static @Nonnull FramsClass processFetchedInfo(Tree tree, File file) {
36                assert tree.isActive();
37                FramsClass framsClass = Loaders.loadFramsClass(file.getContent());
38                log.debug("process fetched info for " + tree + ": " + framsClass);
39                tree.putInfoIntoCache(framsClass);
40                return framsClass;
41        }
42
43        public static void processFetchedValues(Path path, List<File> files) {
44                Tree tree = path.getTree();
45                assert tree.isActive();
46                assert files.size() == 1;
47                assert path.isTheSame(files.get(0).getPath());
48
49                if (!path.isResolved()) {
50                        AccessInterface access = tree.prepareAccess(path.getTop().getParam());
51                        Object child = access.createAccessee();
52                        assert child != null;
53                        if (path.size() == 1) {
54                                tree.assignRootObject(child);
55                        } else {
56                                bindAccess(path.getUnder()).set(path.getTop().getParam(), child);
57                        }
58                        path = path.appendResolution(child);
59                }
60
61                log.debug("process fetched values: " + path);
62                Node node = path.getTop();
63                MultiParamLoader loader = new MultiParamLoader();
64                loader.setNewSource(files.get(0).getContent());
65                loader.addBreakCondition(MultiParamLoader.Status.AfterObject);
66
67                try {
68                        if (node.getParam() instanceof ObjectParam) {
69                                loader.addAccessInterface(bindAccess(node));
70                                loader.go();
71                                return;
72                        }
73
74                        ListAccess listAccess = (ListAccess) bindAccess(node);
75                        listAccess.clearValues();
76
77                        AccessInterface elementAccess = listAccess.getElementAccess();
78                        loader.addAccessInterface(elementAccess);
79                        MultiParamLoader.Status status;
80                        while ((status = loader.go()) != MultiParamLoader.Status.Finished) {
81                                if (status == MultiParamLoader.Status.AfterObject) {
82                                        AccessInterface accessInterface = loader.getLastAccessInterface();
83
84                                        String id = listAccess.computeIdentifierFor(accessInterface.getSelected());
85                                        //TODO listAccessParam
86                                        CompositeParam param = Param.build().forAccess(accessInterface).id(id).finish(CompositeParam.class);
87                                        Object child = accessInterface.getSelected();
88                                        accessInterface.select(null);
89                                        assert child != null;
90                                        bindAccess(node).set(param, child);
91                                }
92                        }
93
94                } catch (FramsticksException e) {
95                        throw new FramsticksException().msg("exception occurred while loading").cause(e);
96                }
97        }
98
99        public static FramsClass getInfo(Path path) {
100                Tree tree = path.getTree();
101                assert tree.isActive();
102                log.debug("get info for: " + path);
103                final String name = path.getTop().getParam().getContainedTypeName();
104                return tree.getInfoFromCache(name);
105        }
106
107        public static void findInfo(final Path path, final Future<FramsClass> future) {
108                log.debug("find info for: " + path);
109                try {
110                        Tree tree = path.getTree();
111                        assert tree.isActive();
112                        final FramsClass framsClass = getInfo(path);
113                        if (framsClass != null) {
114                                future.pass(framsClass);
115                                return;
116                        }
117                        tree.info(path, future);
118                } catch (FramsticksException e) {
119                        future.handle(e);
120                }
121        }
122
123
124
125        public static @Nonnull AccessInterface bindAccess(Tree tree, String path) {
126                log.debug("bind access for textual: " + path + " in " + tree);
127                return bindAccess(Path.to(tree, path));
128        }
129
130        public static @Nonnull AccessInterface bindAccess(Node node) {
131                Tree tree = node.getTree();
132                assert tree.isActive();
133                assert node.getObject() != null;
134
135                try {
136                        return tree.prepareAccess(node.getParam()).select(node.getObject());
137                } catch (FramsticksException e) {
138                        throw new FramsticksException().msg("failed to prepare access for param").arg("param", node.getParam()).cause(e);
139                        // log.error("failed to bind access for " + node.getParam() + ": " + e);
140                }
141        }
142
143        public static @Nonnull AccessInterface bindAccess(Path path) {
144                assert path.getTree().isActive();
145                path.assureResolved();
146                log.debug("bind access for: " + path);
147                return bindAccess(path.getTop());
148        }
149
150        public static void set(final Path path, final PrimitiveParam<?> param, final Object value, final Future<Integer> future) {
151                final Tree tree = path.getTree();
152
153                dispatchIfNotActive(tree, new RunAt<Tree>(future) {
154                        @Override
155                        protected void runAt() {
156                                tree.set(path, param, value, future);
157                        }
158                });
159        }
160
161        public static void call(final Path path, final ProcedureParam param, final Object[] arguments, final Future<Object> future) {
162                final Tree tree = path.getTree();
163
164                dispatchIfNotActive(tree, new RunAt<Tree>(future) {
165                        @Override
166                        protected void runAt() {
167                                tree.call(path, param, arguments, future);
168                        }
169                });
170        }
171
172
173        /** This might not be correct. */
174        public static void tryGet(final Tree tree, final String targetPath, final Future<Path> future) {
175                log.debug("resolve textual: " + targetPath + " for " + tree);
176                dispatchIfNotActive(tree, new RunAt<Tree>(future) {
177
178                        @Override
179                        protected void runAt() {
180                                final Path path = Path.to(tree, targetPath);
181                                if (path.isResolved()) {
182                                        future.pass(path);
183                                        return;
184                                }
185
186                                tree.get(path, Mode.FETCH, new FutureHandler<Path>(future) {
187                                        @Override
188                                        protected void result(Path result) {
189                                                tryGet(tree, targetPath, future);
190                                        }
191                                });
192                        }
193                });
194        }
195
196        public static FramsClass getInfoFromCache(Path path) {
197                assert path.getTree().isActive();
198                return path.getTree().getInfoFromCache(path.getTop().getParam().getContainedTypeName());
199        }
200}
Note: See TracBrowser for help on using the repository browser.