Thursday, February 25, 2010

Misc Pivot stuff

Padding choices
In wtkx, adding padding usually looks like: styles="{padding:10}". Nice if you want 10px all around, but you can also specify each side styles="{padding:{top:1,left:2,bottom:3,right:4}}".

Adding validators inline
Normally to add a validator to a component, you code something similar to
@WTKX
private TextInput maxFileSize;
...
...
maxFileSize.setValidator(new IntRangeValidator(0, Integer.MAX_VALUE));
Seems like a bit of a waste? In WTKX, you can include any object that has a no-argument constructor. So we can inline the whole thing.
  1. Include the package to your object as part of the xml namespace (notice xmlns:text)
  2. Define the validator.
  3. attach it to your component
<Sheet wtkx:id="exportDialog" title="Generate Crawl List"
    xmlns:wtkx="http://pivot.apache.org/wtkx"
    xmlns:text="org.apache.pivot.wtk.text.validation"
    xmlns="org.apache.pivot.wtk"  styles="{padding:10}">
 <wtkx:define>
     <text:intrangevalidator id="numvalidator"
       minimum="0" maximum="2147483647"/>
 </wtkx:define>
 <content>
...
...
   <textinput textkey="maxFileSize" validator="$numvalidator"
    id="maxFileSize" text="0"/>
...
 </content>
</Sheet>