source: java/main/src/main/java/com/framsticks/core/AbstractTree.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: 5.4 KB
Line 
1package com.framsticks.core;
2
3import javax.annotation.Nonnull;
4
5import org.apache.log4j.Logger;
6
7import com.framsticks.params.AccessInterface;
8import com.framsticks.params.CompositeParam;
9import com.framsticks.params.FramsClass;
10import com.framsticks.params.ParamsPackage;
11import com.framsticks.params.Registry;
12import com.framsticks.params.annotations.AutoAppendAnnotation;
13import com.framsticks.params.annotations.FramsClassAnnotation;
14import com.framsticks.params.annotations.ParamAnnotation;
15import com.framsticks.util.FramsticksException;
16import com.framsticks.util.dispatching.AbstractJoinable;
17import com.framsticks.util.dispatching.Dispatcher;
18import com.framsticks.util.dispatching.Dispatching;
19import com.framsticks.util.dispatching.ExceptionResultHandler;
20import com.framsticks.util.dispatching.Joinable;
21import com.framsticks.util.dispatching.JoinableDispatcher;
22import com.framsticks.util.dispatching.JoinableParent;
23import com.framsticks.util.dispatching.JoinableState;
24import com.framsticks.util.dispatching.RunAt;
25import com.framsticks.util.dispatching.Thread;
26import com.framsticks.util.dispatching.ThrowExceptionHandler;
27
28/**
29 * @author Piotr Sniegowski
30 */
31@FramsClassAnnotation
32public abstract class AbstractTree extends AbstractJoinable implements Dispatcher<Tree>, Tree, JoinableParent {
33
34        private static final Logger log = Logger.getLogger(Tree.class);
35
36        private Node root = null;
37        private ExceptionResultHandler handler = ThrowExceptionHandler.getInstance();
38
39        private JoinableDispatcher<Tree> dispatcher;
40
41        @Override
42        public void assignRootParam(CompositeParam param) {
43                if (root != null) {
44                        throw new FramsticksException().msg("root has already specified type");
45                }
46                root = new Node(this, param, null);
47                log.info("assigned root type: " + root);
48        }
49
50        @Override
51        public void assignRootObject(Object object) {
52                if (root == null) {
53                        throw new FramsticksException().msg("root is has no type specified");
54                }
55                if (root.getObject() != null) {
56                        throw new FramsticksException().msg("root has already object assigned").arg("current", root.getObject()).arg("candidate", object);
57                }
58                root = new Node(this, root.getParam(), object);
59                log.info("assigned root object: " + root);
60        }
61
62        @Override
63        public @Nonnull Node getAssignedRoot() {
64                if (root == null) {
65                        throw new FramsticksException().msg("root has no type specified yet");
66                }
67                return root;
68        }
69
70        public boolean isRootAssigned() {
71                // assert isActive();
72                return root != null;
73        }
74
75        protected String name;
76
77        public AbstractTree() {
78                setName("tree");
79        }
80
81        protected void tryRegisterOnChangeEvents(Path path) {
82
83        }
84
85        @Override
86        public final FramsClass getInfoFromCache(String id) {
87                assert isActive();
88                return registry.getFramsClass(id);
89        }
90
91        protected Registry registry = new Registry();
92
93
94        @Override
95        public @Nonnull AccessInterface prepareAccess(CompositeParam param) {
96                return registry.prepareAccess(param);
97        }
98
99        @Override
100        public void takeAllFrom(Registry source) {
101                registry.takeAllFrom(source);
102        }
103
104        @AutoAppendAnnotation
105        public void usePackage(ParamsPackage paramsPackage) {
106                log.debug("using package " + paramsPackage + " in tree " + this);
107                paramsPackage.register(registry);
108        }
109
110        @AutoAppendAnnotation
111        public void takeFromRegistry(Registry registry) {
112                log.debug("taking from registry " + registry + " in tree " + this);
113                this.registry.takeAllFrom(registry);
114        }
115
116
117        @Override
118        public void putInfoIntoCache(FramsClass framclass) {
119                registry.putFramsClass(framclass);
120        }
121
122
123        /**
124         * @return the handler
125         */
126        @Override
127        public ExceptionResultHandler getExceptionHandler() {
128                return handler;
129        }
130
131        /**
132         * @param handler the handler to set
133         */
134        @Override
135        public void setExceptionHandler(ExceptionResultHandler handler) {
136                this.handler = handler;
137        }
138
139        @Override
140        public void handle(FramsticksException exception) {
141                handler.handle(exception);
142        }
143
144        /**
145         * @return the dispatcher
146         */
147        @Override
148        public JoinableDispatcher<Tree> getDispatcher() {
149                return dispatcher;
150        }
151
152        /**
153         * @param dispatcher the dispatcher to set
154         */
155        @Override
156        public void setDispatcher(JoinableDispatcher<Tree> dispatcher) {
157                if (this.dispatcher != null) {
158                        throw new FramsticksException().msg("dispatcher is already set").arg("tree", this).arg("dispatcher", dispatcher);
159                }
160                this.dispatcher = dispatcher;
161        }
162
163        /**
164         * @return the name
165         */
166        @ParamAnnotation
167        public String getName() {
168                return name;
169        }
170
171        /**
172         * @param name the name to set
173         */
174        @ParamAnnotation
175        public void setName(String name) {
176                this.name = name;
177        }
178
179        @Override
180        protected void joinableStart() {
181                if (dispatcher == null) {
182                        dispatcher = new Thread<Tree>();
183                }
184                Dispatching.use(dispatcher, this);
185        }
186
187        @Override
188        protected void joinableInterrupt() {
189                Dispatching.drop(dispatcher, this);
190        }
191
192        @Override
193        protected void joinableFinish() {
194
195        }
196
197        @Override
198        protected void joinableJoin() throws InterruptedException {
199                Dispatching.join(dispatcher);
200        }
201
202        @Override
203        public void childChangedState(Joinable joinable, JoinableState state) {
204                if (joinable == dispatcher) {
205                        proceedToState(state);
206                }
207        }
208
209        @Override
210        public boolean isActive() {
211                if (dispatcher == null) {
212                        throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this);
213                }
214                return dispatcher.isActive();
215        }
216
217        @Override
218        public void dispatch(RunAt<? extends Tree> runnable) {
219                if (dispatcher == null) {
220                        throw new FramsticksException().msg("no dispatcher is set for tree yet").arg("tree", this);
221                }
222                dispatcher.dispatch(runnable);
223        }
224
225}
226
Note: See TracBrowser for help on using the repository browser.