You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Bill van Melle <bi...@gmail.com> on 2011/10/19 06:16:09 UTC
Why can't I set a TabPane's buttonPadding to a dictionary?
I must be missing something really obvious here. TablePane happily
accepts a padding value expressed as a dictionary. So does Label.
But when the bxml serializer gets down to the TabPane below where I
try to set its buttonPadding to the same dictionary, it barfs, saying
"Unable to coerce org.apache.pivot.collections.HashMap to class
org.apache.pivot.wtk.Insets". Aren't the padding values also of type
Insets? What am I doing wrong?
<Window xmlns="org.apache.pivot.wtk">
<TablePane styles="{padding:{left:10,right:10,top:5,bottom:5}}">
<columns>
<TablePane.Column width="1*" />
</columns>
<TablePane.Row>
<Label text="Some text"
styles="{padding:{left:10,right:10,top:5,bottom:5}}" />
</TablePane.Row>
<TablePane.Row>
<TabPane styles="{buttonPadding:{left:10,right:10,top:5,bottom:5}}" >
<BoxPane TabPane.tabData="Test" />
</TabPane>
</TablePane.Row>
</TablePane>
</Window>
Re: Why can't I set a TabPane's buttonPadding to a dictionary?
Posted by Chris Bartlett <cb...@gmail.com>.
The problem is exacerbated in this case because Insets is immutable
and doesn't have a zero arg constructor, so cannot be instantiated
directly in BXML either. Otherwise you could have worked around by
creating your own Insets instance explicitly and setting is against
the 'buttonPadding' style
On 19 October 2011 11:55, Chris Bartlett <cb...@gmail.com> wrote:
> It is due to the different setters in the TabPane's skin.
> http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.html
>
> The 'buttonPadding' style only has explicit setters for Insets and int
> void setButtonPadding(Insets)
> void setButtonPadding(int)
>
> But 'padding' has setters for these.
> void setPadding(Dictionary<String,?> padding)
> void setPadding(Insets padding)
> void setPadding(int padding)
> void setPadding(Number padding)
> void setPadding(String padding)
>
> Off the top of my head, I think it is because BXMLSerializer handles
> the parsing of the 'styles' attribute (via Pivot's JSONSerializer) and
> produces a HashMap. BXMLSerializer then tries to find a setter in
> TerraTabPaneSkin that accepts a HashMap.
>
> As you see above, 'padding' has a setter which a Dictionary argument,
> but 'buttonPadding' doesn't, so it fails, but only after trying to
> coerce the HashMap to an Inset.
>
>
> This current process is simple and transparent, but means that if you
> had a skin with 10 different style properties that controlled various
> padding settings, each would need to have the same multiple setters in
> order to maintain a level of consistency and flexibility for those
> properties.
>
> BXMLSerializer could perhaps go one step further in the coercion phase
> and attempt to find a single parameter constructor on the
> 'destination' type which accepts the 'source' type? (I haven't fully
> thought through the implications of this, so it might not work or be
> desirable behaviour.) Then the multiple setters could be removed, and
> the various constructors used instead.
>
> Chris
>
> On 19 October 2011 11:16, Bill van Melle <bi...@gmail.com> wrote:
>> I must be missing something really obvious here. TablePane happily
>> accepts a padding value expressed as a dictionary. So does Label.
>> But when the bxml serializer gets down to the TabPane below where I
>> try to set its buttonPadding to the same dictionary, it barfs, saying
>> "Unable to coerce org.apache.pivot.collections.HashMap to class
>> org.apache.pivot.wtk.Insets". Aren't the padding values also of type
>> Insets? What am I doing wrong?
>>
>> <Window xmlns="org.apache.pivot.wtk">
>> <TablePane styles="{padding:{left:10,right:10,top:5,bottom:5}}">
>> <columns>
>> <TablePane.Column width="1*" />
>> </columns>
>> <TablePane.Row>
>> <Label text="Some text"
>> styles="{padding:{left:10,right:10,top:5,bottom:5}}" />
>> </TablePane.Row>
>> <TablePane.Row>
>> <TabPane styles="{buttonPadding:{left:10,right:10,top:5,bottom:5}}" >
>> <BoxPane TabPane.tabData="Test" />
>> </TabPane>
>> </TablePane.Row>
>> </TablePane>
>> </Window>
>>
>
Re: Why can't I set a TabPane's buttonPadding to a dictionary?
Posted by Chris Bartlett <cb...@gmail.com>.
Sandro,
I don't have time to commit anything at the moment, but a ticket would
be good. I'll wait to see if anyone else has any ideas or
suggestions.
Noel's fix was to create extra setters, which is absolutely fine, but
a more flexible approach *might* be useful and would allow us to
remove quite a lot of setters. This would be similar to when I added
in the support for Enums into the BeanAdapter coercion code.
Overall though, I don't think this is a huge problem.
Chris
On 19 October 2011 17:34, Sandro Martini <sa...@gmail.com> wrote:
> Hi all,
>
> @Bill,
> thank for having found the problem.
>
> @Chris:
> I've just seen that Noel has committed a fix for this, and resolved the issue :
> https://issues.apache.org/jira/browse/PIVOT-804
> On your suggested changes I think could be an interesting feature to
> have a more generalized approach, probably it would be better to add a
> ticket for 2.1, and attach there some patch, or commit as soon as
> we'll freeze the 2.0.x in a maintenance branch, Ok ?
>
> Bye,
> Sandro
>
Re: Why can't I set a TabPane's buttonPadding to a dictionary?
Posted by Sandro Martini <sa...@gmail.com>.
Hi all,
@Bill,
thank for having found the problem.
@Chris:
I've just seen that Noel has committed a fix for this, and resolved the issue :
https://issues.apache.org/jira/browse/PIVOT-804
On your suggested changes I think could be an interesting feature to
have a more generalized approach, probably it would be better to add a
ticket for 2.1, and attach there some patch, or commit as soon as
we'll freeze the 2.0.x in a maintenance branch, Ok ?
Bye,
Sandro
Re: Why can't I set a TabPane's buttonPadding to a dictionary?
Posted by Chris Bartlett <cb...@gmail.com>.
On 19 October 2011 11:55, Chris Bartlett <cb...@gmail.com> wrote:
> BXMLSerializer could perhaps go one step further in the coercion phase
> and attempt to find a single parameter constructor on the
> 'destination' type which accepts the 'source' type? (I haven't fully
> thought through the implications of this, so it might not work or be
> desirable behaviour.) Then the multiple setters could be removed, and
> the various constructors used instead.
(Just noting a few things that popped into my head as a result of this...)
The type coercion is performed in the BeanAdapter.coerce(Object,
Class) static method.
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/beans/BeanAdapter.html#coerce(java.lang.Object,
java.lang.Class)
http://svn.apache.org/repos/asf/pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java
I suppose another option would be to create a trivial convert/coerce
interface and accompanying registry to maintain the mappings.
BeanAdapter.coerce() could query the registry and use a found
converter instance, either instead of the built in coercion or if the
built in one failed.
A very simple kind of service provider interface might be a good fit.
Just drop the converter implementations in a specific classpath
location and BeanAdapter would take care of registering whatever it
discovered when it is first instantiated.
Chris
Re: Why can't I set a TabPane's buttonPadding to a dictionary?
Posted by Chris Bartlett <cb...@gmail.com>.
It is due to the different setters in the TabPane's skin.
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/skin/terra/TerraTabPaneSkin.html
The 'buttonPadding' style only has explicit setters for Insets and int
void setButtonPadding(Insets)
void setButtonPadding(int)
But 'padding' has setters for these.
void setPadding(Dictionary<String,?> padding)
void setPadding(Insets padding)
void setPadding(int padding)
void setPadding(Number padding)
void setPadding(String padding)
Off the top of my head, I think it is because BXMLSerializer handles
the parsing of the 'styles' attribute (via Pivot's JSONSerializer) and
produces a HashMap. BXMLSerializer then tries to find a setter in
TerraTabPaneSkin that accepts a HashMap.
As you see above, 'padding' has a setter which a Dictionary argument,
but 'buttonPadding' doesn't, so it fails, but only after trying to
coerce the HashMap to an Inset.
This current process is simple and transparent, but means that if you
had a skin with 10 different style properties that controlled various
padding settings, each would need to have the same multiple setters in
order to maintain a level of consistency and flexibility for those
properties.
BXMLSerializer could perhaps go one step further in the coercion phase
and attempt to find a single parameter constructor on the
'destination' type which accepts the 'source' type? (I haven't fully
thought through the implications of this, so it might not work or be
desirable behaviour.) Then the multiple setters could be removed, and
the various constructors used instead.
Chris
On 19 October 2011 11:16, Bill van Melle <bi...@gmail.com> wrote:
> I must be missing something really obvious here. TablePane happily
> accepts a padding value expressed as a dictionary. So does Label.
> But when the bxml serializer gets down to the TabPane below where I
> try to set its buttonPadding to the same dictionary, it barfs, saying
> "Unable to coerce org.apache.pivot.collections.HashMap to class
> org.apache.pivot.wtk.Insets". Aren't the padding values also of type
> Insets? What am I doing wrong?
>
> <Window xmlns="org.apache.pivot.wtk">
> <TablePane styles="{padding:{left:10,right:10,top:5,bottom:5}}">
> <columns>
> <TablePane.Column width="1*" />
> </columns>
> <TablePane.Row>
> <Label text="Some text"
> styles="{padding:{left:10,right:10,top:5,bottom:5}}" />
> </TablePane.Row>
> <TablePane.Row>
> <TabPane styles="{buttonPadding:{left:10,right:10,top:5,bottom:5}}" >
> <BoxPane TabPane.tabData="Test" />
> </TabPane>
> </TablePane.Row>
> </TablePane>
> </Window>
>
Re: Why can't I set a TabPane's buttonPadding to a dictionary?
Posted by Chris Bartlett <cb...@gmail.com>.
Can you please provide the relevant stack track too?
On 19 October 2011 11:16, Bill van Melle <bi...@gmail.com> wrote:
> I must be missing something really obvious here. TablePane happily
> accepts a padding value expressed as a dictionary. So does Label.
> But when the bxml serializer gets down to the TabPane below where I
> try to set its buttonPadding to the same dictionary, it barfs, saying
> "Unable to coerce org.apache.pivot.collections.HashMap to class
> org.apache.pivot.wtk.Insets". Aren't the padding values also of type
> Insets? What am I doing wrong?
>
> <Window xmlns="org.apache.pivot.wtk">
> <TablePane styles="{padding:{left:10,right:10,top:5,bottom:5}}">
> <columns>
> <TablePane.Column width="1*" />
> </columns>
> <TablePane.Row>
> <Label text="Some text"
> styles="{padding:{left:10,right:10,top:5,bottom:5}}" />
> </TablePane.Row>
> <TablePane.Row>
> <TabPane styles="{buttonPadding:{left:10,right:10,top:5,bottom:5}}" >
> <BoxPane TabPane.tabData="Test" />
> </TabPane>
> </TablePane.Row>
> </TablePane>
> </Window>
>