Re: [Figleaf-developer] Need for a ViewRegistry
Status: Alpha
Brought to you by:
steckman
|
From: Greg S. <ste...@on...> - 2004-07-05 14:57:35
|
sam...@ma... wrote: >Playing around with your SwingViewer last night, I had some problems getting my >registered views to be picked up. I think this is down to the fact that I didn't >register specific classes with views - that is I registered Informative not my >applications ImageAlbum class. I think we could do with defining a ViewRegistry >class which could be used with any viewing mechanism. It would define the >following methods: > >void addViewMapping(Class clazz, View view); > >View getView(Class clazz); > >And would define the following behaviour: > >1. If a direct mapping exists, it returns that view >2. If no direct mapping exists, it looks for mappings for its immediate >superclass, then interfaces >3. If no mapping exists for its immediate superclass or interfaces, it >recursively traverses the superclass structure looking for a match >4. Finally if no match can be found null is returned. > >This allows us to assume a mapping for Informative but let the user override >this. It also lets us map to classes or interfaces - your code seems to only >support mapping to interfaces. This should be a very simple thing to write and >can drop right into your code (it should even make your code a little simpler) - >I'm happy to work on this while you concentrate on the UI if you want. > >sam >http://www.magpiebrain.com/ > > > > The implementation is already written to do precisely this. It first traverses the complete class hierarchy, if none found it then traverses the interface hierarchy in a way to try and find the closest superinterface (in terms of inheritence distance) for which there is a view registered. I was going to write some test cases for it next though...because it hasn't been tested on anything but the InformativeDescriptorImpl class. That said, I registered a view for Informative, and it found it for my InformativeDesctiprorImpl which implements Informative directly, so I'm not sure why it didn't work on your ImageAlbum class. Perhaps once I write a test I will see... Greg |