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

2

5

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.

Consequential answered 26/5, 2012 at 1:37 Comment(0)
I
6

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.

Inanition answered 26/5, 2012 at 9:14 Comment(3)
Thanks! This is something to start with. Frankly lazy me hoped for a link to some code :-).Consequential
I think some type of standard SetEditor (probably delegating to ListEditor) should be provided by GWT. I had the same problem as OP and ended up exposing List-typed accessors (converting real Set-typed property) on domain class just to be able to use ListEditor. But it's not always possible to do (sometimes we just need Set-wise behaviour on client side)Aluminate
The problem is that a) a Set by definition has no specific order and sub-editors for the values are necessarily a list, and b) you probably want to allow duplicate values in the course of editing and only check uniqueness at flush time, but you have to somehow tell the user when that's the case ("hey, I had 4 values and when I saved it only kept 3 of them!"); and uniqueness depends on how you implemented equals() in the edited objects. If you can come up with a standard SetEditor however, then please contribute it!Inanition
E
3

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 {

...

}
Examen answered 26/5, 2012 at 21:24 Comment(2)
I see what you mean but the question is: Given that the PointProxy has several fields and an Editor of it self how I connect the dots? And pay attention that the question is about Set<?> not List<?> list editing is trivial given helper class in GWT SDK and corresponding sample code.Consequential
Forgot to mention RouteProxy (EntityProxy) and PointProxy (ValueProxy). Both were added on the answer. Just try to do with Set in place of List.Merci

© 2022 - 2024 — McMap. All rights reserved.