2012-04-08 45 views
3

我在我的POJO中有一個HashMap,我正在使用GWT中的編輯器框架進行編輯。雖然我可以訪問通過getter/setter綁定的標準成員變量,但我不知道如何訪問HashMap中的值。我如何通過使用SimpleBeanEditorDriver的編輯器訪問正在編輯的底層POJO?如何從GWT編輯器訪問底層的POJO類

我的POJO:

@Entity(noClassnameStored=true) 
public class ProfileConfig extends BaseEntity { 
    @Indexed(unique=true) 
    private String name; 
    private boolean isDefault; 
    private HashMap<ProfileID, ProfileInfo> profiles= new HashMap<ProfileID, ProfileInfo>(); 

    public ProfileInfo getProfile(ProfileID id) { 
      return profiles.get(id); 
    } 

    public void setProfile(ProfileID id, ProfileInfo p) { 
     profiles.put(id, p); 
    } 

我的責任編輯:

public class ProfileConfigEditor extends Composite implements ManagedObjectEditor<ProfileConfig> { 

    private static ProfileConfigEditorUiBinder uiBinder = GWT.create(ProfileConfigEditorUiBinder.class); 
    interface ProfileConfigEditorUiBinder extends UiBinder<Widget, ProfileConfigEditor> { 
} 

    private UserManager userManager; 

    @UiField 
    CellList Profiles; 
    @UiField 
    TextBox name; 
    @UiField 
    CheckBox isDefault; 

所以考慮到我已經從的UserManager有效的配置文件ID的列表,我怎麼去調用從getProfile方法我POJO從我的編輯器中?

回答

2

你需要的是一個ValueAwareEditor

public class ProfileConfigEditor extends Composite implements ManagedObjectEditor<ProfileConfig>, ValueAwareEditor<ProfileConfig> { 

void setValue(ProfileConfig value){ 
    // TODO: Call ProfileConfig.getProfile() 
} 

void flush(){ 
    // TODO: Call ProfileConfig.setProfile() 
} 


// ... Other methods here 

或者,如果你想要一個更大的挑戰,你可以看看滾動您自己CompositeEditor,例如查看源代碼ListEditor。在你的情況下,你會實現一個CompositeEditor<ProfileConfig, ProfileInfo, MyNewProfileInfoEditor>。您可以將其作爲「此編輯器將採取ProfileConfig對象,提取一個或多個ProfileInfo對象並使用一個或多個MyNewProfileInfoEditor編輯器」