source: java/main/src/main/java/com/framsticks/gui/console/ManagedConsole.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: 3.8 KB
Line 
1package com.framsticks.gui.console;
2
3import java.util.LinkedList;
4import java.util.List;
5
6
7import com.framsticks.communication.ClientSideManagedConnection;
8import com.framsticks.communication.ClientSideResponseFuture;
9import com.framsticks.communication.File;
10import com.framsticks.communication.Request;
11import com.framsticks.communication.Response;
12import com.framsticks.communication.queries.ApplicationRequest;
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.remote.RemoteTree;
20import com.framsticks.util.FramsticksException;
21import com.framsticks.util.dispatching.FutureHandler;
22import com.framsticks.util.lang.Casting;
23import com.framsticks.util.lang.Containers;
24import com.framsticks.util.lang.Pair;
25import com.framsticks.util.lang.Strings;
26
27@FramsClassAnnotation
28public class ManagedConsole extends InteractiveConsole {
29
30        protected RemoteTree tree;
31
32        /**
33         * @param connection
34         */
35        public ManagedConsole() {
36        }
37
38        /**
39         * @return the connection
40         */
41        @Override
42        public ClientSideManagedConnection getConnection() {
43                return (ClientSideManagedConnection) connection;
44        }
45
46        protected void sendImplementation(String line) {
47                if (!connection.isConnected()) {
48                        throw new FramsticksException().msg("not connected").arg("console", this);
49                }
50                //Move that to managed connection
51                ApplicationRequest request;
52                try {
53                        Pair<String, String> command = Strings.splitIntoPair(line, ' ', "");
54                        request = Casting.throwCast(ApplicationRequest.class, Request.createRequestByTypeString(command.first));
55                        request.parseRest(command.second);
56                } catch (FramsticksException e) {
57                        throw new FramsticksException().msg("invalid line").arg("line", line).cause(e);
58                }
59
60                paintLine(line);
61
62                getConnection().send(request, SwingDispatcher.getInstance(), new ClientSideResponseFuture(this) {
63                        @Override
64                        protected void processOk(Response response) {
65                                for (File f : response.getFiles()) {
66                                        consolePainter.paintMessage(f);
67                                }
68                        }
69                });
70        }
71
72        @Override
73        protected void findCompletionPropositions(final String prefix) {
74                Pair<CharSequence, CharSequence> command = Request.takeIdentifier(prefix);
75
76                Casting.throwCast(ApplicationRequest.class, Request.createRequestByTypeString(command.first.toString()));
77                // Pair<String, String> rest = Strings
78                Pair<CharSequence, CharSequence> rest = Request.takeIdentifier(command.second);
79                if (rest == null) {
80                        List<String> propositions = new LinkedList<String>();
81                        propositions.add(command.first.toString() + " /");
82                        processCompletionResult(prefix, propositions);
83                        return;
84                }
85
86                final String textual = rest.first.toString();
87                if (!textual.startsWith("/")) {
88                        throw new FramsticksException().msg("invalid line").arg("line", prefix);
89                }
90                // final Iterator<String> iterator = Path.splitPath(textual);
91
92                resolve(tree, textual, new FutureHandler<Path>(this) {
93
94                        @Override
95                        protected void result(Path path) {
96                                if (!textual.startsWith(path.getTextual())) {
97                                        throw new FramsticksException().msg("invalid state").arg("line", prefix).arg("path", path);
98                                }
99
100                                List<String> propositions = new LinkedList<String>();
101                                String remaining = textual.substring(path.getTextual().length());
102                                remaining = Path.PathBuilder.splitPath(remaining).next();
103
104                                for (CompositeParam p : Containers.filterInstanceof(bindAccess(path).getParams(), CompositeParam.class)) {
105                                        if (p.getId().startsWith(remaining)) {
106                                                propositions.add(p.getId());
107                                        }
108                                }
109                                processCompletionResult(prefix, propositions);
110                        }
111                });
112
113
114        }
115
116        @AutoAppendAnnotation
117        public void setTree(RemoteTree tree) {
118                this.tree = tree;
119                connection = tree.getConnection();
120        }
121}
Note: See TracBrowser for help on using the repository browser.