Re: Action and ActionConvertors

[email protected] Fri, 25 Feb 2005 08:20:49 +0100
Newsgroups gmane.comp.embedded.carlsbad-cubes
Organization http://freemail.web.de/
Message-ID <[email protected]>
List for Users of Carlsbad Cubes' Technologies and Products <[email protected]> schrieb am 24.02.05 23:06:42:
> 
> Hi
> 
> I saw the foll code in Parser.java
> 
>             if (Action.class.equals( paraType )) {
>               para = engine.getClient().getClass().getField( attr.getValue() ).get( engine.getClient() );
>               action = (Action) para;
>             } else {
>               para = converter.convert( paraType, attr, engine.getLocalizer() );
>             }
> 
> 			method.invoke( obj, new Object[]{para} ); // ATTR SET
> 
> But after the method.invoke, the action object is not used again, that I can
> see.  Can someone please give a quick explanation, or a pointer for where to
> look further?

Have a careful look at the code, it is (or may be) used again ;) Probably you
look in the wrong direction? It is not obvious, though...

> 
> I am assuming that if this Action was associated with a button or something,
> then that button has to call the action when clicked? Where can I find the
> code for this in Swix?

It is the line you mentioned:
method.invoke( obj, new Object[]{para} ); // ATTR SET

If the (first) argument type of the associated method (e.g. for the attribute  
'xyz="abc"' the code looks in the "tag class", e.g. JLabel for the <label>-tag
for a method  named setXyz. For the attribute name "action", it evaluates
to setAction, conveniently provided with a Action-type as on and only
parameter.

> 
> The method object is retrieved using a guessSetter .. for my action, say Back,
> I have a setter method setBack(Action a) in my class as well as a getBack().

If you mean "my class" as in "the tag class implementing my UI element" you
are right. The getBack() method is not used because it there is no code to
query the value of the "back" in the "tag class" (see above). There are only
setters needed -- that's the whole thing for.

> 
> However, instead of using getBack() as I would expect, the code on line 2
> above looks for a field of my class called Back (lcased) rather than a getter ?

Yes, if you mean "my class" as in "the object I gave to the
SwingEngine(myClass) or by extension of SwingEngine".

> 
> In short, it uses setters, but not getters?

The reason is simple: SwixML uses setters if there is no other choice.
E.g. the attribute "action" setted indirectly in <button
action="myAction"> boils down to AbstractButton.action which is
private. Furthermore, the AbstractButton.setAction(Action a) does
a bit more the just
this.action = action;
So, SwixML has to use the setter, likewise in probably 99% of all
other attribute assignments. The attribute "myAction" of the class
provided to the SwingEngine-constructor is another thing. It may
be seen as "public interface" because it is used as user interface
anyway -- that's what actions are for, arent't they? See the
public Action attributes somewhat as unibersal "button"
represantations. The last point is pure practical: the object given
to SwingEngine is usally written by yourself, so you have the
choice/possibility to make these attributes public.

I hope I did shed some light on the topic,

Frank

> 
> thx,
> n
> 
> -- 
> Nandan Bagchee
> 
> Excuse me, but what the hell?
> 
> 	-- Slava Pestov
> 	   on seeing:
>   	   FunctorParser parser = new FunctorParser();
>   	   BinaryFunctor toggleOther = parser.parseBinary("x.setEnabled(!x.isEnabled())",
> 	   											   JButton.class, ActionEvent.class);
> 
> 
> 
> 
> _______________________________________________
> Forum mailing list
> [email protected]
> http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com