source: java/main/src/main/java/com/framsticks/gui/Browser.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: 7.2 KB
Line 
1package com.framsticks.gui;
2
3import com.framsticks.core.*;
4import com.framsticks.gui.console.Console;
5import com.framsticks.gui.console.TrackConsole;
6import com.framsticks.params.annotations.AutoAppendAnnotation;
7import com.framsticks.params.annotations.FramsClassAnnotation;
8import com.framsticks.params.annotations.ParamAnnotation;
9import com.framsticks.remote.RemoteTree;
10import com.framsticks.util.FramsticksException;
11import com.framsticks.util.dispatching.AbstractJoinable;
12import com.framsticks.util.dispatching.Dispatcher;
13import com.framsticks.util.dispatching.Dispatching;
14import com.framsticks.util.dispatching.ExceptionResultHandler;
15import com.framsticks.util.dispatching.Future;
16import com.framsticks.util.dispatching.FutureHandler;
17import com.framsticks.util.dispatching.Joinable;
18import com.framsticks.util.dispatching.JoinableCollection;
19import com.framsticks.util.dispatching.JoinableParent;
20import com.framsticks.util.dispatching.JoinableState;
21
22import javax.swing.*;
23
24import org.apache.log4j.Logger;
25
26import java.awt.Dimension;
27import java.awt.Toolkit;
28import java.awt.datatransfer.StringSelection;
29import java.awt.event.ActionEvent;
30import java.util.ArrayList;
31import java.util.LinkedList;
32import java.util.List;
33import com.framsticks.util.dispatching.RunAt;
34
35/**
36 * @author Piotr Sniegowski
37 */
38@FramsClassAnnotation
39public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent, ExceptionResultHandler {
40
41        private static final Logger log = Logger.getLogger(Browser.class);
42
43        protected final JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames");
44        protected final JoinableCollection<Tree> trees = new JoinableCollection<Tree>().setObservableName("trees");
45        protected final JoinableCollection<Console> consoles = new JoinableCollection<Console>().setObservableName("consoles");
46
47        protected final List<PopupMenuEntryProvider> popupMenuEntryProviders = new LinkedList<>();
48
49        protected final MainFrame mainFrame;
50        protected final List<PanelProvider> panelProviders = new ArrayList<PanelProvider>();
51        protected Dimension defaultFrameDimension;
52
53        String name;
54
55        public void addFrame(Frame frame) {
56                frames.add(frame);
57        }
58
59        public Browser() {
60                setName("browser");
61                JPopupMenu.setDefaultLightWeightPopupEnabled(false);
62                addPanelProvider(new StandardPanelProvider());
63
64                mainFrame = new MainFrame(Browser.this);
65                addFrame(mainFrame);
66
67                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
68                        @Override
69                        public void provide(JPopupMenu menu, Path path) {
70                                menu.add(new JMenuItem(path.getFullTextual()));
71                                menu.addSeparator();
72                        }
73                });
74
75                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
76                        @SuppressWarnings("serial")
77                        @Override
78                        public void provide(JPopupMenu menu, final Path path) {
79                                menu.add(new AbstractAction("Copy path to clipboard") {
80                                        @Override
81                                        public void actionPerformed(ActionEvent e) {
82                                                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(path.getFullTextual()), null);
83                                        }
84                                });
85                        }
86                });
87
88                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
89                        @SuppressWarnings("serial")
90                        @Override
91                        public void provide(JPopupMenu menu, final Path path) {
92                                if (!(path.getTree() instanceof RemoteTree)) {
93                                        return;
94                                }
95                                final RemoteTree remoteTree = (RemoteTree) path.getTree();
96                                menu.add(new AbstractAction("Open tracking console") {
97                                        @Override
98                                        public void actionPerformed(ActionEvent e) {
99                                                consoles.add(new TrackConsole().setConnection(remoteTree.getConnection()));
100                                        }
101                                });
102                        }
103                });
104                // addNodeActionToTreePopupMenu("", new NodeAction() )
105
106        }
107
108        @AutoAppendAnnotation
109        public void addPanelProvider(PanelProvider panelProvider) {
110                log.debug("added panel provider of type: " + panelProvider.getClass().getCanonicalName());
111                panelProviders.add(panelProvider);
112        }
113
114        @AutoAppendAnnotation
115        public void addPopupMenuEntryProvider(PopupMenuEntryProvider popupMenuEntryProvider) {
116                popupMenuEntryProviders.add(popupMenuEntryProvider);
117        }
118
119        @AutoAppendAnnotation
120        public void addTree(Tree tree) {
121                log.info("adding tree: " + tree);
122                trees.add(tree);
123        }
124
125        public void autoResolvePath(final String path, final Future<Path> future) {
126                final Tree i = trees.get("localhost");
127                i.dispatch(new RunAt<Tree>(future) {
128                        @Override
129                        protected void runAt() {
130                                TreeOperations.resolveAndGet(i, path, new FutureHandler<Path>(future) {
131                                        @Override
132                                        protected void result(final Path p) {
133                                                future.pass(p);
134                                                mainFrame.dispatch(new RunAt<Frame>(future) {
135                                                        @Override
136                                                        protected void runAt() {
137                                                                mainFrame.goTo(p);
138                                                        }
139                                                });
140                                        }
141                                });
142                        }
143                });
144        }
145
146        public void clear() {
147                assert isActive();
148                for (Frame f : frames) {
149                        f.clear();
150                }
151        }
152
153        public void createTreeNodeForChild(final Path path) {
154                assert !isActive();
155                //assert tree.isActive();
156
157                /*
158                 final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject();
159                 if (parentTreeNode == null) {
160                 Dispatching.invokeDispatch(this, manager, new Runnable() {
161                 @Override
162                 public void run() {
163                 createTreeNodeForChild(child);
164                 }
165                 });
166                 return;
167                 }
168                 log.debug(child.getClass().getSimpleName() + " created: " + child);
169
170
171                 invokeLater(new Runnable() {
172                 @Override
173                 public void run() {
174                 parentTreeNode.getOrCreateChildTreeNodeFor(child);
175                 }
176                 });
177                 */
178        }
179
180        @Override
181        protected void joinableStart() {
182                Dispatching.use(frames, this);
183                Dispatching.use(trees, this);
184                Dispatching.use(consoles, this);
185
186                dispatch(new RunAt<Browser>(this) {
187                        @Override
188                        protected void runAt() {
189
190                                for (final Tree i : trees) {
191                                        i.dispatch(new RunAt<Tree>(this) {
192                                                @Override
193                                                protected void runAt() {
194                                                        final Path p = Path.to(i, "/");
195                                                        dispatch(new RunAt<Browser>(this) {
196                                                                @Override
197                                                                protected void runAt() {
198                                                                        mainFrame.addRootPath(p);
199                                                                }
200                                                        });
201                                                }
202                                        });
203                                }
204                        }
205                });
206        }
207
208        /**
209         * @return the tree
210         */
211        public JoinableCollection<Tree> getTrees() {
212                return trees;
213        }
214
215        /**
216         * @return the mainFrame
217         */
218        public MainFrame getMainFrame() {
219                return mainFrame;
220        }
221
222        /**
223         * @return the name
224         */
225        @ParamAnnotation
226        public String getName() {
227                return name;
228        }
229
230        /**
231         * @param name the name to set
232         */
233        @ParamAnnotation
234        public void setName(String name) {
235                this.name = name;
236        }
237
238        @Override
239        public boolean isActive() {
240                return SwingDispatcher.getInstance().isActive();
241        }
242
243        @Override
244        public void dispatch(RunAt<? extends Browser> runnable) {
245                SwingDispatcher.getInstance().dispatch(runnable);
246        }
247
248        @Override
249        protected void joinableJoin() throws InterruptedException {
250                Dispatching.join(frames);
251                Dispatching.join(trees);
252                Dispatching.join(consoles);
253                // super.join();
254        }
255
256        @Override
257        protected void joinableInterrupt() {
258                Dispatching.drop(consoles, this);
259                Dispatching.drop(frames, this);
260                Dispatching.drop(trees, this);
261        }
262
263        @Override
264        public void childChangedState(Joinable joinable, JoinableState state) {
265                if (joinable == frames) {
266                        proceedToState(state);
267                }
268
269        }
270
271        @Override
272        protected void joinableFinish() {
273
274        }
275
276        @Override
277        public String toString() {
278                return getName();
279        }
280
281        @Override
282        public void handle(FramsticksException exception) {
283                mainFrame.handle(exception);
284        }
285
286        // @Override
287        // public boolean isDone() {
288        //      return frames.isDone() && trees.isDone();
289        // }
290}
Note: See TracBrowser for help on using the repository browser.