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

780 views Asked by At

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.

2

There are 2 answers

3
Thomas Broyer On BEST ANSWER

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.

2
André Salvati On

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 {

...

}