I'm editing List of ValueProxies and I'm trying to implement reordering of 
items (move to front, move to back, move up, move down the list). Since 
ListEditors work by reflecting change in underlying List and List interface 
does not support atomic "move" operation for item reordering, my only 
option is to first remove item from List and then add elements at desired 
index. So far so good, but in ListEditor, underlying List contains 
*unflushed* values so when I reinsert them, newely created editors get old 
values and I loose changes made before reordering took place.

Since flushing ListEditor before remove/add didn't seem as a good idea 
(breaks editor contract and I would have to propagate Driver down the 
editors hierarchy) I've ended up cloning ListEditor and its underlying 
ListEditorWrapper to my own DynamicListEditor and DynamicListEditorWrapper 
(couldn't even extend them, because relevant members are private).

In DynamicListEditorWrapper I've added one additional method to reorder 
both elements in underlying list and their corresponding editors in-place:

public void move(int fromIndex, int toIndex) {
workingCopy.add(toIndex, workingCopy.remove(fromIndex));
editors.add(toIndex, editors.remove(fromIndex));
for (int i = Math.min(fromIndex, toIndex), j = Math.max(fromIndex, 
toIndex); i <= j; i++)
editorSource.setIndex(editors.get(i), i);
}

In DynamicListEditor I've used that new wrapper and exposed it in getList 
method:

public DynamicListEditorWrapper<T, E> getList() {
return list;
}

Now I'm able to move item one place up the list by calling:

int currIndex = /* get current index, easy */;
if (currIndex == 0)
return;
listEditor.getList().move(currIndex, currIndex - 1);

I works, but I can't shake off the feeling that I'm over-engineering it and 
that there is a better (simpler) way for doing this. After all, Lists are 
ordered collections and editing that order should not be this complicated.

Any advice?

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to