Hi Niclas,
It looks very convenient. I'd really like to try it.
What if multiple adapters can handle a property type (for instance combobox and
checkbox for boolean or slider and
textfield for number etc) ?
Perhaps a hint annotation at the property helps.
Do you plan to do something about the layouting (position, groups, order,
separators) and presentation (titles,
tooltips, formats) as well?
Perhaps you can commit it to the 0.2 version of the branch ?
Michael
Niclas Hedhman schrieb:
> Gang,
> I am working on a demo of Qi4j + Swing, and looking at how to do widget
> bindings.
>
> Let's say we have;
>
> public interface Person
> {
> Property<String> firstName();
> Property<String> lastName();
> Property<Address> address();
> }
> public interface Address
> {
> Property<String> line1();
> Property<String> line2();
> :
> }
>
> // Swing "as usual"
> public class PersonPanel extends JPanel
> {
> public PersonPanel( StateModel<Person> model )
> {
> TextField tf1 = new TextField();
> add( tf1 );
> model.bind( model.firstName() ).to( tf1 );
>
> TextField tf3 = new TextField();
> add( tf3 );
> model.bind( model.address().get().line1() )
> .to( tf3 );
> }
> }
>
> Right now the StateModel is a normal class that needs to be created with the
> ObjectBuilder, but we are planning to make it into a Composite instead.
>
> Additionally, there are SwingAdapters which are responsible for the actual
> binding, and the requirements of those are;
>
> * implement SwingAdapter
> * be ServiceComposites
> * be visible from where the StateModel is used.
>
> The SwingAdapter looks like this;
>
> public interface SwingAdapter
> {
> Set<Pair> canHandle();
>
> void fromSwingToProperty( JComponent component, Property<?> property );
>
> void fromPropertyToSwing( JComponent component, Property<?> property );
>
> public class Pair
> {
> public Class<? extends JComponent> component;
> public Class<?> propertyType;
>
> public Pair( Class<? extends JComponent> component,
> Class<?> propertyType )
> {
> this.component = component;
> this.propertyType = propertyType;
> }
> }
> }
>
> All SwingAdapters will be looked up in the "bind" phase, and asked for which
> type and component combinations they can handle.
>
>
> The "use"-phase is when a Person instance is set to the StateModel, such as;
>
> StateModel<Person> model = .... ;
> PersonPanel panel = new PersonPanel( model );
> :
> :
> model.use( somePerson );
> :
> :
> model.use( someOtherPerson );
>
>
> Changes to the Property instance in "Person" will occur on focusLost events.
> There are no buffering, as it is expected that all objects modified are
> backed by a UnitOfWork.
>
>
> We don't want to commit the code to trunk, since trunk is unstable at the
> moment and the small sample can't be run. That is just a matter of... days?
> Until then, I will fix up Associations and ManyAssociations.
>
> Ok folks, WDYAT??
>
>
> This will all end up in a library, and this is a perfect project for YOU to
> get your hands dirty, since a lot of work is needed for the binding adapters.
>
>
> Cheers
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev