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.

Boris Daich
  • 2,431
  • 3
  • 23
  • 27

2 Answers2

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.

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks! This is something to start with. Frankly lazy me hoped for a link to some code :-). – Boris Daich May 28 '12 at 08:05
  • 1
    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) – Piotr Sobczyk May 29 '12 at 09:28
  • 2
    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! – Thomas Broyer May 29 '12 at 10:40
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 {

...

}
André Salvati
  • 504
  • 6
  • 17
  • 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. – Boris Daich May 28 '12 at 16:24
  • Forgot to mention RouteProxy (EntityProxy) and PointProxy (ValueProxy). Both were added on the answer. Just try to do with Set in place of List. – André Salvati May 28 '12 at 17:04