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/core/Instance.java

    r78 r84  
    33import com.framsticks.communication.*;
    44import com.framsticks.params.*;
    5 import com.framsticks.params.types.CompositeParam;
    65import com.framsticks.params.types.ObjectParam;
    76import com.framsticks.parsers.Loaders;
     
    98import com.framsticks.util.*;
    109import com.framsticks.util.UnsupportedOperationException;
     10import com.framsticks.util.dispatching.Dispatching;
     11import com.framsticks.util.dispatching.Future;
     12import com.framsticks.util.lang.Casting;
    1113import org.apache.log4j.Logger;
    1214
     
    1820public abstract class Instance extends Entity {
    1921
    20         private static final Logger LOGGER = Logger.getLogger(Instance.class.getName());
    21 
    22 
    23     protected Node root;
    24 
    25     public Set<InstanceListener> listeners = new HashSet<InstanceListener>();
    26 
    27     public Instance(Parameters parameters) {
    28         super(parameters);
    29         root = new Node((CompositeParam)new ParamBuilder().setName("Instance").setId(name).setType("o").build(), null);
    30         }
    31 
    32     @Override
    33     protected void run() {
    34         super.run();
     22        private static final Logger log = Logger.getLogger(Instance.class.getName());
     23
     24
     25        protected Node root;
     26
     27        public Set<InstanceListener> listeners = new HashSet<InstanceListener>();
     28
     29        public Instance() {
     30        }
     31
     32        @Override
     33        protected void run() {
     34                super.run();
     35                root = new Node((CompositeParam)new ParamBuilder().setName("Instance").setId(name).setType("o").build(), null);
    3536                com.framsticks.model.Package.register(registry);
    36     }
    37 
    38     @Override
    39     protected void configure() throws Exception {
    40         super.configure();
    41     }
    42 
    43     protected void fetchInfo(Path path, Future<FramsClass> future) {
     37        }
     38
     39        protected void fetchInfo(Path path, Future<FramsClass> future) {
    4440                future.result(null, new UnsupportedOperationException());
    4541        }
     
    6157        }
    6258
    63     public void fetchValue(Path path, Param param, StateFunctor stateFunctor) {
     59        public void fetchValue(Path path, Param param, StateFunctor stateFunctor) {
    6460                stateFunctor.call(null);
    6561        }
    6662
    67     public void fetchValues(Path path, StateFunctor stateFunctor) {
     63        public void fetchValues(Path path, StateFunctor stateFunctor) {
    6864                stateFunctor.call(null);
    6965        }
    7066
    71     protected void tryRegisterOnChangeEvents(Path path) {
     67        protected void tryRegisterOnChangeEvents(Path path) {
    7268
    7369        }
     
    8379        }
    8480
    85     protected void fireRun(Exception e) {
    86         for (InstanceListener l : this.listeners) {
    87             l.onRun(e);
    88         }
    89     }
    90 
    91     protected void fireStop(Exception e) {
    92         for (InstanceListener l : this.listeners) {
    93             l.onStop(e);
    94         }
    95     }
    96 
    97     public void addListener(final InstanceListener listener) {
    98         assert Dispatching.isThreadSafe();
    99         Dispatching.invokeLaterOrNow(this, new Runnable() {
    100             @Override
    101             public void run() {
    102                 listeners.add(listener);
    103             }
    104         });
    105     }
    106 
    107     public void removeListener(final InstanceListener listener) {
    108         assert Dispatching.isThreadSafe();
    109         Dispatching.invokeLaterOrNow(this, new Runnable() {
    110             @Override
    111             public void run() {
    112                 listeners.remove(listener);
    113             }
    114         });
    115     }
    116 
    117 
    118     protected void fireListChange(Path path, ListChange change) {
    119         assert isActive();
    120         for (InstanceListener l : this.listeners) {
     81        protected void fireRun(Exception e) {
     82                for (InstanceListener l : this.listeners) {
     83                        l.onRun(e);
     84                }
     85        }
     86
     87        protected void fireStop(Exception e) {
     88                for (InstanceListener l : this.listeners) {
     89                        l.onStop(e);
     90                }
     91        }
     92
     93        public void addListener(final InstanceListener listener) {
     94                assert Dispatching.isThreadSafe();
     95                Dispatching.invokeLaterOrNow(this, new Runnable() {
     96                        @Override
     97                        public void run() {
     98                                listeners.add(listener);
     99                        }
     100                });
     101        }
     102
     103        public void removeListener(final InstanceListener listener) {
     104                assert Dispatching.isThreadSafe();
     105                Dispatching.invokeLaterOrNow(this, new Runnable() {
     106                        @Override
     107                        public void run() {
     108                                listeners.remove(listener);
     109                        }
     110                });
     111        }
     112
     113
     114        protected void fireListChange(Path path, ListChange change) {
     115                assert isActive();
     116                for (InstanceListener l : this.listeners) {
    121117                        l.onListChange(path, change);
    122118                }
    123119        }
    124120
    125 
    126     public final FramsClass getInfoFromCache(Path path) {
    127         return getInfoFromCache(path.getTop().getParam().getContainedTypeName());
    128     }
    129 
    130 
    131     public FramsClass getInfoFromCache(String id) {
    132         assert isActive();
     121        protected void fireFetch(Path path) {
     122                assert isActive();
     123                for (InstanceListener l : this.listeners) {
     124                        l.onFetch(path);
     125                }
     126        }
     127
     128
     129        public final FramsClass getInfoFromCache(Path path) {
     130                return getInfoFromCache(path.getTop().getParam().getContainedTypeName());
     131        }
     132
     133
     134        public FramsClass getInfoFromCache(String id) {
     135                assert isActive();
    133136                return registry.getInfoFromCache(id);
    134137        }
     
    137140
    138141        public AccessInterface createAccess(String name) {
    139         assert isActive();
    140         if (name == null) {
     142                assert isActive();
     143                return registry.createAccess(name);
     144        }
     145
     146
     147        // TODO: make ValueParam
     148        public <T> T get(Node node, Param childParam, Class<T> type) {
     149                return bindAccess(node).get((ValueParam) childParam, type);
     150        }
     151
     152        public void findInfo(final Path path, final Future<FramsClass> future) {
     153                assert isActive();
     154                final String name = path.getTop().getParam().getContainedTypeName();
     155                final FramsClass framsClass = getInfoFromCache(name);
     156                if (framsClass != null) {
     157                        log.trace("info for " + name + " found in cache");
     158                        future.result(framsClass, null);
     159                        return;
     160                }
     161                fetchInfo(path, future);
     162        }
     163
     164        public final AccessInterface bindAccess(Node node) {
     165                assert node.getObject() != null;
     166                AccessInterface access = registry.prepareAccess(node.getParam());
     167                if (access == null) {
     168                        log.error("missing access for: " + node.getParam());
    141169                        return null;
    142170                }
    143                 FramsClass framsClass = getInfoFromCache(name);
    144                 if (framsClass == null) {
    145                         return null;
    146                 }
    147 
    148                 return registry.createAccess(name, framsClass);
    149         }
    150 
    151         public static AccessInterface wrapAccessWithListIfNeeded(CompositeParam param, AccessInterface access) {
    152         if (access == null) {
    153                         return null;
    154                 }
    155         return param.prepareAccessInterface(access);
    156         }
    157 
    158     public AccessInterface prepareAccess(CompositeParam param) {
    159         return wrapAccessWithListIfNeeded(param, createAccess(param.getContainedTypeName()));
    160     }
    161 
    162     public <T> T get(Node node, Param childParam, Class<T> type) {
    163         return bindAccess(node).get(childParam, type);
    164     }
    165 
    166     public void findInfo(final Path path, final Future<FramsClass> future) {
    167         assert isActive();
    168         final String name = path.getTop().getParam().getContainedTypeName();
    169         final FramsClass framsClass = getInfoFromCache(name);
    170         if (framsClass != null) {
    171             LOGGER.trace("info for " + name + " found in cache");
    172             future.result(framsClass, null);
    173             return;
    174         }
    175         fetchInfo(path, future);
    176     }
    177 
    178     public final AccessInterface bindAccess(Node node) {
    179         assert node.getObject() != null;
    180         AccessInterface access = prepareAccess(node.getParam());
    181         if (access == null) {
    182                         LOGGER.error("missing access for: " + node.getParam());
    183             return null;
    184         }
    185         access.select(node.getObject());
    186         return access;
    187     }
    188 
    189     public final <T> T getParam(Path path, String id, Class<T> type) {
    190         return Casting.tryCast(type, prepareAccess(path.getTop().getParam()).getParam(id));
    191     }
    192 
    193     public final AccessInterface bindAccess(Path path) {
    194         assert path.isResolved();
    195         return bindAccess(path.getTop());
    196     }
    197 
    198     public void resolve(final String targetPath, final Future<Path> future) {
    199         assert isActive();
    200         final Path path = new Path(this, targetPath);
    201         resolve(path, new Future<Path>() {
    202             @Override
    203             public void result(Path result, Exception e) {
    204                 assert isActive();
    205                 if (e != null) {
    206                     future.result(path, e);
    207                     return;
    208                 }
    209                 if (path.isResolved(targetPath)) {
    210                     future.result(path, null);
    211                     return;
    212                 }
    213                 if (path.isResolved()) {
    214                     future.result(path, new Exception("testing"));
    215                     return;
    216                 }
    217                 resolve(targetPath, future);
    218             }
    219         });
    220     }
    221 
    222     public void resolveAndFetch(final String targetPath, final Future<Path> future) {
    223         assert isActive();
    224         resolve(targetPath, new Future<Path>() {
    225             @Override
    226             public void result(final Path path, Exception e) {
    227                 if (e != null) {
    228                     future.result(path, e);
    229                     return;
    230                 }
    231                 assert path.isResolved(targetPath);
    232                 fetchValues(path, new StateFunctor() {
    233                     @Override
    234                     public void call(Exception e) {
    235                         future.result(path, e);
    236                     }
    237                 });
    238             }
    239         });
    240     }
    241 
    242     public Path createIfNeeded(String path) {
    243         Path p;
    244         while (!(p = new Path(this, path)).isResolved(path)) {
    245             create(p);
    246         }
    247         return p;
    248     }
    249 
    250     public Path create(Path path) {
    251         assert isActive();
    252         assert !path.isResolved();
    253         Path resolved = path.findResolution();
    254         if (!resolved.isResolved()) {
    255             LOGGER.debug("creating: " + path);
    256             AccessInterface access = prepareAccess(path.getTop().getParam());
    257             assert access != null;
    258             Object child = access.createAccessee();
    259             assert child != null;
    260             if (path.size() == 1) {
    261                 root = new Node(root.getParam(), child);
    262             } else {
    263                 bindAccess(path.getUnder()).set(path.getTop().getParam(), child);
    264             }
    265             resolved = path.appendResolution(child);
    266         }
    267         tryRegisterOnChangeEvents(resolved);
    268         return resolved;
    269     }
    270 
    271 
    272 
    273 
    274     public FramsClass processFetchedInfo(File file) {
    275         assert isActive();
    276         FramsClass framsClass = Loaders.loadFramsClass(file.getContent());
    277         if ("/".equals(file.getPath())) {
    278             if (root.getParam().getContainedTypeName() == null) {
    279                 root = new Node((CompositeParam)new ParamBuilder().setName("Instance").setId(name).setType("o " + framsClass.getId()).build(), root.getObject());
    280             }
    281         }
    282         registry.putInfoIntoCache(framsClass);
    283         return framsClass;
    284     }
    285 
    286     public void processFetchedValues(Path path, List<File> files) {
    287         assert isActive();
    288         assert files.size() == 1;
    289         assert path.isTheSame(files.get(0).getPath());
    290         Node node = path.getTop();
    291         MultiParamLoader loader = new MultiParamLoader();
    292         loader.setNewSource(files.get(0).getContent());
    293         loader.addBreakCondition(MultiParamLoader.Status.AfterObject);
    294 
    295         try {
    296             if (node.getParam() instanceof ObjectParam) {
    297                 loader.addAccessInterface(bindAccess(node));
    298                 loader.go();
    299     //            for (NodeListener l : listeners) {
    300     //                l.onChange(this);
    301     //            }
    302                 return;
    303             }
    304 
    305             ListAccess listAccess = ((ListAccess)bindAccess(node));
    306             assert listAccess != null;
    307             listAccess.clearValues();
    308 
    309             AccessInterface elementAccess = listAccess.getElementAccess();
    310             loader.addAccessInterface(elementAccess);
    311             MultiParamLoader.Status status;
    312             while ((status = loader.go()) != MultiParamLoader.Status.Finished) {
    313                 if (status == MultiParamLoader.Status.AfterObject) {
    314                     AccessInterface accessInterface = loader.getLastAccessInterface();
    315 
    316                     String id = listAccess.computeIdentifierFor(accessInterface.getSelected());
    317                     Param param = new ParamBuilder().setType("o " + accessInterface.getId()).setId(id).build();
    318                     Object child = accessInterface.getSelected();
    319                     accessInterface.select(null);
    320                     assert child != null;
    321                     bindAccess(node).set(param, child);
    322                 }
    323             }
    324     //        for (NodeListener l : listeners) {
    325     //            l.onChange(this);
    326     //        }
    327         } catch (Exception e) {
    328             LOGGER.error("exception occurred while loading: " + e);
    329         }
    330 
    331     }
    332 
    333     public static Iterator<String> splitPath(String path) {
    334         List<String> list = new LinkedList<String>();
    335         for (String s : path.split("/")) {
    336             if (!s.isEmpty()) {
    337                 list.add(s);
    338             }
    339         }
    340         return list.iterator();
    341     }
     171                access.select(node.getObject());
     172                return access;
     173        }
     174
     175        public final <T> T getParam(Path path, String id, Class<T> type) {
     176                return Casting.tryCast(type, registry.prepareAccess(path.getTop().getParam()).getParam(id));
     177        }
     178
     179        public final AccessInterface bindAccess(Path path) {
     180                assert path.isResolved();
     181                return bindAccess(path.getTop());
     182        }
     183
     184        public void resolve(final String targetPath, final Future<Path> future) {
     185                assert isActive();
     186                final Path path = getPath(targetPath);
     187                resolve(path, new Future<Path>() {
     188                        @Override
     189                        public void result(Path result, Exception e) {
     190                                assert isActive();
     191                                if (e != null) {
     192                                        future.result(path, e);
     193                                        return;
     194                                }
     195                                if (path.isResolved(targetPath)) {
     196                                        future.result(path, null);
     197                                        return;
     198                                }
     199                                if (path.isResolved()) {
     200                                        future.result(path, new Exception("testing"));
     201                                        return;
     202                                }
     203                                resolve(targetPath, future);
     204                        }
     205                });
     206        }
     207
     208        public void resolveAndFetch(final String targetPath, final Future<Path> future) {
     209                assert isActive();
     210                resolve(targetPath, new Future<Path>() {
     211                        @Override
     212                        public void result(final Path path, Exception e) {
     213                                if (e != null) {
     214                                        future.result(path, e);
     215                                        return;
     216                                }
     217                                assert path.isResolved(targetPath);
     218                                fetchValues(path, new StateFunctor() {
     219                                        @Override
     220                                        public void call(Exception e) {
     221                                                future.result(path, e);
     222                                        }
     223                                });
     224                        }
     225                });
     226        }
     227
     228        public Path createIfNeeded(String path) {
     229                Path p;
     230                while (!(p = getPath(path)).isResolved(path)) {
     231                        create(p);
     232                }
     233                return p;
     234        }
     235
     236        public Path createIfNeeded(Path path) {
     237                assert isActive();
     238                if (path.isResolved()) {
     239                        return path;
     240                }
     241                return create(path);
     242        }
     243
     244        public Path create(Path path) {
     245                assert isActive();
     246                assert !path.isResolved();
     247                Path resolved = path.tryFindResolution();
     248                if (!resolved.isResolved()) {
     249                        log.debug("creating: " + path);
     250                        AccessInterface access = registry.prepareAccess(path.getTop().getParam());
     251                        assert access != null;
     252                        Object child = access.createAccessee();
     253                        assert child != null;
     254                        if (path.size() == 1) {
     255                                root = new Node(root.getParam(), child);
     256                        } else {
     257                                bindAccess(path.getUnder()).set(path.getTop().getParam(), child);
     258                        }
     259                        resolved = path.appendResolution(child);
     260                }
     261                tryRegisterOnChangeEvents(resolved);
     262                return resolved;
     263        }
     264
     265
     266
     267
     268        public FramsClass processFetchedInfo(File file) {
     269                assert isActive();
     270                FramsClass framsClass = Loaders.loadFramsClass(file.getContent());
     271                if ("/".equals(file.getPath())) {
     272                        if (root.getParam().getContainedTypeName() == null) {
     273                                root = new Node((CompositeParam)new ParamBuilder().setName("Instance").setId(name).setType("o " + framsClass.getId()).build(), root.getObject());
     274                        }
     275                }
     276                registry.putInfoIntoCache(framsClass);
     277                return framsClass;
     278        }
     279
     280        public void processFetchedValues(Path path, List<File> files) {
     281                assert isActive();
     282                assert files.size() == 1;
     283                assert path.isTheSame(files.get(0).getPath());
     284                Node node = path.getTop();
     285                MultiParamLoader loader = new MultiParamLoader();
     286                loader.setNewSource(files.get(0).getContent());
     287                loader.addBreakCondition(MultiParamLoader.Status.AfterObject);
     288
     289                try {
     290                        if (node.getParam() instanceof ObjectParam) {
     291                                loader.addAccessInterface(bindAccess(node));
     292                                loader.go();
     293                                fireFetch(path);
     294        //            for (NodeListener l : listeners) {
     295        //                l.onChange(this);
     296        //            }
     297                                return;
     298                        }
     299
     300                        ListAccess listAccess = ((ListAccess)bindAccess(node));
     301                        assert listAccess != null;
     302                        listAccess.clearValues();
     303
     304                        AccessInterface elementAccess = listAccess.getElementAccess();
     305                        loader.addAccessInterface(elementAccess);
     306                        MultiParamLoader.Status status;
     307                        while ((status = loader.go()) != MultiParamLoader.Status.Finished) {
     308                                if (status == MultiParamLoader.Status.AfterObject) {
     309                                        AccessInterface accessInterface = loader.getLastAccessInterface();
     310
     311                                        String id = listAccess.computeIdentifierFor(accessInterface.getSelected());
     312                                        Param param = new ParamBuilder().setType("o " + accessInterface.getId()).setId(id).build();
     313                                        Object child = accessInterface.getSelected();
     314                                        accessInterface.select(null);
     315                                        assert child != null;
     316                                        bindAccess(node).set((ValueParam) param, child);
     317                                }
     318                        }
     319
     320                        fireFetch(path);
     321        //        for (NodeListener l : listeners) {
     322        //            l.onChange(this);
     323        //        }
     324                } catch (Exception e) {
     325                        log.error("exception occurred while loading: " + e);
     326                }
     327
     328        }
     329
     330        public static Iterator<String> splitPath(String path) {
     331                List<String> list = new LinkedList<String>();
     332                for (String s : path.split("/")) {
     333                        if (!s.isEmpty()) {
     334                                list.add(s);
     335                        }
     336                }
     337                return list.iterator();
     338        }
    342339
    343340        public Registry getRegistry() {
    344341                return registry;
    345342        }
     343
     344        public Path getPath(String textual) {
     345                return new Path(this, textual);
     346        }
     347
     348        public Path getRootPath() {
     349                return getPath("/");
     350        }
    346351}
    347352
Note: See TracChangeset for help on using the changeset viewer.