Ignore:
Timestamp:
07/06/13 03:51:11 (11 years ago)
Author:
psniegowski
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/gui/Browser.java

    r96 r97  
    22
    33import com.framsticks.core.*;
     4import com.framsticks.gui.console.Console;
     5import com.framsticks.gui.console.TrackConsole;
    46import com.framsticks.params.annotations.AutoAppendAnnotation;
    57import com.framsticks.params.annotations.FramsClassAnnotation;
    68import com.framsticks.params.annotations.ParamAnnotation;
     9import com.framsticks.remote.RemoteTree;
     10import com.framsticks.util.FramsticksException;
    711import com.framsticks.util.dispatching.AbstractJoinable;
    812import com.framsticks.util.dispatching.Dispatcher;
    913import com.framsticks.util.dispatching.Dispatching;
     14import com.framsticks.util.dispatching.ExceptionResultHandler;
    1015import com.framsticks.util.dispatching.Future;
     16import com.framsticks.util.dispatching.FutureHandler;
    1117import com.framsticks.util.dispatching.Joinable;
    1218import com.framsticks.util.dispatching.JoinableCollection;
     
    1925
    2026import java.awt.Dimension;
     27import java.awt.Toolkit;
     28import java.awt.datatransfer.StringSelection;
     29import java.awt.event.ActionEvent;
    2130import java.util.ArrayList;
     31import java.util.LinkedList;
    2232import java.util.List;
    2333import com.framsticks.util.dispatching.RunAt;
     
    2737 */
    2838@FramsClassAnnotation
    29 public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent {
    30 
    31         private static final Logger log = Logger.getLogger(Browser.class.getName());
    32 
    33         protected JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames");
    34         protected JoinableCollection<Instance> instances = new JoinableCollection<Instance>().setObservableName("instances");
    35 
    36         protected MainFrame mainFrame;
    37         public List<PanelProvider> panelProviders = new ArrayList<PanelProvider>();
     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>();
    3851        protected Dimension defaultFrameDimension;
    3952
     
    5164                mainFrame = new MainFrame(Browser.this);
    5265                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
    53106        }
    54107
     
    60113
    61114        @AutoAppendAnnotation
    62         public void addInstance(Instance instance) {
    63                 log.info("adding instance: " + instance);
    64                 instances.add(instance);
     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);
    65123        }
    66124
    67125        public void autoResolvePath(final String path, final Future<Path> future) {
    68                 final Instance i = instances.get("localhost");
    69                 i.dispatch(new RunAt<Instance>() {
    70                         @Override
    71                         public void run() {
    72                                 InstanceUtils.resolveAndFetch(i, path, new 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) {
    73131                                        @Override
    74132                                        protected void result(final Path p) {
    75133                                                future.pass(p);
    76                                                 mainFrame.dispatch(new RunAt<Frame>() {
     134                                                mainFrame.dispatch(new RunAt<Frame>(future) {
    77135                                                        @Override
    78                                                         public void run() {
     136                                                        protected void runAt() {
    79137                                                                mainFrame.goTo(p);
    80138                                                        }
     
    93151        }
    94152
    95         protected void initializeGUI() {
    96                 assert isActive();
    97                 log.debug("executing first task");
    98 
    99                 try {
    100                         boolean found = false;
    101                         // for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
    102                         //      log.info("look and feel available: " + info.getName());
    103                         //      if ("Nimbus".equals(info.getName())) {
    104                         //              UIManager.setLookAndFeel(info.getClassName());
    105                         //              found = true;
    106                         //              break;
    107                         //      }
    108                         // }
    109                         if (!found) {
    110                                 UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    111                         }
    112                 } catch (Exception ex) {
    113                         log.warn("failed loading Look&Feel: ", ex);
    114                 }
    115 
    116                 javax.swing.JFrame.setDefaultLookAndFeelDecorated(true);
    117 
    118 
    119                 for (Frame f : frames) {
    120                         f.configure();
    121                 }
    122 
    123                 for (final Instance i : instances) {
    124                         i.dispatch(new RunAt<Instance>() {
    125                                 @Override
    126                                 public void run() {
    127                                         final Path p = Path.to(i, "/");
    128                                         dispatch(new RunAt<Browser>() {
    129                                                 @Override
    130                                                 public void run() {
    131                                                         mainFrame.addRootPath(p);
    132                                                 }
    133                                         });
    134                                 }
    135                         });
    136                 }
    137 
    138                 for (Frame f : frames) {
    139                         f.getSwing().setVisible(true);
    140                 }
    141 
    142                 // autoResolvePath("/simulator/genepools/groups/0", null);
    143                 // autoResolvePath("/", null);
    144         }
    145 
    146153        public void createTreeNodeForChild(final Path path) {
    147154                assert !isActive();
    148                 //assert instance.isActive();
     155                //assert tree.isActive();
    149156
    150157                /*
     
    174181        protected void joinableStart() {
    175182                Dispatching.use(frames, this);
    176                 Dispatching.use(instances, this);
    177 
    178                 dispatch(new RunAt<Browser>() {
    179                         @Override
    180                         public void run() {
    181                                 initializeGUI();
    182                         }
    183                 });
    184         }
    185 
    186         /**
    187          * @return the instances
    188          */
    189         public JoinableCollection<Instance> getInstances() {
    190                 return instances;
     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;
    191213        }
    192214
     
    227249        protected void joinableJoin() throws InterruptedException {
    228250                Dispatching.join(frames);
    229                 Dispatching.join(instances);
     251                Dispatching.join(trees);
     252                Dispatching.join(consoles);
    230253                // super.join();
    231254        }
     
    233256        @Override
    234257        protected void joinableInterrupt() {
     258                Dispatching.drop(consoles, this);
    235259                Dispatching.drop(frames, this);
    236                 Dispatching.drop(instances, this);
     260                Dispatching.drop(trees, this);
    237261        }
    238262
     
    255279        }
    256280
     281        @Override
     282        public void handle(FramsticksException exception) {
     283                mainFrame.handle(exception);
     284        }
    257285
    258286        // @Override
    259287        // public boolean isDone() {
    260         //      return frames.isDone() && instances.isDone();
     288        //      return frames.isDone() && trees.isDone();
    261289        // }
    262290}
Note: See TracChangeset for help on using the changeset viewer.