Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 185573 Details for
Bug 330482
[diagram] Support diagram editing in Sapphire UI
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Support node images
sapphire_diagram_editor_1220.txt (text/plain), 209.34 KB, created by
Shenxue Zhou
on 2010-12-20 13:28:59 EST
(
hide
)
Description:
Support node images
Filename:
MIME Type:
Creator:
Shenxue Zhou
Created:
2010-12-20 13:28:59 EST
Size:
209.34 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.sapphire.samples >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.samples/META-INF/MANIFEST.MF,v >retrieving revision 1.2 >diff -u -r1.2 MANIFEST.MF >--- META-INF/MANIFEST.MF 16 Nov 2010 04:26:06 -0000 1.2 >+++ META-INF/MANIFEST.MF 20 Dec 2010 18:26:02 -0000 >@@ -12,7 +12,12 @@ > org.eclipse.wst.xml.ui, > org.eclipse.ui, > org.eclipse.ui.views, >- org.eclipse.help >+ org.eclipse.help, >+ org.eclipse.emf.transaction, >+ org.eclipse.ui.views.properties.tabbed, >+ org.eclipse.gef, >+ org.eclipse.graphiti, >+ org.eclipse.graphiti.ui > Bundle-ActivationPolicy: lazy > Bundle-RequiredExecutionEnvironment: J2SE-1.5 > Bundle-Vendor: %providerName >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.samples/plugin.xml,v >retrieving revision 1.4 >diff -u -r1.4 plugin.xml >--- plugin.xml 13 Dec 2010 16:46:27 -0000 1.4 >+++ plugin.xml 20 Dec 2010 18:26:02 -0000 >@@ -146,5 +146,24 @@ > id="org.eclipse.sapphire.samples.ezbug.ui.BugDatabaseEditor" > name="Bug Database Editor (Sapphire Sample)"/> > </extension> >+ >+ <extension point="org.eclipse.ui.editors"> >+ <editor >+ class="org.eclipse.sapphire.samples.map.ui.MapEditor" >+ default="true" >+ filenames="map.xml" >+ id="org.eclipse.sapphire.samples.map.ui.MapEditor" >+ name="Map Editor"/> >+ </extension> >+ >+ <extension point="org.eclipse.ui.editors"> >+ <editor >+ class="org.eclipse.sapphire.samples.library.ui.LibraryEditor" >+ default="true" >+ filenames="library.xml" >+ id="org.eclipse.sapphire.samples.library.ui.LibraryEditor" >+ name="Library Editor"/> >+ </extension> >+ > > </plugin> >Index: sdef/LibraryEditor.sdef >=================================================================== >RCS file: sdef/LibraryEditor.sdef >diff -N sdef/LibraryEditor.sdef >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ sdef/LibraryEditor.sdef 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,104 @@ >+<definition> >+ >+ <import> >+ <bundle>org.eclipse.sapphire.samples</bundle> >+ <package>org.eclipse.sapphire.samples.library</package> >+ <package>org.eclipse.sapphire.samples.library.ui</package> >+ <package>org.eclipse.sapphire.samples.library.internal</package> >+ </import> >+ >+ <diagram-page> >+ <id>diagram</id> >+ <page-name>Diagram</page-name> >+ <page-header-text>Diagram</page-header-text> >+ <node> >+ <hint><name>width</name><value>95</value></hint> >+ <hint><name>height</name><value>85</value></hint> >+ <hint><name>resizable</name><value>false</value></hint> >+ <id>books</id> >+ <tool-palette-label>Book</tool-palette-label> >+ <tool-palette-desc>Book</tool-palette-desc> >+ <property>Books</property> >+ <image> >+ <id>bookImage</id> >+ <path>images/book.png</path> >+ <hint><name>x</name><value>0</value></hint> >+ <hint><name>y</name><value>0</value></hint> >+ <hint><name>width</name><value>64</value></hint> >+ <hint><name>height</name><value>64</value></hint> >+ </image> >+ <label> >+ <content>${Title == null ? "<Title>" : Title}</content> >+ <hint><name>x</name><value>0</value></hint> >+ <hint><name>y</name><value>70</value></hint> >+ <hint><name>height</name><value>15</value></hint> >+ </label> >+ <instance-id>${Title}</instance-id> >+ <connection> >+ <id>connections</id> >+ <tool-palette-label>Book Reference</tool-palette-label> >+ <tool-palette-desc>Book Reference</tool-palette-desc> >+ <property>ReferencedBooks</property> >+ <label> >+ <content>Reference</content> >+ </label> >+ <endpoint> >+ <property>ReferencedBook</property> >+ <value>${Title}</value> >+ <type>ARROW</type> >+ </endpoint> >+ <instance-id>${ReferencedBook}</instance-id> >+ </connection> >+ </node> >+ </diagram-page> >+ >+ <editor-page> >+ <id>overview</id> >+ <page-name>Overview</page-name> >+ <page-header-text>Overview</page-header-text> >+ <root-node> >+ <node> >+ <label>Books</label> >+ <section> >+ <description>Books in the library</description> >+ <content> >+ <property-editor> >+ <property>Books</property> >+ <child-property> >+ <property>Title</property> >+ </child-property> >+ <child-property> >+ <property>Author</property> >+ </child-property> >+ <hint><name>show.label.above</name><value>true</value></hint> >+ <hint> >+ <name>column.widths</name> >+ <value>150,150</value> >+ </hint> >+ </property-editor> >+ <separator> >+ <label>References</label> >+ </separator> >+ <switching-panel> >+ <list-selection-controller> >+ <property>Books</property> >+ </list-selection-controller> >+ <panel> >+ <key>IBook</key> >+ <content> >+ <property-editor>ReferencedBooks</property-editor> >+ </content> >+ </panel> >+ <default-panel> >+ <content> >+ <label>Select a book above to configure additional properties.</label> >+ </content> >+ </default-panel> >+ </switching-panel> >+ </content> >+ </section> >+ </node> >+ </root-node> >+ </editor-page> >+ >+</definition> >\ No newline at end of file >Index: sdef/MapEditor.sdef >=================================================================== >RCS file: sdef/MapEditor.sdef >diff -N sdef/MapEditor.sdef >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ sdef/MapEditor.sdef 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,73 @@ >+<definition> >+ >+ <import> >+ <bundle>org.eclipse.sapphire.samples</bundle> >+ <package>org.eclipse.sapphire.samples.map</package> >+ <package>org.eclipse.sapphire.samples.map.ui</package> >+ </import> >+ >+ <diagram-page> >+ <id>diagram</id> >+ <page-name>Diagram</page-name> >+ <page-header-text>Diagram</page-header-text> >+ <node> >+ <id>destinations</id> >+ <tool-palette-label>Destination</tool-palette-label> >+ <tool-palette-desc>Map Destination</tool-palette-desc> >+ <hint><name>width</name><value>70</value></hint> >+ <hint><name>height</name><value>85</value></hint> >+ <property>Destinations</property> >+ <label> >+ <content>${Name == null ? "<Destination>" : Name}</content> >+ </label> >+ <instance-id>${Name}</instance-id> >+ </node> >+ <connection> >+ <id>connections</id> >+ <tool-palette-label>Route</tool-palette-label> >+ <tool-palette-desc>Map Route</tool-palette-desc> >+ <property>Routes</property> >+ <label> >+ <content>${Distance == null ? "<Distance>" : Distance}</content> >+ </label> >+ <endpoint1> >+ <property>FromDestination</property> >+ <value>${Name}</value> >+ <type>NONE</type> >+ </endpoint1> >+ <endpoint2> >+ <property>ToDestination</property> >+ <value>${Name}</value> >+ <type>ARROW</type> >+ </endpoint2> >+ <instance-id>${FromDestination}-${ToDestination}</instance-id> >+ </connection> >+ </diagram-page> >+ >+ <editor-page> >+ <id>overview</id> >+ <page-name>Overview</page-name> >+ <page-header-text>Overview</page-header-text> >+ <root-node> >+ <node> >+ <label>Destinations</label> >+ <section> >+ <description>Destinations in the map</description> >+ <content> >+ <property-editor>Destinations</property-editor> >+ </content> >+ </section> >+ </node> >+ <node> >+ <label>Routes</label> >+ <section> >+ <description>Routes in the map</description> >+ <content> >+ <property-editor>Routes</property-editor> >+ </content> >+ </section> >+ </node> >+ </root-node> >+ </editor-page> >+</definition> >+ >\ No newline at end of file >Index: src/org/eclipse/sapphire/samples/library/IBook.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/library/IBook.java >diff -N src/org/eclipse/sapphire/samples/library/IBook.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/library/IBook.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,53 @@ >+package org.eclipse.sapphire.samples.library; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.NonNullValue; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; >+ >+@GenerateImpl >+ >+public interface IBook extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IBook.class ); >+ >+ // *** Title *** >+ >+ @XmlBinding( path = "title" ) >+ @Label( standard = "title" ) >+ @NonNullValue >+ >+ ValueProperty PROP_TITLE = new ValueProperty( TYPE, "Title" ); >+ >+ Value<String> getTitle(); >+ void setTitle( String name ); >+ >+ // *** Author *** >+ >+ @XmlBinding( path = "Author" ) >+ @Label( standard = "Author" ) >+ @NonNullValue >+ >+ ValueProperty PROP_AUTHOR = new ValueProperty( TYPE, "Author" ); >+ >+ Value<String> getAuthor(); >+ void setAuthor( String author ); >+ >+ // *** ReferencedBooks *** >+ >+ @Type( base = IBookReference.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "referenced-book", type = IBookReference.class ) ) >+ >+ ListProperty PROP_REFERENCED_BOOKS = new ListProperty( TYPE, "ReferencedBooks" ); >+ >+ ModelElementList<IBookReference> getReferencedBooks(); >+ >+} >Index: src/org/eclipse/sapphire/samples/library/IBookReference.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/library/IBookReference.java >diff -N src/org/eclipse/sapphire/samples/library/IBookReference.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/library/IBookReference.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+package org.eclipse.sapphire.samples.library; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.ReferenceValue; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.NonNullValue; >+import org.eclipse.sapphire.modeling.annotations.Reference; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.samples.library.internal.BookReferenceService; >+ >+@GenerateImpl >+ >+public interface IBookReference extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IBookReference.class ); >+ >+ // *** ReferencedBook *** >+ >+ @Reference( target = IBook.class, service = BookReferenceService.class ) >+ @XmlBinding( path = "referenced-book") >+ @NonNullValue >+ @Label(standard = "referenced book") >+ >+ ValueProperty PROP_REFERENCED_BOOK = new ValueProperty( TYPE, "ReferencedBook" ); >+ >+ ReferenceValue<IBook> getReferencedBook(); >+ void setReferencedBook( String name ); >+ >+} >Index: src/org/eclipse/sapphire/samples/library/ILibrary.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/library/ILibrary.java >diff -N src/org/eclipse/sapphire/samples/library/ILibrary.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/library/ILibrary.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+package org.eclipse.sapphire.samples.library; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding; >+ >+@GenerateImpl >+@XmlRootBinding( elementName = "library") >+ >+public interface ILibrary extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( ILibrary.class ); >+ >+ // *** Books *** >+ >+ @Type( base = IBook.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "book", type = IBook.class ) ) >+ >+ ListProperty PROP_BOOKS = new ListProperty( TYPE, "Books" ); >+ >+ ModelElementList<IBook> getBooks(); >+ >+ >+} >Index: src/org/eclipse/sapphire/samples/library/internal/BookReferenceService.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/library/internal/BookReferenceService.java >diff -N src/org/eclipse/sapphire/samples/library/internal/BookReferenceService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/library/internal/BookReferenceService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+package org.eclipse.sapphire.samples.library.internal; >+ >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ReferenceService; >+import org.eclipse.sapphire.samples.library.IBook; >+import org.eclipse.sapphire.samples.library.ILibrary; >+ >+public class BookReferenceService extends ReferenceService >+{ >+ >+ @Override >+ public Object resolve(String reference) >+ { >+ if (reference != null) >+ { >+ ILibrary library = element().nearest(ILibrary.class); >+ ModelElementList<IBook> books = library.getBooks(); >+ for (IBook book : books) >+ { >+ if (reference.equals(book.getTitle().getContent())) >+ { >+ return book; >+ } >+ } >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/sapphire/samples/library/ui/LibraryEditor.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/library/ui/LibraryEditor.java >diff -N src/org/eclipse/sapphire/samples/library/ui/LibraryEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/library/ui/LibraryEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,83 @@ >+package org.eclipse.sapphire.samples.library.ui; >+ >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.xml.RootXmlResource; >+import org.eclipse.sapphire.samples.library.ILibrary; >+import org.eclipse.sapphire.ui.SapphireEditor; >+import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorInput; >+import org.eclipse.sapphire.ui.editor.views.masterdetails.MasterDetailsPage; >+import org.eclipse.sapphire.ui.xml.XmlEditorResourceStore; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.part.FileEditorInput; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; >+ >+public class LibraryEditor extends SapphireEditor >+{ >+ private ILibrary modelLibrary; >+ private StructuredTextEditor librarySourceEditor; >+ private SapphireDiagramEditorPart libraryDiagramPart; >+ private MasterDetailsPage libraryOverviewPage; >+ >+ public LibraryEditor() >+ { >+ super( "org.eclipse.sapphire.samples" ); >+ } >+ >+ @Override >+ protected void createSourcePages() throws PartInitException >+ { >+ this.librarySourceEditor = new StructuredTextEditor(); >+ this.librarySourceEditor.setEditorPart(this); >+ final FileEditorInput rootEditorInput = (FileEditorInput) getEditorInput(); >+ >+ int index = addPage( this.librarySourceEditor, rootEditorInput ); >+ setPageText( index, "library.xml" ); >+ } >+ >+ @Override >+ protected IModelElement createModel() >+ { >+ this.modelLibrary = ILibrary.TYPE.instantiate(new RootXmlResource(new XmlEditorResourceStore(this, this.librarySourceEditor))); >+ return this.modelLibrary; >+ } >+ >+ @Override >+ protected void createDiagramPages() throws PartInitException >+ { >+ IPath path = new Path( "org.eclipse.sapphire.samples/sdef/LibraryEditor.sdef/diagram" ); >+ this.libraryDiagramPart = new SapphireDiagramEditorPart(this, this.modelLibrary, path); >+ SapphireDiagramEditor diagramEditor = this.libraryDiagramPart.getDiagramEditor(); >+ SapphireDiagramEditorInput diagramEditorInput = this.libraryDiagramPart.getDiagramEditorInput(); >+ addPage(0, diagramEditor, diagramEditorInput); >+ setPageText( 0, "Diagram" ); >+ setPageId(this.pages.get(0), "Diagram"); >+ } >+ >+ @Override >+ protected void createFormPages() throws PartInitException >+ { >+ IPath path = new Path( "org.eclipse.sapphire.samples/sdef/LibraryEditor.sdef/overview" ); >+ this.libraryOverviewPage = new MasterDetailsPage(this, this.modelLibrary, path); >+ addPage(1, this.libraryOverviewPage); >+ setPageText(1, "Overview"); >+ setPageId(this.pages.get(1), "Overview"); >+ } >+ >+ public ILibrary getMap() >+ { >+ return this.modelLibrary; >+ } >+ >+ @Override >+ public void doSave( final IProgressMonitor monitor ) >+ { >+ super.doSave(monitor); >+ SapphireDiagramEditor diagramEditor = this.libraryDiagramPart.getDiagramEditor(); >+ diagramEditor.doSave(monitor); >+ } >+} >Index: src/org/eclipse/sapphire/samples/map/IDestination.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/map/IDestination.java >diff -N src/org/eclipse/sapphire/samples/map/IDestination.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/map/IDestination.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,30 @@ >+package org.eclipse.sapphire.samples.map; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.NonNullValue; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+ >+@GenerateImpl >+ >+public interface IDestination extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IDestination.class ); >+ >+ // *** Name *** >+ >+ @XmlBinding( path = "name" ) >+ @Label( standard = "name" ) >+ @NonNullValue >+ //@DefaultValue( text = "Destination" ) >+ >+ ValueProperty PROP_NAME = new ValueProperty( TYPE, "Name" ); >+ >+ Value<String> getName(); >+ void setName( String name ); >+ >+} >Index: src/org/eclipse/sapphire/samples/map/IMap.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/map/IMap.java >diff -N src/org/eclipse/sapphire/samples/map/IMap.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/map/IMap.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,37 @@ >+package org.eclipse.sapphire.samples.map; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding; >+ >+@GenerateImpl >+@XmlRootBinding( elementName = "map") >+ >+public interface IMap extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IMap.class ); >+ >+ // *** Destinations *** >+ >+ @Type( base = IDestination.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "destination", type = IDestination.class ) ) >+ >+ ListProperty PROP_DESTINATIONS = new ListProperty( TYPE, "Destinations" ); >+ >+ ModelElementList<IDestination> getDestinations(); >+ >+ // *** Routes *** >+ >+ @Type( base = IRoute.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "route", type = IRoute.class ) ) >+ >+ ListProperty PROP_ROUTES = new ListProperty( TYPE, "Routes" ); >+ >+ ModelElementList<IRoute> getRoutes(); >+ >+} >Index: src/org/eclipse/sapphire/samples/map/IRoute.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/map/IRoute.java >diff -N src/org/eclipse/sapphire/samples/map/IRoute.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/map/IRoute.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,56 @@ >+package org.eclipse.sapphire.samples.map; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.ReferenceValue; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.NonNullValue; >+import org.eclipse.sapphire.modeling.annotations.Reference; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.samples.map.internal.DestinationReferenceService; >+ >+@GenerateImpl >+ >+public interface IRoute extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IRoute.class ); >+ >+ // *** FromDestination *** >+ >+ @Reference( target = IDestination.class, service = DestinationReferenceService.class ) >+ @XmlBinding( path = "from-destination") >+ @NonNullValue >+ @Label(standard = "from destination") >+ >+ ValueProperty PROP_FROM_DESTINATION = new ValueProperty( TYPE, "FromDestination" ); >+ >+ ReferenceValue<IDestination> getFromDestination(); >+ void setFromDestination( String name ); >+ >+ // *** ToDestination *** >+ >+ @Reference( target = IDestination.class, service = DestinationReferenceService.class ) >+ @XmlBinding( path = "to-destination") >+ @NonNullValue >+ @Label(standard = "to destination") >+ >+ ValueProperty PROP_TO_DESTINATION = new ValueProperty( TYPE, "ToDestination" ); >+ >+ ReferenceValue<IDestination> getToDestination(); >+ void setToDestination( String name ); >+ >+ // *** Distance *** >+ >+ @XmlBinding( path = "distance" ) >+ @Label( standard = "distance" ) >+ @NonNullValue >+ >+ ValueProperty PROP_DISTANCE = new ValueProperty( TYPE, "Distance" ); >+ >+ Value<String> getDistance(); >+ void setDistance( String distance ); >+ >+} >Index: src/org/eclipse/sapphire/samples/map/internal/DestinationReferenceService.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/map/internal/DestinationReferenceService.java >diff -N src/org/eclipse/sapphire/samples/map/internal/DestinationReferenceService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/map/internal/DestinationReferenceService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,29 @@ >+package org.eclipse.sapphire.samples.map.internal; >+ >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ReferenceService; >+import org.eclipse.sapphire.samples.map.IDestination; >+import org.eclipse.sapphire.samples.map.IMap; >+ >+public class DestinationReferenceService extends ReferenceService >+{ >+ >+ @Override >+ public Object resolve(String reference) >+ { >+ if (reference != null) >+ { >+ IMap map = element().nearest(IMap.class); >+ ModelElementList<IDestination> dests = map.getDestinations(); >+ for (IDestination dest : dests) >+ { >+ if (reference.equals(dest.getName().getContent())) >+ { >+ return dest; >+ } >+ } >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/sapphire/samples/map/ui/MapEditor.java >=================================================================== >RCS file: src/org/eclipse/sapphire/samples/map/ui/MapEditor.java >diff -N src/org/eclipse/sapphire/samples/map/ui/MapEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/samples/map/ui/MapEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,83 @@ >+package org.eclipse.sapphire.samples.map.ui; >+ >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.xml.RootXmlResource; >+import org.eclipse.sapphire.samples.map.IMap; >+import org.eclipse.sapphire.ui.SapphireEditor; >+import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorInput; >+import org.eclipse.sapphire.ui.editor.views.masterdetails.MasterDetailsPage; >+import org.eclipse.sapphire.ui.xml.XmlEditorResourceStore; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.part.FileEditorInput; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; >+ >+public class MapEditor extends SapphireEditor >+{ >+ private IMap modelMap; >+ private StructuredTextEditor mapSourceEditor; >+ private SapphireDiagramEditorPart mapDiagramPart; >+ private MasterDetailsPage mapOverviewPage; >+ >+ public MapEditor() >+ { >+ super( "org.eclipse.sapphire.samples" ); >+ } >+ >+ @Override >+ protected void createSourcePages() throws PartInitException >+ { >+ this.mapSourceEditor = new StructuredTextEditor(); >+ this.mapSourceEditor.setEditorPart(this); >+ final FileEditorInput rootEditorInput = (FileEditorInput) getEditorInput(); >+ >+ int index = addPage( this.mapSourceEditor, rootEditorInput ); >+ setPageText( index, "map.xml" ); >+ } >+ >+ @Override >+ protected IModelElement createModel() >+ { >+ this.modelMap = IMap.TYPE.instantiate(new RootXmlResource(new XmlEditorResourceStore(this, this.mapSourceEditor))); >+ return this.modelMap; >+ } >+ >+ @Override >+ protected void createDiagramPages() throws PartInitException >+ { >+ IPath path = new Path( "org.eclipse.sapphire.samples/sdef/MapEditor.sdef/diagram" ); >+ this.mapDiagramPart = new SapphireDiagramEditorPart(this, this.modelMap, path); >+ SapphireDiagramEditor diagramEditor = this.mapDiagramPart.getDiagramEditor(); >+ SapphireDiagramEditorInput diagramEditorInput = this.mapDiagramPart.getDiagramEditorInput(); >+ addPage(0, diagramEditor, diagramEditorInput); >+ setPageText( 0, "Diagram" ); >+ setPageId(this.pages.get(0), "Diagram"); >+ } >+ >+ @Override >+ protected void createFormPages() throws PartInitException >+ { >+ IPath path = new Path( "org.eclipse.sapphire.samples/sdef/MapEditor.sdef/overview" ); >+ this.mapOverviewPage = new MasterDetailsPage(this, this.modelMap, path); >+ addPage(1, this.mapOverviewPage); >+ setPageText(1, "Overview"); >+ setPageId(this.pages.get(1), "Overview"); >+ } >+ >+ public IMap getMap() >+ { >+ return this.modelMap; >+ } >+ >+ @Override >+ public void doSave( final IProgressMonitor monitor ) >+ { >+ super.doSave(monitor); >+ SapphireDiagramEditor diagramEditor = this.mapDiagramPart.getDiagramEditor(); >+ diagramEditor.doSave(monitor); >+ } >+} >#P org.eclipse.sapphire.ui >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.3 >diff -u -r1.3 MANIFEST.MF >--- META-INF/MANIFEST.MF 27 Nov 2010 03:44:29 -0000 1.3 >+++ META-INF/MANIFEST.MF 20 Dec 2010 18:26:06 -0000 >@@ -19,7 +19,9 @@ > org.eclipse.sapphire.ui.swt.renderer, > org.eclipse.sapphire.ui.swt.renderer.actions, > org.eclipse.sapphire.ui.util, >- org.eclipse.sapphire.ui.xml >+ org.eclipse.sapphire.ui.xml, >+ org.eclipse.sapphire.ui.diagram.editor, >+ org.eclipse.sapphire.ui.diagram.graphiti.editor > Require-Bundle: org.eclipse.debug.ui, > org.eclipse.jdt.ui, > org.eclipse.ui.forms;visibility:=reexport, >@@ -37,6 +39,13 @@ > org.eclipse.help, > org.eclipse.ui.views, > org.eclipse.jface.text, >- org.apache.ant >+ org.apache.ant, >+ org.eclipse.gef, >+ org.eclipse.graphiti, >+ org.eclipse.graphiti.mm, >+ org.eclipse.graphiti.pattern, >+ org.eclipse.graphiti.ui, >+ org.eclipse.emf.transaction, >+ org.eclipse.ui.views.properties.tabbed > Bundle-ActivationPolicy: lazy > Bundle-RequiredExecutionEnvironment: J2SE-1.5 >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/plugin.properties,v >retrieving revision 1.2 >diff -u -r1.2 plugin.properties >--- plugin.properties 16 Nov 2010 04:26:07 -0000 1.2 >+++ plugin.properties 20 Dec 2010 18:26:06 -0000 >@@ -15,3 +15,7 @@ > showInSourceCommandName = Show in Source > showInSourceCommandDescription = Shows the location in the source file that corresponds to the selected entity. > builderName = Sapphire UI Builder >+sapphireDiagramTypeDescription = Sapphire Diagram Type >+sapphireDiagramTypeName = Sapphire Diagram Type >+sapphireDiagramTypeProviderDescription = Sapphire Diagram Type Provider >+sapphireDiagramTypeProviderName = Sapphire Diagram Type Provider >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/plugin.xml,v >retrieving revision 1.4 >diff -u -r1.4 plugin.xml >--- plugin.xml 13 Dec 2010 16:46:37 -0000 1.4 >+++ plugin.xml 20 Dec 2010 18:26:06 -0000 >@@ -24,4 +24,32 @@ > </builder> > </extension> > >+ <extension point="org.eclipse.graphiti.ui.diagramTypes"> >+ <diagramType >+ description="%sapphireDiagramTypeDescription" >+ id="org.eclipse.sapphire.ui.SapphireDiagramType" >+ name="%sapphireDiagramTypeName" >+ type="sapphireDiagram"> >+ </diagramType> >+ </extension> >+ >+ <extension point="org.eclipse.graphiti.ui.diagramTypeProviders"> >+ <diagramTypeProvider >+ class="org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramTypeProvider" >+ description="%sapphireDiagramTypeProviderDescription" >+ id="org.eclipse.sapphire.ui.sapphireDiagramTypeProvider" >+ name="%sapphireDiagramTypeProviderName"> >+ <diagramType id="org.eclipse.sapphire.ui.SapphireDiagramType"/> >+ <imageProvider id="org.eclipse.sapphire.diagram.graphiti.SapphireDiagramImageProvider"/> >+ </diagramTypeProvider> >+ </extension> >+ >+ <extension >+ point="org.eclipse.graphiti.ui.imageProviders"> >+ <imageProvider >+ class="org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramImageProvider" >+ id="org.eclipse.sapphire.diagram.graphiti.SapphireDiagramImageProvider"> >+ </imageProvider> >+ </extension> >+ > </plugin> >Index: src/org/eclipse/sapphire/ui/SapphireEditor.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/SapphireEditor.java,v >retrieving revision 1.5 >diff -u -r1.5 SapphireEditor.java >--- src/org/eclipse/sapphire/ui/SapphireEditor.java 13 Dec 2010 16:46:35 -0000 1.5 >+++ src/org/eclipse/sapphire/ui/SapphireEditor.java 20 Dec 2010 18:26:06 -0000 >@@ -18,6 +18,7 @@ > import java.net.URI; > import java.util.Collections; > import java.util.HashMap; >+import java.util.Iterator; > import java.util.Map; > import java.util.Set; > >@@ -285,6 +286,8 @@ > this.model = createModel(); > adaptModel( this.model ); > >+ createDiagramPages(); >+ > createFormPages(); > > createFileChangeListener(); >@@ -330,6 +333,12 @@ > protected abstract void createSourcePages() throws PartInitException; > protected abstract void createFormPages() throws PartInitException; > >+ // default impl does nothing, subclass may override it to add diagram pages >+ protected void createDiagramPages() throws PartInitException >+ { >+ >+ } >+ > protected final void setPageId( final Object page, > final String id ) > { >Index: src/org/eclipse/sapphire/ui/def/ISapphireUiDef.java >=================================================================== >RCS file: /cvsroot/technology/org.eclipse.sapphire/plugins/org.eclipse.sapphire.ui/src/org/eclipse/sapphire/ui/def/ISapphireUiDef.java,v >retrieving revision 1.3 >diff -u -r1.3 ISapphireUiDef.java >--- src/org/eclipse/sapphire/ui/def/ISapphireUiDef.java 13 Dec 2010 16:46:36 -0000 1.3 >+++ src/org/eclipse/sapphire/ui/def/ISapphireUiDef.java 20 Dec 2010 18:26:07 -0000 >@@ -26,6 +26,7 @@ > import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; > import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding; > import org.eclipse.sapphire.ui.def.internal.SapphireUiDefMethods; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramPageDef; > > /** > * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a> >@@ -129,6 +130,15 @@ > > ModelElementList<IEditorPageDef> getEditorPageDefs(); > >+ // *** DiagramPageDefs *** >+ >+ @Type( base = IDiagramPageDef.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "diagram-page", type = IDiagramPageDef.class ) ) >+ >+ ListProperty PROP_DIAGRAM_PAGE_DEFS = new ListProperty( TYPE, "DiagramPageDefs" ); >+ >+ ModelElementList<IDiagramPageDef> getDiagramPageDefs(); >+ > // *** DialogDefs *** > > @Type( base = ISapphireDialogDef.class ) >Index: src/org/eclipse/sapphire/ui/def/SapphireDiagramDefFactory.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/def/SapphireDiagramDefFactory.java >diff -N src/org/eclipse/sapphire/ui/def/SapphireDiagramDefFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/def/SapphireDiagramDefFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,51 @@ >+package org.eclipse.sapphire.ui.def; >+ >+import org.eclipse.sapphire.modeling.BundleResourceStore; >+import org.eclipse.sapphire.modeling.ResourceStoreException; >+import org.eclipse.sapphire.modeling.SharedModelsCache; >+import org.eclipse.sapphire.modeling.xml.RootXmlResource; >+import org.eclipse.sapphire.modeling.xml.XmlResourceStore; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramPageDef; >+import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin; >+ >+public class SapphireDiagramDefFactory >+{ >+ public static IDiagramPageDef load(final String bundleId, final String path) >+ { >+ try >+ { >+ return load( new XmlResourceStore( new BundleResourceStore( bundleId, path ) ), false ); >+ } >+ catch( ResourceStoreException e ) >+ { >+ SapphireUiFrameworkPlugin.log( e ); >+ return null; >+ } >+ } >+ >+ public static IDiagramPageDef load( final XmlResourceStore resourceStore, >+ final boolean writable ) >+ { >+ IDiagramPageDef model; >+ >+ if( writable ) >+ { >+ model = IDiagramPageDef.TYPE.instantiate( new RootXmlResource( resourceStore ) ); >+ } >+ else >+ { >+ final SharedModelsCache.StandardKey key = new SharedModelsCache.StandardKey( resourceStore, IDiagramPageDef.TYPE ); >+ >+ model = (IDiagramPageDef) SharedModelsCache.retrieve( key ); >+ >+ if( model == null ) >+ { >+ model = IDiagramPageDef.TYPE.instantiate( new RootXmlResource( resourceStore ) ); >+ SharedModelsCache.store( key, model ); >+ } >+ } >+ return model; >+ } >+ >+} >+ >Index: src/org/eclipse/sapphire/ui/diagram/def/ConnectionEndpointType.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/ConnectionEndpointType.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/ConnectionEndpointType.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/ConnectionEndpointType.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,10 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+ >+public enum ConnectionEndpointType >+{ >+ NONE, >+ ARROW, >+ CIRCLE, >+ ELLIPSE; >+} >Index: src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionDef.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionDef.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionDef.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionDef.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,100 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+import org.eclipse.sapphire.modeling.ElementProperty; >+import org.eclipse.sapphire.modeling.ModelElementHandle; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+ >+@GenerateImpl >+ >+public interface IDiagramConnectionDef >+ >+ extends ISapphirePartDef >+ >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramConnectionDef.class ); >+ >+ // *** Id *** >+ >+ @Label( standard = "ID" ) >+ @XmlBinding( path = "id" ) >+ >+ ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" ); >+ >+ Value<String> getId(); >+ void setId( String id ); >+ >+ // *** Property *** >+ >+ @Label( standard = "property" ) >+ @XmlBinding( path = "property" ) >+ >+ ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" ); >+ >+ Value<String> getProperty(); >+ void setProperty( String property ); >+ >+ // *** ToolPaletteLabel *** >+ >+ @Label( standard = "tool palette label" ) >+ @XmlBinding( path = "tool-palette-label" ) >+ >+ ValueProperty PROP_TOOL_PALETTE_LABEL = new ValueProperty( TYPE, "ToolPaletteLabel" ); >+ >+ Value<String> getToolPaletteLabel(); >+ void setToolPaletteLabel( String paletteLabel ); >+ >+ // *** ToolPaletteDesc *** >+ >+ @Label( standard = "tool palette description" ) >+ @XmlBinding( path = "tool-palette-desc" ) >+ >+ ValueProperty PROP_TOOL_PALETTE_DESC = new ValueProperty( TYPE, "ToolPaletteDesc" ); >+ >+ Value<String> getToolPaletteDesc(); >+ void setToolPaletteDesc( String paletteDesc ); >+ >+ // *** Label *** >+ >+ @Type( base = IDiagramLabelDef.class ) >+ @XmlBinding( path = "label" ) >+ >+ ElementProperty PROP_LABEL = new ElementProperty( TYPE, "Label" ); >+ >+ ModelElementHandle<IDiagramLabelDef> getLabel(); >+ >+ // *** Endpoint1 *** >+ >+ @Type( base = IDiagramConnectionEndpointDef.class ) >+ @XmlBinding( path = "endpoint1" ) >+ >+ ElementProperty PROP_ENDPOINT_1 = new ElementProperty( TYPE, "Endpoint1" ); >+ >+ ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint1(); >+ >+ // *** Endpoint2 *** >+ >+ @Type( base = IDiagramConnectionEndpointDef.class ) >+ @XmlBinding( path = "endpoint2" ) >+ >+ ElementProperty PROP_ENDPOINT_2 = new ElementProperty( TYPE, "Endpoint2" ); >+ >+ ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint2(); >+ >+ // *** InstanceId *** >+ >+ @Label( standard = "instance id" ) >+ @XmlBinding( path = "instance-id" ) >+ >+ ValueProperty PROP_INSTANCE_ID = new ValueProperty( TYPE, "InstanceId" ); >+ >+ Value<String> getInstanceId(); >+ void setInstanceId( String instanceId ); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionEndpointDef.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionEndpointDef.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionEndpointDef.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionEndpointDef.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,54 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+ >+@GenerateImpl >+ >+public interface IDiagramConnectionEndpointDef >+ >+ extends ISapphirePartDef >+ >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramConnectionEndpointDef.class ); >+ >+ // *** Property *** >+ >+ @Label( standard = "property" ) >+ @XmlBinding( path = "property" ) >+ >+ ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" ); >+ >+ Value<String> getProperty(); >+ void setProperty( String property ); >+ >+ // *** Value *** >+ >+ @Label( standard = "value" ) >+ @XmlBinding( path = "value" ) >+ >+ ValueProperty PROP_VALUE = new ValueProperty( TYPE, "Value" ); >+ >+ Value<String> getValue(); >+ void setValue( String value ); >+ >+ >+ // *** Type *** >+ >+ @Type( base = ConnectionEndpointType.class ) >+ @XmlBinding( path = "connectionDecoratorType" ) >+ >+ ValueProperty PROP_TYPE = new ValueProperty( TYPE, "Type" ); >+ >+ Value<ConnectionEndpointType> getType(); >+ void setType( String value ); >+ void setType( ConnectionEndpointType value ); >+ >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/def/IDiagramEmbeddedConnectionDef.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/IDiagramEmbeddedConnectionDef.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/IDiagramEmbeddedConnectionDef.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/IDiagramEmbeddedConnectionDef.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,92 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+import org.eclipse.sapphire.modeling.ElementProperty; >+import org.eclipse.sapphire.modeling.ModelElementHandle; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+ >+@GenerateImpl >+ >+public interface IDiagramEmbeddedConnectionDef >+ >+ extends ISapphirePartDef >+ >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramEmbeddedConnectionDef.class ); >+ >+ // *** Id *** >+ >+ @Label( standard = "ID" ) >+ @XmlBinding( path = "id" ) >+ >+ ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" ); >+ >+ Value<String> getId(); >+ void setId( String id ); >+ >+ // *** Property *** >+ >+ @Label( standard = "property" ) >+ @XmlBinding( path = "property" ) >+ >+ ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" ); >+ >+ Value<String> getProperty(); >+ void setProperty( String property ); >+ >+ // *** ToolPaletteLabel *** >+ >+ @Label( standard = "tool palette label" ) >+ @XmlBinding( path = "tool-palette-label" ) >+ >+ ValueProperty PROP_TOOL_PALETTE_LABEL = new ValueProperty( TYPE, "ToolPaletteLabel" ); >+ >+ Value<String> getToolPaletteLabel(); >+ void setToolPaletteLabel( String paletteLabel ); >+ >+ // *** ToolPaletteDesc *** >+ >+ @Label( standard = "tool palette description" ) >+ @XmlBinding( path = "tool-palette-desc" ) >+ >+ ValueProperty PROP_TOOL_PALETTE_DESC = new ValueProperty( TYPE, "ToolPaletteDesc" ); >+ >+ Value<String> getToolPaletteDesc(); >+ void setToolPaletteDesc( String paletteDesc ); >+ >+ // *** Label *** >+ >+ @Type( base = IDiagramLabelDef.class ) >+ @XmlBinding( path = "label" ) >+ >+ ElementProperty PROP_LABEL = new ElementProperty( TYPE, "Label" ); >+ >+ ModelElementHandle<IDiagramLabelDef> getLabel(); >+ >+ // *** Endpoint *** >+ >+ @Type( base = IDiagramConnectionEndpointDef.class ) >+ @XmlBinding( path = "endpoint" ) >+ >+ ElementProperty PROP_ENDPOINT = new ElementProperty( TYPE, "Endpoint" ); >+ >+ ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint(); >+ >+ // *** InstanceId *** >+ >+ @Label( standard = "instance id" ) >+ @XmlBinding( path = "instance-id" ) >+ >+ ValueProperty PROP_INSTANCE_ID = new ValueProperty( TYPE, "InstanceId" ); >+ >+ Value<String> getInstanceId(); >+ void setInstanceId( String instanceId ); >+ >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/def/IDiagramLabelDef.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/IDiagramLabelDef.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/IDiagramLabelDef.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/IDiagramLabelDef.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,30 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+ >+@GenerateImpl >+ >+public interface IDiagramLabelDef >+ >+ extends ISapphirePartDef >+ >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramLabelDef.class ); >+ >+ // *** Content *** >+ >+ @Label( standard = "content" ) >+ @XmlBinding( path = "content" ) >+ >+ ValueProperty PROP_CONTENT = new ValueProperty( TYPE, "Content" ); >+ >+ Value<String> getContent(); >+ void setContent( String content ); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeDef.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeDef.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeDef.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeDef.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,100 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+import org.eclipse.sapphire.modeling.ElementProperty; >+import org.eclipse.sapphire.modeling.ModelElementHandle; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+ >+@GenerateImpl >+ >+public interface IDiagramNodeDef >+ >+ extends ISapphirePartDef >+ >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramNodeDef.class ); >+ >+ // *** Id *** >+ >+ @Label( standard = "ID" ) >+ @XmlBinding( path = "id" ) >+ >+ ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" ); >+ >+ Value<String> getId(); >+ void setId( String id ); >+ >+ // *** ToolPaletteLabel *** >+ >+ @Label( standard = "tool palette label" ) >+ @XmlBinding( path = "tool-palette-label" ) >+ >+ ValueProperty PROP_TOOL_PALETTE_LABEL = new ValueProperty( TYPE, "ToolPaletteLabel" ); >+ >+ Value<String> getToolPaletteLabel(); >+ void setToolPaletteLabel( String paletteLabel ); >+ >+ // *** ToolPaletteDesc *** >+ >+ @Label( standard = "tool palette description" ) >+ @XmlBinding( path = "tool-palette-desc" ) >+ >+ ValueProperty PROP_TOOL_PALETTE_DESC = new ValueProperty( TYPE, "ToolPaletteDesc" ); >+ >+ Value<String> getToolPaletteDesc(); >+ void setToolPaletteDesc( String paletteDesc ); >+ >+ // *** Property *** >+ >+ @Label( standard = "property" ) >+ @XmlBinding( path = "property" ) >+ >+ ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" ); >+ >+ Value<String> getProperty(); >+ void setProperty( String property ); >+ >+ // *** Image *** >+ >+ @Type( base = IDiagramNodeImageDef.class ) >+ @XmlBinding( path = "image" ) >+ >+ ElementProperty PROP_IMAGE = new ElementProperty( TYPE, "Image" ); >+ >+ ModelElementHandle<IDiagramNodeImageDef> getImage(); >+ >+ // *** Label *** >+ >+ @Type( base = IDiagramLabelDef.class ) >+ @XmlBinding( path = "label" ) >+ >+ ElementProperty PROP_LABEL = new ElementProperty( TYPE, "Label" ); >+ >+ ModelElementHandle<IDiagramLabelDef> getLabel(); >+ >+ // *** InstanceId *** >+ >+ @Label( standard = "instance id" ) >+ @XmlBinding( path = "instance-id" ) >+ >+ ValueProperty PROP_INSTANCE_ID = new ValueProperty( TYPE, "InstanceId" ); >+ >+ Value<String> getInstanceId(); >+ void setInstanceId( String instanceId ); >+ >+ // *** EmbeddedConnections *** >+ >+ @Type( base = IDiagramEmbeddedConnectionDef.class ) >+ @XmlBinding( path = "connection" ) >+ >+ ElementProperty PROP_EMBEDDED_CONNECTIONS = new ElementProperty( TYPE, "EmbeddedConnections" ); >+ >+ ModelElementHandle<IDiagramEmbeddedConnectionDef> getEmbeddedConnections(); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeImageDef.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeImageDef.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeImageDef.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeImageDef.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+ >+@GenerateImpl >+ >+public interface IDiagramNodeImageDef >+ >+ extends ISapphirePartDef >+ >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramNodeImageDef.class ); >+ >+ // *** ImageId *** >+ >+ @Label( standard = "image id" ) >+ @XmlBinding( path = "id" ) >+ >+ ValueProperty PROP_IMAGE_ID = new ValueProperty( TYPE, "ImageId" ); >+ >+ Value<String> getImageId(); >+ void setImageId( String Id ); >+ >+ // *** ImagePath *** >+ >+ @Label( standard = "image path" ) >+ @XmlBinding( path = "path" ) >+ >+ ValueProperty PROP_IMAGE_PATH = new ValueProperty( TYPE, "ImagePath" ); >+ >+ Value<String> getImagePath(); >+ void setImagePath( String path ); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/def/IDiagramPageDef.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/def/IDiagramPageDef.java >diff -N src/org/eclipse/sapphire/ui/diagram/def/IDiagramPageDef.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/def/IDiagramPageDef.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,75 @@ >+package org.eclipse.sapphire.ui.diagram.def; >+ >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.DefaultValue; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Label; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+ >+@GenerateImpl >+ >+public interface IDiagramPageDef >+ >+ extends ISapphirePartDef >+ >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramPageDef.class); >+ >+ // *** Id *** >+ >+ @Label( standard = "ID" ) >+ @XmlBinding( path = "id" ) >+ >+ ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" ); >+ >+ Value<String> getId(); >+ void setId( String id ); >+ >+ // *** PageName *** >+ >+ @Label( standard = "page name" ) >+ @DefaultValue( text = "Diagram" ) >+ @XmlBinding( path = "page-name" ) >+ >+ ValueProperty PROP_PAGE_NAME = new ValueProperty( TYPE, "PageName" ); >+ >+ Value<String> getPageName(); >+ void setPageName( String pageName ); >+ >+ // *** PageHeaderText *** >+ >+ @Label( standard = "page header text" ) >+ @DefaultValue( text = "Diagram View" ) >+ @XmlBinding( path = "page-header-text" ) >+ >+ ValueProperty PROP_PAGE_HEADER_TEXT = new ValueProperty( TYPE, "PageHeaderText" ); >+ >+ Value<String> getPageHeaderText(); >+ void setPageHeaderText( String pageHeaderText ); >+ >+ // *** DiagramNodeDefs *** >+ >+ @Type( base = IDiagramNodeDef.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "node", type = IDiagramNodeDef.class ) ) >+ >+ ListProperty PROP_DIAGRAM_NODE_DEFS = new ListProperty( TYPE, "DiagramNodeDefs" ); >+ >+ ModelElementList<IDiagramNodeDef> getDiagramNodeDefs(); >+ >+ // *** DiagramConnectionDefs *** >+ >+ @Type( base = IDiagramConnectionDef.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "connection", type = IDiagramConnectionDef.class ) ) >+ >+ ListProperty PROP_DIAGRAM_CONNECTION_DEFS = new ListProperty( TYPE, "DiagramConnectionDefs" ); >+ >+ ModelElementList<IDiagramConnectionDef> getDiagramConnectionDefs(); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionPart.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionPart.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,234 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.ModelProperty; >+import org.eclipse.sapphire.modeling.ReferenceValue; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.el.Function; >+import org.eclipse.sapphire.ui.SapphirePart; >+import org.eclipse.sapphire.ui.SapphireRenderingContext; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef; >+ >+public class DiagramConnectionPart extends SapphirePart >+{ >+ private DiagramConnectionTemplate connectionTemplate; >+ private IDiagramConnectionDef localDefinition; >+ protected IModelElement modelElement; >+ private IDiagramConnectionEndpointDef endpoint1Def; >+ private IDiagramConnectionEndpointDef endpoint2Def; >+ private IModelElement endpoint1Model; >+ private IModelElement endpoint2Model; >+ protected Function labelFunction; >+ protected ValueProperty labelProperty; >+ protected Function idFunction; >+ private Function endpoint1Function; >+ private Function endpoint2Function; >+ >+ public DiagramConnectionPart() {} >+ >+ public DiagramConnectionPart(DiagramConnectionTemplate connectionTemplate) >+ { >+ this.connectionTemplate = connectionTemplate; >+ } >+ >+ @Override >+ protected void init() >+ { >+ super.init(); >+ >+ this.localDefinition = (IDiagramConnectionDef)super.definition; >+ this.modelElement = getModelElement(); >+ this.labelFunction = initExpression >+ ( >+ this.localDefinition.getLabel().element().getContent().getLocalizedText(), >+ new Runnable() >+ { >+ public void run() >+ { >+ } >+ } >+ ); >+ >+ this.labelProperty = FunctionUtil.getFunctionProperty(this.modelElement, this.labelFunction); >+ >+ this.idFunction = initExpression >+ ( >+ this.localDefinition.getInstanceId().getLocalizedText(), >+ new Runnable() >+ { >+ public void run() >+ { >+ } >+ } >+ ); >+ >+ this.endpoint1Def = this.localDefinition.getEndpoint1().element(); >+ this.endpoint2Def = this.localDefinition.getEndpoint2().element(); >+ this.endpoint1Model = processEndpoint(this.endpoint1Def); >+ this.endpoint2Model = processEndpoint(this.endpoint2Def); >+ this.endpoint1Function = initExpression >+ ( >+ this.endpoint1Model, >+ this.endpoint1Def.getValue().getContent(), >+ new Runnable() >+ { >+ public void run() >+ { >+ refreshEndpoint1(); >+ } >+ } >+ ); >+ this.endpoint2Function = initExpression >+ ( >+ this.endpoint2Model, >+ this.endpoint2Def.getValue().getContent(), >+ new Runnable() >+ { >+ public void run() >+ { >+ refreshEndpoint2(); >+ } >+ } >+ ); >+ } >+ >+ public DiagramConnectionTemplate getDiagramConnectionTemplate() >+ { >+ return this.connectionTemplate; >+ } >+ >+ public IModelElement getLocalModelElement() >+ { >+ return this.modelElement; >+ } >+ >+ public IModelElement getEndpoint1() >+ { >+ return this.endpoint1Model; >+ } >+ >+ public IModelElement getEndpoint2() >+ { >+ return this.endpoint2Model; >+ } >+ >+ public boolean canEditLabel() >+ { >+ return this.labelProperty != null; >+ } >+ >+ public String getLabel() >+ { >+ String label = null; >+ >+ if( this.labelFunction != null ) >+ { >+ label = (String) this.labelFunction.value(); >+ } >+ >+ if( label == null ) >+ { >+ label = "#null#"; >+ } >+ >+ return label; >+ } >+ >+ public void setLabel(String newValue) >+ { >+ if (this.labelProperty != null) >+ { >+ this.modelElement.write(this.labelProperty, newValue); >+ } >+ } >+ >+ public String getInstanceId() >+ { >+ String id = null; >+ >+ if( this.idFunction != null ) >+ { >+ id = (String) this.idFunction.value(); >+ } >+ >+ if( id == null ) >+ { >+ id = "#null#"; >+ } >+ >+ return id; >+ } >+ >+ @Override >+ public void render(SapphireRenderingContext context) >+ { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public void refreshEndpoint1() >+ { >+ if (this.endpoint1Function != null) >+ { >+ Object value = this.endpoint1Function.value(); >+ String property = this.endpoint1Def.getProperty().getContent(); >+ setModelProperty(this.modelElement, property, value); >+ } >+ } >+ >+ public void refreshEndpoint2() >+ { >+ if (this.endpoint2Function != null) >+ { >+ Object value = this.endpoint2Function.value(); >+ String property = this.endpoint2Def.getProperty().getContent(); >+ setModelProperty(this.modelElement, property, value); >+ } >+ } >+ >+ protected IModelElement processEndpoint(IDiagramConnectionEndpointDef endpointDef) >+ { >+ String propertyName = endpointDef.getProperty().getContent(); >+ ModelProperty modelProperty = resolve(this.modelElement, propertyName); >+ if (!(modelProperty instanceof ValueProperty)) >+ { >+ throw new RuntimeException( "Property " + propertyName + " not a ValueProperty"); >+ } >+ ValueProperty property = (ValueProperty)modelProperty; >+ Value<?> valObj = this.modelElement.read(property); >+ if (!(valObj instanceof ReferenceValue)) >+ { >+ throw new RuntimeException( "Property " + propertyName + " value not a reference"); >+ } >+ ReferenceValue<?> refVal = (ReferenceValue<?>)valObj; >+ Object targetObj = refVal.resolve(); >+ if (!(targetObj instanceof IModelElement)) >+ { >+ throw new RuntimeException( "Target not an IModelElement"); >+ } >+ return (IModelElement)targetObj; >+ } >+ >+ protected void setModelProperty(final IModelElement modelElement, >+ String propertyName, Object value) >+ { >+ if (propertyName != null) >+ { >+ final ModelElementType type = modelElement.getModelElementType(); >+ final ModelProperty property = type.getProperty( propertyName ); >+ if( property == null ) >+ { >+ throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() ); >+ } >+ if (!(property instanceof ValueProperty)) >+ { >+ throw new RuntimeException( "Property " + propertyName + " not a ValueProperty"); >+ } >+ >+ modelElement.write((ValueProperty)property, value); >+ } >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionTemplate.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionTemplate.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionTemplate.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionTemplate.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,212 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.sapphire.modeling.ElementProperty; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.ModelProperty; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.Reference; >+import org.eclipse.sapphire.modeling.el.Function; >+import org.eclipse.sapphire.modeling.el.FunctionContext; >+import org.eclipse.sapphire.modeling.el.ModelElementFunctionContext; >+import org.eclipse.sapphire.modeling.el.parser.ExpressionLanguageParser; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef; >+import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin; >+ >+public class DiagramConnectionTemplate >+{ >+ private SapphireDiagramEditorPart diagramEditor; >+ private IDiagramConnectionDef definition; >+ private IModelElement modelElement; >+ private ModelProperty modelProperty; >+ protected String toolPaletteLabel; >+ protected String toolPaletteDesc; >+ >+ protected List<DiagramConnectionPart> diagramConnections; >+ >+ public DiagramConnectionTemplate() {} >+ >+ public DiagramConnectionTemplate(final SapphireDiagramEditorPart diagramEditor, >+ IDiagramConnectionDef definition, IModelElement modelElement) >+ { >+ this.diagramEditor = diagramEditor; >+ this.modelElement = modelElement; >+ this.definition = definition; >+ >+ this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent(); >+ this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent(); >+ >+ this.diagramConnections = new ArrayList<DiagramConnectionPart>(); >+ >+ String propertyName = this.definition.getProperty().getContent(); >+ this.modelProperty = resolve(this.modelElement, propertyName); >+ if (this.modelProperty instanceof ListProperty) >+ { >+ ListProperty listProperty = (ListProperty)this.modelProperty; >+ >+ ModelElementList<?> list = this.modelElement.read(listProperty); >+ for( IModelElement listEntryModelElement : list ) >+ { >+ DiagramConnectionPart connection = new DiagramConnectionPart(this); >+ connection.init(this.diagramEditor, listEntryModelElement, definition, >+ Collections.<String,String>emptyMap()); >+ this.diagramConnections.add(connection); >+ } >+ } >+ else if (this.modelProperty instanceof ElementProperty) >+ { >+ ElementProperty elementProperty = (ElementProperty)this.modelProperty; >+ if (this.modelElement.read(elementProperty) != null) >+ { >+ IModelElement localModelElement = this.modelElement.read(elementProperty).element(); >+ DiagramConnectionPart connection = new DiagramConnectionPart(this); >+ connection.init(this.diagramEditor, localModelElement, definition, >+ Collections.<String,String>emptyMap()); >+ >+ this.diagramConnections.add(connection); >+ } >+ } >+ } >+ >+ public List<DiagramConnectionPart> getDiagramConnections() >+ { >+ return this.diagramConnections; >+ } >+ >+ public String getToolPaletteLabel() >+ { >+ return this.toolPaletteLabel; >+ } >+ >+ public String getToolPaletteDesc() >+ { >+ return this.toolPaletteDesc; >+ } >+ >+ public boolean canCreateNewConnection(DiagramNodePart srcNode, DiagramNodePart targetNode) >+ { >+ boolean canCreate = false; >+ ModelElementType srcType = srcNode.getModelElement().getModelElementType(); >+ ModelElementType targetType = targetNode.getModelElement().getModelElementType(); >+ >+ ModelElementType type = this.modelProperty.getType(); >+ ModelProperty prop1 = type.getProperty(this.definition.getEndpoint1().element().getProperty().getContent()); >+ if (prop1.getType() == null && prop1.hasAnnotation(Reference.class)) >+ { >+ canCreate = prop1.getAnnotation(Reference.class).target().isAssignableFrom(srcType.getModelElementClass()); >+ if (!canCreate) >+ return false; >+ } >+ ModelProperty prop2 = type.getProperty(this.definition.getEndpoint2().element().getProperty().getContent()); >+ if (prop2.getType() == null && prop2.hasAnnotation(Reference.class)) >+ { >+ canCreate = prop2.getAnnotation(Reference.class).target().isAssignableFrom(targetType.getModelElementClass()); >+ } >+ return canCreate; >+ } >+ >+ public DiagramConnectionPart createNewDiagramConnection(DiagramNodePart srcNode, >+ DiagramNodePart targetNode) >+ { >+ IModelElement newElement = null; >+ if (this.modelProperty instanceof ListProperty) >+ { >+ ListProperty listProperty = (ListProperty)this.modelProperty; >+ ModelElementList<?> list = this.modelElement.read(listProperty); >+ newElement = list.addNewElement(); >+ } >+ else if (this.modelProperty instanceof ElementProperty) >+ { >+ // TODO what if the element property does exist? >+ ElementProperty elementProperty = (ElementProperty)this.modelProperty; >+ newElement = this.modelElement.read(elementProperty).element(true); >+ } >+ >+ IDiagramConnectionEndpointDef srcAnchorDef = this.definition.getEndpoint1().element(); >+ String srcProperty = srcAnchorDef.getProperty().getContent(); >+ String srcExpr = srcAnchorDef.getValue().getContent(); >+ Function srcFunc = getNodeReferenceFunction(srcNode, srcExpr); >+ Object srcValue = srcFunc.value(); >+ srcFunc.dispose(); >+ setModelProperty(newElement, srcProperty, srcValue); >+ >+ IDiagramConnectionEndpointDef targetAnchorDef = this.definition.getEndpoint2().element(); >+ String targetProperty = targetAnchorDef.getProperty().getContent(); >+ String targetExpr = targetAnchorDef.getValue().getContent(); >+ Function targetFunc = getNodeReferenceFunction(targetNode, targetExpr); >+ Object targetValue = targetFunc.value(); >+ targetFunc.dispose(); >+ setModelProperty(newElement, targetProperty, targetValue); >+ >+ DiagramConnectionPart newConn = new DiagramConnectionPart(this); >+ newConn.init(this.diagramEditor, newElement, this.definition, >+ Collections.<String,String>emptyMap()); >+ this.diagramConnections.add(newConn); >+ return newConn; >+ } >+ >+ protected ModelProperty resolve(final IModelElement modelElement, >+ String propertyName) >+ { >+ if (propertyName != null) >+ { >+ final ModelElementType type = modelElement.getModelElementType(); >+ final ModelProperty property = type.getProperty( propertyName ); >+ if( property == null ) >+ { >+ throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() ); >+ } >+ return property; >+ } >+ return null; >+ } >+ >+ protected void setModelProperty(final IModelElement modelElement, >+ String propertyName, Object value) >+ { >+ if (propertyName != null) >+ { >+ final ModelElementType type = modelElement.getModelElementType(); >+ final ModelProperty property = type.getProperty( propertyName ); >+ if( property == null ) >+ { >+ throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() ); >+ } >+ if (!(property instanceof ValueProperty)) >+ { >+ throw new RuntimeException( "Property " + propertyName + " not a ValueProperty"); >+ } >+ >+ modelElement.write((ValueProperty)property, ((Value<?>)value).getContent()); >+ } >+ } >+ >+ protected Function getNodeReferenceFunction(final DiagramNodePart nodePart, >+ final String expression) >+ { >+ final FunctionContext context = new ModelElementFunctionContext( nodePart.getLocalModelElement() ); >+ Function result = null; >+ >+ if( expression != null ) >+ { >+ try >+ { >+ result = ExpressionLanguageParser.parse( context, expression ); >+ } >+ catch( Exception e ) >+ { >+ SapphireUiFrameworkPlugin.log( e ); >+ result = null; >+ } >+ } >+ return result; >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionPart.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionPart.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,115 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.el.Function; >+import org.eclipse.sapphire.ui.SapphireRenderingContext; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramEmbeddedConnectionDef; >+ >+public class DiagramEmbeddedConnectionPart extends DiagramConnectionPart >+{ >+ private DiagramEmbeddedConnectionTemplate connTemplate; >+ private IDiagramEmbeddedConnectionDef localDefinition; >+ private IModelElement srcNodeModel; >+ private IModelElement endpointModel; >+ private Function endpointFunction; >+ private IDiagramConnectionEndpointDef endpointDef; >+ >+ public DiagramEmbeddedConnectionPart(DiagramEmbeddedConnectionTemplate connTemplate, >+ IModelElement srcNodeModel) >+ { >+ this.connTemplate = connTemplate; >+ this.srcNodeModel = srcNodeModel; >+ } >+ >+ @Override >+ protected void init() >+ { >+ this.localDefinition = (IDiagramEmbeddedConnectionDef)super.definition; >+ this.modelElement = super.getModelElement(); >+ this.labelFunction = initExpression >+ ( >+ this.localDefinition.getLabel().element().getContent().getLocalizedText(), >+ new Runnable() >+ { >+ public void run() >+ { >+ } >+ } >+ ); >+ this.labelProperty = FunctionUtil.getFunctionProperty(this.modelElement, this.labelFunction); >+ >+ this.idFunction = initExpression >+ ( >+ this.localDefinition.getInstanceId().getLocalizedText(), >+ new Runnable() >+ { >+ public void run() >+ { >+ } >+ } >+ ); >+ >+ this.endpointDef = this.localDefinition.getEndpoint().element(); >+ this.endpointModel = processEndpoint(this.endpointDef); >+ this.endpointFunction = initExpression >+ ( >+ this.endpointModel, >+ this.endpointDef.getValue().getContent(), >+ new Runnable() >+ { >+ public void run() >+ { >+ refreshEndpoint2(); >+ } >+ } >+ ); >+ } >+ >+ public DiagramEmbeddedConnectionTemplate getConnectionTemplate() >+ { >+ return this.connTemplate; >+ } >+ >+ @Override >+ public IModelElement getEndpoint1() >+ { >+ return this.srcNodeModel; >+ } >+ >+ @Override >+ public IModelElement getEndpoint2() >+ { >+ return this.endpointModel; >+ } >+ >+ @Override >+ public void refreshEndpoint1() >+ { >+ } >+ >+ @Override >+ public void refreshEndpoint2() >+ { >+ if (this.endpointFunction != null) >+ { >+ Object value = this.endpointFunction.value(); >+ String property = this.endpointDef.getProperty().getContent(); >+ setModelProperty(this.modelElement, property, value); >+ } >+ } >+ >+ public DiagramNodePart getSourceNodePart() >+ { >+ SapphireDiagramEditorPart diagramPart = (SapphireDiagramEditorPart)getParentPart(); >+ return diagramPart.getDiagramNodePart(this.srcNodeModel); >+ } >+ >+ @Override >+ public void render(SapphireRenderingContext context) >+ { >+ // TODO Auto-generated method stub >+ >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionTemplate.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionTemplate.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionTemplate.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionTemplate.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,176 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+ >+import org.eclipse.sapphire.modeling.ElementProperty; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.ModelProperty; >+import org.eclipse.sapphire.modeling.annotations.Reference; >+import org.eclipse.sapphire.modeling.el.Function; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramEmbeddedConnectionDef; >+ >+public class DiagramEmbeddedConnectionTemplate extends DiagramConnectionTemplate >+{ >+ private SapphireDiagramEditorPart diagramEditor; >+ private DiagramNodeTemplate nodeTemplate; >+ private IDiagramEmbeddedConnectionDef definition; >+ private IModelElement modelElement; >+ >+ public DiagramEmbeddedConnectionTemplate(final SapphireDiagramEditorPart diagramEditor, >+ final DiagramNodeTemplate nodeTemplate, >+ IDiagramEmbeddedConnectionDef definition, >+ IModelElement modelElement) >+ { >+ this.diagramEditor = diagramEditor; >+ this.nodeTemplate = nodeTemplate; >+ this.modelElement = modelElement; >+ this.definition = definition; >+ >+ this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent(); >+ this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent(); >+ >+ this.diagramConnections = new ArrayList<DiagramConnectionPart>(); >+ >+ ModelProperty nodeProperty = this.nodeTemplate.getModelProperty(); >+ String connPropName = this.definition.getProperty().getContent(); >+ if (nodeProperty instanceof ListProperty) >+ { >+ ListProperty listProperty = (ListProperty)nodeProperty; >+ ModelElementList<?> list = this.modelElement.read(listProperty); >+ for (IModelElement srcNodeModel : list) >+ { >+ ModelProperty connProp = resolve(srcNodeModel, connPropName); >+ if (connProp instanceof ListProperty) >+ { >+ ListProperty connListProperty = (ListProperty)connProp; >+ ModelElementList<?> connList = srcNodeModel.read(connListProperty); >+ for (IModelElement endpointModel : connList) >+ { >+ DiagramEmbeddedConnectionPart connPart = >+ new DiagramEmbeddedConnectionPart(this, srcNodeModel); >+ connPart.init(this.diagramEditor, endpointModel, this.definition, >+ Collections.<String,String>emptyMap()); >+ this.diagramConnections.add(connPart); >+ } >+ } >+ else if (connProp instanceof ElementProperty) >+ { >+ ElementProperty elementProperty = (ElementProperty)connProp; >+ if (this.modelElement.read(elementProperty) != null) >+ { >+ IModelElement endpointModel = this.modelElement.read(elementProperty).element(); >+ DiagramEmbeddedConnectionPart connPart = >+ new DiagramEmbeddedConnectionPart(this, srcNodeModel); >+ connPart.init(this.diagramEditor, endpointModel, this.definition, >+ Collections.<String,String>emptyMap()); >+ this.diagramConnections.add(connPart); >+ } >+ } >+ } >+ } >+ } >+ >+ @Override >+ public boolean canCreateNewConnection(DiagramNodePart srcNode, DiagramNodePart targetNode) >+ { >+ IModelElement srcNodeModel = srcNode.getLocalModelElement(); >+ >+ // check the source node type >+ ModelElementType srcNodeType = srcNodeModel.getModelElementType(); >+ ModelElementType desiredsrcNodeType = this.nodeTemplate.getNodeType(); >+ >+ if (!srcNodeType.equals(desiredsrcNodeType)) >+ { >+ return false; >+ } >+ >+ // check the target node type >+ ModelElementType targetType = targetNode.getLocalModelElement().getModelElementType(); >+ >+ String connPropName = this.definition.getProperty().getContent(); >+ ModelProperty connProp = resolve(srcNodeModel, connPropName); >+ ModelElementType connType = connProp.getType(); >+ ModelProperty endpointProp = >+ connType.getProperty(this.definition.getEndpoint().element().getProperty().getContent()); >+ if (endpointProp.getType() == null && endpointProp.hasAnnotation(Reference.class)) >+ { >+ return endpointProp.getAnnotation(Reference.class).target().isAssignableFrom(targetType.getModelElementClass()); >+ } >+ return false; >+ } >+ >+ @Override >+ public DiagramEmbeddedConnectionPart createNewDiagramConnection(DiagramNodePart srcNode, >+ DiagramNodePart targetNode) >+ { >+ IModelElement srcNodeModel = srcNode.getModelElement(); >+ ModelProperty modelProperty = this.nodeTemplate.getModelProperty(); >+ boolean found = false; >+ if (modelProperty instanceof ListProperty) >+ { >+ ListProperty listProperty = (ListProperty)modelProperty; >+ ModelElementList<?> list = this.modelElement.read(listProperty); >+ for (IModelElement listEntryModelElement : list) >+ { >+ if (listEntryModelElement == srcNodeModel) >+ { >+ found = true; >+ break; >+ } >+ } >+ } >+ else if (modelProperty instanceof ElementProperty) >+ { >+ ElementProperty elementProperty = (ElementProperty)modelProperty; >+ if (this.modelElement.read(elementProperty) != null) >+ { >+ IModelElement localModelElement = this.modelElement.read(elementProperty).element(); >+ if (localModelElement == srcNodeModel) >+ { >+ found = true; >+ } >+ } >+ } >+ if (!found) >+ { >+ throw new RuntimeException( "Cannot locate the source node element"); >+ } >+ >+ String connPropName = this.definition.getProperty().getContent(); >+ ModelProperty connProp = resolve(srcNodeModel, connPropName); >+ IModelElement newEndpoint = null; >+ if (connProp instanceof ListProperty) >+ { >+ ListProperty listProperty = (ListProperty)connProp; >+ ModelElementList<?> list = srcNodeModel.read(listProperty); >+ newEndpoint = list.addNewElement(); >+ } >+ else if (connProp instanceof ElementProperty) >+ { >+ // TODO what if the element property does exist? >+ ElementProperty elementProperty = (ElementProperty)connProp; >+ newEndpoint = this.modelElement.read(elementProperty).element(true); >+ } >+ IDiagramConnectionEndpointDef endpointDef = this.definition.getEndpoint().element(); >+ String endpointProperty = endpointDef.getProperty().getContent(); >+ String endpointExpr = endpointDef.getValue().getContent(); >+ Function endpointFunc = getNodeReferenceFunction(targetNode, endpointExpr); >+ Object endpointValue = endpointFunc.value(); >+ endpointFunc.dispose(); >+ setModelProperty(newEndpoint, endpointProperty, endpointValue); >+ >+ DiagramEmbeddedConnectionPart connPart = >+ new DiagramEmbeddedConnectionPart(this, srcNodeModel); >+ connPart.init(this.diagramEditor, newEndpoint, this.definition, >+ Collections.<String,String>emptyMap()); >+ this.diagramConnections.add(connPart); >+ >+ return connPart; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/DiagramGeometryWrapper.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/DiagramGeometryWrapper.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/DiagramGeometryWrapper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/DiagramGeometryWrapper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,360 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ResourceStoreException; >+import org.eclipse.sapphire.modeling.WorkspaceFileResourceStore; >+import org.eclipse.sapphire.modeling.xml.RootXmlResource; >+import org.eclipse.sapphire.modeling.xml.XmlResourceStore; >+import org.eclipse.sapphire.ui.diagram.geometry.IBendPoint; >+import org.eclipse.sapphire.ui.diagram.geometry.IDiagramConnectionGeometry; >+import org.eclipse.sapphire.ui.diagram.geometry.IDiagramGeometry; >+import org.eclipse.sapphire.ui.diagram.geometry.IDiagramNodeGeometry; >+ >+public class DiagramGeometryWrapper >+{ >+ private IFile file; >+ private IDiagramGeometry geometryModel; >+ private SapphireDiagramEditorPart diagramPart; >+ >+ private HashMap<DiagramNodePart, Bounds> nodeGeometries; >+ private HashMap<DiagramConnectionPart, List<Point>> connectionBendpoints; >+ private HashMap<DiagramNodePart, HashMap<DiagramConnectionPart, List<Point>>> embeddedConnectionBendpoints; >+ >+ public DiagramGeometryWrapper(IFile file, SapphireDiagramEditorPart diagramPart) >+ throws ResourceStoreException >+ { >+ this.file = file; >+ this.diagramPart = diagramPart; >+ this.nodeGeometries = new HashMap<DiagramNodePart, Bounds>(); >+ this.connectionBendpoints = new HashMap<DiagramConnectionPart, List<Point>>(); >+ this.embeddedConnectionBendpoints = >+ new HashMap<DiagramNodePart, HashMap<DiagramConnectionPart, List<Point>>>(); >+ read(); >+ } >+ >+ public void addNode(DiagramNodePart nodePart, int x, int y, int w, int h) >+ { >+ Bounds bounds = new Bounds(x, y, w, h); >+ this.nodeGeometries.put(nodePart, bounds); >+ } >+ >+ public void removeNode(DiagramNodePart nodePart) >+ { >+ this.nodeGeometries.remove(nodePart); >+ } >+ >+ public void updateNode(DiagramNodePart nodePart, int x, int y) >+ { >+ Bounds bounds = this.nodeGeometries.get(nodePart); >+ if (bounds != null) >+ { >+ bounds.x = x; >+ bounds.y = y; >+ } >+ } >+ >+ public void updateNode(DiagramNodePart nodePart, int x, int y, int w, int h) >+ { >+ Bounds bounds = this.nodeGeometries.get(nodePart); >+ if (bounds != null) >+ { >+ bounds.x = x; >+ bounds.y = y; >+ bounds.height = h; >+ bounds.width = w; >+ } >+ } >+ >+ public Bounds getNode(DiagramNodePart nodePart) >+ { >+ return this.nodeGeometries.get(nodePart); >+ } >+ >+ public void addConnectionBendpoint(DiagramConnectionPart connPart, int index, int x, int y) >+ { >+ HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = >+ getConnectionBenpointsMap(connPart, true); >+ List<Point> bendpoints = connBendpointsMap.get(connPart); >+ if (bendpoints == null) >+ { >+ bendpoints = new ArrayList<Point>(); >+ connBendpointsMap.put(connPart, bendpoints); >+ } >+ Point newPt = new Point(x, y); >+ bendpoints.add(index, newPt); >+ } >+ >+ public void removeConnectionBendpoint(DiagramConnectionPart connPart, int index) >+ { >+ HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = >+ getConnectionBenpointsMap(connPart, false); >+ if (connBendpointsMap == null) >+ { >+ throw new RuntimeException("Could not locate connection benpoints map for the embedded connection"); >+ } >+ List<Point> bendpoints = connBendpointsMap.get(connPart); >+ if (bendpoints != null) >+ { >+ bendpoints.remove(index); >+ } >+ } >+ >+ public boolean updateConnectionBendpoint(DiagramConnectionPart connPart, int index, int x, int y) >+ { >+ HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = >+ getConnectionBenpointsMap(connPart, false); >+ if (connBendpointsMap == null) >+ { >+ throw new RuntimeException("Could not locate connection benpoints map for the embedded connection"); >+ } >+ List<Point> bendpoints = connBendpointsMap.get(connPart); >+ if (bendpoints != null && index < bendpoints.size()) >+ { >+ bendpoints.set(index, new Point(x, y)); >+ return true; >+ } >+ return false; >+ } >+ >+ >+ public List<Point> getConnectionBendpoints(DiagramConnectionPart connPart) >+ { >+ HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = >+ getConnectionBenpointsMap(connPart, false); >+ if (connBendpointsMap != null) >+ { >+ return connBendpointsMap.get(connPart); >+ } >+ return null; >+ } >+ >+ public void read() throws ResourceStoreException >+ { >+ final XmlResourceStore resourceStore = new XmlResourceStore( new WorkspaceFileResourceStore(this.file )); >+ this.geometryModel = IDiagramGeometry.TYPE.instantiate(new RootXmlResource( resourceStore )); >+ >+ ModelElementList<IDiagramNodeGeometry> nodes = this.geometryModel.getDiagramNodeGeometries(); >+ for (IDiagramNodeGeometry node : nodes) >+ { >+ String id = node.getNodeId().getContent(); >+ DiagramNodePart nodePart = getNodeElement(id); >+ if (nodePart != null) >+ { >+ int x = node.getX().getContent() != null ? node.getX().getContent() : -1; >+ int y = node.getY().getContent() != null ? node.getY().getContent() : -1; >+ int width = node.getWidth().getContent() != null ? node.getWidth().getContent() : -1; >+ int height = node.getHeight().getContent() != null ? node.getHeight().getContent() : -1; >+ this.addNode(nodePart, x, y, width, height); >+ >+ ModelElementList<IDiagramConnectionGeometry> connList = node.getEmbeddedConnectionGeometries(); >+ for (IDiagramConnectionGeometry connBend : connList) >+ { >+ String connId = connBend.getConnectionId().getContent(); >+ DiagramConnectionPart connPart = getConnectionElement(nodePart, connId); >+ if (connPart != null) >+ { >+ ModelElementList<IBendPoint> bps = connBend.getConnectionBendpoints(); >+ int index = 0; >+ for (IBendPoint pt : bps) >+ { >+ this.addConnectionBendpoint(connPart, index++, pt.getX().getContent(), pt.getY().getContent()); >+ } >+ } >+ } >+ >+ } >+ } >+ >+ ModelElementList<IDiagramConnectionGeometry> connList = this.geometryModel.getDiagramConnectionGeometries(); >+ for (IDiagramConnectionGeometry connBend : connList) >+ { >+ String connId = connBend.getConnectionId().getContent(); >+ DiagramConnectionPart connPart = getConnectionElement(connId); >+ if (connPart != null) >+ { >+ ModelElementList<IBendPoint> bps = connBend.getConnectionBendpoints(); >+ int index = 0; >+ for (IBendPoint pt : bps) >+ { >+ this.addConnectionBendpoint(connPart, index++, pt.getX().getContent(), pt.getY().getContent()); >+ } >+ } >+ } >+ } >+ >+ public void write() throws ResourceStoreException >+ { >+ this.geometryModel.getDiagramNodeGeometries().clear(); >+ Iterator<DiagramNodePart> it = this.nodeGeometries.keySet().iterator(); >+ while (it.hasNext()) >+ { >+ DiagramNodePart nodePart = it.next(); >+ Bounds bounds = this.nodeGeometries.get(nodePart); >+ String id = nodePart.getInstanceId(); >+ >+ if (bounds != null && id != null) >+ { >+ IDiagramNodeGeometry diagramNode = this.geometryModel.getDiagramNodeGeometries().addNewElement(); >+ diagramNode.setNodeId(id); >+ diagramNode.setX(bounds.x); >+ diagramNode.setY(bounds.y); >+ diagramNode.setWidth(bounds.width); >+ diagramNode.setHeight(bounds.height); >+ >+ // save the embedded connection bendpoints >+ HashMap<DiagramConnectionPart, List<Point>> embeddedConnBendpointsMap = >+ this.embeddedConnectionBendpoints.get(nodePart); >+ if (embeddedConnBendpointsMap != null) >+ { >+ diagramNode.getEmbeddedConnectionGeometries().clear(); >+ addConnectionBenpointsToModel(embeddedConnBendpointsMap, >+ diagramNode.getEmbeddedConnectionGeometries()); >+ } >+ } >+ } >+ >+ this.geometryModel.getDiagramConnectionGeometries().clear(); >+ addConnectionBenpointsToModel(this.connectionBendpoints, >+ this.geometryModel.getDiagramConnectionGeometries()); >+ this.geometryModel.resource().save(); >+ } >+ >+ private DiagramNodePart getNodeElement(String nodeId) >+ { >+ for (DiagramNodeTemplate nodeTemplate : this.diagramPart.getNodeTemplates()) >+ { >+ for (DiagramNodePart nodePart : nodeTemplate.getDiagramNodes()) >+ { >+ String nodeId2 = nodePart.getInstanceId(); >+ if (nodeId != null && nodeId2 != null && nodeId.equals(nodeId2)) >+ { >+ return nodePart; >+ } >+ } >+ } >+ return null; >+ } >+ >+ private DiagramConnectionPart getConnectionElement(String connId) >+ { >+ for (DiagramConnectionTemplate connTemplate : this.diagramPart.getConnectionTemplates()) >+ { >+ for (DiagramConnectionPart connPart : connTemplate.getDiagramConnections()) >+ { >+ String connId2 = connPart.getInstanceId(); >+ if (connId != null && connId2 != null && connId.equals(connId2)) >+ { >+ return connPart; >+ } >+ } >+ } >+ return null; >+ } >+ >+ private DiagramConnectionPart getConnectionElement(DiagramNodePart nodePart, String connId) >+ { >+ DiagramNodeTemplate nodeTemplate = nodePart.getDiagramNodeTemplate(); >+ DiagramEmbeddedConnectionTemplate connTemplate = >+ nodeTemplate.getEmbeddedConnectionTemplate(); >+ if (connTemplate != null) >+ { >+ List<DiagramConnectionPart> connParts = connTemplate.getDiagramConnections(); >+ for (DiagramConnectionPart connPart : connParts) >+ { >+ String connId2 = connPart.getInstanceId(); >+ if (connId != null && connId2 != null && connId.equals(connId2)) >+ { >+ return connPart; >+ } >+ } >+ } >+ return null; >+ } >+ >+ private HashMap<DiagramConnectionPart, List<Point>> getConnectionBenpointsMap(DiagramConnectionPart connPart, boolean create) >+ { >+ HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = null; >+ if (connPart instanceof DiagramEmbeddedConnectionPart) >+ { >+ DiagramNodePart srcNodePart = ((DiagramEmbeddedConnectionPart)connPart).getSourceNodePart(); >+ if (srcNodePart == null) >+ { >+ throw new RuntimeException("Could not locate the source node for the embedded connection"); >+ } >+ connBendpointsMap = this.embeddedConnectionBendpoints.get(srcNodePart); >+ if (connBendpointsMap == null) >+ { >+ if (create) >+ { >+ connBendpointsMap = new HashMap<DiagramConnectionPart, List<Point>>(); >+ this.embeddedConnectionBendpoints.put(srcNodePart, connBendpointsMap); >+ } >+ } >+ } >+ else >+ { >+ connBendpointsMap = this.connectionBendpoints; >+ } >+ return connBendpointsMap; >+ } >+ >+ private void addConnectionBenpointsToModel(HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap, >+ ModelElementList<IDiagramConnectionGeometry> connGeometries) >+ { >+ Iterator<DiagramConnectionPart> connIt = connBendpointsMap.keySet().iterator(); >+ while (connIt.hasNext()) >+ { >+ DiagramConnectionPart connPart = connIt.next(); >+ List<Point> bps = connBendpointsMap.get(connPart); >+ String id = connPart.getInstanceId(); >+ >+ if (bps != null && id != null) >+ { >+ IDiagramConnectionGeometry conn = connGeometries.addNewElement(); >+ conn.setConnectionId(id); >+ for (Point pt : bps) >+ { >+ IBendPoint pt2 = conn.getConnectionBendpoints().addNewElement(); >+ pt2.setX(pt.x); >+ pt2.setY(pt.y); >+ } >+ } >+ } >+ >+ } >+ >+ // ------------------------------------------------------------------- >+ // Inner classes >+ // ------------------------------------------------------------------- >+ >+ public static class Point >+ { >+ public int x; >+ public int y; >+ >+ public Point(int x, int y) >+ { >+ this.x = x; >+ this.y = y; >+ } >+ } >+ >+ public static final class Bounds extends Point >+ { >+ public int width; >+ public int height; >+ >+ public Bounds(int x, int y, int width, int height) >+ { >+ super(x, y); >+ this.width = width; >+ this.height = height; >+ } >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodePart.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodePart.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodePart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodePart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,122 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.el.Function; >+import org.eclipse.sapphire.ui.SapphirePart; >+import org.eclipse.sapphire.ui.SapphireRenderingContext; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef; >+ >+public class DiagramNodePart extends SapphirePart >+{ >+ private DiagramNodeTemplate nodeTemplate; >+ private IDiagramNodeDef definition; >+ private IModelElement modelElement; >+ private Function labelFunction; >+ private Function idFunction; >+ private ValueProperty labelProperty; >+ >+ public DiagramNodePart(DiagramNodeTemplate nodeTemplate) >+ { >+ this.nodeTemplate = nodeTemplate; >+ } >+ >+ @Override >+ protected void init() >+ { >+ super.init(); >+ >+ this.definition = (IDiagramNodeDef)super.definition; >+ this.modelElement = getModelElement(); >+ this.labelFunction = initExpression >+ ( >+ this.definition.getLabel().element().getContent().getLocalizedText(), >+ new Runnable() >+ { >+ public void run() >+ { >+ } >+ } >+ ); >+ this.labelProperty = FunctionUtil.getFunctionProperty(this.modelElement, this.labelFunction); >+ >+ this.idFunction = initExpression >+ ( >+ this.definition.getInstanceId().getLocalizedText(), >+ new Runnable() >+ { >+ public void run() >+ { >+ } >+ } >+ ); >+ } >+ >+ public DiagramNodeTemplate getDiagramNodeTemplate() >+ { >+ return this.nodeTemplate; >+ } >+ >+ public IModelElement getLocalModelElement() >+ { >+ return this.modelElement; >+ } >+ >+ @Override >+ public void render(SapphireRenderingContext context) >+ { >+ throw new UnsupportedOperationException(); >+ } >+ >+ public String getLabel() >+ { >+ String label = null; >+ >+ if( this.labelFunction != null ) >+ { >+ label = (String) this.labelFunction.value(); >+ } >+ >+ if( label == null ) >+ { >+ label = "#null#"; >+ } >+ >+ return label; >+ } >+ >+ public void setLabel(String newValue) >+ { >+ if (this.labelProperty != null) >+ { >+ this.modelElement.write(this.labelProperty, newValue); >+ } >+ } >+ >+ public boolean canEditLabel() >+ { >+ return this.labelProperty != null; >+ } >+ >+ public String getInstanceId() >+ { >+ String id = null; >+ >+ if( this.idFunction != null ) >+ { >+ id = (String) this.idFunction.value(); >+ } >+ >+ if( id == null ) >+ { >+ id = "#null#"; >+ } >+ >+ return id; >+ } >+ >+ public boolean canResizeShape() >+ { >+ return this.definition.getHint("resizable", true); >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodeTemplate.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodeTemplate.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodeTemplate.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodeTemplate.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,154 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.sapphire.modeling.ElementProperty; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.ModelProperty; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramEmbeddedConnectionDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef; >+ >+public class DiagramNodeTemplate >+{ >+ private SapphireDiagramEditorPart diagramEditor; >+ private IDiagramNodeDef definition; >+ private IModelElement modelElement; >+ private ModelProperty modelProperty; >+ private String toolPaletteLabel; >+ private String toolPaletteDesc; >+ private DiagramEmbeddedConnectionTemplate embeddedConnTemplate; >+ >+ private List<DiagramNodePart> diagramNodes; >+ >+ public DiagramNodeTemplate(final SapphireDiagramEditorPart diagramEditor, IDiagramNodeDef definition, IModelElement modelElement) >+ { >+ this.diagramEditor = diagramEditor; >+ this.modelElement = modelElement; >+ this.definition = definition; >+ >+ this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent(); >+ this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent(); >+ >+ this.diagramNodes = new ArrayList<DiagramNodePart>(); >+ >+ String propertyName = this.definition.getProperty().getContent(); >+ this.modelProperty = resolve(this.modelElement, propertyName); >+ if (this.modelProperty instanceof ListProperty) >+ { >+ ListProperty listProperty = (ListProperty)this.modelProperty; >+ ModelElementList<?> list = this.modelElement.read(listProperty); >+ for( IModelElement listEntryModelElement : list ) >+ { >+ DiagramNodePart node = new DiagramNodePart(this); >+ node.init(this.diagramEditor, listEntryModelElement, definition, >+ Collections.<String,String>emptyMap()); >+ this.diagramNodes.add(node); >+ } >+ } >+ else if (this.modelProperty instanceof ElementProperty) >+ { >+ ElementProperty elementProperty = (ElementProperty)this.modelProperty; >+ if (this.modelElement.read(elementProperty) != null) >+ { >+ IModelElement localModelElement = this.modelElement.read(elementProperty).element(); >+ DiagramNodePart node = new DiagramNodePart(this); >+ node.init(this.diagramEditor, localModelElement, definition, >+ Collections.<String,String>emptyMap()); >+ >+ this.diagramNodes.add(node); >+ } >+ } >+ >+ // handle embedded connections >+ if (this.definition.getEmbeddedConnections().element() != null) >+ { >+ IDiagramEmbeddedConnectionDef embeddedConnDef = >+ this.definition.getEmbeddedConnections().element(); >+ this.embeddedConnTemplate = new DiagramEmbeddedConnectionTemplate( >+ this.diagramEditor, >+ this, >+ embeddedConnDef, >+ this.modelElement); >+ } >+ } >+ >+ public IDiagramNodeDef getDefinition() >+ { >+ return this.definition; >+ } >+ >+ public List<DiagramNodePart> getDiagramNodes() >+ { >+ return this.diagramNodes; >+ } >+ >+ public String getToolPaletteLabel() >+ { >+ return this.toolPaletteLabel; >+ } >+ >+ public String getToolPaletteDesc() >+ { >+ return this.toolPaletteDesc; >+ } >+ >+ public DiagramNodePart createNewDiagramNode() >+ { >+ IModelElement newElement = null; >+ if (this.modelProperty instanceof ListProperty) >+ { >+ ListProperty listProperty = (ListProperty)this.modelProperty; >+ ModelElementList<?> list = this.modelElement.read(listProperty); >+ newElement = list.addNewElement(); >+ } >+ else if (this.modelProperty instanceof ElementProperty) >+ { >+ // TODO what if the element property does exist? >+ ElementProperty elementProperty = (ElementProperty)this.modelProperty; >+ newElement = this.modelElement.read(elementProperty).element(true); >+ } >+ DiagramNodePart newNode = new DiagramNodePart(this); >+ newNode.init(this.diagramEditor, newElement, this.definition, >+ Collections.<String,String>emptyMap()); >+ this.diagramNodes.add(newNode); >+ return newNode; >+ } >+ >+ public ModelProperty getModelProperty() >+ { >+ return this.modelProperty; >+ } >+ >+ public ModelElementType getNodeType() >+ { >+ return this.modelProperty.getType(); >+ } >+ >+ public DiagramEmbeddedConnectionTemplate getEmbeddedConnectionTemplate() >+ { >+ return this.embeddedConnTemplate; >+ } >+ >+ private ModelProperty resolve(final IModelElement modelElement, >+ String propertyName) >+ { >+ if (propertyName != null) >+ { >+ final ModelElementType type = modelElement.getModelElementType(); >+ final ModelProperty property = type.getProperty( propertyName ); >+ >+ if( property == null ) >+ { >+ throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() ); >+ } >+ return property; >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/FunctionUtil.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/FunctionUtil.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/FunctionUtil.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/FunctionUtil.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import java.util.List; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.ModelProperty; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.el.Function; >+import org.eclipse.sapphire.modeling.el.RootPropertyAccessFunction; >+ >+public class FunctionUtil >+{ >+ public static ValueProperty getFunctionProperty(IModelElement modelElement, Function function) >+ { >+ if (function instanceof RootPropertyAccessFunction) >+ { >+ RootPropertyAccessFunction rpaf = (RootPropertyAccessFunction)function; >+ if (rpaf.operand(0).value() instanceof String) >+ { >+ String propName = (String)rpaf.operand(0).value(); >+ final ModelElementType type = modelElement.getModelElementType(); >+ final ModelProperty property = type.getProperty(propName); >+ if (property instanceof ValueProperty) >+ { >+ return (ValueProperty)property; >+ } >+ } >+ } >+ else >+ { >+ List<Function> subFuncs = function.operands(); >+ for (Function subFunc : subFuncs) >+ { >+ ValueProperty property = getFunctionProperty(modelElement, subFunc); >+ if (property != null) >+ { >+ return property; >+ } >+ } >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/editor/SapphireDiagramEditorPart.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/editor/SapphireDiagramEditorPart.java >diff -N src/org/eclipse/sapphire/ui/diagram/editor/SapphireDiagramEditorPart.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/editor/SapphireDiagramEditorPart.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,226 @@ >+package org.eclipse.sapphire.ui.diagram.editor; >+ >+import java.util.ArrayList; >+import java.util.List; >+import java.util.Set; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.help.IContext; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.ui.ISapphirePart; >+import org.eclipse.sapphire.ui.SapphireAction; >+import org.eclipse.sapphire.ui.SapphireActionGroup; >+import org.eclipse.sapphire.ui.SapphireEditor; >+import org.eclipse.sapphire.ui.SapphireImageCache; >+import org.eclipse.sapphire.ui.SapphirePartListener; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+import org.eclipse.sapphire.ui.def.ISapphireUiDef; >+import org.eclipse.sapphire.ui.def.SapphireUiDefFactory; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramPageDef; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorFactory; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorInput; >+import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin; >+ >+public class SapphireDiagramEditorPart >+ implements ISapphirePart >+{ >+ private final SapphireEditor editor; >+ private final IModelElement rootModelElement; >+ private IDiagramPageDef diagramPageDef = null; >+ private DiagramGeometryWrapper diagramGeometry; >+ private List<DiagramNodeTemplate> nodeTemplates; >+ private List<DiagramConnectionTemplate> connectionTemplates; >+ private SapphireDiagramEditorInput diagramInput; >+ private SapphireDiagramEditor diagramEditor; >+ >+ public SapphireDiagramEditorPart(final SapphireEditor editor, >+ final IModelElement rootModelElement, >+ final IPath pageDefinitionLocation ) >+ { >+ this(editor, rootModelElement, pageDefinitionLocation, null); >+ } >+ >+ public SapphireDiagramEditorPart(final SapphireEditor editor, >+ final IModelElement rootModelElement, >+ final IPath pageDefinitionLocation, >+ String pageName ) >+ { >+ this.editor = editor; >+ this.rootModelElement = rootModelElement; >+ >+ final String bundleId = pageDefinitionLocation.segment( 0 ); >+ final String pageId = pageDefinitionLocation.lastSegment(); >+ final String relPath = pageDefinitionLocation.removeFirstSegments( 1 ).removeLastSegments( 1 ).toPortableString(); >+ >+ final ISapphireUiDef def = SapphireUiDefFactory.load( bundleId, relPath ); >+ >+ for( IDiagramPageDef pg : def.getDiagramPageDefs() ) >+ { >+ if( pageId.equals( pg.getId().getText() ) ) >+ { >+ this.diagramPageDef = pg; >+ break; >+ } >+ } >+ >+ this.nodeTemplates = new ArrayList<DiagramNodeTemplate>(); >+ ModelElementList<IDiagramNodeDef> nodeDefs = this.diagramPageDef.getDiagramNodeDefs(); >+ >+ for (IDiagramNodeDef nodeDef : nodeDefs) >+ { >+ DiagramNodeTemplate nodeTemplate = new DiagramNodeTemplate(this, nodeDef, this.rootModelElement); >+ this.nodeTemplates.add(nodeTemplate); >+ } >+ >+ this.connectionTemplates = new ArrayList<DiagramConnectionTemplate>(); >+ ModelElementList<IDiagramConnectionDef> connectionDefs = this.diagramPageDef.getDiagramConnectionDefs(); >+ for (IDiagramConnectionDef connectionDef : connectionDefs) >+ { >+ DiagramConnectionTemplate connectionTemplate = new DiagramConnectionTemplate(this, connectionDef, this.rootModelElement); >+ this.connectionTemplates.add(connectionTemplate); >+ } >+ >+ initializeDiagramEditor(); >+ } >+ >+ private void initializeDiagramEditor() >+ { >+ try >+ { >+ this.diagramInput = SapphireDiagramEditorFactory.createEditorInput(this.editor.getEditorInput()); >+ IFile npFile = this.diagramInput.getNodePositionFile(); >+ this.diagramGeometry = new DiagramGeometryWrapper(npFile, this); >+ } >+ catch( Exception e ) >+ { >+ SapphireUiFrameworkPlugin.log( e ); >+ } >+ this.diagramEditor = new SapphireDiagramEditor(this); >+ } >+ >+ public SapphireDiagramEditorInput getDiagramEditorInput() >+ { >+ return this.diagramInput; >+ } >+ >+ public SapphireDiagramEditor getDiagramEditor() >+ { >+ return this.diagramEditor; >+ } >+ >+ public List<DiagramNodeTemplate> getNodeTemplates() >+ { >+ return this.nodeTemplates; >+ } >+ >+ public List<DiagramConnectionTemplate> getConnectionTemplates() >+ { >+ return this.connectionTemplates; >+ } >+ >+ public DiagramGeometryWrapper getDiagramGeometry() >+ { >+ return this.diagramGeometry; >+ } >+ >+ public ISapphirePart getParentPart() >+ { >+ return this.editor; >+ } >+ >+ public <T> T getNearestPart(Class<T> partType) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public IModelElement getModelElement() >+ { >+ return this.rootModelElement; >+ } >+ >+ public DiagramNodePart getDiagramNodePart(IModelElement nodeElement) >+ { >+ List<DiagramNodeTemplate> nodeTemplates = this.getNodeTemplates(); >+ for (DiagramNodeTemplate nodeTemplate : nodeTemplates) >+ { >+ if (nodeTemplate.getNodeType().equals(nodeElement.getModelElementType())) >+ { >+ List<DiagramNodePart> nodeParts = nodeTemplate.getDiagramNodes(); >+ for (DiagramNodePart nodePart : nodeParts) >+ { >+ if (nodePart.getLocalModelElement().equals(nodeElement)) >+ { >+ return nodePart; >+ } >+ } >+ } >+ } >+ return null; >+ } >+ >+ public IStatus getValidationState() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public IContext getDocumentationContext() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public SapphireImageCache getImageCache() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public void addListener(SapphirePartListener listener) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public void removeListener(SapphirePartListener listener) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public void dispose() { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public ISapphirePartDef getDefinition() >+ { >+ return this.diagramPageDef; >+ } >+ >+ public Set<String> getActionContexts() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public String getMainActionContext() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public SapphireActionGroup getActions() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public SapphireActionGroup getActions(String context) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public SapphireAction getAction(String id) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/geometry/IBendPoint.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/geometry/IBendPoint.java >diff -N src/org/eclipse/sapphire/ui/diagram/geometry/IBendPoint.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/geometry/IBendPoint.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+package org.eclipse.sapphire.ui.diagram.geometry; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.CustomXmlValueBinding; >+import org.eclipse.sapphire.ui.diagram.geometry.internal.GeometryAttributeBinding; >+ >+@GenerateImpl >+ >+public interface IBendPoint extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IBendPoint.class ); >+ >+ // *** X *** >+ >+ @Type( base = Integer.class ) >+ @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"x"}) >+ >+ ValueProperty PROP_X = new ValueProperty( TYPE, "X"); >+ >+ Value<Integer> getX(); >+ void setX(Integer value); >+ void setX(String value); >+ >+ // *** Y *** >+ >+ @Type( base = Integer.class ) >+ @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"y"}) >+ >+ ValueProperty PROP_Y = new ValueProperty( TYPE, "Y"); >+ >+ Value<Integer> getY(); >+ void setY(Integer value); >+ void setY(String value); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramConnectionGeometry.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramConnectionGeometry.java >diff -N src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramConnectionGeometry.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramConnectionGeometry.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,41 @@ >+package org.eclipse.sapphire.ui.diagram.geometry; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.NonNullValue; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; >+ >+@GenerateImpl >+ >+public interface IDiagramConnectionGeometry extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramConnectionGeometry.class ); >+ >+ // *** ConnectionId *** >+ >+ @XmlBinding( path = "id") >+ @NonNullValue >+ >+ ValueProperty PROP_CONNECTION_ID = new ValueProperty( TYPE, "ConnectionId" ); >+ >+ Value<String> getConnectionId(); >+ void setConnectionId( String name ); >+ >+ // *** ConnectionBendpoints*** >+ >+ @Type( base = IBendPoint.class ) >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "bendpoint", type = IBendPoint.class ) ) >+ >+ ListProperty PROP_CONNECTION_BENDPOINTS = new ListProperty( TYPE, "ConnectionBendPoints" ); >+ >+ ModelElementList<IBendPoint> getConnectionBendpoints(); >+ >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramGeometry.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramGeometry.java >diff -N src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramGeometry.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramGeometry.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,39 @@ >+package org.eclipse.sapphire.ui.diagram.geometry; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding; >+ >+@GenerateImpl >+@XmlRootBinding( elementName = "diagram-geometry" ) >+ >+public interface IDiagramGeometry extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramGeometry.class ); >+ >+ // *** DiagramNodeGeometries *** >+ >+ @Type( base = IDiagramNodeGeometry.class ) >+ >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "node", type = IDiagramNodeGeometry.class ) ) >+ >+ ListProperty PROP_DIAGRAM_NODE_GEOMETRIES = new ListProperty( TYPE, "DiagramNodeGeometries" ); >+ >+ ModelElementList<IDiagramNodeGeometry> getDiagramNodeGeometries(); >+ >+ // *** DiagramConnectionGeometries *** >+ >+ @Type( base = IDiagramConnectionGeometry.class ) >+ >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "connection", type = IDiagramConnectionGeometry.class ) ) >+ >+ ListProperty PROP_DIAGRAM_CONNECTION_GEOMETRIES = new ListProperty( TYPE, "DiagramConnectionGeometries" ); >+ >+ ModelElementList<IDiagramConnectionGeometry> getDiagramConnectionGeometries(); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramNodeGeometry.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramNodeGeometry.java >diff -N src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramNodeGeometry.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramNodeGeometry.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+package org.eclipse.sapphire.ui.diagram.geometry; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ListProperty; >+import org.eclipse.sapphire.modeling.ModelElementList; >+import org.eclipse.sapphire.modeling.ModelElementType; >+import org.eclipse.sapphire.modeling.Value; >+import org.eclipse.sapphire.modeling.ValueProperty; >+import org.eclipse.sapphire.modeling.annotations.GenerateImpl; >+import org.eclipse.sapphire.modeling.annotations.NonNullValue; >+import org.eclipse.sapphire.modeling.annotations.Type; >+import org.eclipse.sapphire.modeling.xml.annotations.CustomXmlValueBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding; >+import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding; >+import org.eclipse.sapphire.ui.diagram.geometry.internal.GeometryAttributeBinding; >+ >+@GenerateImpl >+ >+public interface IDiagramNodeGeometry extends IModelElement >+{ >+ ModelElementType TYPE = new ModelElementType( IDiagramNodeGeometry.class ); >+ >+ // *** NodeId *** >+ >+ @XmlBinding( path = "id") >+ @NonNullValue >+ >+ ValueProperty PROP_NODE_ID = new ValueProperty( TYPE, "NodeId" ); >+ >+ Value<String> getNodeId(); >+ void setNodeId( String name ); >+ >+ // *** X *** >+ >+ @Type( base = Integer.class ) >+ @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "x"}) >+ >+ ValueProperty PROP_X = new ValueProperty( TYPE, "X"); >+ >+ Value<Integer> getX(); >+ void setX(Integer value); >+ void setX(String value); >+ >+ // *** Y *** >+ >+ @Type( base = Integer.class ) >+ @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "y"}) >+ >+ ValueProperty PROP_Y = new ValueProperty( TYPE, "Y"); >+ >+ Value<Integer> getY(); >+ void setY(Integer value); >+ void setY(String value); >+ >+ // *** Width *** >+ >+ @Type( base = Integer.class ) >+ @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "width"}) >+ >+ ValueProperty PROP_WIDTH = new ValueProperty( TYPE, "Width"); >+ >+ Value<Integer> getWidth(); >+ void setWidth(Integer value); >+ void setWidth(String value); >+ >+ // *** Height *** >+ >+ @Type( base = Integer.class ) >+ @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "height"}) >+ >+ ValueProperty PROP_HEIGHT = new ValueProperty( TYPE, "Height"); >+ >+ Value<Integer> getHeight(); >+ void setHeight(Integer value); >+ void setHeight(String value); >+ >+ // *** EmbeddedConnectionGeometries *** >+ >+ @Type( base = IDiagramConnectionGeometry.class ) >+ >+ @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "connection", type = IDiagramConnectionGeometry.class ) ) >+ >+ ListProperty PROP_EMBEDDED_CONNECTION_GEOMETRIES = new ListProperty( TYPE, "EmbeddedConnectionGeometries" ); >+ >+ ModelElementList<IDiagramConnectionGeometry> getEmbeddedConnectionGeometries(); >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/geometry/internal/GeometryAttributeBinding.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/geometry/internal/GeometryAttributeBinding.java >diff -N src/org/eclipse/sapphire/ui/diagram/geometry/internal/GeometryAttributeBinding.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/geometry/internal/GeometryAttributeBinding.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,68 @@ >+package org.eclipse.sapphire.ui.diagram.geometry.internal; >+ >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.modeling.ModelProperty; >+import org.eclipse.sapphire.modeling.xml.XmlElement; >+import org.eclipse.sapphire.modeling.xml.XmlValueBindingImpl; >+ >+public class GeometryAttributeBinding extends XmlValueBindingImpl >+{ >+ private String modelPath = null; >+ private String attrName = null; >+ >+ @Override >+ public void init( final IModelElement element, >+ final ModelProperty property, >+ final String[] params ) >+ { >+ super.init(element, property, params); >+ if (params != null) >+ { >+ if (params.length > 1) >+ { >+ this.modelPath = params[0]; >+ this.attrName = params[1]; >+ } >+ else if (params.length > 0) >+ { >+ this.attrName = params[0]; >+ } >+ } >+ } >+ >+ @Override >+ public String read() >+ { >+ String attrVal = null; >+ if (this.attrName != null) >+ { >+ XmlElement geometryEl = xml(false); >+ if (geometryEl != null) >+ { >+ if (this.modelPath != null) >+ { >+ geometryEl = geometryEl.getChildElement(this.modelPath, false); >+ } >+ if (geometryEl != null) >+ { >+ attrVal = ( geometryEl.getAttributeText(this.attrName) ); >+ } >+ } >+ } >+ return attrVal; >+ } >+ >+ @Override >+ public void write(String value) >+ { >+ if (this.attrName != null) >+ { >+ XmlElement geometryEl = xml(true); >+ if (this.modelPath != null) >+ { >+ geometryEl = geometryEl.getChildElement(this.modelPath, true); >+ } >+ geometryEl.setAttributeText( this.attrName, value, true ); >+ } >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/GraphitiFileService.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/GraphitiFileService.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/GraphitiFileService.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/GraphitiFileService.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,172 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti; >+ >+import java.io.IOException; >+import java.io.PrintWriter; >+import java.io.StringWriter; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.HashSet; >+import java.util.Map; >+import java.util.Map.Entry; >+import java.util.Set; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IWorkspaceRunnable; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.emf.common.command.CommandStack; >+import org.eclipse.emf.common.util.EList; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.common.util.WrappedException; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.emf.transaction.RecordingCommand; >+import org.eclipse.emf.transaction.Transaction; >+import org.eclipse.emf.transaction.TransactionalEditingDomain; >+import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl; >+import org.eclipse.graphiti.mm.pictograms.Diagram; >+import org.eclipse.graphiti.ui.editor.DiagramEditorFactory; >+ >+public class GraphitiFileService >+{ >+ public static TransactionalEditingDomain createEmfFileForDiagram(URI diagramResourceUri, final Diagram diagram) { >+ >+ // Create a resource set and EditingDomain >+ final TransactionalEditingDomain editingDomain = DiagramEditorFactory.createResourceSetAndEditingDomain(); >+ final ResourceSet resourceSet = editingDomain.getResourceSet(); >+ // Create a resource for this file. >+ final Resource resource = resourceSet.createResource(diagramResourceUri); >+ final CommandStack commandStack = editingDomain.getCommandStack(); >+ commandStack.execute(new RecordingCommand(editingDomain) { >+ >+ @Override >+ protected void doExecute() { >+ resource.setTrackingModification(true); >+ resource.getContents().add(diagram); >+ >+ } >+ }); >+ >+ save(editingDomain, Collections.<Resource, Map<?, ?>> emptyMap()); >+ return editingDomain; >+ } >+ >+ private static void save(TransactionalEditingDomain editingDomain, Map<Resource, Map<?, ?>> options) { >+ saveInWorkspaceRunnable(editingDomain, options); >+ } >+ >+ private static void saveInWorkspaceRunnable(final TransactionalEditingDomain editingDomain, final Map<Resource, Map<?, ?>> options) { >+ >+ final Map<URI, Throwable> failedSaves = new HashMap<URI, Throwable>(); >+ final IWorkspaceRunnable wsRunnable = new IWorkspaceRunnable() { >+ public void run(final IProgressMonitor monitor) throws CoreException { >+ >+ final Runnable runnable = new Runnable() { >+ >+ public void run() { >+ Transaction parentTx; >+ if (editingDomain != null >+ && (parentTx = ((TransactionalEditingDomainImpl) editingDomain).getActiveTransaction()) != null) { >+ do { >+ if (!parentTx.isReadOnly()) { >+ throw new IllegalStateException( >+ "FileService.save() called from within a command (likely produces a deadlock)"); >+ } >+ } while ((parentTx = ((TransactionalEditingDomainImpl) editingDomain).getActiveTransaction().getParent()) != null); >+ } >+ >+ final EList<Resource> resources = editingDomain.getResourceSet().getResources(); >+ // Copy list to an array to prevent >+ // ConcurrentModificationExceptions >+ // during the saving of the dirty resources >+ Resource[] resourcesArray = new Resource[resources.size()]; >+ resourcesArray = resources.toArray(resourcesArray); >+ final Set<Resource> savedResources = new HashSet<Resource>(); >+ for (int i = 0; i < resourcesArray.length; i++) { >+ // In case resource modification tracking is >+ // switched on, we can check if a resource >+ // has been modified, so that we only need to same >+ // really changed resources; otherwise >+ // we need to save all resources in the set >+ final Resource resource = resourcesArray[i]; >+ if (resource.isModified()) { >+ try { >+ resource.save(options.get(resource)); >+ savedResources.add(resource); >+ } catch (final Throwable t) { >+ failedSaves.put(resource.getURI(), t); >+ } >+ } >+ } >+ } >+ }; >+ >+ try { >+ editingDomain.runExclusive(runnable); >+ } catch (final InterruptedException e) { >+ throw new RuntimeException(e); >+ } >+ editingDomain.getCommandStack().flush(); >+ } >+ }; >+ try { >+ ResourcesPlugin.getWorkspace().run(wsRunnable, null); >+ if (!failedSaves.isEmpty()) { >+ throw new WrappedException(createMessage(failedSaves), new RuntimeException()); >+ } >+ } catch (final CoreException e) { >+ final Throwable cause = e.getStatus().getException(); >+ if (cause instanceof RuntimeException) { >+ throw (RuntimeException) cause; >+ } >+ throw new RuntimeException(e); >+ } >+ } >+ >+ private static String createMessage(Map<URI, Throwable> failedSaves) { >+ final StringBuilder buf = new StringBuilder("The following resources could not be saved:"); >+ for (final Entry<URI, Throwable> entry : failedSaves.entrySet()) { >+ buf.append("\nURI: ").append(entry.getKey().toString()).append(", cause: \n").append(getExceptionAsString(entry.getValue())); >+ } >+ return buf.toString(); >+ } >+ >+ private static String getExceptionAsString(Throwable t) { >+ final StringWriter stringWriter = new StringWriter(); >+ final PrintWriter printWriter = new PrintWriter(stringWriter); >+ t.printStackTrace(printWriter); >+ final String result = stringWriter.toString(); >+ try { >+ stringWriter.close(); >+ } catch (final IOException e) { >+ // $JL-EXC$ ignore >+ } >+ printWriter.close(); >+ return result; >+ } >+ >+ public static IFile EmfResourceToIFile(Resource resource) >+ { >+ IFile ifile = null; >+ >+ URI uri = resource.getURI(); >+ uri = resource.getResourceSet().getURIConverter().normalize(uri); >+ >+ String scheme = uri.scheme(); >+ if ("platform".equals(scheme) && uri.segmentCount() > 1 && >+ "resource".equals(uri.segment(0))) >+ { >+ StringBuffer platformResourcePath = new StringBuffer(); >+ for (int j = 1, size = uri.segmentCount(); j < size; ++j) >+ { >+ platformResourcePath.append('/'); >+ platformResourcePath.append(uri.segment(j)); >+ } >+ return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformResourcePath.toString())); >+ } >+ return ifile; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditor.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditor.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,236 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.editor; >+ >+import java.util.Collection; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.emf.transaction.RecordingCommand; >+import org.eclipse.emf.transaction.TransactionalEditingDomain; >+import org.eclipse.emf.transaction.util.TransactionUtil; >+import org.eclipse.graphiti.features.IAddFeature; >+import org.eclipse.graphiti.features.context.impl.AddConnectionContext; >+import org.eclipse.graphiti.features.context.impl.AddContext; >+import org.eclipse.graphiti.mm.algorithms.styles.Point; >+import org.eclipse.graphiti.mm.pictograms.Anchor; >+import org.eclipse.graphiti.mm.pictograms.Connection; >+import org.eclipse.graphiti.mm.pictograms.ContainerShape; >+import org.eclipse.graphiti.mm.pictograms.Diagram; >+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.graphiti.mm.pictograms.Shape; >+import org.eclipse.graphiti.services.Graphiti; >+import org.eclipse.graphiti.ui.editor.DiagramEditor; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionTemplate; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramEmbeddedConnectionTemplate; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper.Bounds; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate; >+import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart; >+import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin; >+ >+@SuppressWarnings("restriction") >+public class SapphireDiagramEditor extends DiagramEditor >+{ >+ private SapphireDiagramEditorPart diagramPart; >+ >+ public SapphireDiagramEditor(SapphireDiagramEditorPart diagramPart) >+ { >+ this.diagramPart = diagramPart; >+ } >+ >+ public SapphireDiagramEditorPart getDiagramEditorPart() >+ { >+ return this.diagramPart; >+ } >+ >+ @Override >+ public void doSave(final IProgressMonitor monitor ) >+ { >+ super.doSave(monitor); >+ try >+ { >+ this.diagramPart.getDiagramGeometry().write(); >+ } >+ catch( Exception e ) >+ { >+ SapphireUiFrameworkPlugin.log( e ); >+ } >+ } >+ >+ public void syncDiagramWithModel() >+ { >+ final Diagram diagram = getDiagramTypeProvider().getDiagram(); >+ >+ TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram); >+ ted.getCommandStack().execute(new RecordingCommand(ted) >+ { >+ protected void doExecute() >+ { >+ removeConnections(diagram); >+ removeNodes(diagram); >+ >+ reconstructNodes(diagram); >+ reconstructConnections(diagram); >+ } >+ }); >+ } >+ >+ private void removeConnections(final Diagram diagram) >+ { >+ List<Connection> cons = diagram.getConnections(); >+ Iterator<Connection> consIt = cons.iterator(); >+ // don't cause ConcurrentModificationException >+ Collection<Connection> allCons = new HashSet<Connection>(); >+ while (consIt.hasNext()) >+ { >+ Connection con = consIt.next(); >+ allCons.add(con); >+ } >+ consIt = allCons.iterator(); >+ while (consIt.hasNext()) >+ { >+ Connection con = consIt.next(); >+ Graphiti.getPeService().deletePictogramElement(con); >+ } >+ } >+ >+ private void removeNodes(final Diagram diagram) >+ { >+ List<Shape> containerShapes = diagram.getChildren(); >+ Iterator<Shape> shapeIt = containerShapes.iterator(); >+ // don't cause ConcurrentModificationException >+ Collection<Shape> allShapes = new HashSet<Shape>(); >+ while (shapeIt.hasNext()) >+ { >+ Shape shape = shapeIt.next(); >+ allShapes.add(shape); >+ } >+ shapeIt = allShapes.iterator(); >+ while (shapeIt.hasNext()) >+ { >+ Shape containerShape = shapeIt.next(); >+ Graphiti.getPeService().deletePictogramElement(containerShape); >+ } >+ } >+ >+ private void reconstructNodes(final Diagram diagram) >+ { >+ // Add the nodes back to the diagram thus re-establishing mapping between >+ // pictograms and business objects >+ >+ int nodeX = 50; >+ int nodeY = 50; >+ int xInc = 100; >+ DiagramGeometryWrapper diagramGeometry = this.diagramPart.getDiagramGeometry(); >+ >+ for (DiagramNodeTemplate nodeTemplate : this.diagramPart.getNodeTemplates()) >+ { >+ for (DiagramNodePart nodePart : nodeTemplate.getDiagramNodes()) >+ { >+ Bounds bounds = diagramGeometry.getNode(nodePart); >+ if (bounds == null) >+ { >+ bounds = new Bounds(nodeX, nodeY, -1, -1); >+ nodeX += xInc; >+ } >+ AddContext ctx = new AddContext(); >+ ctx.setNewObject(nodePart); >+ ctx.setTargetContainer(diagram); >+ ctx.setWidth(bounds.width); >+ ctx.setHeight(bounds.height); >+ ctx.setX(bounds.x); >+ ctx.setY(bounds.y); >+ IAddFeature ft = getDiagramTypeProvider().getFeatureProvider().getAddFeature(ctx); >+ ft.add(ctx); >+ } >+ >+ // add embedded connections >+ DiagramEmbeddedConnectionTemplate embeddedConnTemplate = >+ nodeTemplate.getEmbeddedConnectionTemplate(); >+ if (embeddedConnTemplate != null) >+ { >+ for (DiagramConnectionPart connPart : embeddedConnTemplate.getDiagramConnections()) >+ { >+ addConnection(connPart, diagramGeometry); >+ } >+ } >+ } >+ } >+ >+ private void reconstructConnections(final Diagram diagram) >+ { >+ DiagramGeometryWrapper diagramGeometry = this.diagramPart.getDiagramGeometry(); >+ >+ // add the top level connections back to the diagram >+ for (DiagramConnectionTemplate connTemplate : this.diagramPart.getConnectionTemplates()) >+ { >+ for (DiagramConnectionPart connPart : connTemplate.getDiagramConnections()) >+ { >+ addConnection(connPart, diagramGeometry); >+ } >+ } >+ } >+ >+ private ContainerShape getContainerShape(Object bo) >+ { >+ ContainerShape containerShape = null; >+ PictogramElement [] pictograms = >+ getDiagramTypeProvider().getFeatureProvider().getAllPictogramElementsForBusinessObject(bo); >+ for (PictogramElement pictogram : pictograms) >+ { >+ if (pictogram instanceof ContainerShape) >+ { >+ containerShape = (ContainerShape)pictogram; >+ break; >+ } >+ } >+ return containerShape; >+ } >+ >+ private Connection addConnection(DiagramConnectionPart connPart, DiagramGeometryWrapper diagramGeometry) >+ { >+ Connection conn = null; >+ >+ IModelElement endpoint1 = connPart.getEndpoint1(); >+ IModelElement endpoint2 = connPart.getEndpoint2(); >+ DiagramNodePart nodePart1 = this.diagramPart.getDiagramNodePart(endpoint1); >+ DiagramNodePart nodePart2 = this.diagramPart.getDiagramNodePart(endpoint2); >+ if (nodePart1 != null && nodePart2 != null) >+ { >+ ContainerShape sourceShape = getContainerShape(nodePart1); >+ ContainerShape targetShape = getContainerShape(nodePart2); >+ if (sourceShape != null && targetShape != null) >+ { >+ Anchor sourceAnchor = sourceShape.getAnchors().get(0); >+ Anchor targetAnchor = targetShape.getAnchors().get(0); >+ AddConnectionContext connCtx = new AddConnectionContext(sourceAnchor, targetAnchor); >+ connCtx.setNewObject(connPart); >+ IAddFeature fcfp = getDiagramTypeProvider().getFeatureProvider().getAddFeature(connCtx); >+ >+ conn = (Connection)fcfp.add(connCtx); >+ if (conn instanceof FreeFormConnection && >+ diagramGeometry.getConnectionBendpoints(connPart) != null) >+ { >+ FreeFormConnection freeConn = (FreeFormConnection)conn; >+ List<org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper.Point> bps = >+ diagramGeometry.getConnectionBendpoints(connPart); >+ List<Point> bendpoints = freeConn.getBendpoints(); >+ int index = 0; >+ for (org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper.Point pt : bps) >+ { >+ Point newPoint = Graphiti.getGaService().createPoint(pt.x, pt.y); >+ bendpoints.add(index++, newPoint); >+ } >+ } >+ } >+ } >+ >+ return conn; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorFactory.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorFactory.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,120 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.editor; >+ >+import java.io.ByteArrayInputStream; >+import java.io.IOException; >+import java.util.Iterator; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFolder; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.emf.common.util.EList; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.emf.transaction.TransactionalEditingDomain; >+import org.eclipse.graphiti.mm.pictograms.Diagram; >+import org.eclipse.graphiti.services.Graphiti; >+import org.eclipse.graphiti.ui.editor.DiagramEditorFactory; >+import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal; >+import org.eclipse.graphiti.ui.services.GraphitiUi; >+import org.eclipse.sapphire.modeling.util.internal.FileUtil; >+import org.eclipse.sapphire.ui.diagram.graphiti.GraphitiFileService; >+import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin; >+import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.IFileEditorInput; >+ >+public class SapphireDiagramEditorFactory >+{ >+ public static final String SAPPHIRE_DIAGRAM_TYPE = "sapphireDiagram"; >+ >+ public static SapphireDiagramEditorInput createEditorInput(IEditorInput otherInput) >+ throws CoreException >+ { >+ if (otherInput instanceof SapphireDiagramEditorInput) >+ { >+ return (SapphireDiagramEditorInput)otherInput; >+ } >+ else if (otherInput instanceof IFileEditorInput) >+ { >+ final IFileEditorInput fileInput = (IFileEditorInput) otherInput; >+ final IFile file = fileInput.getFile(); >+ final IProject project = file.getProject(); >+ >+ final IFolder diagramFolder = project.getFolder(".settings/diagrams/"); >+ String fileName = file.getName(); >+ if (fileName.endsWith(".xml")) >+ { >+ fileName = fileName.substring(0, fileName.indexOf(".xml")); >+ } >+ >+ TransactionalEditingDomain domain = null; >+ ResourceSet resourceSet = null; >+ Diagram diagram = null; >+ URI diagramFileUri = null; >+ >+ // create diagram file if it doesn't exist >+ final IFile diagramFile = diagramFolder.getFile(fileName + ".xmi"); >+ if (!diagramFile.exists()) >+ { >+ FileUtil.mkdirs( diagramFile.getParent().getLocation().toFile() ); >+ diagramFile.create( new ByteArrayInputStream(new byte[0]), true, null ); >+ >+ // Create Diagram Obj >+ diagram = Graphiti.getPeCreateService().createDiagram( >+ SAPPHIRE_DIAGRAM_TYPE, fileName, 10, false); >+ diagramFileUri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true); >+ domain = GraphitiFileService.createEmfFileForDiagram(diagramFileUri, diagram); >+ } >+ else >+ { >+ domain = DiagramEditorFactory.createResourceSetAndEditingDomain(); >+ resourceSet = domain.getResourceSet(); >+ >+ diagramFileUri = GraphitiUiInternal.getEmfService().getFileURI(diagramFile, resourceSet); >+ if (diagramFileUri != null) >+ { >+ final Resource resource = resourceSet.createResource(diagramFileUri); >+ try >+ { >+ resource.load(null); >+ } >+ catch (IOException ie) >+ { >+ SapphireUiFrameworkPlugin.log(ie); >+ } >+ EList<EObject> objs = resource.getContents(); >+ Iterator<EObject> it = objs.iterator(); >+ while (it.hasNext()) >+ { >+ EObject obj = it.next(); >+ if ((obj == null) && !Diagram.class.isInstance(obj)) >+ continue; >+ diagram = (Diagram)obj; >+ break; >+ } >+ } >+ } >+ // create diagram node position file if it doesn't exist >+ IFile nodePosFile = diagramFile.getParent().getFile(new Path(fileName + ".np")); >+ if (!nodePosFile.exists()) >+ { >+ nodePosFile.create( new ByteArrayInputStream(new byte[0]), true, null ); >+ } >+ >+ // create sapphire diagram editor input >+ if (diagram != null) >+ { >+ String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId()); >+ final SapphireDiagramEditorInput diagramEditorInput = >+ SapphireDiagramEditorInput.createEditorInput(diagram, domain, providerId, false); >+ diagramEditorInput.setNodePositionFile(nodePosFile); >+ return diagramEditorInput; >+ } >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorInput.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorInput.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorInput.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorInput.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,91 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.editor; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.emf.transaction.TransactionalEditingDomain; >+import org.eclipse.graphiti.mm.pictograms.Diagram; >+import org.eclipse.graphiti.ui.editor.DiagramEditorInput; >+ >+public class SapphireDiagramEditorInput extends DiagramEditorInput >+{ >+ private Diagram diagram; >+ private IFile nodePositionFile; >+ >+ public SapphireDiagramEditorInput(Diagram diagram, String diagramUriString, >+ TransactionalEditingDomain domain, String providerId, >+ boolean disposeEditingDomain) >+ { >+ super(diagramUriString, domain, providerId, disposeEditingDomain); >+ this.diagram = diagram; >+ } >+ >+ public SapphireDiagramEditorInput(Diagram diagram, URI diagramUri, >+ TransactionalEditingDomain domain, String providerId, >+ boolean disposeEditingDomain) >+ { >+ super(diagramUri, domain, providerId, disposeEditingDomain); >+ this.diagram = diagram; >+ } >+ >+ public Diagram getDiagram() >+ { >+ return this.diagram; >+ } >+ >+ public TransactionalEditingDomain getEditingDomain() >+ { >+ return this.editingDomain; >+ } >+ >+ @SuppressWarnings("rawtypes") >+ public Object getAdapter(Class adapter) >+ { >+ if (EObject.class.isAssignableFrom(adapter)) >+ { >+ return getDiagram(); >+ } >+ else if (Diagram.class.isAssignableFrom(adapter)) >+ { >+ return getDiagram(); >+ } >+ else if (TransactionalEditingDomain.class.isAssignableFrom(adapter)) >+ { >+ return getEditingDomain(); >+ } >+ else if (ResourceSet.class.isAssignableFrom(adapter)) >+ { >+ return getEditingDomain().getResourceSet(); >+ } >+ return null; >+ } >+ >+ public IFile getNodePositionFile() >+ { >+ return this.nodePositionFile; >+ } >+ >+ public void setNodePositionFile(IFile file) >+ { >+ this.nodePositionFile = file; >+ } >+ >+ >+ public static SapphireDiagramEditorInput createEditorInput(Diagram diagram, >+ TransactionalEditingDomain domain, String providerId, boolean disposeEditingDomain) >+ { >+ final Resource resource = diagram.eResource(); >+ if (resource == null) { >+ throw new IllegalArgumentException(); >+ } >+ final String fragment = resource.getURIFragment(diagram); >+ final URI fragmentUri = resource.getURI().appendFragment(fragment); >+ SapphireDiagramEditorInput diagramEditorInput; >+ diagramEditorInput = new SapphireDiagramEditorInput(diagram, fragmentUri, >+ domain, providerId, disposeEditingDomain); >+ return diagramEditorInput; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/NoResizeConfiguration.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/NoResizeConfiguration.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/NoResizeConfiguration.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/NoResizeConfiguration.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,17 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IResizeConfiguration; >+ >+public class NoResizeConfiguration implements IResizeConfiguration >+{ >+ public boolean isVerticalResizeAllowed() >+ { >+ return false; >+ } >+ >+ public boolean isHorizontalResizeAllowed() >+ { >+ return false; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddBendpointFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddBendpointFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddBendpointFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddBendpointFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,33 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IAddBendpointContext; >+import org.eclipse.graphiti.features.impl.DefaultAddBendpointFeature; >+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper; >+import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider; >+ >+public class SapphireAddBendpointFeature extends DefaultAddBendpointFeature >+{ >+ public SapphireAddBendpointFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ @Override >+ public void addBendpoint(IAddBendpointContext context) >+ { >+ super.addBendpoint(context); >+ >+ FreeFormConnection freeFormConnection = context.getConnection(); >+ Object bo = getBusinessObjectForPictogramElement(freeFormConnection); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramGeometryWrapper dg = >+ ((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry(); >+ dg.addConnectionBendpoint((DiagramConnectionPart)bo, >+ context.getBendpointIndex(), context.getX(), context.getY()); >+ } >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddConnectionFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddConnectionFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddConnectionFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddConnectionFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,97 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IDirectEditingInfo; >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IAddConnectionContext; >+import org.eclipse.graphiti.features.context.IAddContext; >+import org.eclipse.graphiti.features.impl.AbstractAddFeature; >+import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer; >+import org.eclipse.graphiti.mm.algorithms.Polygon; >+import org.eclipse.graphiti.mm.algorithms.Polyline; >+import org.eclipse.graphiti.mm.algorithms.Text; >+import org.eclipse.graphiti.mm.pictograms.Connection; >+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.graphiti.services.Graphiti; >+import org.eclipse.graphiti.services.IGaService; >+import org.eclipse.graphiti.services.IPeCreateService; >+import org.eclipse.graphiti.util.IColorConstant; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+ >+public class SapphireAddConnectionFeature extends AbstractAddFeature >+{ >+ public SapphireAddConnectionFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ public boolean canAdd(IAddContext context) >+ { >+ // return true if given business object is an DiagramConnectionPart >+ // note, that the context must be an instance of IAddConnectionContext >+ if (context instanceof IAddConnectionContext && >+ context.getNewObject() instanceof DiagramConnectionPart) >+ { >+ return true; >+ } >+ return false; >+ } >+ >+ public PictogramElement add(IAddContext context) >+ { >+ IAddConnectionContext addConContext = (IAddConnectionContext) context; >+ DiagramConnectionPart connectionPart = (DiagramConnectionPart) context.getNewObject(); >+ >+ IPeCreateService peCreateService = Graphiti.getPeCreateService(); >+ // CONNECTION WITH POLYLINE >+ Connection connection = peCreateService.createFreeFormConnection(getDiagram()); >+ connection.setStart(addConContext.getSourceAnchor()); >+ connection.setEnd(addConContext.getTargetAnchor()); >+ >+ IGaService gaService = Graphiti.getGaService(); >+ Polyline polyline = gaService.createPolyline(connection); >+ polyline.setForeground(manageColor(IColorConstant.BLACK)); >+ polyline.setLineWidth(1); >+ >+ // create link and wire it >+ link(connection, connectionPart); >+ >+ // add dynamic text decorator for the reference name >+ ConnectionDecorator textDecorator = peCreateService.createConnectionDecorator(connection, true, 0.5, true); >+ Text text = gaService.createDefaultText(textDecorator); >+ text.setForeground(manageColor(IColorConstant.BLACK)); >+ gaService.setLocation(text, 10, 0); >+ >+ text.setValue(connectionPart.getLabel()); >+ >+ // add static graphical decorators (composition and navigable) >+ ConnectionDecorator cd; >+ cd = peCreateService.createConnectionDecorator(connection, false, 1.0, true); >+ createArrow(cd); >+ >+ // provide information to support direct-editing directly >+ >+ // after object creation (must be activated additionally) >+ IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo(); >+ >+ // set container shape for direct editing after object creation >+ directEditingInfo.setMainPictogramElement(connection); >+ >+ // set shape and graphics algorithm where the editor for >+ // direct editing shall be opened after object creation >+ directEditingInfo.setPictogramElement(textDecorator); >+ directEditingInfo.setGraphicsAlgorithm(text); >+ >+ return connection; >+ } >+ >+ private Polygon createArrow(GraphicsAlgorithmContainer gaContainer) >+ { >+ Polygon polygon = Graphiti.getGaCreateService().createPolygon(gaContainer, new int[] { -8, 4, 0, 0, -8, -4, -5, 0 }); >+ polygon.setBackground(manageColor(IColorConstant.BLACK)); >+ //polygon.setStyle(StyleUtil.getStyleForADFView(getDiagram())); >+ polygon.setFilled(true); >+ return polygon; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddNodeFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddNodeFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddNodeFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddNodeFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,150 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IDirectEditingInfo; >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IAddContext; >+import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature; >+import org.eclipse.graphiti.mm.algorithms.Image; >+import org.eclipse.graphiti.mm.algorithms.Polyline; >+import org.eclipse.graphiti.mm.algorithms.Rectangle; >+import org.eclipse.graphiti.mm.algorithms.Text; >+import org.eclipse.graphiti.mm.algorithms.styles.Orientation; >+import org.eclipse.graphiti.mm.pictograms.ContainerShape; >+import org.eclipse.graphiti.mm.pictograms.Diagram; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.graphiti.mm.pictograms.Shape; >+import org.eclipse.graphiti.services.Graphiti; >+import org.eclipse.graphiti.services.IGaService; >+import org.eclipse.graphiti.services.IPeCreateService; >+import org.eclipse.graphiti.util.ColorConstant; >+import org.eclipse.graphiti.util.IColorConstant; >+import org.eclipse.sapphire.ui.def.ISapphirePartDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramLabelDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeImageDef; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider; >+ >+public class SapphireAddNodeFeature extends AbstractAddShapeFeature >+{ >+ private static final IColorConstant CLASS_TEXT_FOREGROUND = new ColorConstant(51, 51, 153); >+ private static final IColorConstant CLASS_FOREGROUND = new ColorConstant(255, 102, 0); >+ private static final IColorConstant CLASS_BACKGROUND = new ColorConstant(255, 204, 153); >+ >+ public SapphireAddNodeFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ public boolean canAdd(IAddContext context) >+ { >+ Object newObj = context.getNewObject(); >+ if (newObj instanceof DiagramNodePart && context.getTargetContainer() instanceof Diagram) >+ { >+ return true; >+ } >+ return false; >+ } >+ >+ public PictogramElement add(IAddContext context) >+ { >+ DiagramNodePart nodePart = (DiagramNodePart)context.getNewObject(); >+ final Diagram targetDiagram = (Diagram) context.getTargetContainer(); >+ >+ // define a default size for the shape >+ IDiagramNodeDef nodeDef = (IDiagramNodeDef)nodePart.getDefinition(); >+ int width = nodeDef.getHint(ISapphirePartDef.HINT_WIDTH, -1); >+ int height = nodeDef.getHint(ISapphirePartDef.HINT_HEIGHT, -1); >+ >+ // CONTAINER SHAPE WITH RECTANGLE >+ IPeCreateService peCreateService = Graphiti.getPeCreateService(); >+ ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true); >+ IGaService gaService = Graphiti.getGaService(); >+ >+ // TODO clean this up >+ // The temporary logic is to create a default rectangle if no icon is associated with the node >+ if (nodeDef.getImage().element() == null) >+ { >+ // create and set graphics algorithm >+ Rectangle rectangle = gaService.createRectangle(containerShape); >+ rectangle.setForeground(manageColor(CLASS_FOREGROUND)); >+ rectangle.setBackground(manageColor(CLASS_BACKGROUND)); >+ rectangle.setLineWidth(2); >+ gaService.setLocationAndSize(rectangle, >+ context.getX(), context.getY(), width, height); >+ >+ // create link and wire it >+ link(containerShape, nodePart); >+ >+ // SHAPE WITH LINE >+ { >+ // create shape for line >+ Shape shape = peCreateService.createShape(containerShape, false); >+ >+ // create and set graphics algorithm >+ Polyline polyline = >+ gaService.createPolyline(shape, new int[] { 0, 20, width, 20 }); >+ polyline.setForeground(manageColor(CLASS_FOREGROUND)); >+ polyline.setLineWidth(2); >+ } >+ } >+ else >+ { >+ IDiagramNodeImageDef imageDef = nodeDef.getImage().element(); >+ Rectangle rectangle = gaService.createRectangle(containerShape); >+ rectangle.setFilled(false); >+ rectangle.setLineVisible(false); >+ gaService.setLocationAndSize(rectangle, context.getX(), context.getY(), width, height); >+ >+ link(containerShape, nodePart); >+ >+ // Shape with Image >+ { >+ Shape shape = peCreateService.createShape(containerShape, false); >+ String imageId = imageDef.getImageId().getContent(); >+ Image image = gaService.createImage(shape, imageId); >+ int imageX = imageDef.getHint("x", 0); >+ int imageY = imageDef.getHint("y", 0); >+ int imageWidth = imageDef.getHint(ISapphirePartDef.HINT_WIDTH, width); >+ int imageHeight = imageDef.getHint(ISapphirePartDef.HINT_HEIGHT, -1); >+ >+ gaService.setLocationAndSize(image, imageX, imageY, imageWidth, imageHeight); >+ } >+ } >+ >+ if (nodeDef.getLabel().element() != null) >+ { >+ // create shape for text >+ Shape shape = peCreateService.createShape(containerShape, false); >+ >+ // create and set text graphics algorithm >+ Text text = gaService.createDefaultText(shape, nodePart.getLabel()); >+ text.setForeground(manageColor(CLASS_TEXT_FOREGROUND)); >+ text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER); >+ text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER); >+ >+ IDiagramLabelDef labelDef = nodeDef.getLabel().element(); >+ int labelX = labelDef.getHint("x", 0); >+ int labelY = labelDef.getHint("y", 0); >+ int labelWidth = labelDef.getHint(ISapphirePartDef.HINT_WIDTH, width); >+ int labelHeight = labelDef.getHint(ISapphirePartDef.HINT_HEIGHT, 15); >+ >+ gaService.setLocationAndSize(text, labelX, labelY, labelWidth, labelHeight); >+ >+ // create link and wire it >+ link(shape, nodePart); >+ } >+ >+ // add a chopbox anchor to the shape >+ peCreateService.createChopboxAnchor(containerShape); >+ >+ // Save the node bounds >+ DiagramGeometryWrapper diagramGeometry = >+ ((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry(); >+ diagramGeometry.addNode(nodePart, context.getX(), context.getY(), width, height); >+ >+ return containerShape; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateConnectionFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateConnectionFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateConnectionFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateConnectionFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,93 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.ICreateConnectionContext; >+import org.eclipse.graphiti.features.context.impl.AddConnectionContext; >+import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature; >+import org.eclipse.graphiti.mm.pictograms.Anchor; >+import org.eclipse.graphiti.mm.pictograms.Connection; >+import org.eclipse.sapphire.ui.SapphirePart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionTemplate; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+ >+public class SapphireCreateConnectionFeature extends AbstractCreateConnectionFeature >+{ >+ private DiagramConnectionTemplate connectionTemplate; >+ >+ public SapphireCreateConnectionFeature(IFeatureProvider fp, DiagramConnectionTemplate connectionTemplate) >+ { >+ super(fp, connectionTemplate.getToolPaletteLabel(), connectionTemplate.getToolPaletteDesc()); >+ this.connectionTemplate = connectionTemplate; >+ } >+ >+ public boolean canCreate(ICreateConnectionContext context) >+ { >+ // return true if both anchors belong to an IModelElement >+ // and those model elements are not identical >+ SapphirePart source = getEndpoint(context.getSourceAnchor()); >+ SapphirePart target = getEndpoint(context.getTargetAnchor()); >+ if (source instanceof DiagramNodePart && >+ target instanceof DiagramNodePart && source != target) >+ { >+ return this.connectionTemplate.canCreateNewConnection((DiagramNodePart)source, >+ (DiagramNodePart)target); >+ } >+ return false; >+ } >+ >+ public Connection create(ICreateConnectionContext context) >+ { >+ Connection newConnection = null; >+ >+ // get model elements which should be connected >+ SapphirePart source = getEndpoint(context.getSourceAnchor()); >+ SapphirePart target = getEndpoint(context.getTargetAnchor()); >+ >+ if (source instanceof DiagramNodePart && target instanceof DiagramNodePart) >+ { >+ DiagramNodePart sourceNode = (DiagramNodePart)source; >+ DiagramNodePart targetNode = (DiagramNodePart)target; >+ // create new business object >+ DiagramConnectionPart connectionPart = >+ this.connectionTemplate.createNewDiagramConnection(sourceNode, targetNode); >+ >+ // add connection for business object >+ AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor()); >+ addContext.setNewObject(connectionPart); >+ newConnection = (Connection) getFeatureProvider().addIfPossible(addContext); >+ >+ // activate direct editing after object creation >+ getFeatureProvider().getDirectEditingInfo().setActive(true); >+ } >+ >+ return newConnection; >+ } >+ >+ public boolean canStartConnection(ICreateConnectionContext context) >+ { >+ // return true if start anchor belongs to an IModelElement >+ if (getEndpoint(context.getSourceAnchor()) instanceof DiagramNodePart) >+ { >+ return true; >+ } >+ return false; >+ } >+ >+ /** >+ * Returns the SapphirePart belonging to the anchor, or null if not available. >+ */ >+ private SapphirePart getEndpoint(Anchor anchor) >+ { >+ if (anchor != null) >+ { >+ Object obj = getBusinessObjectForPictogramElement(anchor.getParent()); >+ if (obj instanceof SapphirePart) >+ { >+ return (SapphirePart) obj; >+ } >+ } >+ return null; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateNodeFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateNodeFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateNodeFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateNodeFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.ICreateContext; >+import org.eclipse.graphiti.features.impl.AbstractCreateFeature; >+import org.eclipse.graphiti.mm.pictograms.Diagram; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate; >+ >+public class SapphireCreateNodeFeature extends AbstractCreateFeature >+{ >+ private DiagramNodeTemplate nodeTemplate; >+ >+ public SapphireCreateNodeFeature(IFeatureProvider fp, DiagramNodeTemplate nodeTemplate) >+ { >+ super(fp, nodeTemplate.getToolPaletteLabel(), nodeTemplate.getToolPaletteDesc()); >+ this.nodeTemplate = nodeTemplate; >+ } >+ >+ public boolean canCreate(ICreateContext context) >+ { >+ return context.getTargetContainer() instanceof Diagram; >+ } >+ >+ public Object[] create(ICreateContext context) >+ { >+ DiagramNodePart nodePart = this.nodeTemplate.createNewDiagramNode(); >+ >+ addGraphicalRepresentation(context, nodePart); >+ return new Object[] { nodePart }; >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditConnectionFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditConnectionFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditConnectionFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditConnectionFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,62 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IDirectEditingContext; >+import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature; >+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+ >+public class SapphireDirectEditConnectionFeature extends AbstractDirectEditingFeature >+{ >+ public SapphireDirectEditConnectionFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ public int getEditingType() >+ { >+ return TYPE_TEXT; >+ } >+ >+ @Override >+ public boolean canDirectEdit(IDirectEditingContext context) >+ { >+ PictogramElement pe = (PictogramElement)context.getPictogramElement().eContainer(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ // support direct editing, if it is a DiagramConnectionPart, and the >+ // DiagramConnectionPart contains editable label >+ if (bo instanceof DiagramConnectionPart && >+ ((DiagramConnectionPart)bo).canEditLabel()) >+ { >+ return true; >+ } >+ // direct editing not supported in all other cases >+ return false; >+ } >+ >+ public String getInitialValue(IDirectEditingContext context) >+ { >+ PictogramElement pe = (PictogramElement)context.getPictogramElement().eContainer(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramConnectionPart connPart = (DiagramConnectionPart)bo; >+ return connPart.getLabel(); >+ } >+ return null; >+ } >+ >+ public void setValue(String value, IDirectEditingContext context) >+ { >+ PictogramElement pe = (PictogramElement)context.getPictogramElement().eContainer(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramConnectionPart connPart = (DiagramConnectionPart)bo; >+ connPart.setLabel(value); >+ updatePictogramElement(pe); >+ } >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditNodeFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditNodeFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditNodeFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditNodeFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,103 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import java.util.Iterator; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IDirectEditingContext; >+import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature; >+import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; >+import org.eclipse.graphiti.mm.algorithms.Text; >+import org.eclipse.graphiti.mm.pictograms.Anchor; >+import org.eclipse.graphiti.mm.pictograms.Connection; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.graphiti.mm.pictograms.Shape; >+import org.eclipse.graphiti.services.Graphiti; >+import org.eclipse.sapphire.modeling.IModelElement; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+ >+public class SapphireDirectEditNodeFeature extends AbstractDirectEditingFeature >+{ >+ public SapphireDirectEditNodeFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ public int getEditingType() >+ { >+ return TYPE_TEXT; >+ } >+ >+ @Override >+ public boolean canDirectEdit(IDirectEditingContext context) >+ { >+ PictogramElement pe = context.getPictogramElement(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ GraphicsAlgorithm ga = context.getGraphicsAlgorithm(); >+ // support direct editing, if it is a DiagramNodePart, and the user clicked >+ // directly on the text and not somewhere else in the rectangle >+ if (bo instanceof DiagramNodePart && ga instanceof Text) >+ { >+ return ((DiagramNodePart)bo).canEditLabel(); >+ } >+ // direct editing not supported in all other cases >+ return false; >+ } >+ >+ public String getInitialValue(IDirectEditingContext context) >+ { >+ // return the current label of the node >+ PictogramElement pe = context.getPictogramElement(); >+ DiagramNodePart nodePart = (DiagramNodePart)getBusinessObjectForPictogramElement(pe); >+ return nodePart.getLabel(); >+ } >+ >+ public void setValue(String value, IDirectEditingContext context) >+ { >+ PictogramElement pe = context.getPictogramElement(); >+ >+ if (pe.eContainer() instanceof Shape) >+ { >+ DiagramNodePart nodePart = (DiagramNodePart)getBusinessObjectForPictogramElement(pe); >+ nodePart.setLabel(value); >+ IModelElement nodeElement = nodePart.getLocalModelElement(); >+ Shape nodeShape = (Shape)pe.eContainer(); >+ >+ // go through all the connections associated with this bo and update them >+ for (Iterator<Anchor> iter = nodeShape.getAnchors().iterator(); iter.hasNext();) >+ { >+ Anchor anchor = iter.next(); >+ for (Iterator<Connection> iterator = Graphiti.getPeService().getAllConnections(anchor).iterator(); iterator.hasNext();) >+ { >+ Connection connection = iterator.next(); >+ Object bo = getBusinessObjectForPictogramElement(connection); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramConnectionPart connectionPart = (DiagramConnectionPart)bo; >+ IModelElement endpoint1 = connectionPart.getEndpoint1(); >+ IModelElement endpoint2 = connectionPart.getEndpoint2(); >+ if (endpoint1 == nodeElement) >+ { >+ connectionPart.refreshEndpoint1(); >+ } >+ else if (endpoint2 == nodeElement) >+ { >+ connectionPart.refreshEndpoint2(); >+ } >+ } >+ } >+ } >+ >+ } >+ >+ // Explicitly update the shape to display the new value in the diagram >+ // Note, that this might not be necessary in future versions of Graphiti >+ // (currently in discussion) >+ >+ // we know, that pe is the Shape of the Text, so its container is the >+ // main shape of the node >+ updatePictogramElement(((Shape)pe).getContainer()); >+ >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveBendpointFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveBendpointFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveBendpointFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveBendpointFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,36 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IMoveBendpointContext; >+import org.eclipse.graphiti.features.impl.DefaultMoveBendpointFeature; >+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper; >+import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider; >+ >+public class SapphireMoveBendpointFeature extends DefaultMoveBendpointFeature >+{ >+ public SapphireMoveBendpointFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ @Override >+ public boolean moveBendpoint(IMoveBendpointContext context) >+ { >+ boolean ret = false; >+ super.moveBendpoint(context); >+ >+ FreeFormConnection freeFormConnection = context.getConnection(); >+ Object bo = getBusinessObjectForPictogramElement(freeFormConnection); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramGeometryWrapper dg = >+ ((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry(); >+ ret = dg.updateConnectionBendpoint((DiagramConnectionPart)bo, >+ context.getBendpointIndex(), context.getX(), context.getY()); >+ } >+ return ret; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveNodeFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveNodeFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveNodeFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveNodeFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,31 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IMoveShapeContext; >+import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider; >+ >+public class SapphireMoveNodeFeature extends DefaultMoveShapeFeature >+{ >+ public SapphireMoveNodeFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ @Override >+ protected void internalMove(IMoveShapeContext context) >+ { >+ super.internalMove(context); >+ PictogramElement pe = context.getPictogramElement(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ if (bo instanceof DiagramNodePart) >+ { >+ DiagramGeometryWrapper dg = >+ ((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry(); >+ dg.updateNode((DiagramNodePart)bo, context.getX(), context.getY()); >+ } >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireRemoveBendpointFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireRemoveBendpointFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireRemoveBendpointFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireRemoveBendpointFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.context.IRemoveBendpointContext; >+import org.eclipse.graphiti.features.impl.DefaultRemoveBendpointFeature; >+import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper; >+import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider; >+ >+public class SapphireRemoveBendpointFeature extends DefaultRemoveBendpointFeature >+{ >+ public SapphireRemoveBendpointFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ @Override >+ public void removeBendpoint(IRemoveBendpointContext context) >+ { >+ super.removeBendpoint(context); >+ >+ FreeFormConnection freeFormConnection = context.getConnection(); >+ Object bo = getBusinessObjectForPictogramElement(freeFormConnection); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramGeometryWrapper dg = >+ ((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry(); >+ dg.removeConnectionBendpoint((DiagramConnectionPart)bo, context.getBendpointIndex()); >+ } >+ >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireResizeShapeFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireResizeShapeFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireResizeShapeFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireResizeShapeFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,41 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.DefaultResizeConfiguration; >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.IResizeConfiguration; >+import org.eclipse.graphiti.features.context.IResizeShapeContext; >+import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+ >+public class SapphireResizeShapeFeature extends DefaultResizeShapeFeature >+{ >+ public SapphireResizeShapeFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ @Override >+ public boolean canResizeShape(IResizeShapeContext context) >+ { >+ PictogramElement pe = context.getPictogramElement(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ if (bo instanceof DiagramNodePart) >+ { >+ DiagramNodePart nodePart = (DiagramNodePart)bo; >+ return nodePart.canResizeShape(); >+ } >+ return super.canResizeShape(context); >+ } >+ >+ @Override >+ public IResizeConfiguration getResizeConfiguration(IResizeShapeContext context) >+ { >+ if (!canResizeShape(context)) >+ { >+ return new NoResizeConfiguration(); >+ } >+ return new DefaultResizeConfiguration(); >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateConnectionFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateConnectionFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateConnectionFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateConnectionFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,94 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.IReason; >+import org.eclipse.graphiti.features.context.IUpdateContext; >+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature; >+import org.eclipse.graphiti.features.impl.Reason; >+import org.eclipse.graphiti.mm.algorithms.Text; >+import org.eclipse.graphiti.mm.pictograms.Connection; >+import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+ >+public class SapphireUpdateConnectionFeature extends AbstractUpdateFeature >+{ >+ public SapphireUpdateConnectionFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ public boolean canUpdate(IUpdateContext context) >+ { >+ PictogramElement pe = context.getPictogramElement(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ return bo instanceof DiagramConnectionPart; >+ } >+ >+ public IReason updateNeeded(IUpdateContext context) >+ { >+ // retrieve name from pictogram model >+ String pictogramName = null; >+ PictogramElement pictogramElement = context.getPictogramElement(); >+ if (pictogramElement instanceof Connection) { >+ Connection c = (Connection) pictogramElement; >+ for (ConnectionDecorator cd : c.getConnectionDecorators()) { >+ if (cd.getGraphicsAlgorithm() instanceof Text) { >+ Text text = (Text) cd.getGraphicsAlgorithm(); >+ pictogramName = text.getValue(); >+ } >+ } >+ } >+ >+ // retrieve name from business model >+ String businessName = null; >+ Object bo = getBusinessObjectForPictogramElement(pictogramElement); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramConnectionPart connPart = (DiagramConnectionPart)bo; >+ businessName = connPart.getLabel(); >+ } >+ >+ // update needed, if names are different >+ boolean updateNameNeeded = ((pictogramName == null && businessName != null) || (pictogramName != null && !pictogramName >+ .equals(businessName))); >+ if (updateNameNeeded) >+ { >+ return Reason.createTrueReason("Name is out of date"); //$NON-NLS-1$ >+ } >+ else >+ { >+ return Reason.createFalseReason(); >+ } >+ } >+ >+ public boolean update(IUpdateContext context) >+ { >+ String businessName = null; >+ PictogramElement pe = context.getPictogramElement(); >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ DiagramConnectionPart connPart = (DiagramConnectionPart)bo; >+ businessName = connPart.getLabel(); >+ } >+ >+ // Set name in pictogram model >+ if (pe instanceof Connection) >+ { >+ Connection c = (Connection) pe; >+ for (ConnectionDecorator cd : c.getConnectionDecorators()) >+ { >+ if (cd.getGraphicsAlgorithm() instanceof Text) >+ { >+ Text text = (Text) cd.getGraphicsAlgorithm(); >+ text.setValue(businessName); >+ return true; >+ } >+ } >+ } >+ >+ return false; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateNodeFeature.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateNodeFeature.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateNodeFeature.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateNodeFeature.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,94 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.features; >+ >+import org.eclipse.graphiti.features.IFeatureProvider; >+import org.eclipse.graphiti.features.IReason; >+import org.eclipse.graphiti.features.context.IUpdateContext; >+import org.eclipse.graphiti.features.impl.AbstractUpdateFeature; >+import org.eclipse.graphiti.features.impl.Reason; >+import org.eclipse.graphiti.mm.algorithms.Text; >+import org.eclipse.graphiti.mm.pictograms.ContainerShape; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.graphiti.mm.pictograms.Shape; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+ >+public class SapphireUpdateNodeFeature extends AbstractUpdateFeature >+{ >+ public SapphireUpdateNodeFeature(IFeatureProvider fp) >+ { >+ super(fp); >+ } >+ >+ public boolean canUpdate(IUpdateContext context) >+ { >+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement()); >+ return bo instanceof DiagramNodePart; >+ } >+ >+ public IReason updateNeeded(IUpdateContext context) >+ { >+ // retrieve name from pictogram model >+ String pictogramName = null; >+ PictogramElement pictogramElement = context.getPictogramElement(); >+ if (pictogramElement instanceof ContainerShape) >+ { >+ ContainerShape cs = (ContainerShape) pictogramElement; >+ for (Shape shape : cs.getChildren()) >+ { >+ if (shape.getGraphicsAlgorithm() instanceof Text) { >+ Text text = (Text) shape.getGraphicsAlgorithm(); >+ pictogramName = text.getValue(); >+ } >+ } >+ } >+ // retrieve name from business model >+ String businessName = null; >+ Object bo = getBusinessObjectForPictogramElement(pictogramElement); >+ if (bo instanceof DiagramNodePart) >+ { >+ DiagramNodePart nodePart = (DiagramNodePart) bo; >+ businessName = nodePart.getLabel(); >+ } >+ // update needed, if names are different >+ boolean updateNameNeeded = >+ ((pictogramName == null && businessName != null) || >+ (pictogramName != null && !pictogramName.equals(businessName))); >+ if (updateNameNeeded) >+ { >+ return Reason.createTrueReason("Name is out of date"); //$NON-NLS-1$ >+ } >+ else >+ { >+ return Reason.createFalseReason(); >+ } >+ } >+ >+ public boolean update(IUpdateContext context) >+ { >+ // retrieve name from business model >+ String businessName = null; >+ PictogramElement pictogramElement = context.getPictogramElement(); >+ Object bo = getBusinessObjectForPictogramElement(pictogramElement); >+ if (bo instanceof DiagramNodePart) { >+ DiagramNodePart nodePart = (DiagramNodePart) bo; >+ businessName = nodePart.getLabel(); >+ } >+ >+ // Set name in pictogram model >+ if (pictogramElement instanceof ContainerShape) >+ { >+ ContainerShape cs = (ContainerShape) pictogramElement; >+ for (Shape shape : cs.getChildren()) >+ { >+ if (shape.getGraphicsAlgorithm() instanceof Text) >+ { >+ Text text = (Text) shape.getGraphicsAlgorithm(); >+ text.setValue(businessName); >+ return true; >+ } >+ } >+ } >+ >+ return false; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramFeatureProvider.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramFeatureProvider.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramFeatureProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramFeatureProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,208 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.providers; >+ >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.graphiti.dt.IDiagramTypeProvider; >+import org.eclipse.graphiti.features.IAddBendpointFeature; >+import org.eclipse.graphiti.features.IAddFeature; >+import org.eclipse.graphiti.features.ICreateConnectionFeature; >+import org.eclipse.graphiti.features.ICreateFeature; >+import org.eclipse.graphiti.features.IDirectEditingFeature; >+import org.eclipse.graphiti.features.IMoveBendpointFeature; >+import org.eclipse.graphiti.features.IMoveShapeFeature; >+import org.eclipse.graphiti.features.IRemoveBendpointFeature; >+import org.eclipse.graphiti.features.IResizeShapeFeature; >+import org.eclipse.graphiti.features.IUpdateFeature; >+import org.eclipse.graphiti.features.context.IAddBendpointContext; >+import org.eclipse.graphiti.features.context.IAddContext; >+import org.eclipse.graphiti.features.context.IDirectEditingContext; >+import org.eclipse.graphiti.features.context.IMoveBendpointContext; >+import org.eclipse.graphiti.features.context.IMoveShapeContext; >+import org.eclipse.graphiti.features.context.IRemoveBendpointContext; >+import org.eclipse.graphiti.features.context.IResizeShapeContext; >+import org.eclipse.graphiti.features.context.IUpdateContext; >+import org.eclipse.graphiti.features.impl.IIndependenceSolver; >+import org.eclipse.graphiti.mm.pictograms.Connection; >+import org.eclipse.graphiti.mm.pictograms.ContainerShape; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionTemplate; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate; >+import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddBendpointFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddConnectionFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddNodeFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireCreateConnectionFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireCreateNodeFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireDirectEditConnectionFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireDirectEditNodeFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireMoveBendpointFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireMoveNodeFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireRemoveBendpointFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireResizeShapeFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireUpdateConnectionFeature; >+import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireUpdateNodeFeature; >+ >+public class SapphireDiagramFeatureProvider extends DefaultFeatureProvider >+{ >+ private SapphireDiagramEditorPart diagramPart; >+ >+ public SapphireDiagramFeatureProvider(IDiagramTypeProvider dtp, IIndependenceSolver solver) >+ { >+ super(dtp); >+ this.setIndependenceSolver(solver); >+ } >+ >+ public void setDiagramPart(SapphireDiagramEditorPart diagramPart) >+ { >+ this.diagramPart = diagramPart; >+ >+ } >+ >+ public SapphireDiagramEditorPart getDiagramPart() >+ { >+ return this.diagramPart; >+ } >+ >+ public DiagramGeometryWrapper getDiagramGeometry() >+ { >+ return this.diagramPart.getDiagramGeometry(); >+ } >+ >+ @Override >+ public IAddFeature getAddFeature(IAddContext context) >+ { >+ Object obj = context.getNewObject(); >+ if (obj instanceof DiagramNodePart) >+ { >+ return new SapphireAddNodeFeature(this); >+ } >+ else if (obj instanceof DiagramConnectionPart) >+ { >+ return new SapphireAddConnectionFeature(this); >+ } >+ >+ return super.getAddFeature(context); >+ } >+ >+ @Override >+ public ICreateFeature[] getCreateFeatures() >+ { >+ List<DiagramNodeTemplate> nodeTemplates = this.diagramPart.getNodeTemplates(); >+ ICreateFeature[] features = new ICreateFeature[nodeTemplates.size()]; >+ int i = 0; >+ for (DiagramNodeTemplate nodeTemplate : nodeTemplates) >+ { >+ SapphireCreateNodeFeature createNodeFeature = >+ new SapphireCreateNodeFeature(this, nodeTemplate); >+ features[i++] = createNodeFeature; >+ } >+ return features; >+ } >+ >+ @Override >+ public ICreateConnectionFeature[] getCreateConnectionFeatures() >+ { >+ List<DiagramConnectionTemplate> connectionTemplates = this.diagramPart.getConnectionTemplates(); >+ List<ICreateConnectionFeature> features = >+ new ArrayList<ICreateConnectionFeature>(connectionTemplates.size()); >+ for (DiagramConnectionTemplate connectionTemplate : connectionTemplates) >+ { >+ SapphireCreateConnectionFeature createConnectionFeature = >+ new SapphireCreateConnectionFeature(this, connectionTemplate); >+ features.add(createConnectionFeature); >+ } >+ >+ // Add Embedded connection features >+ List<DiagramNodeTemplate> nodeTemplates = this.diagramPart.getNodeTemplates(); >+ for (DiagramNodeTemplate nodeTemplate : nodeTemplates) >+ { >+ DiagramConnectionTemplate connTemplate = nodeTemplate.getEmbeddedConnectionTemplate(); >+ if (connTemplate != null) >+ { >+ SapphireCreateConnectionFeature createConnectionFeature = >+ new SapphireCreateConnectionFeature(this, connTemplate); >+ features.add(createConnectionFeature); >+ } >+ } >+ return features.toArray(new ICreateConnectionFeature[0]); >+ } >+ >+ @Override >+ public IDirectEditingFeature getDirectEditingFeature(IDirectEditingContext context) >+ { >+ PictogramElement pe = context.getPictogramElement(); >+ Object bo = getBusinessObjectForPictogramElement((PictogramElement) pe.eContainer()); >+ if (bo instanceof DiagramNodePart) >+ { >+ return new SapphireDirectEditNodeFeature(this); >+ } >+ else if (bo instanceof DiagramConnectionPart) >+ { >+ return new SapphireDirectEditConnectionFeature(this); >+ } >+ return super.getDirectEditingFeature(context); >+ } >+ >+ @Override >+ public IUpdateFeature getUpdateFeature(IUpdateContext context) >+ { >+ PictogramElement pe = context.getPictogramElement(); >+ if (pe instanceof ContainerShape) >+ { >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ if (bo instanceof DiagramNodePart) >+ { >+ return new SapphireUpdateNodeFeature(this); >+ } >+ } >+ else if (pe instanceof Connection) >+ { >+ Object bo = getBusinessObjectForPictogramElement(pe); >+ if (bo instanceof DiagramConnectionPart) >+ { >+ return new SapphireUpdateConnectionFeature(this); >+ } >+ } >+ return super.getUpdateFeature(context); >+ } >+ >+ @Override >+ public IAddBendpointFeature getAddBendpointFeature(IAddBendpointContext context) >+ { >+ IAddBendpointFeature ret = new SapphireAddBendpointFeature(this); >+ return ret; >+ } >+ >+ @Override >+ public IRemoveBendpointFeature getRemoveBendpointFeature(IRemoveBendpointContext context) >+ { >+ IRemoveBendpointFeature ret = new SapphireRemoveBendpointFeature(this); >+ return ret; >+ } >+ >+ @Override >+ public IMoveBendpointFeature getMoveBendpointFeature(IMoveBendpointContext context) >+ { >+ IMoveBendpointFeature ret = new SapphireMoveBendpointFeature(this); >+ return ret; >+ } >+ >+ @Override >+ public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) >+ { >+ return new SapphireMoveNodeFeature(this); >+ } >+ >+ @Override >+ public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) >+ { >+ IResizeShapeFeature ret = new SapphireResizeShapeFeature(this); >+ return ret; >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramImageProvider.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramImageProvider.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramImageProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramImageProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,23 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.providers; >+ >+import org.eclipse.graphiti.ui.platform.AbstractImageProvider; >+ >+public class SapphireDiagramImageProvider extends AbstractImageProvider >+{ >+ public SapphireDiagramImageProvider() >+ { >+ super(); >+ } >+ >+ @Override >+ protected void addAvailableImages() >+ { >+ >+ } >+ >+ public void registerImage(String imageId, String imageFilePath) >+ { >+ this.addImageFilePath(imageId, imageFilePath); >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramSolver.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramSolver.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramSolver.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramSolver.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,45 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.providers; >+ >+import java.util.HashMap; >+ >+import org.eclipse.graphiti.features.impl.IIndependenceSolver; >+import org.eclipse.sapphire.ui.SapphirePart; >+ >+public class SapphireDiagramSolver implements IIndependenceSolver >+{ >+ private HashMap<String, SapphirePart> keyToBOMap; >+ private HashMap<SapphirePart, String> bOToKeyMap; >+ private int counter = 0; >+ >+ public SapphireDiagramSolver() >+ { >+ this.keyToBOMap = new HashMap<String, SapphirePart>(); >+ this.bOToKeyMap = new HashMap<SapphirePart, String>(); >+ } >+ >+ public String getKeyForBusinessObject(Object bo) >+ { >+ if (bo instanceof SapphirePart) >+ { >+ SapphirePart part = (SapphirePart)bo; >+ if (this.bOToKeyMap.containsKey(bo)) >+ { >+ return this.bOToKeyMap.get(bo); >+ } >+ String key = Integer.toString(this.counter++); >+ this.keyToBOMap.put(key, part); >+ this.bOToKeyMap.put(part, key); >+ >+ return key; >+ } >+ return null; >+ } >+ >+ public Object getBusinessObjectForKey(String key) >+ { >+ if (key == null) >+ return null; >+ return this.keyToBOMap.get(key); >+ } >+ >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramToolBehaviorProvider.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramToolBehaviorProvider.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramToolBehaviorProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramToolBehaviorProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,25 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.providers; >+ >+import org.eclipse.graphiti.dt.IDiagramTypeProvider; >+import org.eclipse.graphiti.mm.pictograms.PictogramElement; >+import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; >+import org.eclipse.graphiti.tb.IContextButtonPadData; >+ >+ >+public class SapphireDiagramToolBehaviorProvider extends DefaultToolBehaviorProvider >+{ >+ public SapphireDiagramToolBehaviorProvider(IDiagramTypeProvider dtp) >+ { >+ super(dtp); >+ } >+ >+ /** >+ * Override super class impl to not include "Remove" >+ */ >+ @Override >+ protected void setGenericContextButtons(IContextButtonPadData data, PictogramElement pe, int identifiers) >+ { >+ identifiers -= CONTEXT_BUTTON_REMOVE; >+ super.setGenericContextButtons(data, pe, identifiers); >+ } >+} >Index: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramTypeProvider.java >=================================================================== >RCS file: src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramTypeProvider.java >diff -N src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramTypeProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramTypeProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,145 @@ >+package org.eclipse.sapphire.ui.diagram.graphiti.providers; >+ >+import java.io.File; >+import java.io.IOException; >+import java.net.URL; >+import java.util.List; >+ >+import org.eclipse.core.runtime.FileLocator; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider; >+import org.eclipse.graphiti.mm.pictograms.Diagram; >+import org.eclipse.graphiti.platform.IDiagramEditor; >+import org.eclipse.graphiti.tb.IToolBehaviorProvider; >+import org.eclipse.graphiti.ui.internal.platform.ExtensionManager; >+import org.eclipse.graphiti.ui.platform.IImageProvider; >+import org.eclipse.graphiti.ui.services.GraphitiUi; >+import org.eclipse.sapphire.ui.def.IImportDirective; >+import org.eclipse.sapphire.ui.def.ISapphireUiDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef; >+import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeImageDef; >+import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate; >+import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart; >+import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor; >+import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin; >+import org.eclipse.ui.internal.util.BundleUtility; >+import org.osgi.framework.Bundle; >+ >+public class SapphireDiagramTypeProvider extends AbstractDiagramTypeProvider >+{ >+ private SapphireDiagramEditorPart diagramPart; >+ private SapphireDiagramFeatureProvider featureProvider; >+ private IToolBehaviorProvider[] toolBehaviorProviders; >+ >+ public SapphireDiagramTypeProvider() >+ { >+ this.featureProvider = >+ new SapphireDiagramFeatureProvider(this, new SapphireDiagramSolver()); >+ setFeatureProvider(this.featureProvider); >+ } >+ >+ public void setDiagramPart(SapphireDiagramEditorPart diagramPart) >+ { >+ this.diagramPart = diagramPart; >+ this.featureProvider.setDiagramPart(diagramPart); >+ } >+ >+ public SapphireDiagramEditorPart getDiagramPart() >+ { >+ return this.diagramPart; >+ } >+ >+ @Override >+ public void init(Diagram diagram, IDiagramEditor diagramEditor) >+ { >+ super.init(diagram, diagramEditor); >+ setDiagramPart(((SapphireDiagramEditor)diagramEditor).getDiagramEditorPart()); >+ ExtensionManager extManager = (ExtensionManager)GraphitiUi.getExtensionManager(); >+ IImageProvider imageProviders[] = extManager.getImageProviders(); >+ SapphireDiagramImageProvider sapphireImageProvider = null; >+ for (IImageProvider imageProvider : imageProviders) >+ { >+ if (imageProvider instanceof SapphireDiagramImageProvider) >+ { >+ sapphireImageProvider = (SapphireDiagramImageProvider)imageProvider; >+ break; >+ } >+ } >+ if (sapphireImageProvider != null) >+ { >+ List<DiagramNodeTemplate> nodeTemplates = this.diagramPart.getNodeTemplates(); >+ for (DiagramNodeTemplate nodeTemplate : nodeTemplates) >+ { >+ IDiagramNodeDef nodeDef = nodeTemplate.getDefinition(); >+ if (nodeDef.getImage().element() != null) >+ { >+ IDiagramNodeImageDef imageDef = nodeDef.getImage().element(); >+ ISapphireUiDef uiDef = imageDef.nearest(ISapphireUiDef.class); >+ String imageId = imageDef.getImageId().getContent(); >+ String imagePath = imageDef.getImagePath().getContent(); >+ >+ String bundleId = resolveImageBundle(uiDef, imagePath); >+ // Graphiti's image provider doesn't support images from different plugins. >+ // See http://www.eclipse.org/forums/index.php?t=tree&th=201973&start=0&S=3813ad4d99f2ac8bd56a0072ffa6ebd9 >+ if (bundleId != null) >+ { >+ sapphireImageProvider.setPluginId(bundleId); >+ } >+ >+ if (imageId != null && imagePath != null) >+ { >+ sapphireImageProvider.registerImage(imageId, imagePath); >+ } >+ } >+ } >+ } >+ } >+ >+ @Override >+ public IToolBehaviorProvider[] getAvailableToolBehaviorProviders() >+ { >+ if (this.toolBehaviorProviders == null) >+ { >+ this.toolBehaviorProviders = >+ new IToolBehaviorProvider[] { new SapphireDiagramToolBehaviorProvider(this) }; >+ } >+ return this.toolBehaviorProviders; >+ } >+ >+ @Override >+ public void postInit() >+ { >+ SapphireDiagramEditor sapphireEditor = (SapphireDiagramEditor)getDiagramEditor(); >+ sapphireEditor.syncDiagramWithModel(); >+ sapphireEditor.doSave(null); >+ } >+ >+ private String resolveImageBundle(ISapphireUiDef def, String imagePath) >+ { >+ try >+ { >+ for (IImportDirective directive : def.getImportDirectives()) >+ { >+ final String bundleId = directive.getBundle().getText(); >+ Bundle bundle = Platform.getBundle(bundleId); >+ URL url = BundleUtility.find(bundle, imagePath); >+ URL locatedURL = FileLocator.toFileURL(url); >+ if ("file".equalsIgnoreCase(locatedURL.getProtocol())) >+ { >+ String fullPath = new Path(locatedURL.getPath()).toOSString(); >+ File f = new File(fullPath); >+ if (f.exists()) >+ { >+ return bundleId; >+ } >+ } >+ } >+ } >+ catch (IOException e) >+ { >+ SapphireUiFrameworkPlugin.log(e); >+ } >+ return null; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 330482
:
183320
|
183327
|
183361
|
183403
|
184197
|
184669
|
185156
|
185573
|
185574
|
185576
|
185679
|
186532
|
186776
|
186777