Ignore:
Timestamp:
06/22/13 21:51:33 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

  • simplification of entities management model
  • cleanup around params (improve hierarchy)
  • migrate from JUnit to TestNG
  • introduce FEST to automatically test GUI
  • improve slider control
  • loosen synchronization between gui tree and backend representation
  • and many other bug fixes

NOTICE:

  • a great many of lines is changed only because of substituting spaces with tabs

CHANGELOG (oldest changes at the bottom):

Some cleaning after fix found.

Fix bug with tree.

More changes with TreeNodes?.

Finally fix issue with tree.

Improve gui tree management.

Decouple update of values from fetch request in gui.

Minor changes.

Minor changes.

Minor change.

Change Path construction wording.

More fixes to SliderControl?.

Fix SliderControl?.

Fix SliderControl?.

Minor improvement.

Several changes.

Make NumberParam? a generic class.

Add robot to the gui test.

Setup common testing logging configuration.

Remove Parameters class.

Remove entityOwner from Parameters.

Move name out from Parameters class.

Move configuration to after the construction.

Simplify observers and endpoints.

Remove superfluous configureEntity overrides.

Add dependency on fest-swing-testng.

Use FEST for final print test.

Use FEST for more concise and readable assertions.

Divide test of F0Parser into multiple methods.

Migrate to TestNG

Minor change.

Change convention from LOGGER to log.

Fix reporting of errors during controls filling.

Bound maximal height of SliderControl?.

Minor improvements.

Improve tooltips for controls.

Also use Delimeted in more places.

Move static control utilities to Gui.

Rename package gui.components to controls.

Some cleaning in controls.

Improve Param classes placing.

Move ValueParam?, PrimitiveParam? and CompositeParam? one package up.

Improve ParamBuilder?.

Move getDef to ValueParam? and PrimitiveParam?.

Move getMax and getDef to ValueParam?.

Move getMin to ValueParam?.

Upgrade to laters apache commons versions.

Use filterInstanceof extensively.

Add instanceof filters.

Make ValueParam? in many places of Param.

Place assertions about ValueParam?.

Add ValueParam?

Rename ValueParam? to PrimitiveParam?

Minor changes.

Several improvements to params types.

Add NumberParam?.

Add TextControl? component.

Add .swp files to .gitignore

Greatly improved slider component.

Some improvements.

Make Param.reassign return also a state.

Add IterableIterator?.

Several changes.

  • Move util classes to better packages.
  • Remove warnings from eclim.

Several improvements.

Fix bug with BooleanParam?.

Some experiments with visualization.

Another fix to panel management.

Improve panel management.

Some refactorization around panels.

Add root class for panel.

Location:
java/main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • java/main

    • Property svn:ignore set to
      target
  • java/main/src/main/java/com/framsticks/gui/TreeNode.java

    r78 r84  
    55import com.framsticks.core.ListChange;
    66import com.framsticks.core.Path;
    7 import com.framsticks.gui.components.ValueControl;
     7import com.framsticks.gui.controls.ValueControl;
    88import com.framsticks.gui.view.TreeCellRenderer;
    99import com.framsticks.params.AccessInterface;
    10 import com.framsticks.params.Param;
     10import com.framsticks.params.CompositeParam;
     11import com.framsticks.params.FramsClass;
    1112import com.framsticks.params.types.*;
    1213import com.framsticks.remote.*;
    13 import com.framsticks.util.Casting;
    14 import com.framsticks.util.Future;
     14import com.framsticks.util.lang.Casting;
     15import com.framsticks.util.swing.TooltipConstructor;
     16import com.framsticks.util.dispatching.Future;
    1517import com.framsticks.util.Logging;
    1618import com.framsticks.util.StateFunctor;
     
    1820
    1921import javax.swing.tree.DefaultMutableTreeNode;
    20 import javax.swing.tree.TreePath;
    2122import java.util.HashMap;
    2223import java.util.LinkedList;
    2324import java.util.List;
    2425import java.util.Map;
     26import static com.framsticks.util.lang.Containers.filterInstanceof;
     27import com.framsticks.util.swing.TreeNodeUtils;
    2528
    2629/**
    2730 * @author Piotr Sniegowski
    2831 */
     32@SuppressWarnings("serial")
    2933public class TreeNode extends DefaultMutableTreeNode implements NodeListener {
    3034
    31         private static final Logger LOGGER = Logger.getLogger(TreeNode.class.getName());
     35        private static final Logger log = Logger.getLogger(TreeNode.class.getName());
    3236
    3337        Panel panel;
    3438
    3539        final protected Frame frame;
    36     final protected EndpointAtFrame endpoint;
    37 
    38     final protected Map<EventParam, Subscription> userSubscriptions = new HashMap<EventParam, Subscription>();
    39         protected Map<ValueControl, Object> changedValues = null;
    40     protected String tooltip;
    41     protected String name;
    42     protected String iconName;
    43     protected Path path;
    44 
    45 
    46     public TreeNode(Frame frame, EndpointAtFrame endpoint, final Path path) {
    47         assert frame.isActive();
    48         this.frame = frame;
    49                 LOGGER.debug("creating treenode for: " + path);
    50         this.path = path;
    51         this.endpoint = endpoint;
    52 
    53         name = path.getTop().getParam().getId();
    54         iconName = TreeCellRenderer.findIconName(name, path.getTextual());
    55         tooltip = "?";
    56         path.getInstance().invokeLater(new Runnable() {
    57             @Override
    58             public void run() {
    59                 updateDescriptions(path);
    60             }
    61         });
    62         }
    63 
    64     public void fetch(final Path p) {
    65         assert p.getInstance().isActive();
    66         LOGGER.debug("fetching: " + p);
    67         p.getInstance().fetchValues(p, new StateFunctor() {
    68             @Override
    69             public void call(Exception e) {
    70                 assert p.getInstance().isActive();
    71                 if (Logging.log(LOGGER, "fetch", TreeNode.this, e)) {
    72                     frame.invokeLater(new Runnable() {
    73                         @Override
    74                         public void run() {
    75                             LOGGER.debug("removing node from tree: " + p);
    76                             TreeNode.this.removeFromParent();
    77                             frame.repaintTree();
    78                         }
    79                     });
    80                     return;
    81                 }
    82                 updateChildren(p);
    83                 frame.invokeLater(new Runnable() {
    84                     @Override
    85                     public void run() {
    86                         //TODO maybe this should be called from some better place
    87                         useOrCreatePanel();
    88                     }
    89                 });
    90 
    91             }
    92         });
    93     }
    94 
    95     protected void postUpdatePath(final Path newPath) {
    96         assert !frame.isActive();
    97         /** TODO those two actions could be merged into single closure */
    98         frame.invokeLater(new Runnable() {
    99             @Override
    100             public void run() {
    101                 updatePath(newPath);
    102             }
    103         });
    104         updateDescriptions(newPath);
    105     }
    106 
    107     protected void updatePath(Path newPath) {
    108         assert frame.isActive();
    109         if (!path.isResolved()) {
    110             path = newPath;
    111                         LOGGER.debug("updated treenode's path: " + path);
    112             return;
    113         }
    114         if (path.matches(newPath)) {
    115             return;
    116         }
    117         this.removeAllChildren();
    118     }
    119 
    120     /** Update children, by removing non existing and adding new ones.
    121      */
    122     protected void updateChildren(final Path p) {
    123         assert p.getInstance().isActive();
    124         LOGGER.debug("updating children of " + this);
    125         AccessInterface access = p.getInstance().bindAccess(p.getTop());
     40        final protected EndpointAtFrame endpoint;
     41
     42        final protected Map<EventParam, Subscription> userSubscriptions = new HashMap<EventParam, Subscription>();
     43        protected Map<ValueControl, Object> localChanges = null;
     44        protected String tooltip;
     45        protected String name;
     46        protected final String paramId;
     47        protected String iconName;
     48        protected Path path;
     49
     50        public TreeNode(EndpointAtFrame endpoint, final Path path) {
     51                this.frame = endpoint.getFrame();
     52                assert frame.isActive();
     53                this.paramId = path.getLastElement();
     54                this.name = this.paramId;
     55                log.debug("creating treenode " + name + ": " + path);
     56                this.path = path;
     57                this.endpoint = endpoint;
     58
     59                iconName = TreeCellRenderer.findIconName(name, path.getTextual());
     60                tooltip = "?";
     61                path.getInstance().invokeLater(new Runnable() {
     62                        @Override
     63                        public void run() {
     64                                updateDescriptions(path);
     65                        }
     66                });
     67        }
     68
     69        public void fetch(final Path p) {
     70                assert p.getInstance().isActive();
     71                log.debug("fetching: " + p);
     72                p.getInstance().fetchValues(p, new StateFunctor() {
     73                        @Override
     74                        public void call(Exception e) {
     75                                //TODO removing should stay here
     76                                // reactForFetchResult(p, e);
     77                        }
     78                });
     79        }
     80
     81        protected void reactForFetchResult(final Path p, Exception e) {
     82                assert p.getInstance().isActive();
     83                if (Logging.log(log, "fetch", TreeNode.this, e)) {
     84                        frame.invokeLater(new Runnable() {
     85                                @Override
     86                                public void run() {
     87                                        log.debug("removing node from tree: " + p);
     88                                        frame.treeModel.removeNodeFromParent(TreeNode.this);
     89                                }
     90                        });
     91                        return;
     92                }
     93                updateChildren(p);
     94                frame.invokeLater(new Runnable() {
     95                        @Override
     96                        public void run() {
     97                                //TODO maybe this should be called from some better place
     98                                useOrCreatePanel();
     99                        }
     100                });
     101        }
     102
     103        protected void postUpdatePath(final Path newPath) {
     104                assert !frame.isActive();
     105                /** TODO those two actions could be merged into single closure */
     106                frame.invokeLater(new Runnable() {
     107                        @Override
     108                        public void run() {
     109                                updatePath(newPath);
     110                        }
     111                });
     112                updateDescriptions(newPath);
     113        }
     114
     115        protected void updatePath(Path newPath) {
     116                assert frame.isActive();
     117                if (!path.isResolved()) {
     118                        path = newPath;
     119                        log.debug("updated treenode's path: " + path);
     120                        return;
     121                }
     122                if (path.matches(newPath)) {
     123                        return;
     124                }
     125                log.debug("removing all children due to path update");
     126                this.removeAllChildren();
     127                frame.treeModel.nodeStructureChanged(this);
     128        }
     129
     130        public Iterable<TreeNode> childrenIterable() {
     131                return filterInstanceof(TreeNodeUtils.children(TreeNode.this, frame.treeModel), TreeNode.class);
     132        }
     133
     134        /** Update children, by removing non existing and adding new ones.
     135         */
     136        protected void updateChildren(final Path p) {
     137                assert p.getInstance().isActive();
     138                log.debug("updating children of " + this);
     139                AccessInterface access = p.getInstance().bindAccess(p.getTop());
    126140                if (access == null) {
    127141                        return;
    128142                }
    129         final List<Path> childrenPaths = new LinkedList<Path>();
    130         /**Prepare path for each child.*/
    131         for (Param param : access.getParams()) {
    132             if (!(param instanceof CompositeParam)) {
    133                 continue;
    134             }
    135             Path childPath = p.appendParam((CompositeParam)param);
    136             childrenPaths.add(childPath);
    137         }
    138         /**If some child were found, update in frame context.*/
    139         if (childrenPaths.size() > 0) {
    140             frame.invokeLater(new Runnable() {
    141                 @Override
    142                 public void run() {
    143                     TreePath treePath = frame.startChange();
    144                     updatePath(p);
    145                     Map<String, TreeNode> current = new HashMap<String, TreeNode>();
    146                     for (int c = 0; c < TreeNode.this.getChildCount(); ++c) {
    147                         TreeNode n = (TreeNode)TreeNode.this.getChildAt(c);
    148                         current.put(n.path.getLastElement(), n);
    149                     }
    150                     for (final Path childPath : childrenPaths) {
    151                         String e = childPath.getLastElement();
    152                         if (current.containsKey(e)) {
    153                             /*
    154                             final TreeNode n = current.get(e);
    155                             childPath.getInstance().invokeLater(new Runnable() {
    156                                 @Override
    157                                 public void run() {
    158                                     n.updateChildren(childPath);
    159                                 }
    160                             });
    161                             */
    162                             current.remove(e);
    163                             continue;
    164                         }
    165                         TreeNode childNode = new TreeNode(frame, endpoint, childPath);
    166                         TreeNode.this.add(childNode);
    167                     }
    168                     for (TreeNode n : current.values()) {
    169                         TreeNode.this.remove(n);
    170                     }
    171                     frame.markNodeChanged(TreeNode.this, treePath);
    172                     frame.repaintTree();
    173                     LOGGER.debug("updated children of " + TreeNode.this);
    174                 }
    175             });
    176         } else {
    177             LOGGER.debug("no children in " + TreeNode.this);
    178         }
    179     }
    180 
    181     public void select() {
    182         final Path p = path;
    183 
    184         p.getInstance().invokeLater(new Runnable() {
    185             @Override
    186             public void run() {
    187                 final Path updated = (p.isResolved()) ? p : p.findResolution();
    188                 if (updated.isResolved()) {
    189                     Logging.log(LOGGER, "update", updated, null);
    190                     fetch(updated);
    191                     postUpdatePath(updated);
    192                     return;
    193                 }
    194                 p.getInstance().resolve(updated, new Future<Path>() {
    195                     @Override
    196                     public void result(final Path result, Exception e) {
    197                         if (Logging.log(LOGGER, "resolve and select", TreeNode.this, e)) {
    198                             return;
    199                         }
    200 
    201                         fetch(result);
    202                         postUpdatePath(result);
    203                     }
    204                 });
    205             }
    206         });
    207 
    208     }
    209 
    210     @Override
    211     public String toString() {
    212         return path.toString();
    213     }
     143                final List<Path> childrenPaths = new LinkedList<Path>();
     144                /**Prepare path for each child.*/
     145                for (CompositeParam param : filterInstanceof(access.getParams(), CompositeParam.class)) {
     146                        childrenPaths.add(p.appendParam(param).tryFindResolution());
     147                }
     148
     149                /**If some child were found, update in frame context.*/
     150                if (childrenPaths.size() > 0) {
     151                        frame.invokeLater(new Runnable() {
     152                                @Override
     153                                public void run() {
     154                                        // TreePath treePath = frame.startChange();
     155                                        updatePath(p);
     156                                        Map<String, TreeNode> current = new HashMap<String, TreeNode>();
     157                                        for (TreeNode n : childrenIterable()) {
     158                                                current.put(n.path.getLastElement(), n);
     159                                        }
     160                                        assert current.size() == TreeNode.this.getChildCount();
     161                                        assert TreeNode.this.getChildCount() == frame.treeModel.getChildCount(TreeNode.this);
     162                                        log.trace("current " + TreeNode.this.getChildCount() + " children: " + current.values());
     163                                        for (Path childPath : childrenPaths) {
     164                                                String e = childPath.getLastElement();
     165                                                if (current.containsKey(e)) {
     166                                                        current.remove(e);
     167                                                        continue;
     168                                                }
     169                                                log.debug("update: treenode for " + p);
     170                                                TreeNode childNode = new TreeNode(endpoint, childPath);
     171
     172                                                frame.addNode(childNode, TreeNode.this);
     173                                        }
     174                                        for (TreeNode n : current.values()) {
     175                                                frame.treeModel.removeNodeFromParent(n);
     176                                        }
     177                                        log.debug("updated children of " + TreeNode.this + ": " + TreeNode.this.getChildCount());
     178                                }
     179                        });
     180                } else {
     181                        log.debug("no children in " + TreeNode.this);
     182                }
     183        }
     184
     185        public void select() {
     186                final Path p = path;
     187
     188                p.getInstance().invokeLater(new Runnable() {
     189                        @Override
     190                        public void run() {
     191                                final Path updated = (p.isResolved()) ? p : p.tryFindResolution();
     192                                if (updated.isResolved()) {
     193                                        Logging.log(log, "update", updated, null);
     194                                        fetch(updated);
     195                                        postUpdatePath(updated);
     196                                        return;
     197                                }
     198                                p.getInstance().resolve(updated, new Future<Path>() {
     199                                        @Override
     200                                        public void result(final Path result, Exception e) {
     201                                                if (Logging.log(log, "resolve and select", TreeNode.this, e)) {
     202                                                        return;
     203                                                }
     204
     205                                                fetch(result);
     206                                                postUpdatePath(result);
     207                                        }
     208                                });
     209                        }
     210                });
     211
     212        }
     213
     214        @Override
     215        public String toString() {
     216                return path.toString();
     217        }
    214218
    215219        public final Panel getPanel() {
    216         assert frame.isActive();
     220                assert frame.isActive();
    217221                return panel;
    218222        }
    219223
    220     protected void updateDescriptions(final Path p) {
    221         assert p.getInstance().isActive();
    222         if (!p.isResolved()) {
    223             return;
    224         }
    225         AccessInterface access = p.getInstance().bindAccess(p);
     224        protected void updateDescriptions(Path p) {
     225                assert p.getInstance().isActive();
     226
     227                if (!p.isResolved()) {
     228                        return;
     229                }
     230                AccessInterface access = p.getInstance().bindAccess(p);
    226231                if (access == null) {
    227232                        return;
    228233                }
    229         StringBuilder t = new StringBuilder();
    230         /** html formatting is used here, since tooltips in swing do not support simple \n line breaks */
    231         t.append("<html>");
    232         t.append("frams: ").append(access.getId()).append("<br/>");
    233         t.append("java: ").append(p.getTopObject().getClass().getCanonicalName()).append("<br/>");
    234         t.append("access: ").append(access.getClass().getSimpleName());
    235         t.append("</html>");
    236         final String tooltip = t.toString();
    237 
    238         StringParam nameParam = Casting.tryCast(StringParam.class, access.getParam("name"));
    239         final String name = (nameParam != null ? access.get(nameParam, String.class) : path.getTop().getParam().getId());
    240 
    241         frame.invokeLater(new Runnable() {
    242             @Override
    243             public void run() {
    244 
    245                 TreeNode.this.tooltip = tooltip;
    246                 TreeNode.this.name = name;
    247             }
    248         });
    249     }
     234
     235                final String tooltip = new TooltipConstructor()
     236                        .append("frams", access.getId())
     237                        .append("java", p.getTopObject().getClass().getCanonicalName())
     238                        .append("access", access.getClass().getSimpleName())
     239                        .append("name", name)
     240                        .append("id", paramId)
     241                        .append("object", Integer.toHexString(System.identityHashCode(this)))
     242                        .build()
     243                        ;
     244
     245                StringParam nameParam = Casting.tryCast(StringParam.class, access.getParam("name"));
     246                final String name = (nameParam != null ? access.get(nameParam, String.class) : path.getTop().getParam().getId());
     247
     248                frame.invokeLater(new Runnable() {
     249                        @Override
     250                        public void run() {
     251                                TreeNode.this.tooltip = tooltip;
     252                                TreeNode.this.name = name;
     253
     254                                log.debug("updated descriptions for " + path + ": " + name);
     255                        }
     256                });
     257        }
    250258
    251259/*
    252260        public void updateData() {
    253         assert browser.isActive();
     261                assert browser.isActive();
    254262                final Node node = getNode();
    255         browser.manager.invokeLater(new Runnable() {
    256             @Override
    257             public void run() {
    258                 node.fetchValues(new StateFunctor() {
    259                     @Override
    260                     public void call(Exception e) {
    261                         if (e != null) {
    262                             return;
    263                         }
    264                         browser.invokeLater(new Runnable() {
    265                             @Override
    266                             public void run() {
    267                                 assert browser.isActive();
    268                                 if (panel.getCurrentTreeNode() == TreeNode.this) {
    269                                     panel.refreshComponents();
    270                                 }
    271 
    272                                 browser.tree.repaint();
    273                                 panel.refreshComponents();
    274                             }
    275                         });
    276                     }
    277                 });
    278             }
    279         });
     263                browser.manager.invokeLater(new Runnable() {
     264                        @Override
     265                        public void run() {
     266                                node.fetchValues(new StateFunctor() {
     267                                        @Override
     268                                        public void call(Exception e) {
     269                                                if (e != null) {
     270                                                        return;
     271                                                }
     272                                                browser.invokeLater(new Runnable() {
     273                                                        @Override
     274                                                        public void run() {
     275                                                                assert browser.isActive();
     276                                                                if (panel.getCurrentTreeNode() == TreeNode.this) {
     277                                                                        panel.refreshComponents();
     278                                                                }
     279
     280                                                                browser.tree.repaint();
     281                                                                panel.refreshComponents();
     282                                                        }
     283                                                });
     284                                        }
     285                                });
     286                        }
     287                });
    280288        }
    281289*/
    282290
    283     public void showPanel() {
    284         assert frame.isActive();
    285         assert panel != null;
    286         frame.showPanel(panel);
    287     }
    288 
    289     public void fillPanelWithValues() {
    290         assert frame.isActive();
    291         final Path p = path;
    292         assert p.isResolved();
    293         assert panel != null;
    294         panel.setCurrentTreeNode(this);
    295         p.getInstance().invokeLater(new Runnable() {
    296             @Override
    297             public void run() {
    298                 AccessInterface access = p.getInstance().bindAccess(p);
    299                 panel.refreshComponents(access);
    300 
    301                 frame.invokeLater(new Runnable() {
    302                     @Override
    303                     public void run() {
    304                         showPanel();
    305                     }
    306                 });
    307             }
    308         });
    309 
    310     }
     291        public void showPanel() {
     292                assert frame.isActive();
     293                assert panel != null;
     294                frame.showPanel(panel);
     295        }
     296
     297        public void fillPanelWithValues() {
     298                assert frame.isActive();
     299                if (panel == null) {
     300                        return;
     301                }
     302                final Path p = path;
     303                assert p.isResolved();
     304                panel.setCurrentTreeNode(this);
     305                p.getInstance().invokeLater(new Runnable() {
     306                        @Override
     307                        public void run() {
     308                                AccessInterface access = p.getInstance().bindAccess(p);
     309                                panel.pullValuesFromLocalToUser(access);
     310
     311                                frame.invokeLater(new Runnable() {
     312                                        @Override
     313                                        public void run() {
     314                                                showPanel();
     315                                        }
     316                                });
     317                        }
     318                });
     319
     320        }
    311321
    312322        public void useOrCreatePanel() {
    313         assert frame.isActive();
     323                assert frame.isActive();
    314324                if (panel != null) {
    315             LOGGER.trace("panel is already attached: " + path);
    316             fillPanelWithValues();
    317                         return;
    318                 }
    319         if (!path.isResolved()) {
    320             LOGGER.trace("path is not resolved: " + path);
    321             return;
    322         }
    323 
    324         CompositeParam param = path.getTop().getParam();
    325         panel = endpoint.findPanel(param.computeAccessId());
    326         if (panel != null) {
    327             LOGGER.debug("found prepared panel for: " + path);
    328             fillPanelWithValues();
    329             return;
    330         }
    331         final Path p = path;
    332         LOGGER.debug("preparing panel: " + p);
    333         p.getInstance().invokeLater(new Runnable() {
    334             @Override
    335             public void run() {
    336                 assert p.getInstance().isActive();
    337                 final CompositeParam param = p.getTop().getParam();
    338                 if (param instanceof ObjectParam) {
    339                     AccessInterface access = p.getInstance().prepareAccess(param);
    340                     final List<Param> params = new LinkedList<Param>();
    341                     for (Param p : access.getParams()) {
    342                         if (p instanceof CompositeParam) {
    343                             continue;
    344                         }
    345                         params.add(p);
    346                     }
    347                     frame.invokeLater(new Runnable() {
    348                         @Override
    349                         public void run() {
    350                             panel = new ObjectPanel(endpoint, param.getContainedTypeName(), params);
    351                             fillPanelWithValues();
    352                         }
    353                     });
    354                     return;
    355                 }
    356                 if (param instanceof ListParam) {
    357                                         frame.invokeLater(new Runnable() {
    358                                                 @Override
    359                                                 public void run() {
    360                                                         panel = new ListPanel(endpoint);
    361                                                         fillPanelWithValues();
     325                        log.trace("panel is already attached: " + path);
     326                        fillPanelWithValues();
     327                        return;
     328                }
     329                if (!path.isResolved()) {
     330                        log.trace("path is not resolved: " + path);
     331                        return;
     332                }
     333
     334                CompositeParam param = path.getTop().getParam();
     335                panel = endpoint.findPanel(param.computeAccessId());
     336                if (panel != null) {
     337                        log.debug("found prepared panel for: " + path);
     338                        fillPanelWithValues();
     339                        return;
     340                }
     341                final Path p = path;
     342                log.debug("preparing panel: " + p);
     343                p.getInstance().invokeLater(new Runnable() {
     344                        @Override
     345                        public void run() {
     346                                assert p.getInstance().isActive();
     347                                final CompositeParam param = p.getTop().getParam();
     348                                final FramsClass framsClass = p.getInstance().getInfoFromCache(param.getContainedTypeName());
     349                                frame.invokeLater(new Runnable() {
     350                                        @Override
     351                                        public void run() {
     352                                                panel = endpoint.preparePanel(param, framsClass);
     353                                                fillPanelWithValues();
     354                                        }
     355                                });
     356                        }
     357                });
     358        }
     359
     360        public String getTooltip() {
     361                assert frame.isActive();
     362                return tooltip;
     363        }
     364
     365
     366
     367
     368        /*public void subscribe(final EventParam eventParam) {
     369                assert browser.isActive();
     370                if (hasSubscribed(eventParam)) {
     371                        log.error(eventParam + " is already subscribed for " + this);
     372                        return;
     373                }
     374                Node node = getNode();
     375                node.getConnection().subscribe(node.getPath() + "/" + eventParam.getId(), new SubscriptionCallback() {
     376                        @Override
     377                        public EventCallback subscribed(final Subscription subscription) {
     378                                if (subscription == null) {
     379                                        log.error("subscription failed");
     380                                        return null;
     381                                }
     382                                if (hasSubscribed(eventParam)) {
     383                                        //abort subscription
     384                                        return null;
     385                                }
     386                                userSubscriptions.put(eventParam, subscription);
     387                                log.debug("subscription succeeded: " + subscription);
     388                                subscription.setDispatcher(browser);
     389                                return new EventCallback() {
     390                                        @Override
     391                                        public void call(SourceInterface content) {
     392                                                assert browser.isActive();
     393                                                log.info("event " + subscription + " occurred");
     394                                        }
     395                                };
     396                        }
     397                });
     398
     399        }*/
     400
     401        public boolean hasSubscribed(EventParam param) {
     402                assert frame.isActive();
     403                return userSubscriptions.containsKey(param);
     404        }
     405
     406        public void unsubscribe(EventParam eventParam) {
     407                assert frame.isActive();
     408                if (!hasSubscribed(eventParam)) {
     409                        log.error("could not unsubscribe from " + eventParam);
     410                        return;
     411                }
     412                userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(log, "unsubscribed " + eventParam));
     413                userSubscriptions.remove(eventParam);
     414        }
     415
     416/*
     417
     418        @Override
     419        public void onChildChange(final Child child, ListChange.Action action) {
     420                assert browser.manager.isActive();
     421
     422                switch (action) {
     423                        case Remove: {
     424                                Dispatching.invokeDispatch(browser, browser.manager, new Runnable() {
     425                                        @Override
     426                                        public void run() {
     427                                                assert browser.manager.isActive();
     428                                                final TreeNode treeNode = (TreeNode) child.getUserObject();
     429                                                if (treeNode == null) {
     430                                                        log.error("child " + child + " had no tree node attached");
     431                                                        return;
    362432                                                }
    363                                         });
    364                                         return;
    365                     //return panel = new ListPanel(browser, access);
    366                 }
    367                 assert false;
    368             }
    369         });
    370         }
    371 
    372     public String getTooltip() {
    373         assert frame.isActive();
    374         return tooltip;
    375     }
    376 
    377 
    378 
    379 
    380     /*public void subscribe(final EventParam eventParam) {
    381         assert browser.isActive();
    382         if (hasSubscribed(eventParam)) {
    383             LOGGER.error(eventParam + " is already subscribed for " + this);
    384             return;
    385         }
    386         Node node = getNode();
    387         node.getConnection().subscribe(node.getPath() + "/" + eventParam.getId(), new SubscriptionCallback() {
    388             @Override
    389             public EventCallback subscribed(final Subscription subscription) {
    390                 if (subscription == null) {
    391                     LOGGER.error("subscription failed");
    392                     return null;
    393                 }
    394                 if (hasSubscribed(eventParam)) {
    395                     //abort subscription
    396                     return null;
    397                 }
    398                 userSubscriptions.put(eventParam, subscription);
    399                 LOGGER.debug("subscription succeeded: " + subscription);
    400                 subscription.setDispatcher(browser);
    401                 return new EventCallback() {
    402                     @Override
    403                     public void call(SourceInterface content) {
    404                         assert browser.isActive();
    405                         LOGGER.info("event " + subscription + " occurred");
    406                     }
    407                 };
    408             }
    409         });
    410 
    411     }*/
    412 
    413     public boolean hasSubscribed(EventParam param) {
    414         assert frame.isActive();
    415         return userSubscriptions.containsKey(param);
    416     }
    417 
    418     public void unsubscribe(EventParam eventParam) {
    419         assert frame.isActive();
    420         if (!hasSubscribed(eventParam)) {
    421             LOGGER.error("could not unsubscribe from " + eventParam);
    422             return;
    423         }
    424         userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(LOGGER, "unsubscribed " + eventParam));
    425         userSubscriptions.remove(eventParam);
    426     }
    427 
    428 /*
    429 
    430     @Override
    431     public void onChildChange(final Child child, ListChange.Action action) {
    432         assert browser.manager.isActive();
    433 
    434         switch (action) {
    435             case Remove: {
    436                 Dispatching.invokeDispatch(browser, browser.manager, new Runnable() {
    437                     @Override
    438                     public void run() {
    439                         assert browser.manager.isActive();
    440                         final TreeNode treeNode = (TreeNode) child.getUserObject();
    441                         if (treeNode == null) {
    442                             LOGGER.error("child " + child + " had no tree node attached");
    443                             return;
    444                         }
    445                         browser.invokeLater(new Runnable() {
    446                             @Override
    447                             public void run() {
    448                                 assert browser.isActive();
    449                                 TreePath path = browser.startChange();
    450                                 //assert treeNode.getParent() == TreeNode.this;
    451                                 if (treeNode.getParent() != null) {
    452                                     browser.treeModel.removeNodeFromParent(treeNode);
    453                                 }
    454                                 //remove(treeNode);
    455                                 browser.markNodeChanged(TreeNode.this, path);
    456                             }
    457                         });
    458                     }
    459                 });
    460                 break;
    461             }
    462         }
    463 
    464     }
     433                                                browser.invokeLater(new Runnable() {
     434                                                        @Override
     435                                                        public void run() {
     436                                                                assert browser.isActive();
     437                                                                TreePath path = browser.startChange();
     438                                                                //assert treeNode.getParent() == TreeNode.this;
     439                                                                if (treeNode.getParent() != null) {
     440                                                                        browser.treeModel.removeNodeFromParent(treeNode);
     441                                                                }
     442                                                                //remove(treeNode);
     443                                                                browser.markNodeChanged(TreeNode.this, path);
     444                                                        }
     445                                                });
     446                                        }
     447                                });
     448                                break;
     449                        }
     450                }
     451
     452        }
    465453*/
    466454
    467     public String getName() {
    468         return name;
    469     }
    470 
    471     public String getIconName() {
    472         return iconName;
    473     }
    474 
    475     @Override
    476     public void onUpgrade(Path path) {
    477     }
    478 
    479     @Override
    480     public void onChange(Path path) {
    481     }
    482 
    483     @Override
    484     public void onChildChange(Path path, ListChange.Action action) {
    485     }
    486 
    487     public final Frame getFrame() {
    488         return frame;
    489     }
     455        public String getName() {
     456                return name;
     457        }
     458
     459        public String getIconName() {
     460                return iconName;
     461        }
     462
     463        @Override
     464        public void onUpgrade(Path path) {
     465        }
     466
     467        @Override
     468        public void onChange(Path path) {
     469        }
     470
     471        @Override
     472        public void onChildChange(Path path, ListChange.Action action) {
     473        }
     474
     475        public final Frame getFrame() {
     476                return frame;
     477        }
    490478
    491479        public boolean changeValue(ValueControl component, Object newValue) {
    492                 LOGGER.debug("changing value of " + component + " to '" + newValue + "'");
    493 
    494                 if (changedValues == null) {
    495                         changedValues = new HashMap<ValueControl, Object>();
    496                 }
    497                 changedValues.put(component, newValue);
     480                log.debug("changing value of " + component + " to '" + newValue + "'");
     481
     482                if (localChanges == null) {
     483                        localChanges = new HashMap<ValueControl, Object>();
     484                }
     485                localChanges.put(component, newValue);
    498486
    499487                return true;
     
    505493        }
    506494
    507         public void applyChanges() {
    508                 assert frame.isActive();
    509                 if (changedValues == null) {
    510                         return;
    511                 }
    512                 final Map<ValueControl, Object> changes = changedValues;
    513                 changedValues = null;
     495        public void pushLocalChanges() {
     496                assert frame.isActive();
     497                if (localChanges == null) {
     498                        return;
     499                }
     500                final Map<ValueControl, Object> changes = localChanges;
     501                localChanges = null;
    514502                endpoint.getEndpoint().invokeLater(new Runnable() {
    515503                        @Override
     
    525513                                                                return;
    526514                                                        }
    527                                                         LOGGER.debug("applied changes for: " + p);
     515                                                        log.debug("applied changes for: " + p);
    528516                                                        frame.invokeLater(new Runnable() {
    529517                                                                @Override
Note: See TracChangeset for help on using the changeset viewer.