| Undo SetCommand of a FeatureMapEntry attribute [message #1871886] |
Tue, 15 October 2024 04:40  |
Eclipse User |
|
|
|
Hello,
in my ecore model I define a FeatureMapEntry attribute, let's name it myAttr, in a class, let's say MyClass, in order to allow a mixed order of objects from different features.
Now, when I set a new feature map into myAttr of some object of the type MyClass in the generated editor then everything is OK. But when I use CTRL+Z in order to undo the last SetCommand it does not work anymore and I get an exception. The problem is that the SetCommand does not save the original FeatureMap but an EList which in turn cannot be processed when setting it back to the object.
SetCommand line 545+++:
if (owner.eIsSet(feature))
{
oldValue = new BasicEList<Object>((EList<?>)owner.eGet(feature));
// oldValue = owner.eGet(feature);
}
BasicFeatureMap line 2555+++:
public void set(Object newValue)
{
super.set(newValue instanceof FeatureMap ? newValue : ((FeatureMap.Internal.Wrapper)newValue).featureMap());
}
I think there is a reason why FeatureMaps cannot be used as old values. My first tries to solve it in a quick and dirty way failed. When I subclass the SetCommand and use the original FeatureMap as the old value then it has no effect. First the FeatureMap adds the values from the original FeatureMap but then removes the values from the container which in turn is the new container already. I think it is done by the inverseAdd method.
My question is: How can the problem be solved? How can a SetCommand undo the setting of a FeatureMapEntry attribute?
If not possible, do I really have to set all the objects of the FeatureMapEntry object by object?
Best regards
Franz
|
|
|
|
|
|
|
| Re: Undo SetCommand of a FeatureMapEntry attribute [message #1871973 is a reply to message #1871955] |
Thu, 17 October 2024 03:42   |
Eclipse User |
|
|
|
A test case is worth a thousand words. This works AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType();
FeatureMap anyAttribute = anyType.getAnyAttribute();
EStructuralFeature feature = ExtendedMetaData.INSTANCE.demandFeature("namespace", "name", false);
Entry entry = FeatureMapUtil.createEntry(feature, "value");
anyAttribute.add(entry);
BasicCommandStack basicCommandStack = new BasicCommandStack();
AdapterFactoryEditingDomain adapterFactoryEditingDomain = new AdapterFactoryEditingDomain(new ReflectiveItemProviderAdapterFactory(), basicCommandStack);
AnyType anyType2 = XMLTypeFactory.eINSTANCE.createAnyType();
System.err.println("before> " + anyType2.getAnyAttribute());
Command command = SetCommand.create(adapterFactoryEditingDomain, anyType2, XMLTypePackage.Literals.ANY_TYPE__ANY_ATTRIBUTE, anyAttribute);
basicCommandStack.execute(command);
System.err.println("after> " + anyType2.getAnyAttribute());
The feature you're operating on must be an EReference not a feature map feature, which is an EAttribute, but I cannot deduce your model and scenario to synthesize a representative test case from your description.
|
|
|
| Re: Undo SetCommand of a FeatureMapEntry attribute [message #1872036 is a reply to message #1871973] |
Fri, 18 October 2024 04:23   |
Eclipse User |
|
|
|
Thanks for the base of the test case! That saved a lot of time :D!
The complete test case would be as follows (see the lower part):
AnyType anyType = XMLTypeFactory.eINSTANCE.createAnyType();
FeatureMap anyAttribute = anyType.getAnyAttribute();
EStructuralFeature feature = ExtendedMetaData.INSTANCE.demandFeature("namespace", "name", false);
Entry entry = FeatureMapUtil.createEntry(feature, "value");
anyAttribute.add(entry);
BasicCommandStack basicCommandStack = new BasicCommandStack();
AdapterFactoryEditingDomain adapterFactoryEditingDomain = new AdapterFactoryEditingDomain(new ReflectiveItemProviderAdapterFactory(), basicCommandStack);
AnyType anyType2 = XMLTypeFactory.eINSTANCE.createAnyType();
System.err.println("before> " + anyType2.getAnyAttribute());
Command command = SetCommand.create(adapterFactoryEditingDomain, anyType2, XMLTypePackage.Literals.ANY_TYPE__ANY_ATTRIBUTE, anyAttribute);
basicCommandStack.execute(command);
System.err.println("after> " + anyType2.getAnyAttribute());
// NEW: set the same again and try to undo the command
command = SetCommand.create(adapterFactoryEditingDomain, anyType2, XMLTypePackage.Literals.ANY_TYPE__ANY_ATTRIBUTE, anyAttribute);
basicCommandStack.execute(command);
command.undo(); // <-- throws a ClassCastException
System.err.println("after undo> " + anyType2.getAnyAttribute());
I my ecore model the feature is an attribute of type "EFeatureMapEntry".
[Updated on: Fri, 18 October 2024 04:24] by Moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04928 seconds