I’m diving into EMF now, and have encountered the following problem:
I’m trying to remove fields from fieldset with following code:
FieldElem ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove = new RemoveCommand(editingDomain, nf,
DescPackage.eINSTANCE.getNestedFieldsetElem_Field(), ff);
editingDomain.getCommandStack().execute(remove);
ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove2 = RemoveCommand.create(editingDomain, nf,
DescPackage.eINSTANCE.getNestedFieldsetElem_Field(), ff);
editingDomain.getCommandStack().execute(remove2);
ff = ds.getContent().getNestedFieldset().get(0).getField().get(0);
Command remove3 = RemoveCommand.create(editingDomain, ff);
editingDomain.getCommandStack().execute(remove3);
The first two commands works just fine, but third one not. I’s not even adding to the command stack, and is not removing anything. What am i doing wrong?
UPDATE: As i’ve seen in debugger, execute method return UNEXECUTABLE_COMMAND.
The instruction
RemoveCommand.create(editingDomain, ff)can be used only ifffas a container (ieff.eContainer != null). TheeContaineris set automatically by EMF when you add the object to a relation with containment property.The
remove3command does not work certainly because thegetField()relation is not a containment relation.