I have the next code:
//JFace tableViewer
TableViewer tableViewer = ....
tableViewer.setContentProvider(new ObservableListContentProvider());
WritableValue writable = new WritableValue();
writable.setValue(model);
tableViewer.setInput(EMFProperties.list(ModelPackage.Literals.MODEL__GRAPHIC_CRITERIA).observeDetail(writable));
//We have also tested with:
//tableViewer.setInput(EMFEditObservables.observeList(EVDEditionDomain.getInstance(), //(EObject) data, ModelPackage.Literals.MODEL__GRAPHIC_CRITERIA))
And I do changes in the tableViewer using commands:
List<Command> commandList = new ArrayList<Command>();
...
commandList.add(AddCommand.create(EVDEditionDomain.getInstance(), model, ModelPackage.Literals.MODEL__GRAPHIC_CRITERIA, criteriaRefreshDialog.getSelectedCriteria()));
CompoundCommand refreshmentCriteriaCommand = new CompoundCommand(commandList); EVDEditionDomain.getInstance().getCommandStack().execute(refreshmentCriteriaCommand);
Model is an instance of an EMF EObject
ModelPackage.Literals.MODEL__GRAPHIC_CRITERIA is a multi-value feature around EList<Criterion> attribute
criteriaRefreshDialog.getSelectedCriteria() provides a List<Criterion> instance
EVDEditionDomain.getInstance() provides an AdapterFactoryEditingDomain instance
When I execute the code, the first time is all correct. The tableViewer is refreshed with the new additions criterion in the model. But if I execute Undo action from CommandStack, the tableViewer does not delete the contents previously added from the view. The model instance is correctly updated with the undo action.
If I execute redo action, the tableViewer is refreshed adding again the contents so the view has twice copied elements but the model instance has suitable filled. This undo/redo process can be done ad infinitum with the contents of the tableViewer growing and growing.
But if I change the code:
commandList.add(AddCommand.create(EVDEditionDomain.getInstance(), model, ModelPackage.Literals.MODEL__GRAPHIC_CRITERIA, criteriaRefreshDialog.getSelectedCriteria()));
by a EMF copy of the list:
commandList.add(AddCommand.create(EVDEditionDomain.getInstance(), model, ModelPackage.Literals.MODEL__GRAPHIC_CRITERIA, EcoreUtil.copyAll(criteriaRefreshDialog.getSelectedCriteria())));
all undo/redo actions work perfectly
Any suggestion??