source: java/main/src/main/java/com/framsticks/gui/console/ManagedConsole.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.2 KB
Line 
1package com.framsticks.gui.console;
2
3import java.util.LinkedList;
4import java.util.List;
5
6import com.framsticks.communication.ClientSideManagedConnection;
7import com.framsticks.communication.ClientSideResponseFuture;
8import com.framsticks.communication.File;
9import com.framsticks.communication.Request;
10import com.framsticks.communication.Response;
11import com.framsticks.communication.queries.ApplicationRequest;
12import com.framsticks.core.Mode;
13import com.framsticks.core.Path;
14import static com.framsticks.core.TreeOperations.*;
15import com.framsticks.gui.SwingDispatcher;
16import com.framsticks.params.CompositeParam;
17import com.framsticks.params.annotations.AutoAppendAnnotation;
18import com.framsticks.params.annotations.FramsClassAnnotation;
19import com.framsticks.params.types.ListParam;
20import com.framsticks.remote.RemoteTree;
21import com.framsticks.util.FramsticksException;
22import com.framsticks.util.dispatching.Dispatching;
23import com.framsticks.util.dispatching.FutureHandler;
24import com.framsticks.util.dispatching.RunAt;
25import com.framsticks.util.lang.Casting;
26import com.framsticks.util.lang.Containers;
27import com.framsticks.util.lang.Pair;
28import com.framsticks.util.lang.Strings;
29
30@FramsClassAnnotation
31public class ManagedConsole extends InteractiveConsole {
32
33
34        protected RemoteTree tree;
35
36        /**
37         * @param connection
38         */
39        public ManagedConsole() {
40        }
41
42        /**
43         * @return the connection
44         */
45        @Override
46        public ClientSideManagedConnection getConnection() {
47                return (ClientSideManagedConnection) connection;
48        }
49
50        protected void sendImplementation(String line) {
51                if (!connection.isConnected()) {
52                        throw new FramsticksException().msg("not connected").arg("console", this);
53                }
54                //Move that to managed connection
55                ApplicationRequest request;
56                try {
57                        Pair<String, String> command = Strings.splitIntoPair(line, ' ', "");
58                        request = Casting.throwCast(ApplicationRequest.class, Request.createRequestByTypeString(command.first));
59                        request.parseRest(command.second);
60                } catch (FramsticksException e) {
61                        throw new FramsticksException().msg("invalid line").arg("line", line).cause(e);
62                }
63
64                paintLine(line);
65
66                getConnection().send(request, SwingDispatcher.getInstance(), new ClientSideResponseFuture(this) {
67                        @Override
68                        protected void processOk(Response response) {
69                                for (File f : response.getFiles()) {
70                                        consolePainter.paintMessage(f);
71                                }
72                        }
73                });
74        }
75
76
77        @Override
78        protected void findCompletionPropositions(final String prefix) {
79                Pair<CharSequence, CharSequence> command = Request.takeIdentifier(prefix);
80                if (command == null) {
81                        return;
82                }
83
84                Casting.throwCast(ApplicationRequest.class, Request.createRequestByTypeString(command.first.toString()));
85                // Pair<String, String> rest = Strings
86                Pair<CharSequence, CharSequence> rest = Request.takeIdentifier(command.second);
87                if (rest == null) {
88                        List<String> propositions = new LinkedList<String>();
89                        propositions.add(command.first.toString() + " /");
90                        processCompletionResult(prefix, propositions);
91                        return;
92                }
93
94                final String textual = rest.first.toString();
95                if (!textual.startsWith("/")) {
96                        throw new FramsticksException().msg("invalid line").arg("line", prefix);
97                }
98                // final Iterator<String> iterator = Path.splitPath(textual);
99
100                tryGet(tree, textual, new FutureHandler<Path>(this) {
101
102                        @Override
103                        protected void result(final Path path) {
104                                if (!textual.startsWith(path.getTextual())) {
105                                        throw new FramsticksException().msg("invalid state").arg("line", prefix).arg("path", path);
106                                }
107                                assert path.getTree().isActive();
108
109                                final Runnable finalizeCompletion = new Runnable() {
110                                        @Override
111                                        public void run() {
112                                                String remaining = textual.substring(path.getTextual().length());
113
114                                                String base = prefix.substring(0, prefix.length() - (textual.length() - path.getTextual().length()));
115                                                if (path.size() > 1) {
116                                                        base = base + "/";
117                                                }
118
119                                                if (remaining.startsWith("/")) {
120                                                        remaining = remaining.substring(1);
121                                                }
122
123                                                if (remaining.indexOf('/') != -1) {
124                                                        /** It is to long. */
125                                                        return;
126                                                }
127                                                final List<String> propositions = new LinkedList<String>();
128                                                for (CompositeParam p : Containers.filterInstanceof(bindAccess(path).getParams(), CompositeParam.class)) {
129                                                        if (remaining.equals("") || p.getId().startsWith(remaining)) {
130                                                                propositions.add(base + p.getId());
131                                                        }
132                                                }
133
134                                                dispatch(new RunAt<ManagedConsole>(ManagedConsole.this) {
135
136                                                        @Override
137                                                        protected void runAt() {
138                                                                processCompletionResult(prefix, propositions);
139                                                        }
140                                                });
141                                        }
142                                };
143
144                                if (path.getTop().getParam() instanceof ListParam) {
145                                        tree.get(path, Mode.FETCH, new FutureHandler<Path>(ManagedConsole.this) {
146                                                @Override
147                                                protected void result(Path result) {
148                                                        finalizeCompletion.run();
149                                                }
150                                        });
151                                        return;
152                                }
153                                finalizeCompletion.run();
154
155                        }
156                });
157
158
159        }
160
161        @AutoAppendAnnotation
162        public void setTree(RemoteTree tree) {
163                this.tree = tree;
164                connection = tree.getConnection();
165        }
166
167        @Override
168        protected void joinableStart() {
169                super.joinableStart();
170                Dispatching.use(tree, this);
171        }
172
173        @Override
174        protected void joinableInterrupt() {
175                Dispatching.drop(tree, this);
176                super.joinableInterrupt();
177        }
178
179        @Override
180        protected void joinableJoin() throws InterruptedException {
181                Dispatching.join(tree);
182                super.joinableJoin();
183        }
184}
Note: See TracBrowser for help on using the repository browser.