Issue with flush when implementing a NullableSetEditor by wrapping a NullalbleListEditor

38 views
Skip to first unread message

Jeff

unread,
Sep 4, 2012, 3:08:16 AM9/4/12
to google-we...@googlegroups.com, Jiahu Deng
HI,

I spent a lot of time on the following issue but couldn't figure it out. Any clue is appreciated. Thanks!

I have a working NullableStringListEditor implementation:
public class NullableStringListEditor extends Composite implements IsEditor<OptionalFieldEditor< List<String>, ListEditor<String, StringEditor> >> {...}
   
Now, I am building a NullableStringSetEditor by wrapping it. With the following implementation, values are displayed by the wrapped editor successfully, however any modifications(the NullableStringListEditor supports edit/add strings) are not reflected after flush(). I am using SimpleBeanEditorDriver. I debugged into it and it looks like the underline values(List) in the wrappedEditor(NullableStringListEditor) have been changed, but they are not populated to NullableStringSetEditor. Am I still missing something?

public class NullableStringSetEditor extends Composite implements CompositeEditor<Set<String>, List<String>, ListEditor<String, StringEditor>>, LeafValueEditor<Set<String>> {
    private final NullableStringListEditor wrappedEditor = new NullableStringListEditor();

    @Override
    public void setEditorChain(com.google.gwt.editor.client.CompositeEditor.EditorChain<List<String>, ListEditor<String, StringEditor>> chain) {
        wrappedEditor.asEditor().setEditorChain(chain);                   
    }

    @Override
    public Set<String> getValue() {
        List<String> list = wrappedEditor.asEditor().getValue();
        return (list != null) ? new TreeSet<String>(list) : null;
    }

    @Override
    public void setValue(Set<String> values) {
        List<String> list = new ArrayList<String>();
        list.addAll(values);
        wrappedEditor.asEditor().setValue(list);
   }

   //no-op implementation for other required @Override such as flush() and setDelegate(EditorDelegate<Set<String>> delegate)
   //...
}

Thomas Broyer

unread,
Sep 4, 2012, 4:33:38 AM9/4/12
to google-we...@googlegroups.com, Jiahu Deng
You say you implemented flush() as a no-op, so it's no surprise it doesn't do what you expect, right?

Jeff

unread,
Sep 4, 2012, 11:49:01 AM9/4/12
to google-we...@googlegroups.com, Jiahu Deng
Hi Thomas,

In the original post, I forgot to mention that, I tried the following flush() implementation but it didn't make a difference:
@Override public void flush() {wrappedEditor.asEditor().flush();}


I am not sure what else I can do within flush() since the only member variable of the class is the wrappedEditor.

Thanks!

Thomas Broyer

unread,
Sep 4, 2012, 12:02:31 PM9/4/12
to google-we...@googlegroups.com, Jiahu Deng


On Tuesday, September 4, 2012 5:49:01 PM UTC+2, Jeff wrote:
Hi Thomas,

In the original post, I forgot to mention that, I tried the following flush() implementation but it didn't make a difference:
@Override public void flush() {wrappedEditor.asEditor().flush();}


I am not sure what else I can do within flush() since the only member variable of the class is the wrappedEditor.

Thanks!


OK, looking a bit more in details, I really think you should follow the same pattern as OptionalFieldEditor (as I already told you on StackOverflow), with setValue() transforming the Set into a List and calling chain.attach(theList, theListEditor), and getValue() calling chain.getValue(theListEditor) and transforming the List back to a String.
Not tested but it has more chances to work than your strategy of "hiding" the underlying ListEditor.
Reply all
Reply to author
Forward
0 new messages