Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 341863

Summary: [diagram] Improve diagram layout storage story
Product: z_Archived Reporter: Konstantin Komissarchik <konstantin>
Component: SapphireAssignee: Shenxue Zhou <shenxue.zhou>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: gregory.amerson, ram.venkataswamy
Version: unspecifiedKeywords: usability
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Konstantin Komissarchik CLA 2011-04-05 01:23:57 EDT
I noticed a few deficiencies in how diagram layout is stored:

1. Graphiti .xmi files are being stored. They should not be.

2. Need a better extension for the layout file. Something other than ".np". Perhaps ".layout"?

3. Diagram node size is stored for fixed size nodes. This isn't necessary.

4. Location of .settings/diagrams isn't appropriate. We need something more unique in the settings directory. The "diagrams" folder doesn't cut it. Let's use "org.eclipse.sapphire.ui.diagram". 

5. We need more options for how to store layout information. This should be a setting on diagram page definition. In addition to the existing approach, I'd like to see an option for side-by-side .layout file that is written to the same folder as the original file. 

6. File name for layout should include both the original file name and id of the diagram page. Think of the scenario where multiple diagram views (pages) are presented over the same data stored in the same file. To give a different take on the data.
Comment 1 Greg Amerson CLA 2011-04-21 16:47:00 EDT
Also I noticed that if you don't have a diagrams folder already created, it will fail when you try to load an editor with a diagram part with this exception:

!ENTRY org.eclipse.sapphire.ui 4 0 2011-04-21 15:23:07.130
!MESSAGE Resource '/taglib-test-portlet/.settings/diagrams' does not exist.
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Resource '/taglib-test-portlet/.settings/diagrams' does not exist.
	at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:326)
	at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:200)
	at org.eclipse.core.internal.resources.File.create(File.java:123)
	at org.eclipse.core.internal.resources.File.create(File.java:196)
	at org.eclipse.sapphire.ui.swt.graphiti.editor.SapphireDiagramEditorFactory.createEditorInput(SapphireDiagramEditorFactory.java:71)
	at com.liferay.ide.eclipse.servicebuilder.ui.ServiceBuilderEditor.createDiagramPages(ServiceBuilderEditor.java:36)
	at org.eclipse.sapphire.ui.SapphireEditor.addPages(SapphireEditor.java:368)
	at org.eclipse.ui.forms.editor.FormEditor.createPages(FormEditor.java:138)
	at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:348)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:670)



Even though the diagrams folder exists on the disk drive, it doesn't show up in eclipse, it hasn't been "refreshed".  If you manually refresh the .settings folder, diagrams will show up and then the editor will load correctly.
Comment 2 Shenxue Zhou CLA 2011-04-21 19:17:28 EDT
For the resource exception, I added code to refresh the diagram settings folder and files when opening diagrams. Please let me know if this helps.
Comment 3 Konstantin Komissarchik CLA 2011-04-21 19:35:30 EDT
> For the resource exception, I added code to refresh the diagram settings folder
> and files when opening diagrams. Please let me know if this helps.

That is an incorrect fix. Opening an editor should never cause changes to resources (such as triggering a refresh). The proper fix is to make sure that layout file writing and creation of corresponding folders happens via Eclipse resource API.
Comment 4 Shenxue Zhou CLA 2011-04-22 10:58:24 EDT
The root cause here is the EMF based diagram xmi file used by Graphiti. We don't rely on it to restore diagram layout. I'll need to look into ways to removing it completely.
Comment 5 Greg Amerson CLA 2011-05-18 01:37:07 EDT
While doing some testing on diagrams I noticed that if I have the same filename but in different folders in a project, the diagram for node location and connections is shared between both files.

I found this by doing the following in some project:
test-folder-aaa/service.xml
test-folder-bbb/service.xml

Then trying to save diagram layout changes in either of these files will wipeout the changes saved in the other.  I guess the reason is because both service.xml files will share or resolve to the same diagrams file .settings/diagrams/service.xmi/np
Comment 6 Shenxue Zhou CLA 2011-06-01 12:34:39 EDT
1. There is now a setting in the diagram page def to allow side-by-side layout storage
2. Fixed ResourceException
3. Diagram files with same names but in different folders should not override each other's layout
4. The diagram layout file has ".layout" extension. When it's not stored side by side with the diagram xml file, it's under ".settings/org.eclipse.sapphire.ui.diagram/<project relative path of the diagram xml file>/<file>.layout
5. I'm not able to get rid of the graphiti diagram file. But the graphiti diagram file is always placed under the diretory under ".settings/org.eclipse.sapphire.ui.diagram/...". So it's not in user's way. See http://www.eclipse.org/forums/index.php/t/202467/
6. The diagram layout file won't store node size if the node is not resizable.
7. For file name for layout and graphiti diagram now contains diagram page id
Comment 7 Greg Amerson CLA 2011-06-01 14:26:19 EDT
Verified with build#367
Comment 8 Ram Venkataswamy CLA 2011-06-02 16:00:07 EDT
verified with build 0.3.0.201106021201
Comment 9 Konstantin Komissarchik CLA 2011-06-03 15:32:53 EDT
> 5. I'm not able to get rid of the graphiti diagram file. But the graphiti
> diagram file is always placed under the diretory under
> ".settings/org.eclipse.sapphire.ui.diagram/...". So it's not in user's way. See
> http://www.eclipse.org/forums/index.php/t/202467/

Placing any artifacts not absolutely required into user project is a big deal. If Graphiti absolutely needs a file, can you point it at some location in workspace or better yet, a temporary directory? If you absolutely cannot think of a way to fix this, add a node regarding this to the bug that tracks eliminating dependency on Graphiti.

> 7. For file name for layout and graphiti diagram now contains diagram page id

Not seeing this. At least not for the map sample. The file name is just 
"map.layout".
Comment 10 Konstantin Komissarchik CLA 2011-06-03 15:33:29 EDT
Meant to re-open.
Comment 11 Shenxue Zhou CLA 2011-06-03 15:38:29 EDT
(In reply to comment #9)
> > 5. I'm not able to get rid of the graphiti diagram file. But the graphiti
> > diagram file is always placed under the diretory under
> > ".settings/org.eclipse.sapphire.ui.diagram/...". So it's not in user's way. See
> > http://www.eclipse.org/forums/index.php/t/202467/
> 
> Placing any artifacts not absolutely required into user project is a big deal.
> If Graphiti absolutely needs a file, can you point it at some location in
> workspace or better yet, a temporary directory? If you absolutely cannot think
> of a way to fix this, add a node regarding this to the bug that tracks
> eliminating dependency on Graphiti.
> 
> > 7. For file name for layout and graphiti diagram now contains diagram page id
> 
> Not seeing this. At least not for the map sample. The file name is just 
> "map.layout".

I've tried to use workspace temp dir to store the diagram file but by the time Graphiti/EMF got a hold of it, it'd throw ResourceException.
Comment 12 Shenxue Zhou CLA 2011-06-03 15:42:30 EDT
(In reply to comment #9)
> > 5. I'm not able to get rid of the graphiti diagram file. But the graphiti
> > diagram file is always placed under the diretory under
> > ".settings/org.eclipse.sapphire.ui.diagram/...". So it's not in user's way. See
> > http://www.eclipse.org/forums/index.php/t/202467/
> 
> Placing any artifacts not absolutely required into user project is a big deal.
> If Graphiti absolutely needs a file, can you point it at some location in
> workspace or better yet, a temporary directory? If you absolutely cannot think
> of a way to fix this, add a node regarding this to the bug that tracks
> eliminating dependency on Graphiti.
> 
> > 7. For file name for layout and graphiti diagram now contains diagram page id
> 
> Not seeing this. At least not for the map sample. The file name is just 
> "map.layout".

I added a new method in SapphireDiagramEditorFactory class so that individual editor can pass in a page id. If the editor doesn't pass it, it won't try to attach the page id to the layout file. I'll modify the map editor to pass that additional param.
Comment 13 Konstantin Komissarchik CLA 2011-06-03 15:43:44 EDT
The sdef file has an id for the page definition. Please use that instead.
Comment 14 Shenxue Zhou CLA 2011-06-03 16:36:33 EDT
I modified MapEditor class to pass in the diagram page id defined in page def when creating editor input. So the map sample uses "map_diagram" as the file name for the layout storage.
Comment 15 Konstantin Komissarchik CLA 2011-06-03 16:41:22 EDT
Rather than changing the sample, this should be implemented such that explicit action from the developer is not necessary. The sdef always has page id. That id should be used. The new method on SapphireDiagramEditorFactory should not be necessary.
Comment 16 Konstantin Komissarchik CLA 2011-06-08 17:55:26 EDT
I am going to close this as is. We are going to need to revisit the API for controlling persistence of diagram layout information in the future anyway. Some scenarios, for instance call for storing layout in the same file as the data and you have to follow their schema, etc.

This is good enough for now.