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/TreeNode.java

    r96 r97  
    11package com.framsticks.gui;
    22
    3 import com.framsticks.communication.Connection;
    43import com.framsticks.communication.Subscription;
    54import com.framsticks.communication.util.LoggingStateCallback;
    6 import com.framsticks.core.Instance;
    7 import com.framsticks.core.InstanceUtils;
     5import com.framsticks.core.Mode;
     6import com.framsticks.core.Tree;
     7import com.framsticks.core.TreeOperations;
    88import com.framsticks.core.ListChange;
    99import com.framsticks.core.Path;
     
    1818import com.framsticks.util.lang.Holder;
    1919import com.framsticks.util.swing.TooltipConstructor;
    20 import com.framsticks.util.dispatching.Future;
    21 import com.framsticks.util.AbstractStateFunctor;
     20import com.framsticks.util.dispatching.ExceptionResultHandler;
     21import com.framsticks.util.dispatching.FutureHandler;
     22import com.framsticks.util.FramsticksException;
    2223import com.framsticks.util.Logging;
    2324import org.apache.log4j.Logger;
     
    3132import static com.framsticks.util.lang.Containers.filterInstanceof;
    3233import com.framsticks.util.swing.TreeNodeUtils;
    33 import static com.framsticks.core.InstanceUtils.*;
     34import static com.framsticks.core.TreeOperations.*;
    3435
    3536/**
     
    3738 */
    3839@SuppressWarnings("serial")
    39 public class TreeNode extends DefaultMutableTreeNode implements NodeListener {
     40public class TreeNode extends DefaultMutableTreeNode implements NodeListener, ExceptionResultHandler {
    4041
    4142        private static final Logger log = Logger.getLogger(TreeNode.class.getName());
     
    4445
    4546        final protected Frame frame;
    46         final protected InstanceAtFrame instanceAtFrame;
     47        final protected TreeAtFrame treeAtFrame;
    4748
    4849        final protected Map<EventParam, Subscription<?>> userSubscriptions = new HashMap<>();
     
    5051        protected String tooltip;
    5152        protected String name;
    52         protected final String paramId;
     53        protected final CompositeParam param;
    5354        protected String iconName;
    5455        protected Path path;
    5556
    56         public TreeNode(InstanceAtFrame instanceAtFrame, final Path path) {
    57                 this.frame = instanceAtFrame.getFrame();
    58                 assert frame.isActive();
    59                 this.paramId = path.getLastElement();
    60                 this.name = this.paramId;
     57        public TreeNode(TreeAtFrame treeAtFrame, final Path path) {
     58                this.frame = treeAtFrame.getFrame();
     59                assert frame.isActive();
     60                this.param = path.getTop().getParam();
     61                this.name = this.param.getId();
    6162                log.debug("creating treenode " + name + ": " + path);
    6263                this.path = path;
    63                 this.instanceAtFrame = instanceAtFrame;
     64                this.treeAtFrame = treeAtFrame;
    6465
    6566                iconName = TreeCellRenderer.findIconName(name, path.getTextual());
    6667                tooltip = "?";
    67                 path.getInstance().dispatch(new RunAt<Instance>() {
    68                         @Override
    69                         public void run() {
     68                path.getTree().dispatch(new RunAt<Tree>(this) {
     69                        @Override
     70                        protected void runAt() {
    7071                                updateDescriptions(path);
    7172                        }
     
    7475
    7576        public void fetch(final Path p) {
    76                 assert p.getInstance().isActive();
     77                assert p.getTree().isActive();
    7778                log.debug("fetching: " + p);
    78                 p.getInstance().fetchValues(p, new AbstractStateFunctor() {
    79                         @Override
    80                         public void call() {
    81                                 // reactForFetchResult(p, e);
     79                p.getTree().get(p, Mode.FETCH, new FutureHandler<Object>(this) {
     80                        @Override
     81                        protected void result(Object result) {
     82
    8283                        }
    8384                });
     
    8586
    8687        protected void reactForFetchResult(final Path p, Exception e) {
    87                 assert p.getInstance().isActive();
     88                assert p.getTree().isActive();
    8889                if (Logging.log(log, "fetch", TreeNode.this, e)) {
    89                         frame.dispatch(new RunAt<Frame>() {
     90                        frame.dispatch(new RunAt<Frame>(this) {
    9091                                @Override
    91                                 public void run() {
     92                                protected void runAt() {
    9293                                        log.debug("removing node from tree: " + p);
    9394                                        frame.treeModel.removeNodeFromParent(TreeNode.this);
     
    9798                }
    9899                updateChildren(p);
    99                 frame.dispatch(new RunAt<Frame>() {
    100                         @Override
    101                         public void run() {
     100                frame.dispatch(new RunAt<Frame>(this) {
     101                        @Override
     102                        protected void runAt() {
    102103                                //TODO maybe this should be called from some better place
    103104                                useOrCreatePanel();
     
    109110                assert !frame.isActive();
    110111                /** TODO those two actions could be merged into single closure */
    111                 frame.dispatch(new RunAt<Frame>() {
    112                         @Override
    113                         public void run() {
     112                frame.dispatch(new RunAt<Frame>(this) {
     113                        @Override
     114                        protected void runAt() {
    114115                                updatePath(newPath);
    115116                        }
     
    140141         */
    141142        protected void updateChildren(final Path p) {
    142                 assert p.getInstance().isActive();
     143                assert p.getTree().isActive();
    143144                log.debug("updating children of " + this);
    144                 AccessInterface access = InstanceUtils.bindAccess(p.getInstance(), p.getTop());
    145                 if (access == null) {
    146                         return;
    147                 }
     145                AccessInterface access = TreeOperations.bindAccess(p.getTree(), p.getTop());
    148146                final List<Path> childrenPaths = new LinkedList<Path>();
    149147                /**Prepare path for each child.*/
     
    154152                /**If some child were found, update in frame context.*/
    155153                if (childrenPaths.size() > 0) {
    156                         frame.dispatch(new RunAt<Frame>() {
     154                        frame.dispatch(new RunAt<Frame>(this) {
    157155                                @Override
    158                                 public void run() {
     156                                protected void runAt() {
    159157                                        // TreePath treePath = frame.startChange();
    160158                                        updatePath(p);
     
    173171                                                }
    174172                                                log.debug("update: treenode for " + p);
    175                                                 TreeNode childNode = new TreeNode(instanceAtFrame, childPath);
     173                                                TreeNode childNode = new TreeNode(treeAtFrame, childPath);
    176174
    177175                                                frame.addNode(childNode, TreeNode.this);
     
    191189                final Path p = path;
    192190
    193                 p.getInstance().dispatch(new RunAt<Instance>() {
    194                         @Override
    195                         public void run() {
     191                p.getTree().dispatch(new RunAt<Tree>(this) {
     192                        @Override
     193                        protected void runAt() {
    196194                                final Path updated = (p.isResolved()) ? p : p.tryFindResolution();
    197195                                if (updated.isResolved()) {
     
    201199                                        return;
    202200                                }
    203                                 p.getInstance().resolve(updated, new Future<Path>(Logging.logger(log, "resolve and select", TreeNode.this)) {
     201                                p.getTree().resolve(updated, new FutureHandler<Path>(Logging.logger(log, "resolve and select", TreeNode.this)) {
    204202                                        @Override
    205203                                        protected void result(Path result) {
     
    224222
    225223        protected void updateDescriptions(Path p) {
    226                 assert p.getInstance().isActive();
     224                assert p.getTree().isActive();
    227225
    228226                if (!p.isResolved()) {
    229227                        return;
    230228                }
    231                 AccessInterface access = InstanceUtils.bindAccess(p);
    232 
    233                 final String tooltip = new TooltipConstructor()
    234                         .append("frams", access.getId())
    235                         .append("java", p.getTopObject().getClass().getCanonicalName())
    236                         .append("access", access.getClass().getSimpleName())
    237                         .append("name", name)
    238                         .append("id", paramId)
    239                         .append("object", Integer.toHexString(System.identityHashCode(this)))
    240                         .build()
    241                         ;
     229                AccessInterface access = TreeOperations.bindAccess(p);
     230
     231                final String tooltip = new TooltipConstructor().append("frams", access.getId()).append("java", p.getTopObject().getClass().getCanonicalName()).append("access", access.getClass().getSimpleName()).append("name", name).append("id", param.getId()).append("object", Integer.toHexString(System.identityHashCode(this))).build();
    242232
    243233                StringParam nameParam = Casting.tryCast(StringParam.class, access.getParam("name"));
    244234                final String name = (nameParam != null ? access.get(nameParam, String.class) : path.getTop().getParam().getId());
    245235
    246                 frame.dispatch(new RunAt<Frame>() {
    247                         @Override
    248                         public void run() {
     236                frame.dispatch(new RunAt<Frame>(this) {
     237                        @Override
     238                        protected void runAt() {
    249239                                TreeNode.this.tooltip = tooltip;
    250240                                TreeNode.this.name = name;
     
    254244                });
    255245        }
    256 
    257 /*
    258         public void updateData() {
    259                 assert browser.isActive();
    260                 final Node node = getNode();
    261                 browser.manager.invokeLater(new Runnable() {
    262                         @Override
    263                         public void run() {
    264                                 node.fetchValues(new StateFunctor() {
    265                                         @Override
    266                                         public void call(Exception e) {
    267                                                 if (e != null) {
    268                                                         return;
    269                                                 }
    270                                                 browser.invokeLater(new Runnable() {
    271                                                         @Override
    272                                                         public void run() {
    273                                                                 assert browser.isActive();
    274                                                                 if (panel.getCurrentTreeNode() == TreeNode.this) {
    275                                                                         panel.refreshComponents();
    276                                                                 }
    277 
    278                                                                 browser.tree.repaint();
    279                                                                 panel.refreshComponents();
    280                                                         }
    281                                                 });
    282                                         }
    283                                 });
    284                         }
    285                 });
    286         }
    287 */
    288246
    289247        public void showPanel() {
     
    301259                assert p.isResolved();
    302260                panel.setCurrentTreeNode(this);
    303                 p.getInstance().dispatch(new RunAt<Instance>() {
    304                         @Override
    305                         public void run() {
    306                                 AccessInterface access = InstanceUtils.bindAccess(p);
     261                p.getTree().dispatch(new RunAt<Tree>(this) {
     262                        @Override
     263                        protected void runAt() {
     264                                AccessInterface access = TreeOperations.bindAccess(p);
    307265                                panel.pullValuesFromLocalToUser(access);
    308266
    309                                 frame.dispatch(new RunAt<Frame>() {
     267                                frame.dispatch(new RunAt<Frame>(this) {
    310268                                        @Override
    311                                         public void run() {
     269                                        protected void runAt() {
    312270                                                showPanel();
    313271                                        }
     
    331289
    332290                CompositeParam param = path.getTop().getParam();
    333                 panel = instanceAtFrame.findPanel(param.computeAccessId());
     291                panel = treeAtFrame.findPanel(param.computeAccessId());
    334292                if (panel != null) {
    335293                        log.debug("found prepared panel for: " + path);
     
    339297                final Path p = path;
    340298                log.debug("preparing panel: " + p);
    341                 p.getInstance().dispatch(new RunAt<Instance>() {
    342                         @Override
    343                         public void run() {
    344                                 assert p.getInstance().isActive();
     299                p.getTree().dispatch(new RunAt<Tree>(this) {
     300                        @Override
     301                        protected void runAt() {
     302                                assert p.getTree().isActive();
    345303                                final CompositeParam param = p.getTop().getParam();
    346                                 final FramsClass framsClass = p.getInstance().getInfoFromCache(param.getContainedTypeName());
    347                                 frame.dispatch(new RunAt<Frame>() {
     304                                final FramsClass framsClass = p.getTree().getInfoFromCache(param.getContainedTypeName());
     305                                frame.dispatch(new RunAt<Frame>(this) {
    348306                                        @Override
    349                                         public void run() {
    350                                                 panel = instanceAtFrame.preparePanel(param, framsClass);
     307                                        protected void runAt() {
     308                                                panel = treeAtFrame.preparePanel(param, framsClass);
    351309                                                fillPanelWithValues();
    352310                                        }
     
    360318                return tooltip;
    361319        }
    362 
    363 
    364 
    365320
    366321        /*public void subscribe(final EventParam eventParam) {
     
    408363                        return;
    409364                }
    410                 userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback<Connection>(log, "unsubscribed " + eventParam));
     365                userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(log, "unsubscribed " + eventParam));
    411366                userSubscriptions.remove(eventParam);
    412367        }
    413368
    414 /*
    415 
    416         @Override
    417         public void onChildChange(final Child child, ListChange.Action action) {
    418                 assert browser.manager.isActive();
    419 
    420                 switch (action) {
    421                         case Remove: {
    422                                 Dispatching.invokeDispatch(browser, browser.manager, new Runnable() {
    423                                         @Override
    424                                         public void run() {
    425                                                 assert browser.manager.isActive();
    426                                                 final TreeNode treeNode = (TreeNode) child.getUserObject();
    427                                                 if (treeNode == null) {
    428                                                         log.error("child " + child + " had no tree node attached");
    429                                                         return;
    430                                                 }
    431                                                 browser.invokeLater(new Runnable() {
    432                                                         @Override
    433                                                         public void run() {
    434                                                                 assert browser.isActive();
    435                                                                 TreePath path = browser.startChange();
    436                                                                 //assert treeNode.getParent() == TreeNode.this;
    437                                                                 if (treeNode.getParent() != null) {
    438                                                                         browser.treeModel.removeNodeFromParent(treeNode);
    439                                                                 }
    440                                                                 //remove(treeNode);
    441                                                                 browser.markNodeChanged(TreeNode.this, path);
    442                                                         }
    443                                                 });
    444                                         }
    445                                 });
    446                                 break;
    447                         }
    448                 }
    449 
    450         }
    451 */
     369        // @Override
     370        // public void onChildChange(final Child child, ListChange.Action action) {
     371        // assert browser.manager.isActive();
     372
     373        // switch (action) {
     374        // case Remove: {
     375        // Dispatching.invokeDispatch(browser, browser.manager, new Runnable() {
     376        // @Override
     377        // public void run() {
     378        // assert browser.manager.isActive();
     379        // final TreeNode treeNode = (TreeNode) child.getUserObject();
     380        // if (treeNode == null) {
     381        // log.error("child " + child + " had no tree node attached");
     382        // return;
     383        // }
     384        // browser.invokeLater(new Runnable() {
     385        // @Override
     386        // public void run() {
     387        // assert browser.isActive();
     388        // TreePath path = browser.startChange();
     389        // //assert treeNode.getParent() == TreeNode.this;
     390        // if (treeNode.getParent() != null) {
     391        // browser.treeModel.removeNodeFromParent(treeNode);
     392        // }
     393        // //remove(treeNode);
     394        // browser.markNodeChanged(TreeNode.this, path);
     395        // }
     396        // });
     397        // }
     398        // });
     399        // break;
     400        // }
     401        // }
     402
     403        // }
    452404
    453405        public String getName() {
     
    486438        }
    487439
    488         public Path getInstancePath() {
     440        public Path getTreePath() {
    489441                assert frame.isActive();
    490442                return path;
     
    501453                final Path p = path;
    502454
    503                 for (Map.Entry<ValueControl, Object> e : localChanges.entrySet()) {
    504                         storeValue(p, e.getKey().getParam(), e.getValue(), new AbstractStateFunctor() {
     455                for (Map.Entry<ValueControl, Object> e : changes.entrySet()) {
     456                        set(p, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(this) {
    505457                                @Override
    506                                 public void call() {
     458                                protected void result(Integer flag) {
    507459                                        counter.set(counter.get() - 1);
    508460                                        if (counter.get() != 0) {
     
    510462                                        }
    511463                                        log.debug("applied changes for: " + p);
    512                                         frame.dispatch(new RunAt<Frame>() {
     464                                        frame.dispatch(new RunAt<Frame>(this) {
    513465                                                @Override
    514                                                 public void run() {
     466                                                protected void runAt() {
    515467                                                        fillPanelWithValues();
    516468                                                }
    517469                                        });
    518470                                }
     471
    519472                        });
    520473                }
    521474        }
     475
     476        @Override
     477        public void handle(FramsticksException exception) {
     478                frame.handle(exception);
     479        }
    522480}
Note: See TracChangeset for help on using the changeset viewer.