PDA

View Full Version : ListStoreEditor doesn't flush changes to edited model



Firelight
25 Sep 2014, 5:32 AM
I have the GridEditor editor (code below) to edit lists in model.
RecipeEditor is a widget class initializes with Editor & RequestFactory, also implements Editor<> initerface.

Everything works ok, except that ListStore editor flushes, but doesn't commit changes into edited model (as it is not LeafValueEditor).

Traced this behavior to Flusher.class to GWT 2.6.1:

LeafValueEditor<Q> asLeaf = ctx.asLeafValueEditor(); if (delegate.shouldFlush() && asLeaf != null && ctx.canSetInModel()) {
ctx.setInModel(asLeaf.getValue());




So the question is how to transfer commited data to model list?



public class RecipeEditor extends BaseEditor<RecipeProxy> {

interface RecipeEditorDriver extends RequestFactoryEditorDriver<RecipeProxy, RecipeEditor> {
}


private RecipeRequestContext requestContext;
private RecipeProxy model;


@Path("name")
TextField name;


TextField title;
TextField annotation;
TextArea content;
CheckBox published;


@Ignore
TextButton selectGoods;


GridEditor<GoodsProxy> goods;

...





public class GridEditor<T extends BaseEntityProxy> extends Composite implements IsEditor<Editor<List<T>>> {

protected ListStore<T> listStore;
protected GridEditing<T> editing;
private ListStoreEditor<T> editor;


public class EmptyValueProvider<T> implements ValueProvider<T, String> {


@Override
public String getValue(T object) {
return ""; //To change body of implemented methods use File | Settings | File Templates.
}


@Override
public void setValue(T object, String value) {
//To change body of implemented methods use File | Settings | File Templates.
}


@Override
public String getPath() {
return ""; //To change body of implemented methods use File | Settings | File Templates.
}
}


public GridEditor(BaseProxyProperties<T> properties, List<ColumnConfig<T, ?>> columns) {
this(properties, columns, null);
}


public GridEditor(BaseProxyProperties<T> properties, List<ColumnConfig<T, ?>> columns, List<IsField> editors) {


listStore = new ListStore<>(properties.stableId());
editor = new ListStoreEditor<>(listStore);


for (ColumnConfig<T, ?> column : columns) {
if (column.getCell() instanceof AnchorCell) {
((AnchorCell<T>) column.getCell()).setListStore(listStore);
}
}


ColumnConfig<T, String> colActions = new ColumnConfig<>(new EmptyValueProvider<>(), 50, AppBundle.MESSAGES.label_remove());
ButtonCell<String> remove = new ButtonCell<>();
remove.setText("");
remove.setIcon(AppBundle.IMAGES.cancel());
remove.addSelectHandler(new SelectEvent.SelectHandler() {
@Override
public void onSelect(SelectEvent event) {
listStore.remove(event.getContext().getIndex());
//T proxy = listStore.get(event.getContext().getIndex());
}
});
colActions.setCell(remove);
columns.add(colActions);


ColumnModel<T> cm = new ColumnModel<>(columns);


Grid<T> grid = new Grid<>(listStore, cm);
grid.setPixelSize(500, 200);


editing = new GridInlineEditing<>(grid);
if (editors != null) {
for (IsField editor : editors) {
if (editor != null) {
editing.addEditor(columns.get(editors.indexOf(editor)), editor);
}
}
}


if (getBeforeStartEditHandler() != null)
editing.addBeforeStartEditHandler(getBeforeStartEditHandler());


initWidget(grid);


//grid.getView().setAutoExpandColumn(colValue);
}


public BeforeStartEditEvent.BeforeStartEditHandler<T> getBeforeStartEditHandler() {
return null;
}


public void addCompleteEditHandler(CompleteEditEvent.CompleteEditHandler<T> handler) {
editing.addCompleteEditHandler(handler);
}


public void startEdit(T value) {
listStore.add(value);
editing.startEditing(new Grid.GridCell(listStore.size(), 0));
}


public void add(T entity) {
listStore.add(entity);
}


public List<T> getValue() {
return listStore.getAll();
}


public void cancelEdit() {
editing.cancelEditing();
}


@Override
public Editor<List<T>> asEditor() {
return editor;
}


public void setValue(List<T> newList) {
listStore.clear();
listStore.addAll(newList);
}
}

kpater87
19 Nov 2015, 5:08 AM
Hi,

I have the same problem. Have you found a solution? I am using GXT 3.1.4 and GWT 2.7.