Hmm, Google Groups doesn't appear to let me reply to Lukas's post, so I 
will do it here.

I ended up writing a couple of classes. The first was a pretty basic 
RecordListener that fires off changes in response to updates, inserts and 
deletes.

The other one was more complex. It lets objects be registered for receiving 
callbacks based on updates, deletes and inserts. Registration happens with 
methods like

    public void registerForUpdate(Object receiver, UpdatableRecord<?> 
thatChanged, Field<?> ... fields)

    

where 'receiver' annotates a method to be called back, whenever an 
UpdateableRecord matching the primary key of 'thatChanged' was updated 
where one of 'fields' changed.


The annotated methods on receiver look like 


    @Receiver(recordType=UpdatableRecord.class, handlerType=HandlerTypes.
UPDATE)

    public void recordChanged(UpdatableRecord<?> r, Boolean newSelection)

For reference, a simple checkbox that is bound to a particular field looks 
like this. 

public class BoundCheckBox extends JCheckBox

{

    private UpdatableRecord<?> myRecord;

    private Field<Boolean> myField;


    public BoundCheckBox(UpdatableRecord<?> bindMe, Field<Boolean> 
bindField, RecordDispatcher rd)

    {

        myRecord = bindMe;

        myField  = bindField;

        

        setSelected(bindMe.getValue(bindField));

        

        addActionListener

        (

                new ActionListener()

                {

                    @Override

                    public void actionPerformed(ActionEvent arg0)

                    {

                        myRecord.setValue(myField, isSelected());

        myRecord.update();

                    }

                }

        );

        

        rd.registerForUpdate(this, myRecord, myField);

    }


    private void selectionChanged()

    {

        

    }

    

    @Receiver(recordType=UpdatableRecord.class, handlerType=HandlerTypes.
UPDATE)

    public void recordChanged(UpdatableRecord<?> r, Boolean newSelection)

    {

        if (!newSelection.equals(isSelected()))

        {

            setSelected(newSelection);

        }

    }



On Thursday, May 1, 2014 7:49:13 AM UTC+10, Joe Thurbon wrote:
>
> Sorry if this is already solved elsewhere, but I haven't been able to find 
> this here or on StackOverflow.
>
> First off, great framework! So happy to find it.
>
> I'm building a small swing GUI, and have found myself writing a lot of 
> stub classes that extend Observable for the BlahRecord classes generated by 
> jOOQ so I could do MVC "properly".
>
> Things like
>
> public class MyClass extends Observable
> {
>     private MyClassRecord wasGeneratedByJOOQ;
>
>     public void setSomeField(String newValue)
>     {
>        if (!newValue.equals(wasGeneratedByJOOQ.getSomeField()))
>        {
>            setChanged();
>            wasGeneratedByJOOQ.setSomeField(newValue);
>            notifyObservers(newValue);
>        }
>     }
>
>     ...etc for each field
> }
>
> There seem to be three ways to go about this, but I was wondering if 
> someone had already just solved the whole binding issue for swing anyway.
>
> For what it's worth, the three ways I think this could be solved would be
>
>
>    1. Find the right place in the Record<> class hierarchy to make 
>    something extend Observable and change the definition of "setField()" in 
>    updatable record (this seems a poor choice, because it's classes all the 
>    way up to AbstractStore, which really has no business being Observable)
>    2. Generate something like at PoJo at the class generation time, but 
>    that just wraps a record-derived class for its implementation, as per the 
>    above code (this seems like a reasonable choice, but might be missing 
>    something very obvious)
>    3. Find out what someone who's already solved this problem would do :)
>
>
> Any advice would be most appreciated. Even if the advice is "step back, 
> there's better ways to solve this MVC thing with JOOQ"
>
> Many thanks,
> Joe
>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to