Sharing a resource between transactional editing domains [message #1472148] |
Thu, 13 November 2014 16:40 |
Laurent Le Moux Messages: 184 Registered: September 2011 |
Senior Member |
|
|
Hi all,
I try to handle the following use case : two Graphiti editors display diagrams that are accessing a same and shared underlying business model.
Each editor is using a dedicated transactional editing domain (TED) which contains the resource holding the open diagram.
When the user modifies the name of a shape in a diagram, the modification must also take place for the name attribute of the corresponding element in the underlying business model.
Therefore, the resource containing the business model is added to the editor's TED so that the modifications can take place in both the diagram and the business model resources in a transactional context. This works fine and is implemented as follow :
TransactionalEditingDomain owningTED = TransactionUtil.getEditingDomain((Resource) editedElement.cdoResource());
TransactionalEditingDomain currentTED = getDiagramBehavior().getEditingDomain();
if (!currentTED.equals(owningTED)) {
currentTED.getResourceSet().getResources().add(editedElement.cdoResource());
if (owningTED != null) {
owningTED.getResourceSet().getResources().remove(editedElement.cdoResource());
TransactionUtil.disconnectFromEditingDomain((Resource) editedElement.cdoResource());
}
}
At this stage, there's no 'owningTED' yet and 'currentTED' becomes the owning one.
If now, the second editor needs to access the business model resource to also apply a modification, the resource must be disconnected from the first TED and added to the second editor's one which is done by the same code lines as above.
This also works fine and the business model resource is "switching TEDs".
But, when the user goes back to the first editor and tries to undo the modification, it fails.
In this case, following the execution in the debugger shows that 'owningTED' is null when I was expecting it to hold the reference of the second editor's TED.
'TransactionUtil.getEditingDomain' returns null because editedElement.cdoResource() has apparently no containing resource set.
How comes it is not contained by the second editor's TED resource set anymore ?
Regards,
Laurent
|
|
|
Re: Sharing a resource between transactional editing domains [message #1472309 is a reply to message #1472148] |
Thu, 13 November 2014 19:35 |
|
Hi, Laurent,
The TransactionalEditingDomain is most definitely designed not to share
resources with other editing domains. Each is a self-sufficient,
enclosed universe. I would recommend that either (a) each of your
graphiti editors have a distinct copy of the business model in its
editing domain, or else (b) let the graphiti editors share a single
editing domain between them.
Cheers,
Christian
On 2014-11-13 16:40:40 +0000, Laurent Le Moux said:
> Hi all,
>
> I try to handle the following use case : two Graphiti editors display
> diagrams that are accessing a same and shared underlying business model.
>
> Each editor is using a dedicated transactional editing domain (TED)
> which contains the resource holding the open diagram.
>
> When the user modifies the name of a shape in a diagram, the
> modification must also take place for the name attribute of the
> corresponding element in the underlying business model.
>
> Therefore, the resource containing the business model is added to the
> editor's TED so that the modifications can take place in both the
> diagram and the business model resources in a transactional context.
> This works fine and is implemented as follow :
>
>
> TransactionalEditingDomain owningTED =
> TransactionUtil.getEditingDomain((Resource)
> editedElement.cdoResource());
> TransactionalEditingDomain currentTED =
> getDiagramBehavior().getEditingDomain();
> if (!currentTED.equals(owningTED)) {
> currentTED.getResourceSet().getResources().add(editedElement.cdoResource());
> if (owningTED != null) {
>
> owningTED.getResourceSet().getResources().remove(editedElement.cdoResource());
>
> TransactionUtil.disconnectFromEditingDomain((Resource)
> editedElement.cdoResource());
> }
> }
>
>
> At this stage, there's no 'owningTED' yet and 'currentTED' becomes the
> owning one.
>
> If now, the second editor needs to access the business model resource
> to also apply a modification, the resource must be disconnected from
> the first TED and added to the second editor's one which is done by the
> same code lines as above.
>
> This also works fine and the business model resource is "switching TEDs".
>
> But, when the user goes back to the first editor and tries to undo the
> modification, it fails.
>
> In this case, following the execution in the debugger shows that
> 'owningTED' is null when I was expecting it to hold the reference of
> the second editor's TED.
> 'TransactionUtil.getEditingDomain' returns null because
> editedElement.cdoResource() has apparently no containing resource set.
>
> How comes it is not contained by the second editor's TED resource set anymore ?
>
> Regards,
>
> Laurent
|
|
|
|
Powered by
FUDForum. Page generated in 0.03610 seconds