Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit a Set<? extends EntityProxy> with GWT Editor framework?

for sake of simplicity:

public class Person 
{
    String name; 
    Set<Address> addresses;
}

public class Address
{
     String city;
     String street;
}

with and matching

public interface PersonProxy extends EntityProxy 
{
     public String getName();
     public Set<AdressProxy> getAddresses();
}

and

public interface AdressProxy extends EntityProxy 
{
    public String getCity();
    public String getStreet();
}

I got UiBuinder classes to edit AddressProxy and it clear to me how to use ListEditor in case if I got List but data is Set in the Person class how do I use Editor Framework to edit them? Or may be how do I convert Set to List when it becomes PersonProxy?

I did an attempt to put a kind of adapter Editor class that would implement

LeafValueEditor<Set<AddressProxy>>

and then inside of the LeafValueEditor.setValue() move to a List and start a new driver.edit() on a separate Editor hierarchy that takes care of List editing but with now luck.

like image 934
Boris Daich Avatar asked May 26 '12 01:05

Boris Daich


2 Answers

You should create a CompositeEditor<Set<AddressProxy>, AddressProxy, AddressEditor>, similar to a ListEditor but handling a Set instead of a List. I suppose you could somehow delegate to a ListEditor though I'm really not sure.

like image 200
Thomas Broyer Avatar answered Nov 08 '22 12:11

Thomas Broyer


I've done it with Points and Routes (one Route contains N Points):

Route (Composite):

@UiField
TextBox name;

@Ignore
@UiField
FlexTable listPoints;

PointsEditor pointsEditor = new PointsEditor();

     ....

pointsEditor.add(String id);

PointsEditor:

public class PointsEditor implements HasRequestContext<List<PointProxy>>, ValueAwareEditor<List<PointProxy>> {

    List<PointProxy> points = new ArrayList<PointProxy>(); 

    public void add(String id) {
       PointProxy point = ctx.create(PointProxy.class);
       point.setId(id);
       points.add(point);           
    }

Route (server side):

@Embedded
private List<Point> points = new ArrayList<Point>();

RouteProxy

public interface RouteProxy extends EntityProxy {

       abstract List<PointProxy> getPoints();

       abstract void setPoints(List<PointProxy> points);

PointProxy

public interface PointProxy extends ValueProxy {

...

}
like image 3
André Salvati Avatar answered Nov 08 '22 12:11

André Salvati