Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forums [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1693170/#msg_1693170
I created a SimpleOperationObserver instance where I fire changes using model ids of AbstractOperation argument in operationPerformed method. The problem is that I cannot get deleted objects from this method, as Project.getModelElement(ModelElementId) returns null for objects that do not exist withing the project anymore.
Is there a nice solution to get all added/modified/deleted EObject elements after some operation or command?]]>Yuriy Flyud2015-04-22T08:47:05-00:00Re: [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1693919/#msg_1693919
sorry for the delay, I somehow missed your question.
Yes, there is such a possibility to retrieve deleted elements (or their
respective IDs) but you need to adhere two things:
- you need to use the internal API, since we intentionally did not
expose any of the data structures that maintain deleted elements and
- you need to use commands and you can only retrieve deleted elements
within such a command
Here's basic example that illustrates both points which is based on our
tests:
@Test
public void getIdForDeletedElement() {
final Project project = getProject();
final TestElement testElement = Create.testElement();
Add.toProject(getLocalProject(), testElement);
final ModelElementId testElementId =
project.getModelElementId(testElement);
new EMFStoreCommand() {
@Override
protected void doRun() {
project.deleteModelElement(testElement);
// necessary cast to IdEObjectCollectionImpl
final ModelElementId testElementIdAfterDeletion =
((IdEObjectCollectionImpl) project)
.getDeletedModelElementId(testElement);
assertEquals(testElementId, testElementIdAfterDeletion);
}
}.run(false);
// after command completion the element is gone
assertNull(project.getModelElementId(testElement));
}
Hope this helps,
Edgar
> I tried to improve performance of application and noticed that I can
> perform some actions not on every model change but after some operation.
>
> I created a SimpleOperationObserver instance where I fire changes using
> model ids of AbstractOperation argument in operationPerformed method.
> The problem is that I cannot get deleted objects from this method, as
> Project.getModelElement(ModelElementId) returns null for objects that do
> not exist withing the project anymore.
>
> Is there a nice solution to get all added/modified/deleted EObject
> elements after some operation or command?
--
Edgar Mueller
Get Professional Eclipse Support: http://eclipsesource.com/munich]]>Edgar Mueller2015-04-29T09:47:03-00:00Re: [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1694580/#msg_1694580
Thank you so much for your answer! This works as expected and finally I could remove all the rude workarounds. There is only one thing left. In the end of my "operationPerformed" method I notify all observers about changed/deleted objects. This looks like this: ESWorkspaceProviderImpl.getObserverBus().notify(ESLocalProjectContentObserver.class).projectContentChanged(project, changedObjects, deletedObjects);
One of the observers is a Decorator that decorates the navigator in a separate thread. The exception I get is the following:
_____________________________________________________________________________________ !ENTRY org.eclipse.emf.emfstore.common.model 2 2 2015-05-06 15:41:07.284
!MESSAGE Command Observer threw exception
!STACK 0
java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at org.eclipse.emf.emfstore.internal.client.model.impl.ProjectSpaceBase.addOperations(ProjectSpaceBase.java:191)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationManager.operationsRecorded(OperationManager.java:177)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationRecorder.operationsRecorded(OperationRecorder.java:306)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationRecorder.commandCompleted(OperationRecorder.java:521)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationRecorder.commandCompleted(OperationRecorder.java:468)
at org.eclipse.emf.emfstore.internal.client.model.impl.OperationManager.commandCompleted(OperationManager.java:226)
at org.eclipse.emf.emfstore.internal.client.model.changeTracking.commands.EMFStoreCommandNotifier$3.run(EMFStoreCommandNotifier.java:96)
at org.eclipse.emf.emfstore.common.ESSafeRunner.run(ESSafeRunner.java:38)
at org.eclipse.emf.emfstore.internal.client.model.changeTracking.commands.EMFStoreCommandNotifier.notifiyListenersAboutCommandCompleted(EMFStoreCommandNotifier.java:104)
at org.eclipse.emf.emfstore.internal.client.model.changeTracking.commands.EMFStoreBasicCommandStack.execute(EMFStoreBasicCommandStack.java:79)
at org.eclipse.emf.emfstore.internal.client.model.util.AbstractEMFStoreCommand.aRun(AbstractEMFStoreCommand.java:108)
at org.eclipse.emf.emfstore.internal.client.model.util.EMFStoreCommandWithResult.run(EMFStoreCommandWithResult.java:59)
at org.eclipse.emf.emfstore.client.util.RunESCommand.runWithResult(RunESCommand.java:171)
at org.eclipse.emf.emfstore.internal.client.model.impl.api.ESWorkspaceImpl.getLocalProject(ESWorkspaceImpl.java:176)
at com.ibi.id.ui.navigator.decorators.ValidationFailedDecorator.decorate(ValidationFailedDecorator.java:45)
at org.eclipse.ui.internal.decorators.LightweightDecoratorDefinition.decorate(LightweightDecoratorDefinition.java:269)
at org.eclipse.ui.internal.decorators.LightweightDecoratorManager$LightweightRunnable.run(LightweightDecoratorManager.java:81)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.decorators.LightweightDecoratorManager.decorate(LightweightDecoratorManager.java:365)
at org.eclipse.ui.internal.decorators.LightweightDecoratorManager.getDecorations(LightweightDecoratorManager.java:347)
at org.eclipse.ui.internal.decorators.DecorationScheduler$1.ensureResultCached(DecorationScheduler.java:371)
at org.eclipse.ui.internal.decorators.DecorationScheduler$1.run(DecorationScheduler.java:331)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
_____________________________________________________________________________________
Looks like ESWorkspaceProvider.INSTANCE.getWorkspace().getLocalProject(element) is not thread safe. Is there some special way for calling EMFStore functionality (e.g. through ESCommand)? Are there any other ways to provide thread safety?
Thank you in advance!]]>Yuriy Flyud2015-05-06T12:52:30-00:00Re: [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1694693/#msg_1694693
The getDeletedModelElement method works fine. But only when performing new operations. For undo - deleted elements can't be retrieved by the id I get from operation affected elements. I get nothing also when calling getModelElement by the same id here.
I don't think this is an expected behavior but need you input before creating an issue in Bugzilla.]]>Yuriy Flyud2015-05-07T08:34:59-00:00Re: [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1695083/#msg_1695083
regarding the ConcurrentModificationException: I'll try to investigate
this, but please feel to free to report this as a bug. Meanwhile, you
could you try to fallback to the internal API (see implementation of
ESWorkspace#getLocalProject(EObject)) that avoids the outer command.
Concerning the undo/redo issue: how did you implement redo/undo?
Ideally, can you provide a test case?
Thanks,
Edgar
> Edgar, in addition to my reply about ConcurrentModificationException
> there is one more issue that really looks like a bug and is more related
> to the original question.
>
> The getDeletedModelElement method works fine. But only when performing
> new operations. For undo - deleted elements can't be retrieved by the id
> I get from operation affected elements. I get nothing also when calling
> getModelElement by the same id here.
>
> I don't think this is an expected behavior but need you input before
> creating an issue in Bugzilla.
--
Edgar Mueller
Get Professional Eclipse Support: http://eclipsesource.com/munich]]>Edgar Mueller2015-05-11T21:13:12-00:00Re: [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1695300/#msg_1695300
Here is the undo sample:
new UIUndoLastOperationController(getShell(), requireSelection(ESLocalProjectImpl.class))
.execute();
Regarding internal API - I will try. I will create the issue as well after some additional investigation.
Thanks!
Best regards,
Yuriy]]>Yuriy Flyud2015-05-13T11:54:53-00:00Re: [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1695722/#msg_1695722
thanks for the info.
The reason for getDeletedModelElement returning null during an undo of a
reversed create (that is, a delete) is a current limitation of our API,
since we always clear our internal deleted element caches when a delete
operation has been applied, which causes the getDeletedModelElement to
find nothing. Please file a bug for this issue.
Depending on what you are trying to do with the deleted element, a
possible workaround might be to check if you have a
CreateDeleteOperation in the operationUndone method of your observer.
If it returns true for isDelete() you can obtain the deleted element via
getModelElement(). Note though, that this might not cover all your use
cases, since getModelElement returns a copy of the deleted element.
Thanks,
Edgar
Am 13.05.2015 13:54, schrieb Yuriy Flyud:
> Edgar,
>
> Here is the undo sample:
> new UIUndoLastOperationController(getShell(),
> requireSelection(ESLocalProjectImpl.class))
> .execute();
> I register observer via:
> ((ESLocalProjectImpl)
> esLocalProject).toInternalAPI().getOperationManager().addOperationObserver(observer);
>
>
> Regarding internal API - I will try. I will create the issue as well
> after some additional investigation.
> Thanks!
>
> Best regards,
> Yuriy
--
Edgar Mueller
Get Professional Eclipse Support: http://eclipsesource.com/munich]]>Edgar Mueller2015-05-18T15:42:06-00:00Re: [EMFStore] Detecting changes of operations
https://www.eclipse.org/forums/index.php/mv/msg/1065922/1696078/#msg_1696078
The corresponding issues have been reported. And using internal API really prevents the Concurrent Modification exceptions.
Best regards,
Yuriy]]>Yuriy Flyud2015-05-21T14:04:05-00:00