2012-05-26 44 views
5

爲了簡潔起見:如何編輯Set <?用GWT編輯器框架擴展EntityProxy>?

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

public class Address 
{ 
    String city; 
    String street; 
} 

與和匹配

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

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

我UiBuinder類編輯AddressProxy ,它清楚地知道如何使用ListEditor在如果我有List但數據設置在Person類中 如何使用Editor Framework編輯它們? 或者當它變成PersonProxy時,我該如何將設置轉換爲列表?在

我做了一個企圖把一種適配器編輯器類將實現

LeafValueEditor<Set<AddressProxy>> 

,然後LeafValueEditor.setValue()移動到列表內,開始新的driver.edit()一個獨立的編輯器層次結構,負責列表編輯,但現在運氣好。

回答

6

您應該創建CompositeEditor<Set<AddressProxy>, AddressProxy, AddressEditor>,類似於ListEditor,但是處理Set而不是List。 我想你可以以某種方式委託給ListEditor,儘管我真的不確定。

+0

謝謝!這是從一開始。坦率地懶惰我希望鏈接到一些代碼:-)。 –

+1

我認爲一些標準的'SetEditor'(可能委託給'ListEditor')應該由GWT提供。我和OP有同樣的問題,最後暴露了List類的訪問器(轉換真正的Set類型的屬性),只是爲了能夠使用ListEditor。但是並不總是可以做到的(有時候我們只需要在客戶端使用Set-wise行爲) –

+2

問題是a)按定義設置沒有特定順序,值的子編輯器必須是_list_, b)你可能想要在編輯過程中允許重複的值,並且只在_flush_時間檢查唯一性,但是你必須以某種方式告訴用戶何時是這種情況(「嘿,我有4個值,當我保存時只保留3個值他們!「);唯一性取決於你如何在編輯的對象中實現equals()。如果你可以想出一個_standard_'SetEditor',那麼請提供它! –

3

我已經點和路線(一條路線包含N個點)來完成它:

路線(複合):

@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);   
    } 

路線(服務器端):

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

Rout eProxy

public interface RouteProxy extends EntityProxy { 

     abstract List<PointProxy> getPoints(); 

     abstract void setPoints(List<PointProxy> points); 

PointProxy

public interface PointProxy extends ValueProxy { 

... 

} 
+0

我明白你的意思,但問題是: 鑑於PointProxy有幾個字段和一個編輯器自我如何連接點? 並注意,問題是關於Set 而不是列表列表編輯在GWT SDK中給出的幫助類和相應的示例代碼是微不足道的。 –

+0

忘了提及RouteProxy(EntityProxy)和PointProxy(ValueProxy)。這兩個答案都加上了。試着用Set來代替List。 –