Re: Re: SwiXML robustitude

Frank Meissner <[email protected]> Fri, 14 Jan 2005 20:22:15 +0100
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Chuck Dillon wrote:
> Frank Meissner wrote:
> 
>>>>
>>>>> Q5) How well does it support GUI glue functionality?  ...  Can 
>>>>> object A reference object B in the XML?
>>>>
>>>>
>>>> This is not a builitin facility in swixml. You may try to solve this 
>>>> through
>>>> custom converters, but I'm not sure whether this is possible...
>>>
>>>
>>> Unfortunate, it would be a powerful feature.
>>
>>
>>
>> But not that easy to implement if the requirements are somewhat 
>> advanced. E.g. I had the problem I wanted to disable a button if the 
>> number of lines is less than one. This is not that trivial 
>> (describable in XML) but perhaps it's out of your intended scope...
> 
> 
> Let me preface the following comments with admitting I'm basing them on 
> limited information about SwiXML.  I've been looking at the samples and 
> browsing the JavaDoc.  But since I can't find any detail functional 
> description of it's capabilities I'm assuming what's in the samples is 
> what there is.
> 
>  From the samples it appears the XML references Java Objects by name 
> using tags like "id" and "action".  This direct reference by name is a 
> useful feature but if it is the only way to bind the XML to the code it 
> is too limiting IMHO.  It forces me to mirrow the GUI structure with 
> Java code which has marginal utility.  What is needed is an indirect way 
> of referencing objects so that I don't need Java code that shadows the 
> GUI structure.  I want to be able to build the majority of my action 
> code so that it can be applied to the GUI by indirect reference so that 
> my business logic is as agnostic as possible about the GUI.
> 
> What I'm suggesting is that the engine needs an indirect way to revolve 
> what tags like "id" and "action" are referring to.  I envision the 
> SwingEngine class (or something within) to have a methods  like:
>  - registerActionClass(String nameToBeUsedInXML,Class class)

Chuck, this can already be done through the use of "initclass" (sorry to 
get always on this subject). Just use e.g. <button 
initclass="MyActionClass"/> and another <menuitem 
initclass="MyActionClass"/>. This is the way I choose generally for the 
main application frame where some "heavy" actions are mentioned but need 
to remain configurable. To instantiate all these actions in the class 
calling swingEngine.render(myMainGuiFile) sounds not that charming to 
me. Especially when I discover I did forget to instantiate one or they 
are expensive in creation and only some users see them in their GUI at 
all. I always wanted to write a tutorial or some examples about this...

>  - registerActionInstance(String nameToBeUsedInXML,AbstractAction action)

This can somewhat be done by using a singleton for the action class. But 
it limits the number of actions to one. E.g. in the example given above, 
you may use a singleton-function "getInstance()" in MyActionClass. Then, 
you only have a single instance of MyActionClass...


>  - registerDataObject(String nameToBeUsedInXML,Object object)
> Then I can create an action class or instance or a data object, register 
> it and use it whereever I want in the GUI.  I'm not seeing this kind of 
> capability.  Is it there?
> 

If you can provide the object as constructor parameter, you may use the 
"initclass" attribute. There are limitations, though:
- only a single parameter may be used (initclass cannot mention multiple 
classes)
- the number of GUI elements using a specific initclass is either n:1 
(through singleton) or n:n

Does this help you somewhat?

Frank