Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing domain
Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing domain [message #689991] Tue, 28 June 2011 13:43 Go to next message
Dobrou Mising name is currently offline Dobrou Mising name
Messages: 16
Registered: December 2010
Junior Member
Hello, I would like to ask you for help with this problem:

My custom editor use Graphiti to edit data. If multiple instances of editor edit data from same file, they share editing domain where is file Resource.
I open two instances of graphiti editor (for example E1 and E2), both of them share same editing domain and edit EObjects from same Resource.

Problem occurs when org.eclipse.graphiti.ui.internal.editor.DiagramEditorBehavior.handleChangedResources() is called. It can be because one of the editors saved data or external change on resource was detected. Until here, it's fine.

After that every time I switch focus from E1 editor to E2, focused editor always refreshes whole content as it thinks its resource has changed. But while refreshing, it set second editor resource changed flag to true. So every time focus is switched between those 2 editors, newly focused editor calls "handleChangedResources()" and refreshes.
This is not good, and even worse it's when I make some changes to data in editor, because after that editor asks to discard those changes and reloads resource.

I found out that this behaviour is caused by this code in
org.eclipse.graphiti.ui.internal.editor.DiagramEditorBehavior

Every time resource change is detected, resources are unloaded.
from line 376:
private void handleChangedResources() {
if (!isDirty() || handleDirtyConflict()) {
getOperationHistory().dispose(getUndoContext(), true, true, true);

updateProblemIndication = false;

//Disable adapter temporarily.
setAdapterActive(false);
try {
// We unload our resources such that refreshEditorContent does a complete diagram refresh.
EList<Resource> resources = getEditingDomain().getResourceSet().getResources();
for (Resource resource : resources) {
resource.unload();
}

Every time resource unload is detected, resource change flag is set to true.
from line 268:
if (msg.getFeatureID(Resource.class) == Resource.RESOURCE__IS_LOADED) {
if (msg.getNewBooleanValue() == Boolean.FALSE) {
final Resource resource = (Resource) msg.getNotifier();
final URI uri = resource.getURI();
if (editingDomain.getResourceSet().getURIConverter().exists(uri, null)) {
// file content has changes
setResourceChanged(true);

----------
This all is fine until only one editor is active because "setAdapterActive(false);" handles it for one editor.
But when multiple instances of editor are running over same data, adapter for another editor is not disabled, so unloading and seting resourceChangedFlag continues in infinite loop.

E1:handleChangedResources() calls unload on Resource, it leads to calling E2:setResourceChanged(true). After focusing to E2,
E2:handleChangedResources() and so on.


I thought about using own implementation of DiagramEditorBehavior, but it's not possible because DiagramEditorBehavior is hardcoded to Graphiti internals.

Is there anyone who can help with solving this issue?
Is it bug in graphiti or am I doing something wrong?


I use Graphiti 0.8.0, final version.
Re: Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing dom [message #690239 is a reply to message #689991] Wed, 29 June 2011 04:52 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
Hi,

i think it should work well if you use two distinct editing domains. Can you
do that?
(Using one editing domain for several editors is not supported as of now)

Best, Tim
Re: Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing dom [message #690285 is a reply to message #690239] Wed, 29 June 2011 06:13 Go to previous messageGo to next message
Dobrou Mising name is currently offline Dobrou Mising name
Messages: 16
Registered: December 2010
Junior Member
Every instance of editor can edit different part of same file, so I have to use same editing domain for them.

Data model is like:

File
-DiagramsCollection
-Diagram
-Diagram
...


Using own editing domain would cause editor to overwrite others changes.
Re: Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing dom [message #690325 is a reply to message #690285] Wed, 29 June 2011 07:29 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
You need to put the diagram data for different diagrams into different
files. That is best practice.
Otherwise for too many notifications are sent etc.

Then, you can reference your business data from the diagram files, it should
reside in another distinct file. That approach should work when you use one
editing domain per editor instance. Graphiti has a mechanism to ask the user
if another party has modified the underlying business data if he wants to
keep his changes or not...
Re: Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing dom [message #690360 is a reply to message #690325] Wed, 29 June 2011 08:40 Go to previous messageGo to next message
Dobrou Mising name is currently offline Dobrou Mising name
Messages: 16
Registered: December 2010
Junior Member
Thank you for reply.

Even if I put diagrams EObject outsite to separate files, data objects are still in one file.
Nevertheless I would like to keep data and diagrams compact, in one file. If it will be possible...
So separating diagrams to multiple files is last solution for me, and may be still not working. Because of data object still stored in one file.

I know resource reload is properly handled by editor (if domain is not shared), but it would not allow editing those data in one file simultaneously form multiple diagrams.

I see I will have to change editor behaviour on resource change, but I can't find how, because DiagramEditorBehaviour is internal part of Graphiti.
Re: Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing dom [message #690445 is a reply to message #690360] Wed, 29 June 2011 10:07 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
I think it will work if diagrams are stored in seperate files.
This is really required by Graphiti, for instance:
/**
* Maps the fileURI to an URI which points directly to the Diagram
Object.
* This methods assumes the Diagram object is the first root object in
the
* given file.
*
* @param diagramFileUri
* URI of the diagramFile
* @return URI of the diagram
*/
public abstract URI mapDiagramFileUriToDiagramUri(URI diagramFileUri);

It should be ok to have the business data in one file. It is referenced from
the diagram files.
If the business data file is changed via one editor the other editor is
notified by Graphtis Workspace Listener.
The other Editor will reload the business data file if required in its own
editing domain.
This should NOT cause any problems for the former editing domain, since no
changes occur.

An important point is, that the resource containing the business data should
have modification tracking turned on to make sure that the business data
file is only saved if the data changed. The same counts for the diagram
files as well if you create the corresponding resources.
You might have a look at Graphiti's FileService method
public static TransactionalEditingDomain createEmfFileForDiagram(URI
diagramResourceUri, final Diagram diagram)
on how this is done.
Re: Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing dom [message #690769 is a reply to message #690445] Thu, 30 June 2011 03:53 Go to previous messageGo to next message
Dobrou Mising name is currently offline Dobrou Mising name
Messages: 16
Registered: December 2010
Junior Member
I would like to allow simultaneous editing in multiple editors.

In case where every editor has it's own editing domain:
As I understand how it works, this scenario wouldn't work for me:
1) open editor E1 and editor E2, both editing different business data but from same file.
2) make changes in E1 (and don't save, so E2 doesn't realize any changes)
3) make changes in E2 and save
4) E1 won't be able to merge changes, so changes in E1 or E2 will be lost.

User can easily forgot to save changes, every time editor is switched.
And automatic saving on switching editors would not be nice.

Shared editing domain is solution for me here, that's why I am trying to find some workaround for this issue.


-----
mapDiagramFileUriToDiagramUri() is not problem, because I have subclassed and customized all classes where I see it's used (DiagramEditorFactory, DiagramEditorInput etc.)
Re: Incorrect behaviour of DiagramEditorBehavior when two instances of editor share same editing dom [message #690941 is a reply to message #690769] Thu, 30 June 2011 08:52 Go to previous message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
You might open an enhancement request in bugzilla for supporting shared
editing domains.

Since the shared editing domain setup is currently not really supported by
Graphiti,
my idea for a workaround would be to save the model file after a feature
modifies the model.

So if you just modify the visuals, e.g. MoveFeature (which you would not
want to be reflected in the sibling diagram, i guess?) you would
do as before. If you execute a feature which modifies existing model
elements you might do a save of your model file as post-op.

Does this work for you?
Previous Topic:Drilldown feature DiagramInput
Next Topic:Diagram Editor doesn't close when file is deleted
Goto Forum:
  


Current Time: Wed Jul 23 12:16:03 EDT 2014

Powered by FUDForum. Page generated in 0.02025 seconds