Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 330482 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +6 lines)
Lines 12-18 Link Here
12
 org.eclipse.wst.xml.ui,
12
 org.eclipse.wst.xml.ui,
13
 org.eclipse.ui,
13
 org.eclipse.ui,
14
 org.eclipse.ui.views,
14
 org.eclipse.ui.views,
15
 org.eclipse.help
15
 org.eclipse.help,
16
 org.eclipse.emf.transaction,
17
 org.eclipse.ui.views.properties.tabbed,
18
 org.eclipse.gef,
19
 org.eclipse.graphiti,
20
 org.eclipse.graphiti.ui
16
Bundle-ActivationPolicy: lazy
21
Bundle-ActivationPolicy: lazy
17
Bundle-RequiredExecutionEnvironment: J2SE-1.5
22
Bundle-RequiredExecutionEnvironment: J2SE-1.5
18
Bundle-Vendor: %providerName
23
Bundle-Vendor: %providerName
(-)plugin.xml (+19 lines)
Lines 146-150 Link Here
146
      id="org.eclipse.sapphire.samples.ezbug.ui.BugDatabaseEditor"
146
      id="org.eclipse.sapphire.samples.ezbug.ui.BugDatabaseEditor"
147
      name="Bug Database Editor (Sapphire Sample)"/>
147
      name="Bug Database Editor (Sapphire Sample)"/>
148
  </extension>
148
  </extension>
149
150
  <extension point="org.eclipse.ui.editors">
151
    <editor
152
      class="org.eclipse.sapphire.samples.map.ui.MapEditor"
153
      default="true"
154
      filenames="map.xml"
155
      id="org.eclipse.sapphire.samples.map.ui.MapEditor"
156
      name="Map Editor"/>
157
  </extension>
158
  
159
  <extension point="org.eclipse.ui.editors">
160
    <editor
161
      class="org.eclipse.sapphire.samples.library.ui.LibraryEditor"
162
      default="true"
163
      filenames="library.xml"
164
      id="org.eclipse.sapphire.samples.library.ui.LibraryEditor"
165
      name="Library Editor"/>
166
  </extension>
167
149
  
168
  
150
</plugin>
169
</plugin>
(-)sdef/LibraryEditor.sdef (+104 lines)
Added Link Here
1
<definition>
2
3
  <import>
4
    <bundle>org.eclipse.sapphire.samples</bundle>
5
    <package>org.eclipse.sapphire.samples.library</package>
6
    <package>org.eclipse.sapphire.samples.library.ui</package>
7
    <package>org.eclipse.sapphire.samples.library.internal</package>
8
  </import>
9
  
10
  <diagram-page>
11
    <id>diagram</id>
12
    <page-name>Diagram</page-name>
13
    <page-header-text>Diagram</page-header-text>
14
    <node>
15
      <hint><name>width</name><value>95</value></hint>
16
      <hint><name>height</name><value>85</value></hint>
17
      <hint><name>resizable</name><value>false</value></hint>    
18
      <id>books</id>
19
      <tool-palette-label>Book</tool-palette-label>
20
      <tool-palette-desc>Book</tool-palette-desc>
21
      <property>Books</property>
22
      <image>
23
        <id>bookImage</id>
24
        <path>images/book.png</path>
25
        <hint><name>x</name><value>0</value></hint>
26
        <hint><name>y</name><value>0</value></hint>
27
        <hint><name>width</name><value>64</value></hint>
28
        <hint><name>height</name><value>64</value></hint>
29
      </image>
30
      <label>
31
        <content>${Title == null ? "&lt;Title&gt;" : Title}</content>
32
        <hint><name>x</name><value>0</value></hint>
33
        <hint><name>y</name><value>70</value></hint>
34
        <hint><name>height</name><value>15</value></hint>
35
      </label>
36
      <instance-id>${Title}</instance-id>
37
      <connection>
38
        <id>connections</id>
39
        <tool-palette-label>Book Reference</tool-palette-label>
40
        <tool-palette-desc>Book Reference</tool-palette-desc>
41
        <property>ReferencedBooks</property>
42
        <label>
43
          <content>Reference</content>
44
        </label>
45
        <endpoint>
46
          <property>ReferencedBook</property>
47
          <value>${Title}</value>
48
          <type>ARROW</type>
49
        </endpoint>
50
        <instance-id>${ReferencedBook}</instance-id>
51
      </connection>
52
    </node>
53
  </diagram-page>
54
  
55
  <editor-page>
56
    <id>overview</id>
57
    <page-name>Overview</page-name>
58
    <page-header-text>Overview</page-header-text>
59
    <root-node>
60
      <node>
61
        <label>Books</label>
62
        <section>
63
          <description>Books in the library</description>
64
          <content>
65
            <property-editor>
66
              <property>Books</property>
67
              <child-property>
68
                <property>Title</property>
69
              </child-property>
70
              <child-property>
71
                <property>Author</property>
72
              </child-property>
73
              <hint><name>show.label.above</name><value>true</value></hint>
74
              <hint>
75
                <name>column.widths</name>
76
                <value>150,150</value>
77
              </hint>
78
            </property-editor>
79
            <separator>
80
              <label>References</label>
81
            </separator>
82
            <switching-panel>
83
              <list-selection-controller>
84
                <property>Books</property>
85
              </list-selection-controller>
86
              <panel>
87
                <key>IBook</key>
88
                <content>
89
                  <property-editor>ReferencedBooks</property-editor>
90
                </content>          
91
              </panel>
92
              <default-panel>
93
                <content>
94
                  <label>Select a book above to configure additional properties.</label>
95
                </content>
96
              </default-panel>
97
            </switching-panel>
98
          </content>  
99
        </section>
100
      </node>
101
    </root-node>
102
  </editor-page>
103
  
104
</definition>
(-)sdef/MapEditor.sdef (+73 lines)
Added Link Here
1
<definition>
2
3
  <import>
4
    <bundle>org.eclipse.sapphire.samples</bundle>
5
    <package>org.eclipse.sapphire.samples.map</package>
6
    <package>org.eclipse.sapphire.samples.map.ui</package>
7
  </import>
8
  
9
  <diagram-page>
10
    <id>diagram</id>
11
    <page-name>Diagram</page-name>
12
    <page-header-text>Diagram</page-header-text>
13
    <node>
14
      <id>destinations</id>
15
      <tool-palette-label>Destination</tool-palette-label>
16
      <tool-palette-desc>Map Destination</tool-palette-desc>
17
      <hint><name>width</name><value>70</value></hint>
18
      <hint><name>height</name><value>85</value></hint>      
19
      <property>Destinations</property>
20
      <label>
21
        <content>${Name == null ? "&lt;Destination&gt;" : Name}</content>
22
      </label>
23
      <instance-id>${Name}</instance-id>
24
    </node>
25
    <connection>
26
      <id>connections</id>
27
      <tool-palette-label>Route</tool-palette-label>
28
      <tool-palette-desc>Map Route</tool-palette-desc>
29
      <property>Routes</property>
30
      <label>
31
        <content>${Distance == null ? "&lt;Distance&gt;" : Distance}</content>
32
      </label>
33
      <endpoint1>
34
        <property>FromDestination</property>
35
        <value>${Name}</value>
36
        <type>NONE</type>
37
      </endpoint1>
38
      <endpoint2>
39
        <property>ToDestination</property>
40
        <value>${Name}</value>
41
        <type>ARROW</type>
42
      </endpoint2>
43
      <instance-id>${FromDestination}-${ToDestination}</instance-id>
44
    </connection>
45
  </diagram-page>
46
  
47
  <editor-page>
48
    <id>overview</id>
49
    <page-name>Overview</page-name>
50
    <page-header-text>Overview</page-header-text>
51
    <root-node>
52
      <node>
53
        <label>Destinations</label>
54
        <section>
55
          <description>Destinations in the map</description>
56
          <content>
57
            <property-editor>Destinations</property-editor>
58
          </content>
59
        </section>
60
      </node>
61
      <node>
62
        <label>Routes</label>
63
        <section>
64
          <description>Routes in the map</description>
65
          <content>
66
            <property-editor>Routes</property-editor>
67
          </content>
68
        </section>
69
      </node>
70
    </root-node>
71
  </editor-page>
72
</definition>
73
    
(-)src/org/eclipse/sapphire/samples/library/IBook.java (+53 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.library;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ListProperty;
5
import org.eclipse.sapphire.modeling.ModelElementList;
6
import org.eclipse.sapphire.modeling.ModelElementType;
7
import org.eclipse.sapphire.modeling.Value;
8
import org.eclipse.sapphire.modeling.ValueProperty;
9
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
10
import org.eclipse.sapphire.modeling.annotations.Label;
11
import org.eclipse.sapphire.modeling.annotations.NonNullValue;
12
import org.eclipse.sapphire.modeling.annotations.Type;
13
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
14
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
15
16
@GenerateImpl
17
18
public interface IBook extends IModelElement 
19
{
20
    ModelElementType TYPE = new ModelElementType( IBook.class );
21
22
    // *** Title ***
23
    
24
    @XmlBinding( path = "title" )
25
    @Label( standard = "title" )
26
    @NonNullValue
27
28
    ValueProperty PROP_TITLE = new ValueProperty( TYPE, "Title" );
29
30
    Value<String> getTitle();
31
    void setTitle( String name );
32
33
    // *** Author ***
34
    
35
    @XmlBinding( path = "Author" )
36
    @Label( standard = "Author" )
37
    @NonNullValue
38
39
    ValueProperty PROP_AUTHOR = new ValueProperty( TYPE, "Author" );
40
41
    Value<String> getAuthor();
42
    void setAuthor( String author );
43
    
44
    // *** ReferencedBooks ***
45
    
46
    @Type( base = IBookReference.class )
47
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "referenced-book", type = IBookReference.class ) )
48
    
49
    ListProperty PROP_REFERENCED_BOOKS = new ListProperty( TYPE, "ReferencedBooks" );
50
    
51
    ModelElementList<IBookReference> getReferencedBooks();
52
    
53
}
(-)src/org/eclipse/sapphire/samples/library/IBookReference.java (+32 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.library;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ModelElementType;
5
import org.eclipse.sapphire.modeling.ReferenceValue;
6
import org.eclipse.sapphire.modeling.ValueProperty;
7
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
8
import org.eclipse.sapphire.modeling.annotations.Label;
9
import org.eclipse.sapphire.modeling.annotations.NonNullValue;
10
import org.eclipse.sapphire.modeling.annotations.Reference;
11
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
12
import org.eclipse.sapphire.samples.library.internal.BookReferenceService;
13
14
@GenerateImpl
15
16
public interface IBookReference extends IModelElement 
17
{
18
	ModelElementType TYPE = new ModelElementType( IBookReference.class );
19
	
20
	// *** ReferencedBook ***
21
	
22
	@Reference( target = IBook.class, service = BookReferenceService.class )
23
	@XmlBinding( path = "referenced-book")
24
	@NonNullValue
25
	@Label(standard = "referenced book")
26
27
	ValueProperty PROP_REFERENCED_BOOK = new ValueProperty( TYPE, "ReferencedBook" );
28
29
    ReferenceValue<IBook> getReferencedBook();
30
    void setReferencedBook( String name );
31
	
32
}
(-)src/org/eclipse/sapphire/samples/library/ILibrary.java (+29 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.library;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ListProperty;
5
import org.eclipse.sapphire.modeling.ModelElementList;
6
import org.eclipse.sapphire.modeling.ModelElementType;
7
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
8
import org.eclipse.sapphire.modeling.annotations.Type;
9
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
10
import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding;
11
12
@GenerateImpl
13
@XmlRootBinding( elementName = "library")
14
15
public interface ILibrary extends IModelElement 
16
{
17
	ModelElementType TYPE = new ModelElementType( ILibrary.class );
18
	
19
    // *** Books ***
20
21
    @Type( base = IBook.class )
22
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "book", type = IBook.class ) )
23
    
24
    ListProperty PROP_BOOKS = new ListProperty( TYPE, "Books" );
25
    
26
    ModelElementList<IBook> getBooks();
27
	
28
29
}
(-)src/org/eclipse/sapphire/samples/library/internal/BookReferenceService.java (+29 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.library.internal;
2
3
import org.eclipse.sapphire.modeling.ModelElementList;
4
import org.eclipse.sapphire.modeling.ReferenceService;
5
import org.eclipse.sapphire.samples.library.IBook;
6
import org.eclipse.sapphire.samples.library.ILibrary;
7
8
public class BookReferenceService extends ReferenceService 
9
{
10
11
	@Override
12
	public Object resolve(String reference) 
13
	{
14
		if (reference != null)
15
		{
16
			ILibrary library = element().nearest(ILibrary.class);
17
			ModelElementList<IBook> books = library.getBooks();
18
			for (IBook book : books)
19
			{
20
				if (reference.equals(book.getTitle().getContent()))
21
				{
22
					return book;
23
				}
24
			}
25
		}
26
		return null;
27
	}
28
29
}
(-)src/org/eclipse/sapphire/samples/library/ui/LibraryEditor.java (+83 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.library.ui;
2
3
import org.eclipse.core.runtime.IPath;
4
import org.eclipse.core.runtime.IProgressMonitor;
5
import org.eclipse.core.runtime.Path;
6
import org.eclipse.sapphire.modeling.IModelElement;
7
import org.eclipse.sapphire.modeling.xml.RootXmlResource;
8
import org.eclipse.sapphire.samples.library.ILibrary;
9
import org.eclipse.sapphire.ui.SapphireEditor;
10
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
11
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor;
12
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorInput;
13
import org.eclipse.sapphire.ui.editor.views.masterdetails.MasterDetailsPage;
14
import org.eclipse.sapphire.ui.xml.XmlEditorResourceStore;
15
import org.eclipse.ui.PartInitException;
16
import org.eclipse.ui.part.FileEditorInput;
17
import org.eclipse.wst.sse.ui.StructuredTextEditor;
18
19
public class LibraryEditor extends SapphireEditor 
20
{
21
	private ILibrary modelLibrary;
22
	private StructuredTextEditor librarySourceEditor;
23
	private SapphireDiagramEditorPart libraryDiagramPart;
24
	private MasterDetailsPage libraryOverviewPage;
25
	
26
    public LibraryEditor()
27
    {
28
        super( "org.eclipse.sapphire.samples" );
29
    }
30
31
	@Override
32
	protected void createSourcePages() throws PartInitException 
33
	{
34
		this.librarySourceEditor = new StructuredTextEditor();
35
		this.librarySourceEditor.setEditorPart(this);
36
        final FileEditorInput rootEditorInput = (FileEditorInput) getEditorInput();
37
        
38
        int index = addPage( this.librarySourceEditor, rootEditorInput );
39
        setPageText( index, "library.xml" );
40
	}
41
42
	@Override
43
	protected IModelElement createModel() 
44
	{
45
		this.modelLibrary = ILibrary.TYPE.instantiate(new RootXmlResource(new XmlEditorResourceStore(this, this.librarySourceEditor)));
46
		return this.modelLibrary;
47
	}
48
49
	@Override
50
	protected void createDiagramPages() throws PartInitException
51
	{
52
		IPath path = new Path( "org.eclipse.sapphire.samples/sdef/LibraryEditor.sdef/diagram" );
53
		this.libraryDiagramPart = new SapphireDiagramEditorPart(this, this.modelLibrary, path);
54
		SapphireDiagramEditor diagramEditor = this.libraryDiagramPart.getDiagramEditor();
55
		SapphireDiagramEditorInput diagramEditorInput = this.libraryDiagramPart.getDiagramEditorInput();
56
		addPage(0, diagramEditor, diagramEditorInput);
57
		setPageText( 0, "Diagram" );
58
		setPageId(this.pages.get(0), "Diagram");
59
	}
60
	
61
	@Override
62
	protected void createFormPages() throws PartInitException 
63
	{
64
		IPath path = new Path( "org.eclipse.sapphire.samples/sdef/LibraryEditor.sdef/overview" );
65
		this.libraryOverviewPage = new MasterDetailsPage(this, this.modelLibrary, path);
66
        addPage(1, this.libraryOverviewPage);
67
        setPageText(1, "Overview");
68
        setPageId(this.pages.get(1), "Overview");		
69
	}
70
71
	public ILibrary getMap()
72
	{
73
		return this.modelLibrary;
74
	}
75
	
76
	@Override
77
	public void doSave( final IProgressMonitor monitor )
78
	{
79
		super.doSave(monitor);
80
		SapphireDiagramEditor diagramEditor = this.libraryDiagramPart.getDiagramEditor();
81
		diagramEditor.doSave(monitor);
82
	}
83
}
(-)src/org/eclipse/sapphire/samples/map/IDestination.java (+30 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.map;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ModelElementType;
5
import org.eclipse.sapphire.modeling.Value;
6
import org.eclipse.sapphire.modeling.ValueProperty;
7
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
8
import org.eclipse.sapphire.modeling.annotations.Label;
9
import org.eclipse.sapphire.modeling.annotations.NonNullValue;
10
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
11
12
@GenerateImpl
13
14
public interface IDestination extends IModelElement 
15
{
16
	ModelElementType TYPE = new ModelElementType( IDestination.class );
17
	
18
    // *** Name ***
19
    
20
    @XmlBinding( path = "name" )
21
    @Label( standard = "name" )
22
    @NonNullValue
23
    //@DefaultValue( text = "Destination" )
24
25
    ValueProperty PROP_NAME = new ValueProperty( TYPE, "Name" );
26
27
    Value<String> getName();
28
    void setName( String name );
29
	
30
}
(-)src/org/eclipse/sapphire/samples/map/IMap.java (+37 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.map;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ListProperty;
5
import org.eclipse.sapphire.modeling.ModelElementList;
6
import org.eclipse.sapphire.modeling.ModelElementType;
7
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
8
import org.eclipse.sapphire.modeling.annotations.Type;
9
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
10
import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding;
11
12
@GenerateImpl
13
@XmlRootBinding( elementName = "map")
14
15
public interface IMap extends IModelElement
16
{
17
	ModelElementType TYPE = new ModelElementType( IMap.class );
18
	
19
    // *** Destinations ***
20
21
    @Type( base = IDestination.class )
22
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "destination", type = IDestination.class ) )
23
    
24
    ListProperty PROP_DESTINATIONS = new ListProperty( TYPE, "Destinations" );
25
    
26
    ModelElementList<IDestination> getDestinations();
27
	
28
    // *** Routes ***
29
    
30
    @Type( base = IRoute.class )
31
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "route", type = IRoute.class ) )
32
    
33
    ListProperty PROP_ROUTES = new ListProperty( TYPE, "Routes" );
34
    
35
    ModelElementList<IRoute> getRoutes();
36
    
37
}
(-)src/org/eclipse/sapphire/samples/map/IRoute.java (+56 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.map;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ModelElementType;
5
import org.eclipse.sapphire.modeling.ReferenceValue;
6
import org.eclipse.sapphire.modeling.Value;
7
import org.eclipse.sapphire.modeling.ValueProperty;
8
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
9
import org.eclipse.sapphire.modeling.annotations.Label;
10
import org.eclipse.sapphire.modeling.annotations.NonNullValue;
11
import org.eclipse.sapphire.modeling.annotations.Reference;
12
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
13
import org.eclipse.sapphire.samples.map.internal.DestinationReferenceService;
14
15
@GenerateImpl
16
17
public interface IRoute extends IModelElement 
18
{
19
	ModelElementType TYPE = new ModelElementType( IRoute.class );
20
	
21
	// *** FromDestination ***
22
	
23
	@Reference( target = IDestination.class, service = DestinationReferenceService.class )
24
	@XmlBinding( path = "from-destination")
25
	@NonNullValue
26
	@Label(standard = "from destination")
27
28
	ValueProperty PROP_FROM_DESTINATION = new ValueProperty( TYPE, "FromDestination" );
29
30
    ReferenceValue<IDestination> getFromDestination();
31
    void setFromDestination( String name );
32
	
33
	// *** ToDestination ***
34
	
35
	@Reference( target = IDestination.class, service = DestinationReferenceService.class )
36
	@XmlBinding( path = "to-destination")
37
	@NonNullValue
38
	@Label(standard = "to destination")
39
40
	ValueProperty PROP_TO_DESTINATION = new ValueProperty( TYPE, "ToDestination" );
41
42
    ReferenceValue<IDestination> getToDestination();
43
    void setToDestination( String name );
44
    
45
    // *** Distance ***
46
    
47
    @XmlBinding( path = "distance" )
48
    @Label( standard = "distance" )
49
    @NonNullValue
50
51
    ValueProperty PROP_DISTANCE = new ValueProperty( TYPE, "Distance" );
52
53
    Value<String> getDistance();
54
    void setDistance( String distance );
55
    
56
}
(-)src/org/eclipse/sapphire/samples/map/internal/DestinationReferenceService.java (+29 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.map.internal;
2
3
import org.eclipse.sapphire.modeling.ModelElementList;
4
import org.eclipse.sapphire.modeling.ReferenceService;
5
import org.eclipse.sapphire.samples.map.IDestination;
6
import org.eclipse.sapphire.samples.map.IMap;
7
8
public class DestinationReferenceService extends ReferenceService 
9
{
10
11
	@Override
12
	public Object resolve(String reference) 
13
	{
14
		if (reference != null)
15
		{
16
			IMap map = element().nearest(IMap.class);
17
			ModelElementList<IDestination> dests = map.getDestinations();
18
			for (IDestination dest : dests)
19
			{
20
				if (reference.equals(dest.getName().getContent()))
21
				{
22
					return dest;
23
				}
24
			}
25
		}
26
		return null;
27
	}
28
29
}
(-)src/org/eclipse/sapphire/samples/map/ui/MapEditor.java (+83 lines)
Added Link Here
1
package org.eclipse.sapphire.samples.map.ui;
2
3
import org.eclipse.core.runtime.IPath;
4
import org.eclipse.core.runtime.IProgressMonitor;
5
import org.eclipse.core.runtime.Path;
6
import org.eclipse.sapphire.modeling.IModelElement;
7
import org.eclipse.sapphire.modeling.xml.RootXmlResource;
8
import org.eclipse.sapphire.samples.map.IMap;
9
import org.eclipse.sapphire.ui.SapphireEditor;
10
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
11
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor;
12
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorInput;
13
import org.eclipse.sapphire.ui.editor.views.masterdetails.MasterDetailsPage;
14
import org.eclipse.sapphire.ui.xml.XmlEditorResourceStore;
15
import org.eclipse.ui.PartInitException;
16
import org.eclipse.ui.part.FileEditorInput;
17
import org.eclipse.wst.sse.ui.StructuredTextEditor;
18
19
public class MapEditor extends SapphireEditor 
20
{
21
	private IMap modelMap;
22
	private StructuredTextEditor mapSourceEditor;
23
	private SapphireDiagramEditorPart mapDiagramPart;
24
	private MasterDetailsPage mapOverviewPage;
25
	
26
    public MapEditor()
27
    {
28
        super( "org.eclipse.sapphire.samples" );
29
    }
30
31
	@Override
32
	protected void createSourcePages() throws PartInitException 
33
	{
34
		this.mapSourceEditor = new StructuredTextEditor();
35
		this.mapSourceEditor.setEditorPart(this);
36
        final FileEditorInput rootEditorInput = (FileEditorInput) getEditorInput();
37
        
38
        int index = addPage( this.mapSourceEditor, rootEditorInput );
39
        setPageText( index, "map.xml" );
40
	}
41
42
	@Override
43
	protected IModelElement createModel() 
44
	{
45
		this.modelMap = IMap.TYPE.instantiate(new RootXmlResource(new XmlEditorResourceStore(this, this.mapSourceEditor)));
46
		return this.modelMap;
47
	}
48
49
	@Override
50
	protected void createDiagramPages() throws PartInitException
51
	{
52
		IPath path = new Path( "org.eclipse.sapphire.samples/sdef/MapEditor.sdef/diagram" );
53
		this.mapDiagramPart = new SapphireDiagramEditorPart(this, this.modelMap, path);
54
		SapphireDiagramEditor diagramEditor = this.mapDiagramPart.getDiagramEditor();
55
		SapphireDiagramEditorInput diagramEditorInput = this.mapDiagramPart.getDiagramEditorInput();
56
		addPage(0, diagramEditor, diagramEditorInput);
57
		setPageText( 0, "Diagram" );
58
		setPageId(this.pages.get(0), "Diagram");
59
	}
60
	
61
	@Override
62
	protected void createFormPages() throws PartInitException 
63
	{
64
		IPath path = new Path( "org.eclipse.sapphire.samples/sdef/MapEditor.sdef/overview" );
65
		this.mapOverviewPage = new MasterDetailsPage(this, this.modelMap, path);
66
        addPage(1, this.mapOverviewPage);
67
        setPageText(1, "Overview");
68
        setPageId(this.pages.get(1), "Overview");		
69
	}
70
71
	public IMap getMap()
72
	{
73
		return this.modelMap;
74
	}
75
	
76
	@Override
77
	public void doSave( final IProgressMonitor monitor )
78
	{
79
		super.doSave(monitor);
80
		SapphireDiagramEditor diagramEditor = this.mapDiagramPart.getDiagramEditor();
81
		diagramEditor.doSave(monitor);
82
	}
83
}
(-)META-INF/MANIFEST.MF (-2 / +11 lines)
Lines 19-25 Link Here
19
 org.eclipse.sapphire.ui.swt.renderer,
19
 org.eclipse.sapphire.ui.swt.renderer,
20
 org.eclipse.sapphire.ui.swt.renderer.actions,
20
 org.eclipse.sapphire.ui.swt.renderer.actions,
21
 org.eclipse.sapphire.ui.util,
21
 org.eclipse.sapphire.ui.util,
22
 org.eclipse.sapphire.ui.xml
22
 org.eclipse.sapphire.ui.xml,
23
 org.eclipse.sapphire.ui.diagram.editor,
24
 org.eclipse.sapphire.ui.diagram.graphiti.editor
23
Require-Bundle: org.eclipse.debug.ui,
25
Require-Bundle: org.eclipse.debug.ui,
24
 org.eclipse.jdt.ui,
26
 org.eclipse.jdt.ui,
25
 org.eclipse.ui.forms;visibility:=reexport,
27
 org.eclipse.ui.forms;visibility:=reexport,
Lines 37-42 Link Here
37
 org.eclipse.help,
39
 org.eclipse.help,
38
 org.eclipse.ui.views,
40
 org.eclipse.ui.views,
39
 org.eclipse.jface.text,
41
 org.eclipse.jface.text,
40
 org.apache.ant
42
 org.apache.ant,
43
 org.eclipse.gef,
44
 org.eclipse.graphiti,
45
 org.eclipse.graphiti.mm,
46
 org.eclipse.graphiti.pattern,
47
 org.eclipse.graphiti.ui,
48
 org.eclipse.emf.transaction,
49
 org.eclipse.ui.views.properties.tabbed
41
Bundle-ActivationPolicy: lazy
50
Bundle-ActivationPolicy: lazy
42
Bundle-RequiredExecutionEnvironment: J2SE-1.5
51
Bundle-RequiredExecutionEnvironment: J2SE-1.5
(-)plugin.properties (+4 lines)
Lines 15-17 Link Here
15
showInSourceCommandName = Show in Source
15
showInSourceCommandName = Show in Source
16
showInSourceCommandDescription = Shows the location in the source file that corresponds to the selected entity.
16
showInSourceCommandDescription = Shows the location in the source file that corresponds to the selected entity.
17
builderName = Sapphire UI Builder
17
builderName = Sapphire UI Builder
18
sapphireDiagramTypeDescription = Sapphire Diagram Type
19
sapphireDiagramTypeName = Sapphire Diagram Type
20
sapphireDiagramTypeProviderDescription = Sapphire Diagram Type Provider
21
sapphireDiagramTypeProviderName = Sapphire Diagram Type Provider
(-)plugin.xml (+28 lines)
Lines 24-27 Link Here
24
    </builder> 
24
    </builder> 
25
  </extension> 
25
  </extension> 
26
  
26
  
27
   <extension point="org.eclipse.graphiti.ui.diagramTypes">
28
      <diagramType
29
            description="%sapphireDiagramTypeDescription"
30
            id="org.eclipse.sapphire.ui.SapphireDiagramType"
31
            name="%sapphireDiagramTypeName"
32
            type="sapphireDiagram">
33
      </diagramType>
34
   </extension>
35
   
36
   <extension point="org.eclipse.graphiti.ui.diagramTypeProviders">
37
      <diagramTypeProvider
38
            class="org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramTypeProvider"
39
            description="%sapphireDiagramTypeProviderDescription"
40
            id="org.eclipse.sapphire.ui.sapphireDiagramTypeProvider"
41
            name="%sapphireDiagramTypeProviderName">
42
         <diagramType id="org.eclipse.sapphire.ui.SapphireDiagramType"/>
43
         <imageProvider id="org.eclipse.sapphire.diagram.graphiti.SapphireDiagramImageProvider"/>
44
      </diagramTypeProvider>
45
   </extension>
46
     
47
   <extension
48
         point="org.eclipse.graphiti.ui.imageProviders">
49
      <imageProvider
50
            class="org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramImageProvider"
51
            id="org.eclipse.sapphire.diagram.graphiti.SapphireDiagramImageProvider">
52
      </imageProvider>
53
   </extension>
54
     
27
</plugin>
55
</plugin>
(-)src/org/eclipse/sapphire/ui/SapphireEditor.java (+9 lines)
Lines 18-23 Link Here
18
import java.net.URI;
18
import java.net.URI;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.HashMap;
20
import java.util.HashMap;
21
import java.util.Iterator;
21
import java.util.Map;
22
import java.util.Map;
22
import java.util.Set;
23
import java.util.Set;
23
24
Lines 285-290 Link Here
285
                this.model = createModel();
286
                this.model = createModel();
286
                adaptModel( this.model );
287
                adaptModel( this.model );
287
                
288
                
289
                createDiagramPages();
290
                
288
                createFormPages();
291
                createFormPages();
289
    
292
    
290
                createFileChangeListener();
293
                createFileChangeListener();
Lines 330-335 Link Here
330
    protected abstract void createSourcePages() throws PartInitException;
333
    protected abstract void createSourcePages() throws PartInitException;
331
    protected abstract void createFormPages() throws PartInitException;
334
    protected abstract void createFormPages() throws PartInitException;
332
    
335
    
336
    // default impl does nothing, subclass may override it to add diagram pages
337
    protected void createDiagramPages() throws PartInitException
338
    {
339
    	
340
    }
341
    
333
    protected final void setPageId( final Object page,
342
    protected final void setPageId( final Object page,
334
                                    final String id )
343
                                    final String id )
335
    {
344
    {
(-)src/org/eclipse/sapphire/ui/def/ISapphireUiDef.java (+10 lines)
Lines 26-31 Link Here
26
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
26
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
27
import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding;
27
import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding;
28
import org.eclipse.sapphire.ui.def.internal.SapphireUiDefMethods;
28
import org.eclipse.sapphire.ui.def.internal.SapphireUiDefMethods;
29
import org.eclipse.sapphire.ui.diagram.def.IDiagramPageDef;
29
30
30
/**
31
/**
31
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
32
 * @author <a href="mailto:konstantin.komissarchik@oracle.com">Konstantin Komissarchik</a>
Lines 129-134 Link Here
129
    
130
    
130
    ModelElementList<IEditorPageDef> getEditorPageDefs();
131
    ModelElementList<IEditorPageDef> getEditorPageDefs();
131
    
132
    
133
    // *** DiagramPageDefs ***
134
    
135
    @Type( base = IDiagramPageDef.class )
136
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "diagram-page", type = IDiagramPageDef.class ) )
137
    
138
    ListProperty PROP_DIAGRAM_PAGE_DEFS = new ListProperty( TYPE, "DiagramPageDefs" );
139
    
140
    ModelElementList<IDiagramPageDef> getDiagramPageDefs();
141
    
132
    // *** DialogDefs ***
142
    // *** DialogDefs ***
133
    
143
    
134
    @Type( base = ISapphireDialogDef.class )
144
    @Type( base = ISapphireDialogDef.class )
(-)src/org/eclipse/sapphire/ui/def/SapphireDiagramDefFactory.java (+51 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.def;
2
3
import org.eclipse.sapphire.modeling.BundleResourceStore;
4
import org.eclipse.sapphire.modeling.ResourceStoreException;
5
import org.eclipse.sapphire.modeling.SharedModelsCache;
6
import org.eclipse.sapphire.modeling.xml.RootXmlResource;
7
import org.eclipse.sapphire.modeling.xml.XmlResourceStore;
8
import org.eclipse.sapphire.ui.diagram.def.IDiagramPageDef;
9
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
10
11
public class SapphireDiagramDefFactory 
12
{
13
	public static IDiagramPageDef load(final String bundleId, final String path)
14
	{
15
        try
16
        {
17
            return load( new XmlResourceStore( new BundleResourceStore( bundleId, path ) ), false );
18
        }
19
        catch( ResourceStoreException e )
20
        {
21
            SapphireUiFrameworkPlugin.log( e );
22
            return null;
23
        }		
24
	}
25
	
26
	public static IDiagramPageDef load( final XmlResourceStore resourceStore,
27
            							final boolean writable )
28
	{
29
		IDiagramPageDef model;
30
31
		if( writable )
32
		{
33
			model = IDiagramPageDef.TYPE.instantiate( new RootXmlResource( resourceStore ) );
34
		}
35
		else
36
		{
37
			final SharedModelsCache.StandardKey key = new SharedModelsCache.StandardKey( resourceStore, IDiagramPageDef.TYPE );
38
			
39
			model = (IDiagramPageDef) SharedModelsCache.retrieve( key );
40
			
41
			if( model == null )
42
			{
43
				model = IDiagramPageDef.TYPE.instantiate( new RootXmlResource( resourceStore ) );
44
				SharedModelsCache.store( key, model );			
45
			}	
46
		}
47
		return model;
48
	}
49
50
}
51
(-)src/org/eclipse/sapphire/ui/diagram/def/ConnectionEndpointType.java (+10 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
4
public enum ConnectionEndpointType 
5
{
6
	NONE,
7
	ARROW,
8
	CIRCLE,
9
	ELLIPSE;
10
}
(-)src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionDef.java (+100 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
import org.eclipse.sapphire.modeling.ElementProperty;
4
import org.eclipse.sapphire.modeling.ModelElementHandle;
5
import org.eclipse.sapphire.modeling.ModelElementType;
6
import org.eclipse.sapphire.modeling.Value;
7
import org.eclipse.sapphire.modeling.ValueProperty;
8
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
9
import org.eclipse.sapphire.modeling.annotations.Label;
10
import org.eclipse.sapphire.modeling.annotations.Type;
11
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
12
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
13
14
@GenerateImpl
15
16
public interface IDiagramConnectionDef 
17
	
18
	extends ISapphirePartDef 
19
	
20
{
21
	ModelElementType TYPE = new ModelElementType( IDiagramConnectionDef.class );
22
	
23
    // *** Id ***
24
    
25
    @Label( standard = "ID" )
26
    @XmlBinding( path = "id" )
27
    
28
    ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" );
29
    
30
    Value<String> getId();
31
    void setId( String id );
32
    
33
    // *** Property ***
34
    
35
    @Label( standard = "property" )
36
    @XmlBinding( path = "property" )
37
    
38
    ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" );
39
    
40
    Value<String> getProperty();
41
    void setProperty( String property );
42
    
43
    // *** ToolPaletteLabel ***
44
    
45
    @Label( standard = "tool palette label" )
46
    @XmlBinding( path = "tool-palette-label" )
47
    
48
    ValueProperty PROP_TOOL_PALETTE_LABEL = new ValueProperty( TYPE, "ToolPaletteLabel" );
49
    
50
    Value<String> getToolPaletteLabel();
51
    void setToolPaletteLabel( String paletteLabel );
52
    
53
    // *** ToolPaletteDesc ***
54
    
55
    @Label( standard = "tool palette description" )
56
    @XmlBinding( path = "tool-palette-desc" )
57
    
58
    ValueProperty PROP_TOOL_PALETTE_DESC = new ValueProperty( TYPE, "ToolPaletteDesc" );
59
    
60
    Value<String> getToolPaletteDesc();
61
    void setToolPaletteDesc( String paletteDesc );    
62
        
63
    // *** Label ***
64
    
65
    @Type( base = IDiagramLabelDef.class )
66
    @XmlBinding( path = "label" )
67
    
68
    ElementProperty PROP_LABEL = new ElementProperty( TYPE, "Label" );
69
    
70
    ModelElementHandle<IDiagramLabelDef> getLabel();
71
72
    // *** Endpoint1 ***
73
    
74
    @Type( base = IDiagramConnectionEndpointDef.class )
75
    @XmlBinding( path = "endpoint1" )
76
77
    ElementProperty PROP_ENDPOINT_1 = new ElementProperty( TYPE, "Endpoint1" );
78
    
79
    ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint1();
80
81
    // *** Endpoint2 ***
82
    
83
    @Type( base = IDiagramConnectionEndpointDef.class )
84
    @XmlBinding( path = "endpoint2" )
85
86
    ElementProperty PROP_ENDPOINT_2 = new ElementProperty( TYPE, "Endpoint2" );
87
    
88
    ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint2();
89
    
90
    // *** InstanceId ***
91
    
92
    @Label( standard = "instance id" )
93
    @XmlBinding( path = "instance-id" )
94
    
95
    ValueProperty PROP_INSTANCE_ID = new ValueProperty( TYPE, "InstanceId" );
96
    
97
    Value<String> getInstanceId();
98
    void setInstanceId( String instanceId );
99
        
100
}
(-)src/org/eclipse/sapphire/ui/diagram/def/IDiagramConnectionEndpointDef.java (+54 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
import org.eclipse.sapphire.modeling.ModelElementType;
4
import org.eclipse.sapphire.modeling.Value;
5
import org.eclipse.sapphire.modeling.ValueProperty;
6
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
7
import org.eclipse.sapphire.modeling.annotations.Label;
8
import org.eclipse.sapphire.modeling.annotations.Type;
9
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
10
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
11
12
@GenerateImpl
13
14
public interface IDiagramConnectionEndpointDef 
15
16
	extends ISapphirePartDef 
17
	
18
{
19
	ModelElementType TYPE = new ModelElementType( IDiagramConnectionEndpointDef.class );
20
	
21
    // *** Property ***
22
    
23
    @Label( standard = "property" )
24
    @XmlBinding( path = "property" )
25
    
26
    ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" );
27
    
28
    Value<String> getProperty();
29
    void setProperty( String property );
30
    
31
    // *** Value ***
32
    
33
    @Label( standard = "value" )
34
    @XmlBinding( path = "value" )
35
    
36
    ValueProperty PROP_VALUE = new ValueProperty( TYPE, "Value" );
37
    
38
    Value<String> getValue();
39
    void setValue( String value );
40
    
41
    
42
	// *** Type ***
43
	
44
	@Type( base = ConnectionEndpointType.class )
45
	@XmlBinding( path = "connectionDecoratorType" )
46
	
47
	ValueProperty PROP_TYPE = new ValueProperty( TYPE, "Type" );
48
	
49
	Value<ConnectionEndpointType> getType();
50
	void setType( String value );
51
	void setType( ConnectionEndpointType value );
52
    
53
	
54
}
(-)src/org/eclipse/sapphire/ui/diagram/def/IDiagramEmbeddedConnectionDef.java (+92 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
import org.eclipse.sapphire.modeling.ElementProperty;
4
import org.eclipse.sapphire.modeling.ModelElementHandle;
5
import org.eclipse.sapphire.modeling.ModelElementType;
6
import org.eclipse.sapphire.modeling.Value;
7
import org.eclipse.sapphire.modeling.ValueProperty;
8
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
9
import org.eclipse.sapphire.modeling.annotations.Label;
10
import org.eclipse.sapphire.modeling.annotations.Type;
11
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
12
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
13
14
@GenerateImpl
15
16
public interface IDiagramEmbeddedConnectionDef 
17
18
	extends ISapphirePartDef
19
	
20
{
21
	ModelElementType TYPE = new ModelElementType( IDiagramEmbeddedConnectionDef.class );
22
	
23
    // *** Id ***
24
    
25
    @Label( standard = "ID" )
26
    @XmlBinding( path = "id" )
27
    
28
    ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" );
29
    
30
    Value<String> getId();
31
    void setId( String id );
32
    
33
    // *** Property ***
34
    
35
    @Label( standard = "property" )
36
    @XmlBinding( path = "property" )
37
    
38
    ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" );
39
    
40
    Value<String> getProperty();
41
    void setProperty( String property );
42
    
43
    // *** ToolPaletteLabel ***
44
    
45
    @Label( standard = "tool palette label" )
46
    @XmlBinding( path = "tool-palette-label" )
47
    
48
    ValueProperty PROP_TOOL_PALETTE_LABEL = new ValueProperty( TYPE, "ToolPaletteLabel" );
49
    
50
    Value<String> getToolPaletteLabel();
51
    void setToolPaletteLabel( String paletteLabel );
52
    
53
    // *** ToolPaletteDesc ***
54
    
55
    @Label( standard = "tool palette description" )
56
    @XmlBinding( path = "tool-palette-desc" )
57
    
58
    ValueProperty PROP_TOOL_PALETTE_DESC = new ValueProperty( TYPE, "ToolPaletteDesc" );
59
    
60
    Value<String> getToolPaletteDesc();
61
    void setToolPaletteDesc( String paletteDesc );    
62
        
63
    // *** Label ***
64
    
65
    @Type( base = IDiagramLabelDef.class )
66
    @XmlBinding( path = "label" )
67
    
68
    ElementProperty PROP_LABEL = new ElementProperty( TYPE, "Label" );
69
    
70
    ModelElementHandle<IDiagramLabelDef> getLabel();
71
    	    
72
    // *** Endpoint ***
73
    
74
    @Type( base = IDiagramConnectionEndpointDef.class )
75
    @XmlBinding( path = "endpoint" )
76
77
    ElementProperty PROP_ENDPOINT = new ElementProperty( TYPE, "Endpoint" );
78
    
79
    ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint();
80
81
    // *** InstanceId ***
82
    
83
    @Label( standard = "instance id" )
84
    @XmlBinding( path = "instance-id" )
85
    
86
    ValueProperty PROP_INSTANCE_ID = new ValueProperty( TYPE, "InstanceId" );
87
    
88
    Value<String> getInstanceId();
89
    void setInstanceId( String instanceId );
90
    
91
92
}
(-)src/org/eclipse/sapphire/ui/diagram/def/IDiagramLabelDef.java (+30 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
import org.eclipse.sapphire.modeling.ModelElementType;
4
import org.eclipse.sapphire.modeling.Value;
5
import org.eclipse.sapphire.modeling.ValueProperty;
6
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
7
import org.eclipse.sapphire.modeling.annotations.Label;
8
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
9
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
10
11
@GenerateImpl
12
13
public interface IDiagramLabelDef 
14
15
	extends ISapphirePartDef
16
	
17
{
18
	ModelElementType TYPE = new ModelElementType( IDiagramLabelDef.class );
19
	
20
    // *** Content ***
21
    
22
    @Label( standard = "content" )
23
    @XmlBinding( path = "content" )
24
    
25
    ValueProperty PROP_CONTENT = new ValueProperty( TYPE, "Content" );
26
    
27
    Value<String> getContent();
28
    void setContent( String content );
29
	
30
}
(-)src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeDef.java (+100 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
import org.eclipse.sapphire.modeling.ElementProperty;
4
import org.eclipse.sapphire.modeling.ModelElementHandle;
5
import org.eclipse.sapphire.modeling.ModelElementType;
6
import org.eclipse.sapphire.modeling.Value;
7
import org.eclipse.sapphire.modeling.ValueProperty;
8
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
9
import org.eclipse.sapphire.modeling.annotations.Label;
10
import org.eclipse.sapphire.modeling.annotations.Type;
11
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
12
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
13
14
@GenerateImpl
15
16
public interface IDiagramNodeDef 
17
18
	extends ISapphirePartDef
19
	
20
{
21
	ModelElementType TYPE = new ModelElementType( IDiagramNodeDef.class );
22
	
23
    // *** Id ***
24
    
25
    @Label( standard = "ID" )
26
    @XmlBinding( path = "id" )
27
    
28
    ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" );
29
    
30
    Value<String> getId();
31
    void setId( String id );
32
    
33
    // *** ToolPaletteLabel ***
34
    
35
    @Label( standard = "tool palette label" )
36
    @XmlBinding( path = "tool-palette-label" )
37
    
38
    ValueProperty PROP_TOOL_PALETTE_LABEL = new ValueProperty( TYPE, "ToolPaletteLabel" );
39
    
40
    Value<String> getToolPaletteLabel();
41
    void setToolPaletteLabel( String paletteLabel );
42
    
43
    // *** ToolPaletteDesc ***
44
    
45
    @Label( standard = "tool palette description" )
46
    @XmlBinding( path = "tool-palette-desc" )
47
    
48
    ValueProperty PROP_TOOL_PALETTE_DESC = new ValueProperty( TYPE, "ToolPaletteDesc" );
49
    
50
    Value<String> getToolPaletteDesc();
51
    void setToolPaletteDesc( String paletteDesc );
52
53
    // *** Property ***
54
    
55
    @Label( standard = "property" )
56
    @XmlBinding( path = "property" )
57
    
58
    ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" );
59
    
60
    Value<String> getProperty();
61
    void setProperty( String property );
62
    
63
    // *** Image ***
64
    
65
    @Type( base = IDiagramNodeImageDef.class )
66
    @XmlBinding( path = "image" )
67
68
    ElementProperty PROP_IMAGE = new ElementProperty( TYPE, "Image" );
69
    
70
    ModelElementHandle<IDiagramNodeImageDef> getImage();
71
    
72
    // *** Label ***
73
    
74
    @Type( base = IDiagramLabelDef.class )
75
    @XmlBinding( path = "label" )
76
    
77
    ElementProperty PROP_LABEL = new ElementProperty( TYPE, "Label" );
78
    
79
    ModelElementHandle<IDiagramLabelDef> getLabel();
80
    	
81
    // *** InstanceId ***
82
    
83
    @Label( standard = "instance id" )
84
    @XmlBinding( path = "instance-id" )
85
    
86
    ValueProperty PROP_INSTANCE_ID = new ValueProperty( TYPE, "InstanceId" );
87
    
88
    Value<String> getInstanceId();
89
    void setInstanceId( String instanceId );
90
    
91
    // *** EmbeddedConnections ***
92
    
93
    @Type( base = IDiagramEmbeddedConnectionDef.class )
94
    @XmlBinding( path = "connection" )
95
96
    ElementProperty PROP_EMBEDDED_CONNECTIONS = new ElementProperty( TYPE, "EmbeddedConnections" );
97
    
98
    ModelElementHandle<IDiagramEmbeddedConnectionDef> getEmbeddedConnections();
99
    
100
}
(-)src/org/eclipse/sapphire/ui/diagram/def/IDiagramNodeImageDef.java (+40 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
import org.eclipse.sapphire.modeling.ModelElementType;
4
import org.eclipse.sapphire.modeling.Value;
5
import org.eclipse.sapphire.modeling.ValueProperty;
6
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
7
import org.eclipse.sapphire.modeling.annotations.Label;
8
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
9
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
10
11
@GenerateImpl
12
13
public interface IDiagramNodeImageDef 
14
15
	extends ISapphirePartDef 
16
17
{
18
	ModelElementType TYPE = new ModelElementType( IDiagramNodeImageDef.class );
19
	
20
    // *** ImageId ***
21
    
22
    @Label( standard = "image id" )
23
    @XmlBinding( path = "id" )
24
    
25
    ValueProperty PROP_IMAGE_ID = new ValueProperty( TYPE, "ImageId" );
26
    
27
    Value<String> getImageId();
28
    void setImageId( String Id );
29
30
    // *** ImagePath ***
31
    
32
    @Label( standard = "image path" )
33
    @XmlBinding( path = "path" )
34
    
35
    ValueProperty PROP_IMAGE_PATH = new ValueProperty( TYPE, "ImagePath" );
36
    
37
    Value<String> getImagePath();
38
    void setImagePath( String path );
39
	
40
}
(-)src/org/eclipse/sapphire/ui/diagram/def/IDiagramPageDef.java (+75 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.def;
2
3
import org.eclipse.sapphire.modeling.ListProperty;
4
import org.eclipse.sapphire.modeling.ModelElementList;
5
import org.eclipse.sapphire.modeling.ModelElementType;
6
import org.eclipse.sapphire.modeling.Value;
7
import org.eclipse.sapphire.modeling.ValueProperty;
8
import org.eclipse.sapphire.modeling.annotations.DefaultValue;
9
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
10
import org.eclipse.sapphire.modeling.annotations.Label;
11
import org.eclipse.sapphire.modeling.annotations.Type;
12
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
13
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
14
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
15
16
@GenerateImpl
17
18
public interface IDiagramPageDef 
19
	
20
	extends ISapphirePartDef
21
	
22
{
23
	ModelElementType TYPE = new ModelElementType( IDiagramPageDef.class);
24
	
25
    // *** Id ***
26
    
27
    @Label( standard = "ID" )
28
    @XmlBinding( path = "id" )
29
    
30
    ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" );
31
    
32
    Value<String> getId();
33
    void setId( String id );
34
    
35
    // *** PageName ***
36
    
37
    @Label( standard = "page name" )
38
    @DefaultValue( text = "Diagram" )
39
    @XmlBinding( path = "page-name" )
40
    
41
    ValueProperty PROP_PAGE_NAME = new ValueProperty( TYPE, "PageName" );
42
    
43
    Value<String> getPageName();
44
    void setPageName( String pageName );
45
    
46
    // *** PageHeaderText ***
47
    
48
    @Label( standard = "page header text" )
49
    @DefaultValue( text = "Diagram View" )
50
    @XmlBinding( path = "page-header-text" )
51
    
52
    ValueProperty PROP_PAGE_HEADER_TEXT = new ValueProperty( TYPE, "PageHeaderText" );
53
    
54
    Value<String> getPageHeaderText();
55
    void setPageHeaderText( String pageHeaderText );
56
	
57
	// *** DiagramNodeDefs ***
58
    
59
    @Type( base = IDiagramNodeDef.class )
60
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "node", type = IDiagramNodeDef.class ) )
61
                             
62
    ListProperty PROP_DIAGRAM_NODE_DEFS = new ListProperty( TYPE, "DiagramNodeDefs" );
63
    
64
    ModelElementList<IDiagramNodeDef> getDiagramNodeDefs();
65
    
66
	// *** DiagramConnectionDefs ***
67
    
68
    @Type( base = IDiagramConnectionDef.class )
69
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "connection", type = IDiagramConnectionDef.class ) )
70
                             
71
    ListProperty PROP_DIAGRAM_CONNECTION_DEFS = new ListProperty( TYPE, "DiagramConnectionDefs" );
72
    
73
    ModelElementList<IDiagramConnectionDef> getDiagramConnectionDefs();
74
	
75
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionPart.java (+234 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ModelElementType;
5
import org.eclipse.sapphire.modeling.ModelProperty;
6
import org.eclipse.sapphire.modeling.ReferenceValue;
7
import org.eclipse.sapphire.modeling.Value;
8
import org.eclipse.sapphire.modeling.ValueProperty;
9
import org.eclipse.sapphire.modeling.el.Function;
10
import org.eclipse.sapphire.ui.SapphirePart;
11
import org.eclipse.sapphire.ui.SapphireRenderingContext;
12
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionDef;
13
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef;
14
15
public class DiagramConnectionPart extends SapphirePart 
16
{
17
	private DiagramConnectionTemplate connectionTemplate;
18
	private IDiagramConnectionDef localDefinition;
19
	protected IModelElement modelElement;
20
	private IDiagramConnectionEndpointDef endpoint1Def;
21
	private IDiagramConnectionEndpointDef endpoint2Def;
22
	private IModelElement endpoint1Model;
23
	private IModelElement endpoint2Model;
24
	protected Function labelFunction;
25
	protected ValueProperty labelProperty;
26
	protected Function idFunction;
27
	private Function endpoint1Function;
28
	private Function endpoint2Function;
29
	
30
	public DiagramConnectionPart() {}
31
	
32
	public DiagramConnectionPart(DiagramConnectionTemplate connectionTemplate)
33
	{
34
		this.connectionTemplate = connectionTemplate;
35
	}
36
	
37
    @Override
38
    protected void init()
39
    {
40
        super.init();
41
        
42
        this.localDefinition = (IDiagramConnectionDef)super.definition;
43
        this.modelElement = getModelElement();
44
        this.labelFunction = initExpression
45
        ( 
46
        	this.localDefinition.getLabel().element().getContent().getLocalizedText(), 
47
            new Runnable()
48
            {
49
                public void run()
50
                {
51
                }
52
            }
53
        );
54
        
55
        this.labelProperty = FunctionUtil.getFunctionProperty(this.modelElement, this.labelFunction);
56
        
57
        this.idFunction = initExpression
58
        ( 
59
            this.localDefinition.getInstanceId().getLocalizedText(), 
60
            new Runnable()
61
            {
62
                public void run()
63
                {
64
                }
65
            }
66
        );
67
        
68
        this.endpoint1Def = this.localDefinition.getEndpoint1().element();
69
        this.endpoint2Def = this.localDefinition.getEndpoint2().element();
70
        this.endpoint1Model = processEndpoint(this.endpoint1Def);
71
        this.endpoint2Model = processEndpoint(this.endpoint2Def);
72
        this.endpoint1Function = initExpression
73
        (
74
        	this.endpoint1Model, 
75
        	this.endpoint1Def.getValue().getContent(), 
76
            new Runnable()
77
        	{
78
	            public void run()
79
	            {
80
	            	refreshEndpoint1();
81
	            }
82
        	}
83
        );
84
        this.endpoint2Function = initExpression
85
        (
86
        	this.endpoint2Model, 
87
        	this.endpoint2Def.getValue().getContent(), 
88
            new Runnable()
89
        	{
90
	            public void run()
91
	            {
92
	            	refreshEndpoint2();
93
	            }
94
        	}
95
        );
96
    }
97
    
98
    public DiagramConnectionTemplate getDiagramConnectionTemplate()
99
    {
100
    	return this.connectionTemplate;
101
    }
102
    
103
    public IModelElement getLocalModelElement()
104
    {
105
        return this.modelElement;
106
    }    
107
    
108
    public IModelElement getEndpoint1()
109
    {
110
    	return this.endpoint1Model;
111
    }
112
    
113
    public IModelElement getEndpoint2()
114
    {
115
    	return this.endpoint2Model;
116
    }
117
118
    public boolean canEditLabel()
119
    {
120
    	return this.labelProperty != null;
121
    }
122
    
123
    public String getLabel()
124
	{
125
        String label = null;
126
        
127
        if( this.labelFunction != null )
128
        {
129
            label = (String) this.labelFunction.value();
130
        }
131
        
132
        if( label == null )
133
        {
134
            label = "#null#";
135
        }
136
        
137
        return label;
138
	}
139
    
140
    public void setLabel(String newValue)
141
    {
142
		if (this.labelProperty != null)
143
		{
144
			this.modelElement.write(this.labelProperty, newValue);
145
		}    	
146
    }
147
    
148
    public String getInstanceId()
149
	{
150
        String id = null;
151
        
152
        if( this.idFunction != null )
153
        {
154
            id = (String) this.idFunction.value();
155
        }
156
        
157
        if( id == null )
158
        {
159
            id = "#null#";
160
        }
161
        
162
        return id;
163
	}
164
165
    @Override
166
	public void render(SapphireRenderingContext context)
167
	{
168
		throw new UnsupportedOperationException();
169
	}
170
	
171
	public void refreshEndpoint1()
172
	{
173
		if (this.endpoint1Function != null)
174
		{
175
			Object value = this.endpoint1Function.value();
176
			String property = this.endpoint1Def.getProperty().getContent();
177
			setModelProperty(this.modelElement, property, value);
178
		}		
179
	}
180
	
181
	public void refreshEndpoint2()
182
	{
183
		if (this.endpoint2Function != null)
184
		{
185
			Object value = this.endpoint2Function.value();
186
			String property = this.endpoint2Def.getProperty().getContent();
187
			setModelProperty(this.modelElement, property, value);
188
		}		
189
	}
190
	
191
	protected IModelElement processEndpoint(IDiagramConnectionEndpointDef endpointDef)
192
	{
193
		String propertyName = endpointDef.getProperty().getContent();
194
		ModelProperty modelProperty = resolve(this.modelElement, propertyName);
195
        if (!(modelProperty instanceof ValueProperty))
196
        {
197
        	throw new RuntimeException( "Property " + propertyName + " not a ValueProperty");
198
        }
199
        ValueProperty property = (ValueProperty)modelProperty;
200
		Value<?> valObj = this.modelElement.read(property);
201
		if (!(valObj instanceof ReferenceValue))
202
		{
203
			throw new RuntimeException( "Property " + propertyName + " value not a reference");
204
		}
205
		ReferenceValue<?> refVal = (ReferenceValue<?>)valObj;
206
		Object targetObj = refVal.resolve();
207
		if (!(targetObj instanceof IModelElement))
208
		{
209
			throw new RuntimeException( "Target not an IModelElement");
210
		}
211
		return (IModelElement)targetObj;
212
	}
213
	
214
    protected void setModelProperty(final IModelElement modelElement, 
215
			String propertyName, Object value)
216
	{
217
		if (propertyName != null)
218
		{
219
			final ModelElementType type = modelElement.getModelElementType();
220
			final ModelProperty property = type.getProperty( propertyName );
221
			if( property == null )
222
			{
223
				throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
224
			}
225
			if (!(property instanceof ValueProperty))
226
			{
227
				throw new RuntimeException( "Property " + propertyName + " not a ValueProperty");
228
			}
229
		
230
			modelElement.write((ValueProperty)property, value);
231
		}    	
232
	}
233
	
234
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionTemplate.java (+212 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.sapphire.modeling.ElementProperty;
8
import org.eclipse.sapphire.modeling.IModelElement;
9
import org.eclipse.sapphire.modeling.ListProperty;
10
import org.eclipse.sapphire.modeling.ModelElementList;
11
import org.eclipse.sapphire.modeling.ModelElementType;
12
import org.eclipse.sapphire.modeling.ModelProperty;
13
import org.eclipse.sapphire.modeling.Value;
14
import org.eclipse.sapphire.modeling.ValueProperty;
15
import org.eclipse.sapphire.modeling.annotations.Reference;
16
import org.eclipse.sapphire.modeling.el.Function;
17
import org.eclipse.sapphire.modeling.el.FunctionContext;
18
import org.eclipse.sapphire.modeling.el.ModelElementFunctionContext;
19
import org.eclipse.sapphire.modeling.el.parser.ExpressionLanguageParser;
20
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionDef;
21
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef;
22
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
23
24
public class DiagramConnectionTemplate 
25
{
26
	private SapphireDiagramEditorPart diagramEditor;
27
	private IDiagramConnectionDef definition;
28
	private IModelElement modelElement;	
29
	private ModelProperty modelProperty;
30
	protected String toolPaletteLabel;
31
	protected String toolPaletteDesc;
32
	
33
	protected List<DiagramConnectionPart> diagramConnections;
34
	
35
	public DiagramConnectionTemplate() {}
36
	
37
    public DiagramConnectionTemplate(final SapphireDiagramEditorPart diagramEditor, 
38
    		IDiagramConnectionDef definition, IModelElement modelElement)
39
    {
40
    	this.diagramEditor = diagramEditor;
41
    	this.modelElement = modelElement;
42
    	this.definition = definition;
43
    	
44
        this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent();
45
        this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent();
46
        
47
        this.diagramConnections = new ArrayList<DiagramConnectionPart>();
48
        
49
        String propertyName = this.definition.getProperty().getContent();
50
        this.modelProperty = resolve(this.modelElement, propertyName);
51
        if (this.modelProperty instanceof ListProperty)
52
        {
53
        	ListProperty listProperty = (ListProperty)this.modelProperty;
54
        	
55
        	ModelElementList<?> list = this.modelElement.read(listProperty);
56
            for( IModelElement listEntryModelElement : list )
57
            {
58
            	DiagramConnectionPart connection = new DiagramConnectionPart(this);
59
            	connection.init(this.diagramEditor, listEntryModelElement, definition, 
60
            			Collections.<String,String>emptyMap());
61
            	this.diagramConnections.add(connection);
62
            }
63
        }
64
        else if (this.modelProperty instanceof ElementProperty)
65
        {
66
        	ElementProperty elementProperty = (ElementProperty)this.modelProperty;
67
        	if (this.modelElement.read(elementProperty) != null)
68
        	{
69
	        	IModelElement localModelElement = this.modelElement.read(elementProperty).element();
70
	        	DiagramConnectionPart connection = new DiagramConnectionPart(this);
71
	        	connection.init(this.diagramEditor, localModelElement, definition, 
72
	        			Collections.<String,String>emptyMap());
73
	        	
74
	        	this.diagramConnections.add(connection);
75
        	}
76
        }
77
    }
78
    
79
    public List<DiagramConnectionPart> getDiagramConnections()
80
    {
81
    	return this.diagramConnections;
82
    }
83
    
84
    public String getToolPaletteLabel()
85
    {
86
    	return this.toolPaletteLabel;
87
    }
88
    
89
    public String getToolPaletteDesc()
90
    {
91
    	return this.toolPaletteDesc;
92
    }
93
    
94
    public boolean canCreateNewConnection(DiagramNodePart srcNode, DiagramNodePart targetNode)
95
    {
96
    	boolean canCreate = false;
97
    	ModelElementType srcType = srcNode.getModelElement().getModelElementType();
98
    	ModelElementType targetType = targetNode.getModelElement().getModelElementType();
99
    	
100
        ModelElementType type = this.modelProperty.getType();
101
        ModelProperty prop1 = type.getProperty(this.definition.getEndpoint1().element().getProperty().getContent());
102
        if (prop1.getType() == null && prop1.hasAnnotation(Reference.class))
103
        {
104
        	canCreate = prop1.getAnnotation(Reference.class).target().isAssignableFrom(srcType.getModelElementClass());
105
        	if (!canCreate)
106
        		return false;
107
        }
108
        ModelProperty prop2 = type.getProperty(this.definition.getEndpoint2().element().getProperty().getContent());
109
        if (prop2.getType() == null && prop2.hasAnnotation(Reference.class))
110
        {
111
        	canCreate = prop2.getAnnotation(Reference.class).target().isAssignableFrom(targetType.getModelElementClass());
112
        }
113
    	return canCreate;
114
    }
115
    
116
    public DiagramConnectionPart createNewDiagramConnection(DiagramNodePart srcNode, 
117
    														DiagramNodePart targetNode)
118
    {
119
    	IModelElement newElement = null;
120
    	if (this.modelProperty instanceof ListProperty)
121
    	{
122
    		ListProperty listProperty = (ListProperty)this.modelProperty;
123
    		ModelElementList<?> list = this.modelElement.read(listProperty);
124
    		newElement = list.addNewElement();
125
    	}
126
    	else if (this.modelProperty instanceof ElementProperty)
127
    	{
128
    		// TODO what if the element property does exist?
129
    		ElementProperty elementProperty = (ElementProperty)this.modelProperty;
130
    		newElement = this.modelElement.read(elementProperty).element(true);
131
    	}
132
    	
133
    	IDiagramConnectionEndpointDef srcAnchorDef = this.definition.getEndpoint1().element();
134
    	String srcProperty = srcAnchorDef.getProperty().getContent();
135
    	String srcExpr = srcAnchorDef.getValue().getContent();
136
    	Function srcFunc = getNodeReferenceFunction(srcNode, srcExpr);
137
    	Object srcValue = srcFunc.value();
138
    	srcFunc.dispose();
139
    	setModelProperty(newElement, srcProperty, srcValue);
140
    	
141
    	IDiagramConnectionEndpointDef targetAnchorDef = this.definition.getEndpoint2().element();
142
    	String targetProperty = targetAnchorDef.getProperty().getContent();
143
    	String targetExpr = targetAnchorDef.getValue().getContent();
144
    	Function targetFunc = getNodeReferenceFunction(targetNode, targetExpr);
145
    	Object targetValue = targetFunc.value();
146
    	targetFunc.dispose();
147
    	setModelProperty(newElement, targetProperty, targetValue);
148
    	
149
    	DiagramConnectionPart newConn = new DiagramConnectionPart(this);
150
    	newConn.init(this.diagramEditor, newElement, this.definition, 
151
    			Collections.<String,String>emptyMap());
152
    	this.diagramConnections.add(newConn);
153
    	return newConn;
154
    }
155
    
156
    protected ModelProperty resolve(final IModelElement modelElement, 
157
    		String propertyName)
158
    {
159
    	if (propertyName != null)
160
    	{
161
	        final ModelElementType type = modelElement.getModelElementType();
162
	        final ModelProperty property = type.getProperty( propertyName );
163
	        if( property == null )
164
	        {
165
	            throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
166
	        }
167
	        return property;
168
    	}    
169
        return null;
170
    }
171
172
    protected void setModelProperty(final IModelElement modelElement, 
173
    								String propertyName, Object value)
174
    {
175
    	if (propertyName != null)
176
    	{
177
	        final ModelElementType type = modelElement.getModelElementType();
178
	        final ModelProperty property = type.getProperty( propertyName );
179
	        if( property == null )
180
	        {
181
	            throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
182
	        }
183
	        if (!(property instanceof ValueProperty))
184
	        {
185
	        	throw new RuntimeException( "Property " + propertyName + " not a ValueProperty");
186
	        }
187
	        		
188
	        modelElement.write((ValueProperty)property, ((Value<?>)value).getContent());
189
    	}    	
190
    }
191
    
192
    protected Function getNodeReferenceFunction(final DiagramNodePart nodePart,
193
    											final String expression)
194
    {
195
        final FunctionContext context = new ModelElementFunctionContext( nodePart.getLocalModelElement() );
196
        Function result = null;
197
        
198
        if( expression != null )
199
        {
200
            try
201
            {
202
                result = ExpressionLanguageParser.parse( context, expression );
203
            }
204
            catch( Exception e )
205
            {
206
                SapphireUiFrameworkPlugin.log( e );
207
                result = null;
208
            }
209
        }
210
        return result;
211
    }
212
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionPart.java (+115 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.el.Function;
5
import org.eclipse.sapphire.ui.SapphireRenderingContext;
6
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef;
7
import org.eclipse.sapphire.ui.diagram.def.IDiagramEmbeddedConnectionDef;
8
9
public class DiagramEmbeddedConnectionPart extends DiagramConnectionPart 
10
{
11
	private DiagramEmbeddedConnectionTemplate connTemplate;
12
	private IDiagramEmbeddedConnectionDef localDefinition;
13
	private IModelElement srcNodeModel;
14
	private IModelElement endpointModel;
15
	private Function endpointFunction;
16
	private IDiagramConnectionEndpointDef endpointDef;
17
	
18
	public DiagramEmbeddedConnectionPart(DiagramEmbeddedConnectionTemplate connTemplate,
19
			IModelElement srcNodeModel)
20
	{
21
		this.connTemplate = connTemplate;
22
		this.srcNodeModel = srcNodeModel;
23
	}
24
	
25
    @Override
26
    protected void init()
27
    {        
28
        this.localDefinition = (IDiagramEmbeddedConnectionDef)super.definition;
29
        this.modelElement = super.getModelElement();
30
        this.labelFunction = initExpression
31
        ( 
32
        	this.localDefinition.getLabel().element().getContent().getLocalizedText(), 
33
            new Runnable()
34
            {
35
                public void run()
36
                {
37
                }
38
            }
39
        );
40
        this.labelProperty = FunctionUtil.getFunctionProperty(this.modelElement, this.labelFunction);
41
        
42
        this.idFunction = initExpression
43
        ( 
44
            this.localDefinition.getInstanceId().getLocalizedText(), 
45
            new Runnable()
46
            {
47
                public void run()
48
                {
49
                }
50
            }
51
        );        
52
53
        this.endpointDef = this.localDefinition.getEndpoint().element();
54
        this.endpointModel = processEndpoint(this.endpointDef);
55
        this.endpointFunction = initExpression
56
        (
57
        	this.endpointModel, 
58
        	this.endpointDef.getValue().getContent(), 
59
            new Runnable()
60
        	{
61
	            public void run()
62
	            {
63
	            	refreshEndpoint2();
64
	            }
65
        	}
66
        );        
67
    }
68
69
    public DiagramEmbeddedConnectionTemplate getConnectionTemplate()
70
    {
71
    	return this.connTemplate;
72
    }
73
    
74
    @Override
75
    public IModelElement getEndpoint1()
76
    {
77
    	return this.srcNodeModel;
78
    }
79
    
80
    @Override
81
    public IModelElement getEndpoint2()
82
    {
83
    	return this.endpointModel;
84
    }
85
86
    @Override
87
	public void refreshEndpoint1()
88
	{
89
	}
90
	
91
    @Override
92
	public void refreshEndpoint2()
93
	{
94
		if (this.endpointFunction != null)
95
		{
96
			Object value = this.endpointFunction.value();
97
			String property = this.endpointDef.getProperty().getContent();
98
			setModelProperty(this.modelElement, property, value);
99
		}		
100
	}
101
        
102
    public DiagramNodePart getSourceNodePart()
103
    {
104
    	SapphireDiagramEditorPart diagramPart = (SapphireDiagramEditorPart)getParentPart();
105
    	return diagramPart.getDiagramNodePart(this.srcNodeModel);
106
    }
107
    
108
	@Override
109
	public void render(SapphireRenderingContext context) 
110
	{
111
		// TODO Auto-generated method stub
112
113
	}
114
115
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramEmbeddedConnectionTemplate.java (+176 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
6
import org.eclipse.sapphire.modeling.ElementProperty;
7
import org.eclipse.sapphire.modeling.IModelElement;
8
import org.eclipse.sapphire.modeling.ListProperty;
9
import org.eclipse.sapphire.modeling.ModelElementList;
10
import org.eclipse.sapphire.modeling.ModelElementType;
11
import org.eclipse.sapphire.modeling.ModelProperty;
12
import org.eclipse.sapphire.modeling.annotations.Reference;
13
import org.eclipse.sapphire.modeling.el.Function;
14
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef;
15
import org.eclipse.sapphire.ui.diagram.def.IDiagramEmbeddedConnectionDef;
16
17
public class DiagramEmbeddedConnectionTemplate extends DiagramConnectionTemplate
18
{
19
	private SapphireDiagramEditorPart diagramEditor;
20
	private DiagramNodeTemplate nodeTemplate;
21
	private IDiagramEmbeddedConnectionDef definition;
22
	private IModelElement modelElement;	
23
		
24
    public DiagramEmbeddedConnectionTemplate(final SapphireDiagramEditorPart diagramEditor,
25
    										final DiagramNodeTemplate nodeTemplate, 
26
    										IDiagramEmbeddedConnectionDef definition, 
27
    										IModelElement modelElement)
28
    {
29
    	this.diagramEditor = diagramEditor;
30
    	this.nodeTemplate = nodeTemplate;
31
    	this.modelElement = modelElement;
32
    	this.definition = definition;
33
    	
34
        this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent();
35
        this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent();
36
        
37
        this.diagramConnections = new ArrayList<DiagramConnectionPart>();
38
        
39
        ModelProperty nodeProperty = this.nodeTemplate.getModelProperty();
40
        String connPropName = this.definition.getProperty().getContent();
41
        if (nodeProperty instanceof ListProperty)
42
        {
43
        	ListProperty listProperty = (ListProperty)nodeProperty;
44
        	ModelElementList<?> list = this.modelElement.read(listProperty);
45
            for (IModelElement srcNodeModel : list)
46
            {
47
            	ModelProperty connProp = resolve(srcNodeModel, connPropName);
48
            	if (connProp instanceof ListProperty)
49
            	{
50
            		ListProperty connListProperty = (ListProperty)connProp;
51
            		ModelElementList<?> connList = srcNodeModel.read(connListProperty);
52
            		for (IModelElement endpointModel : connList)
53
            		{
54
            			DiagramEmbeddedConnectionPart connPart = 
55
            				new DiagramEmbeddedConnectionPart(this, srcNodeModel);
56
            			connPart.init(this.diagramEditor, endpointModel, this.definition, 
57
            					Collections.<String,String>emptyMap());
58
            			this.diagramConnections.add(connPart);
59
            		}
60
            	}
61
            	else if (connProp instanceof ElementProperty)
62
            	{
63
            		ElementProperty elementProperty = (ElementProperty)connProp;
64
                	if (this.modelElement.read(elementProperty) != null)
65
                	{            		
66
                		IModelElement endpointModel = this.modelElement.read(elementProperty).element();
67
               			DiagramEmbeddedConnectionPart connPart = 
68
            				new DiagramEmbeddedConnectionPart(this, srcNodeModel);
69
            			connPart.init(this.diagramEditor, endpointModel, this.definition, 
70
            					Collections.<String,String>emptyMap());               			
71
            			this.diagramConnections.add(connPart);                		
72
                	}
73
            	}            	
74
            }
75
        }    	
76
    }
77
        
78
    @Override
79
    public boolean canCreateNewConnection(DiagramNodePart srcNode, DiagramNodePart targetNode)
80
    {    	
81
    	IModelElement srcNodeModel = srcNode.getLocalModelElement();
82
    	
83
    	// check the source node type
84
    	ModelElementType srcNodeType = srcNodeModel.getModelElementType();
85
    	ModelElementType desiredsrcNodeType = this.nodeTemplate.getNodeType();
86
    	
87
    	if (!srcNodeType.equals(desiredsrcNodeType))
88
    	{
89
    		return false;
90
    	}
91
    	
92
    	// check the target node type
93
    	ModelElementType targetType = targetNode.getLocalModelElement().getModelElementType();
94
    	
95
    	String connPropName = this.definition.getProperty().getContent();
96
    	ModelProperty connProp = resolve(srcNodeModel, connPropName);    	
97
        ModelElementType connType = connProp.getType();
98
        ModelProperty endpointProp = 
99
        	connType.getProperty(this.definition.getEndpoint().element().getProperty().getContent());
100
        if (endpointProp.getType() == null && endpointProp.hasAnnotation(Reference.class))
101
        {
102
        	return endpointProp.getAnnotation(Reference.class).target().isAssignableFrom(targetType.getModelElementClass());
103
        }
104
    	return false;
105
    }
106
        
107
    @Override
108
    public DiagramEmbeddedConnectionPart createNewDiagramConnection(DiagramNodePart srcNode, 
109
			DiagramNodePart targetNode)
110
    {
111
    	IModelElement srcNodeModel = srcNode.getModelElement();
112
    	ModelProperty modelProperty = this.nodeTemplate.getModelProperty();
113
    	boolean found = false;
114
    	if (modelProperty instanceof ListProperty)
115
    	{
116
        	ListProperty listProperty = (ListProperty)modelProperty;
117
        	ModelElementList<?> list = this.modelElement.read(listProperty);
118
            for (IModelElement listEntryModelElement : list)
119
            {
120
            	if (listEntryModelElement == srcNodeModel)
121
            	{
122
            		found = true;
123
            		break;
124
            	}            	
125
            }
126
    	}
127
        else if (modelProperty instanceof ElementProperty)
128
        {
129
        	ElementProperty elementProperty = (ElementProperty)modelProperty;
130
        	if (this.modelElement.read(elementProperty) != null)
131
        	{
132
	        	IModelElement localModelElement = this.modelElement.read(elementProperty).element();
133
	        	if (localModelElement == srcNodeModel)
134
	        	{
135
	        		found = true;
136
	        	}
137
        	}
138
        }
139
    	if (!found)
140
    	{
141
    		throw new RuntimeException( "Cannot locate the source node element");
142
    	}
143
    	
144
    	String connPropName = this.definition.getProperty().getContent();
145
    	ModelProperty connProp = resolve(srcNodeModel, connPropName);
146
    	IModelElement newEndpoint = null;
147
    	if (connProp instanceof ListProperty)
148
    	{
149
    		ListProperty listProperty = (ListProperty)connProp;
150
    		ModelElementList<?> list = srcNodeModel.read(listProperty);
151
    		newEndpoint = list.addNewElement();    		
152
    	}
153
    	else if (connProp instanceof ElementProperty)
154
    	{
155
    		// TODO what if the element property does exist?
156
    		ElementProperty elementProperty = (ElementProperty)connProp;
157
    		newEndpoint = this.modelElement.read(elementProperty).element(true);
158
    	}
159
    	IDiagramConnectionEndpointDef endpointDef = this.definition.getEndpoint().element();
160
    	String endpointProperty = endpointDef.getProperty().getContent();
161
    	String endpointExpr = endpointDef.getValue().getContent();
162
    	Function endpointFunc = getNodeReferenceFunction(targetNode, endpointExpr);
163
    	Object endpointValue = endpointFunc.value();
164
    	endpointFunc.dispose();
165
    	setModelProperty(newEndpoint, endpointProperty, endpointValue);
166
167
		DiagramEmbeddedConnectionPart connPart = 
168
			new DiagramEmbeddedConnectionPart(this, srcNodeModel);
169
		connPart.init(this.diagramEditor, newEndpoint, this.definition, 
170
				Collections.<String,String>emptyMap());               			
171
		this.diagramConnections.add(connPart);                		
172
    	
173
    	return connPart;
174
    }
175
        
176
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramGeometryWrapper.java (+360 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.List;
7
8
import org.eclipse.core.resources.IFile;
9
import org.eclipse.sapphire.modeling.ModelElementList;
10
import org.eclipse.sapphire.modeling.ResourceStoreException;
11
import org.eclipse.sapphire.modeling.WorkspaceFileResourceStore;
12
import org.eclipse.sapphire.modeling.xml.RootXmlResource;
13
import org.eclipse.sapphire.modeling.xml.XmlResourceStore;
14
import org.eclipse.sapphire.ui.diagram.geometry.IBendPoint;
15
import org.eclipse.sapphire.ui.diagram.geometry.IDiagramConnectionGeometry;
16
import org.eclipse.sapphire.ui.diagram.geometry.IDiagramGeometry;
17
import org.eclipse.sapphire.ui.diagram.geometry.IDiagramNodeGeometry;
18
19
public class DiagramGeometryWrapper 
20
{
21
	private IFile file;
22
	private IDiagramGeometry geometryModel;
23
	private SapphireDiagramEditorPart diagramPart;
24
	
25
	private HashMap<DiagramNodePart, Bounds> nodeGeometries;
26
	private HashMap<DiagramConnectionPart, List<Point>> connectionBendpoints;
27
	private HashMap<DiagramNodePart, HashMap<DiagramConnectionPart, List<Point>>> embeddedConnectionBendpoints;
28
	
29
	public DiagramGeometryWrapper(IFile file, SapphireDiagramEditorPart diagramPart)
30
		throws ResourceStoreException
31
	{
32
		this.file = file;
33
		this.diagramPart = diagramPart;
34
		this.nodeGeometries = new HashMap<DiagramNodePart, Bounds>();
35
		this.connectionBendpoints = new HashMap<DiagramConnectionPart, List<Point>>();
36
		this.embeddedConnectionBendpoints = 
37
					new HashMap<DiagramNodePart, HashMap<DiagramConnectionPart, List<Point>>>();
38
		read();
39
	}
40
	
41
	public void addNode(DiagramNodePart nodePart, int x, int y, int w, int h)
42
	{
43
		Bounds bounds = new Bounds(x, y, w, h);
44
		this.nodeGeometries.put(nodePart, bounds);
45
	}
46
	
47
	public void removeNode(DiagramNodePart nodePart)
48
	{
49
		this.nodeGeometries.remove(nodePart);
50
	}
51
	
52
	public void updateNode(DiagramNodePart nodePart, int x, int y)
53
	{
54
		Bounds bounds = this.nodeGeometries.get(nodePart);
55
		if (bounds != null)
56
		{
57
			bounds.x = x;
58
			bounds.y = y;
59
		}
60
	}
61
62
	public void updateNode(DiagramNodePart nodePart, int x, int y, int w, int h)
63
	{
64
		Bounds bounds = this.nodeGeometries.get(nodePart);
65
		if (bounds != null)
66
		{
67
			bounds.x = x;
68
			bounds.y = y;
69
			bounds.height = h;
70
			bounds.width = w;
71
		}
72
	}
73
	
74
	public Bounds getNode(DiagramNodePart nodePart)
75
	{
76
		return this.nodeGeometries.get(nodePart);
77
	}
78
	
79
	public void addConnectionBendpoint(DiagramConnectionPart connPart, int index, int x, int y)
80
	{
81
		HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = 
82
			getConnectionBenpointsMap(connPart, true);
83
		List<Point> bendpoints = connBendpointsMap.get(connPart);
84
		if (bendpoints == null)
85
		{
86
			bendpoints = new ArrayList<Point>();
87
			connBendpointsMap.put(connPart, bendpoints);
88
		}
89
		Point newPt = new Point(x, y);
90
		bendpoints.add(index, newPt);
91
	}
92
	
93
	public void removeConnectionBendpoint(DiagramConnectionPart connPart, int index)
94
	{
95
		HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = 
96
			getConnectionBenpointsMap(connPart, false);
97
		if (connBendpointsMap == null)
98
		{
99
			throw new RuntimeException("Could not locate connection benpoints map for the embedded connection");
100
		}
101
		List<Point> bendpoints = connBendpointsMap.get(connPart);
102
		if (bendpoints != null)
103
		{
104
			bendpoints.remove(index);
105
		}
106
	}
107
	
108
	public boolean updateConnectionBendpoint(DiagramConnectionPart connPart, int index, int x, int y)
109
	{
110
		HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = 
111
			getConnectionBenpointsMap(connPart, false);
112
		if (connBendpointsMap == null)
113
		{
114
			throw new RuntimeException("Could not locate connection benpoints map for the embedded connection");
115
		}
116
		List<Point> bendpoints = connBendpointsMap.get(connPart);
117
		if (bendpoints != null && index < bendpoints.size())
118
		{
119
			bendpoints.set(index, new Point(x, y));
120
			return true;
121
		}
122
		return false;
123
	}
124
	
125
126
	public List<Point> getConnectionBendpoints(DiagramConnectionPart connPart)
127
	{
128
		HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = 
129
			getConnectionBenpointsMap(connPart, false);		
130
		if (connBendpointsMap != null)
131
		{
132
			return connBendpointsMap.get(connPart);
133
		}
134
		return null;
135
	}
136
		
137
	public void read() throws ResourceStoreException
138
	{
139
		final XmlResourceStore resourceStore = new XmlResourceStore( new WorkspaceFileResourceStore(this.file ));
140
		this.geometryModel = IDiagramGeometry.TYPE.instantiate(new RootXmlResource( resourceStore ));
141
142
		ModelElementList<IDiagramNodeGeometry> nodes = this.geometryModel.getDiagramNodeGeometries();
143
		for (IDiagramNodeGeometry node : nodes)
144
		{
145
			String id = node.getNodeId().getContent();
146
			DiagramNodePart nodePart = getNodeElement(id);
147
			if (nodePart != null)
148
			{
149
				int x = node.getX().getContent() != null ? node.getX().getContent() : -1;
150
				int y = node.getY().getContent() != null ? node.getY().getContent() : -1;
151
				int width = node.getWidth().getContent() != null ? node.getWidth().getContent() : -1;
152
				int height = node.getHeight().getContent() != null ? node.getHeight().getContent() : -1;
153
				this.addNode(nodePart, x, y, width, height);
154
				
155
				ModelElementList<IDiagramConnectionGeometry> connList = node.getEmbeddedConnectionGeometries();
156
				for (IDiagramConnectionGeometry connBend : connList)
157
				{
158
					String connId = connBend.getConnectionId().getContent();
159
					DiagramConnectionPart connPart = getConnectionElement(nodePart, connId);
160
					if (connPart != null)
161
					{
162
						ModelElementList<IBendPoint> bps = connBend.getConnectionBendpoints();
163
						int index = 0;
164
						for (IBendPoint pt : bps)
165
						{
166
							this.addConnectionBendpoint(connPart, index++, pt.getX().getContent(), pt.getY().getContent());
167
						}
168
					}			
169
				}
170
				
171
			}
172
		}
173
		
174
		ModelElementList<IDiagramConnectionGeometry> connList = this.geometryModel.getDiagramConnectionGeometries();
175
		for (IDiagramConnectionGeometry connBend : connList)
176
		{
177
			String connId = connBend.getConnectionId().getContent();
178
			DiagramConnectionPart connPart = getConnectionElement(connId);
179
			if (connPart != null)
180
			{
181
				ModelElementList<IBendPoint> bps = connBend.getConnectionBendpoints();
182
				int index = 0;
183
				for (IBendPoint pt : bps)
184
				{
185
					this.addConnectionBendpoint(connPart, index++, pt.getX().getContent(), pt.getY().getContent());
186
				}
187
			}			
188
		}
189
	}
190
	
191
	public void write() throws ResourceStoreException
192
	{
193
		this.geometryModel.getDiagramNodeGeometries().clear();
194
		Iterator<DiagramNodePart> it = this.nodeGeometries.keySet().iterator();
195
		while (it.hasNext())
196
		{
197
			DiagramNodePart nodePart = it.next();
198
			Bounds bounds = this.nodeGeometries.get(nodePart);
199
			String id = nodePart.getInstanceId();
200
			
201
			if (bounds != null && id != null)
202
			{
203
				IDiagramNodeGeometry diagramNode = this.geometryModel.getDiagramNodeGeometries().addNewElement();
204
				diagramNode.setNodeId(id);
205
				diagramNode.setX(bounds.x);
206
				diagramNode.setY(bounds.y);
207
				diagramNode.setWidth(bounds.width);
208
				diagramNode.setHeight(bounds.height);
209
				
210
				// save the embedded connection bendpoints
211
				HashMap<DiagramConnectionPart, List<Point>> embeddedConnBendpointsMap = 
212
					this.embeddedConnectionBendpoints.get(nodePart);
213
				if (embeddedConnBendpointsMap != null)
214
				{
215
					diagramNode.getEmbeddedConnectionGeometries().clear();
216
					addConnectionBenpointsToModel(embeddedConnBendpointsMap, 
217
							diagramNode.getEmbeddedConnectionGeometries());					
218
				}				
219
			}			
220
		}
221
		
222
		this.geometryModel.getDiagramConnectionGeometries().clear();
223
		addConnectionBenpointsToModel(this.connectionBendpoints, 
224
				this.geometryModel.getDiagramConnectionGeometries());
225
		this.geometryModel.resource().save();
226
	}
227
228
	private DiagramNodePart getNodeElement(String nodeId)
229
	{
230
		for (DiagramNodeTemplate nodeTemplate : this.diagramPart.getNodeTemplates())
231
		{
232
			for (DiagramNodePart nodePart : nodeTemplate.getDiagramNodes())
233
			{
234
				String nodeId2 = nodePart.getInstanceId();
235
				if (nodeId != null && nodeId2 != null && nodeId.equals(nodeId2))
236
				{
237
					return nodePart;
238
				}
239
			}
240
		}
241
		return null;
242
	}
243
	
244
	private DiagramConnectionPart getConnectionElement(String connId)
245
	{
246
		for (DiagramConnectionTemplate connTemplate : this.diagramPart.getConnectionTemplates())
247
		{
248
			for (DiagramConnectionPart connPart : connTemplate.getDiagramConnections())
249
			{
250
				String connId2 = connPart.getInstanceId();
251
				if (connId != null && connId2 != null && connId.equals(connId2))
252
				{
253
					return connPart;
254
				}
255
			}
256
		}
257
		return null;
258
	}
259
260
	private DiagramConnectionPart getConnectionElement(DiagramNodePart nodePart, String connId)
261
	{
262
		DiagramNodeTemplate nodeTemplate = nodePart.getDiagramNodeTemplate();
263
		DiagramEmbeddedConnectionTemplate connTemplate = 
264
			nodeTemplate.getEmbeddedConnectionTemplate();
265
		if (connTemplate != null)
266
		{
267
			List<DiagramConnectionPart> connParts = connTemplate.getDiagramConnections();
268
			for (DiagramConnectionPart connPart : connParts)
269
			{
270
				String connId2 = connPart.getInstanceId();
271
				if (connId != null && connId2 != null && connId.equals(connId2))
272
				{
273
					return connPart;
274
				}				
275
			}
276
		}
277
		return null;
278
	}
279
280
	private HashMap<DiagramConnectionPart, List<Point>> getConnectionBenpointsMap(DiagramConnectionPart connPart, boolean create)
281
	{
282
		HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap = null;
283
		if (connPart instanceof DiagramEmbeddedConnectionPart)
284
		{
285
			DiagramNodePart srcNodePart = ((DiagramEmbeddedConnectionPart)connPart).getSourceNodePart();
286
			if (srcNodePart == null)
287
			{
288
				throw new RuntimeException("Could not locate the source node for the embedded connection");
289
			}
290
			connBendpointsMap = this.embeddedConnectionBendpoints.get(srcNodePart);
291
			if (connBendpointsMap == null)
292
			{
293
				if (create)
294
				{
295
					connBendpointsMap = new HashMap<DiagramConnectionPart, List<Point>>();
296
					this.embeddedConnectionBendpoints.put(srcNodePart, connBendpointsMap);
297
				}
298
			}
299
		}
300
		else
301
		{
302
			connBendpointsMap = this.connectionBendpoints;
303
		}
304
		return connBendpointsMap;
305
	}
306
	
307
	private void addConnectionBenpointsToModel(HashMap<DiagramConnectionPart, List<Point>> connBendpointsMap, 
308
			ModelElementList<IDiagramConnectionGeometry> connGeometries)
309
	{
310
		Iterator<DiagramConnectionPart> connIt = connBendpointsMap.keySet().iterator();
311
		while (connIt.hasNext())
312
		{
313
			DiagramConnectionPart connPart = connIt.next();
314
			List<Point> bps = connBendpointsMap.get(connPart);
315
			String id = connPart.getInstanceId();
316
			
317
			if (bps != null && id != null)
318
			{
319
				IDiagramConnectionGeometry conn = connGeometries.addNewElement();
320
				conn.setConnectionId(id);
321
				for (Point pt : bps)
322
				{
323
					IBendPoint pt2 = conn.getConnectionBendpoints().addNewElement();
324
					pt2.setX(pt.x);
325
					pt2.setY(pt.y);
326
				}
327
			}
328
		}
329
		
330
	}
331
	
332
	// -------------------------------------------------------------------
333
	// Inner classes
334
	// -------------------------------------------------------------------
335
	
336
	public static class Point
337
	{
338
		public int x;
339
		public int y;
340
		
341
		public Point(int x, int y)
342
		{
343
			this.x = x;
344
			this.y = y;
345
		}
346
	}
347
	
348
	public static final class Bounds extends Point
349
	{
350
		public int width;
351
		public int height;
352
		
353
		public Bounds(int x, int y, int width, int height)
354
		{
355
			super(x, y);
356
			this.width = width;
357
			this.height = height;
358
		}
359
	}
360
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodePart.java (+122 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ValueProperty;
5
import org.eclipse.sapphire.modeling.el.Function;
6
import org.eclipse.sapphire.ui.SapphirePart;
7
import org.eclipse.sapphire.ui.SapphireRenderingContext;
8
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef;
9
10
public class DiagramNodePart extends SapphirePart 
11
{
12
	private DiagramNodeTemplate nodeTemplate;
13
	private IDiagramNodeDef definition;
14
	private IModelElement modelElement;
15
	private Function labelFunction;
16
	private Function idFunction;
17
	private ValueProperty labelProperty;
18
	
19
	public DiagramNodePart(DiagramNodeTemplate nodeTemplate)
20
	{
21
		this.nodeTemplate = nodeTemplate;
22
	}
23
	
24
    @Override
25
    protected void init()
26
    {
27
        super.init();
28
        
29
        this.definition = (IDiagramNodeDef)super.definition;
30
        this.modelElement = getModelElement();
31
        this.labelFunction = initExpression
32
        ( 
33
            this.definition.getLabel().element().getContent().getLocalizedText(), 
34
            new Runnable()
35
            {
36
                public void run()
37
                {
38
                }
39
            }
40
        );
41
        this.labelProperty = FunctionUtil.getFunctionProperty(this.modelElement, this.labelFunction);
42
        
43
        this.idFunction = initExpression
44
        ( 
45
            this.definition.getInstanceId().getLocalizedText(), 
46
            new Runnable()
47
            {
48
                public void run()
49
                {
50
                }
51
            }
52
        );
53
    }
54
    
55
    public DiagramNodeTemplate getDiagramNodeTemplate()
56
    {
57
    	return this.nodeTemplate;
58
    }
59
    
60
    public IModelElement getLocalModelElement()
61
    {
62
        return this.modelElement;
63
    }    
64
        
65
	@Override
66
	public void render(SapphireRenderingContext context)
67
	{
68
		throw new UnsupportedOperationException();
69
	}
70
71
	public String getLabel()
72
	{
73
        String label = null;
74
        
75
        if( this.labelFunction != null )
76
        {
77
            label = (String) this.labelFunction.value();
78
        }
79
        
80
        if( label == null )
81
        {
82
            label = "#null#";
83
        }
84
        
85
        return label;
86
	}
87
88
	public void setLabel(String newValue)
89
	{
90
		if (this.labelProperty != null)
91
		{
92
			this.modelElement.write(this.labelProperty, newValue);
93
		}
94
	}
95
	
96
	public boolean canEditLabel()
97
	{
98
		return this.labelProperty != null;
99
	}
100
	
101
	public String getInstanceId()
102
	{
103
        String id = null;
104
        
105
        if( this.idFunction != null )
106
        {
107
            id = (String) this.idFunction.value();
108
        }
109
        
110
        if( id == null )
111
        {
112
            id = "#null#";
113
        }
114
        
115
        return id;		
116
	}
117
	
118
	public boolean canResizeShape()
119
	{
120
		return this.definition.getHint("resizable", true);
121
	}
122
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodeTemplate.java (+154 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
7
import org.eclipse.sapphire.modeling.ElementProperty;
8
import org.eclipse.sapphire.modeling.IModelElement;
9
import org.eclipse.sapphire.modeling.ListProperty;
10
import org.eclipse.sapphire.modeling.ModelElementList;
11
import org.eclipse.sapphire.modeling.ModelElementType;
12
import org.eclipse.sapphire.modeling.ModelProperty;
13
import org.eclipse.sapphire.ui.diagram.def.IDiagramEmbeddedConnectionDef;
14
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef;
15
16
public class DiagramNodeTemplate 
17
{
18
	private SapphireDiagramEditorPart diagramEditor;
19
	private IDiagramNodeDef definition;
20
	private IModelElement modelElement;	
21
	private ModelProperty modelProperty;
22
	private String toolPaletteLabel;
23
	private String toolPaletteDesc;
24
	private DiagramEmbeddedConnectionTemplate embeddedConnTemplate;
25
	
26
	private List<DiagramNodePart> diagramNodes;
27
	    
28
    public DiagramNodeTemplate(final SapphireDiagramEditorPart diagramEditor, IDiagramNodeDef definition, IModelElement modelElement)
29
    {
30
    	this.diagramEditor = diagramEditor;
31
    	this.modelElement = modelElement;
32
    	this.definition = definition;
33
    	
34
        this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent();
35
        this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent();
36
        
37
        this.diagramNodes = new ArrayList<DiagramNodePart>();
38
        
39
        String propertyName = this.definition.getProperty().getContent();
40
        this.modelProperty = resolve(this.modelElement, propertyName);
41
        if (this.modelProperty instanceof ListProperty)
42
        {
43
        	ListProperty listProperty = (ListProperty)this.modelProperty;
44
        	ModelElementList<?> list = this.modelElement.read(listProperty);
45
            for( IModelElement listEntryModelElement : list )
46
            {
47
            	DiagramNodePart node = new DiagramNodePart(this);
48
            	node.init(this.diagramEditor, listEntryModelElement, definition, 
49
            			Collections.<String,String>emptyMap());
50
            	this.diagramNodes.add(node);
51
            }
52
        }
53
        else if (this.modelProperty instanceof ElementProperty)
54
        {
55
        	ElementProperty elementProperty = (ElementProperty)this.modelProperty;
56
        	if (this.modelElement.read(elementProperty) != null)
57
        	{
58
	        	IModelElement localModelElement = this.modelElement.read(elementProperty).element();
59
	        	DiagramNodePart node = new DiagramNodePart(this);
60
	        	node.init(this.diagramEditor, localModelElement, definition, 
61
	        			Collections.<String,String>emptyMap());
62
	        	
63
	        	this.diagramNodes.add(node);
64
        	}
65
        }
66
        
67
        // handle embedded connections
68
        if (this.definition.getEmbeddedConnections().element() != null)
69
        {
70
        	IDiagramEmbeddedConnectionDef embeddedConnDef = 
71
        				this.definition.getEmbeddedConnections().element();
72
        	this.embeddedConnTemplate = new DiagramEmbeddedConnectionTemplate(
73
        									this.diagramEditor,
74
        									this, 
75
        									embeddedConnDef, 
76
        									this.modelElement);
77
        }
78
    }
79
    
80
    public IDiagramNodeDef getDefinition()
81
    {
82
    	return this.definition;
83
    }
84
    
85
    public List<DiagramNodePart> getDiagramNodes()
86
    {
87
    	return this.diagramNodes;
88
    }
89
    
90
    public String getToolPaletteLabel()
91
    {
92
    	return this.toolPaletteLabel;
93
    }
94
    
95
    public String getToolPaletteDesc()
96
    {
97
    	return this.toolPaletteDesc;
98
    }
99
    
100
    public DiagramNodePart createNewDiagramNode()
101
    {
102
    	IModelElement newElement = null;
103
    	if (this.modelProperty instanceof ListProperty)
104
    	{
105
    		ListProperty listProperty = (ListProperty)this.modelProperty;
106
    		ModelElementList<?> list = this.modelElement.read(listProperty);
107
    		newElement = list.addNewElement();
108
    	}
109
    	else if (this.modelProperty instanceof ElementProperty)
110
    	{
111
    		// TODO what if the element property does exist?
112
    		ElementProperty elementProperty = (ElementProperty)this.modelProperty;
113
    		newElement = this.modelElement.read(elementProperty).element(true);
114
    	}
115
    	DiagramNodePart newNode = new DiagramNodePart(this);
116
    	newNode.init(this.diagramEditor, newElement, this.definition, 
117
    			Collections.<String,String>emptyMap());
118
    	this.diagramNodes.add(newNode);
119
    	return newNode;
120
    }
121
    
122
    public ModelProperty getModelProperty()
123
    {
124
    	return this.modelProperty;
125
    }
126
    
127
    public ModelElementType getNodeType()
128
    {
129
    	return this.modelProperty.getType();
130
    }
131
    
132
    public DiagramEmbeddedConnectionTemplate getEmbeddedConnectionTemplate()
133
    {
134
    	return this.embeddedConnTemplate;
135
    }
136
    
137
    private ModelProperty resolve(final IModelElement modelElement, 
138
    		String propertyName)
139
    {
140
    	if (propertyName != null)
141
    	{
142
	        final ModelElementType type = modelElement.getModelElementType();
143
	        final ModelProperty property = type.getProperty( propertyName );
144
	        
145
	        if( property == null )
146
	        {
147
	            throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
148
	        }
149
	        return property;
150
    	}    
151
        return null;
152
    }
153
    
154
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/FunctionUtil.java (+45 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import java.util.List;
4
5
import org.eclipse.sapphire.modeling.IModelElement;
6
import org.eclipse.sapphire.modeling.ModelElementType;
7
import org.eclipse.sapphire.modeling.ModelProperty;
8
import org.eclipse.sapphire.modeling.ValueProperty;
9
import org.eclipse.sapphire.modeling.el.Function;
10
import org.eclipse.sapphire.modeling.el.RootPropertyAccessFunction;
11
12
public class FunctionUtil 
13
{
14
    public static ValueProperty getFunctionProperty(IModelElement modelElement, Function function)
15
    {
16
    	if (function instanceof RootPropertyAccessFunction)
17
    	{
18
    		RootPropertyAccessFunction rpaf = (RootPropertyAccessFunction)function;
19
    		if (rpaf.operand(0).value() instanceof String)
20
    		{
21
    			String propName = (String)rpaf.operand(0).value();
22
    	        final ModelElementType type = modelElement.getModelElementType();
23
    	        final ModelProperty property = type.getProperty(propName);
24
    			if (property instanceof ValueProperty)
25
    			{
26
    				return (ValueProperty)property;
27
    			}
28
    		}
29
    	}
30
    	else 
31
    	{
32
    		List<Function> subFuncs = function.operands();
33
    		for (Function subFunc : subFuncs)
34
    		{
35
    			ValueProperty property = getFunctionProperty(modelElement, subFunc);
36
    			if (property != null)
37
    			{
38
    				return property;
39
    			}
40
    		}
41
    	}
42
    	return null;
43
    }
44
45
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/SapphireDiagramEditorPart.java (+226 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.editor;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Set;
6
7
import org.eclipse.core.resources.IFile;
8
import org.eclipse.core.runtime.IPath;
9
import org.eclipse.core.runtime.IStatus;
10
import org.eclipse.help.IContext;
11
import org.eclipse.sapphire.modeling.IModelElement;
12
import org.eclipse.sapphire.modeling.ModelElementList;
13
import org.eclipse.sapphire.ui.ISapphirePart;
14
import org.eclipse.sapphire.ui.SapphireAction;
15
import org.eclipse.sapphire.ui.SapphireActionGroup;
16
import org.eclipse.sapphire.ui.SapphireEditor;
17
import org.eclipse.sapphire.ui.SapphireImageCache;
18
import org.eclipse.sapphire.ui.SapphirePartListener;
19
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
20
import org.eclipse.sapphire.ui.def.ISapphireUiDef;
21
import org.eclipse.sapphire.ui.def.SapphireUiDefFactory;
22
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionDef;
23
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef;
24
import org.eclipse.sapphire.ui.diagram.def.IDiagramPageDef;
25
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor;
26
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorFactory;
27
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorInput;
28
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
29
30
public class SapphireDiagramEditorPart
31
	implements ISapphirePart
32
{
33
    private final SapphireEditor editor;
34
    private final IModelElement rootModelElement;
35
    private IDiagramPageDef diagramPageDef = null;
36
    private DiagramGeometryWrapper diagramGeometry;
37
    private List<DiagramNodeTemplate> nodeTemplates;
38
    private List<DiagramConnectionTemplate> connectionTemplates;
39
    private SapphireDiagramEditorInput diagramInput;
40
    private SapphireDiagramEditor diagramEditor;
41
	
42
	public SapphireDiagramEditorPart(final SapphireEditor editor,
43
								final IModelElement rootModelElement,
44
								final IPath pageDefinitionLocation )
45
	{
46
		this(editor, rootModelElement, pageDefinitionLocation, null);
47
	}
48
49
	public SapphireDiagramEditorPart(final SapphireEditor editor,
50
								final IModelElement rootModelElement,
51
								final IPath pageDefinitionLocation,
52
								String pageName )
53
	{
54
		this.editor = editor;
55
		this.rootModelElement = rootModelElement;
56
57
        final String bundleId = pageDefinitionLocation.segment( 0 );
58
        final String pageId = pageDefinitionLocation.lastSegment();
59
        final String relPath = pageDefinitionLocation.removeFirstSegments( 1 ).removeLastSegments( 1 ).toPortableString();
60
        
61
        final ISapphireUiDef def = SapphireUiDefFactory.load( bundleId, relPath );
62
        
63
        for( IDiagramPageDef pg : def.getDiagramPageDefs() )
64
        {
65
            if( pageId.equals( pg.getId().getText() ) )
66
            {
67
                this.diagramPageDef = pg;
68
                break;
69
            }
70
        }
71
                
72
        this.nodeTemplates = new ArrayList<DiagramNodeTemplate>();
73
        ModelElementList<IDiagramNodeDef> nodeDefs = this.diagramPageDef.getDiagramNodeDefs();
74
        
75
        for (IDiagramNodeDef nodeDef : nodeDefs)
76
        {
77
        	DiagramNodeTemplate nodeTemplate = new DiagramNodeTemplate(this, nodeDef, this.rootModelElement);
78
        	this.nodeTemplates.add(nodeTemplate);
79
        }
80
        
81
        this.connectionTemplates = new ArrayList<DiagramConnectionTemplate>();
82
        ModelElementList<IDiagramConnectionDef> connectionDefs = this.diagramPageDef.getDiagramConnectionDefs();
83
        for (IDiagramConnectionDef connectionDef : connectionDefs)
84
        {
85
        	DiagramConnectionTemplate connectionTemplate = new DiagramConnectionTemplate(this, connectionDef, this.rootModelElement);
86
        	this.connectionTemplates.add(connectionTemplate);
87
        }       
88
        
89
        initializeDiagramEditor();
90
	}
91
92
	private void initializeDiagramEditor()
93
	{
94
        try
95
        {
96
        	this.diagramInput = SapphireDiagramEditorFactory.createEditorInput(this.editor.getEditorInput());
97
        	IFile npFile = this.diagramInput.getNodePositionFile();
98
        	this.diagramGeometry = new DiagramGeometryWrapper(npFile, this);
99
        }
100
        catch( Exception e )
101
        {
102
            SapphireUiFrameworkPlugin.log( e );
103
        }
104
    	this.diagramEditor = new SapphireDiagramEditor(this);
105
	}
106
	
107
	public SapphireDiagramEditorInput getDiagramEditorInput()
108
	{
109
		return this.diagramInput;
110
	}
111
	
112
	public SapphireDiagramEditor getDiagramEditor()
113
	{
114
		return this.diagramEditor;
115
	}
116
	
117
	public List<DiagramNodeTemplate> getNodeTemplates()
118
	{
119
		return this.nodeTemplates;
120
	}
121
	
122
	public List<DiagramConnectionTemplate> getConnectionTemplates()
123
	{
124
		return this.connectionTemplates;
125
	}
126
	
127
	public DiagramGeometryWrapper getDiagramGeometry()
128
	{
129
		return this.diagramGeometry;
130
	}
131
	
132
	public ISapphirePart getParentPart() 
133
	{	
134
		return this.editor;
135
	}
136
137
	public <T> T getNearestPart(Class<T> partType) {
138
		// TODO Auto-generated method stub
139
		return null;
140
	}
141
142
	public IModelElement getModelElement() 
143
	{	
144
		return this.rootModelElement;
145
	}
146
	
147
	public DiagramNodePart getDiagramNodePart(IModelElement nodeElement)
148
	{
149
		List<DiagramNodeTemplate> nodeTemplates = this.getNodeTemplates();
150
		for (DiagramNodeTemplate nodeTemplate : nodeTemplates)
151
		{
152
			if (nodeTemplate.getNodeType().equals(nodeElement.getModelElementType()))
153
			{
154
				List<DiagramNodePart> nodeParts = nodeTemplate.getDiagramNodes();
155
				for (DiagramNodePart nodePart : nodeParts)
156
				{
157
					if (nodePart.getLocalModelElement().equals(nodeElement))
158
					{
159
						return nodePart;
160
					}
161
				}
162
			}
163
		}
164
		return null;
165
	}
166
	
167
	public IStatus getValidationState() {
168
		// TODO Auto-generated method stub
169
		return null;
170
	}
171
172
	public IContext getDocumentationContext() {
173
		// TODO Auto-generated method stub
174
		return null;
175
	}
176
177
	public SapphireImageCache getImageCache() {
178
		// TODO Auto-generated method stub
179
		return null;
180
	}
181
182
	public void addListener(SapphirePartListener listener) {
183
		// TODO Auto-generated method stub
184
		
185
	}
186
187
	public void removeListener(SapphirePartListener listener) {
188
		// TODO Auto-generated method stub
189
		
190
	}
191
192
	public void dispose() {
193
		// TODO Auto-generated method stub
194
		
195
	}
196
197
	public ISapphirePartDef getDefinition() 
198
	{	
199
		return this.diagramPageDef;
200
	}
201
202
	public Set<String> getActionContexts() {
203
		// TODO Auto-generated method stub
204
		return null;
205
	}
206
207
	public String getMainActionContext() {
208
		// TODO Auto-generated method stub
209
		return null;
210
	}
211
212
	public SapphireActionGroup getActions() {
213
		// TODO Auto-generated method stub
214
		return null;
215
	}
216
217
	public SapphireActionGroup getActions(String context) {
218
		// TODO Auto-generated method stub
219
		return null;
220
	}
221
222
	public SapphireAction getAction(String id) {
223
		// TODO Auto-generated method stub
224
		return null;
225
	}
226
}
(-)src/org/eclipse/sapphire/ui/diagram/geometry/IBendPoint.java (+40 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.geometry;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ModelElementType;
5
import org.eclipse.sapphire.modeling.Value;
6
import org.eclipse.sapphire.modeling.ValueProperty;
7
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
8
import org.eclipse.sapphire.modeling.annotations.Type;
9
import org.eclipse.sapphire.modeling.xml.annotations.CustomXmlValueBinding;
10
import org.eclipse.sapphire.ui.diagram.geometry.internal.GeometryAttributeBinding;
11
12
@GenerateImpl
13
14
public interface IBendPoint extends IModelElement 
15
{
16
	ModelElementType TYPE = new ModelElementType( IBendPoint.class );
17
	
18
    // *** X ***
19
    
20
    @Type( base = Integer.class )
21
    @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"x"})
22
    
23
    ValueProperty PROP_X = new ValueProperty( TYPE, "X");
24
    
25
    Value<Integer> getX();
26
    void setX(Integer value);
27
	void setX(String value);
28
29
    // *** Y ***
30
    
31
    @Type( base = Integer.class )
32
    @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"y"})
33
34
    ValueProperty PROP_Y = new ValueProperty( TYPE, "Y");
35
    
36
    Value<Integer> getY();
37
    void setY(Integer value);
38
	void setY(String value);
39
	
40
}
(-)src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramConnectionGeometry.java (+41 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.geometry;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ListProperty;
5
import org.eclipse.sapphire.modeling.ModelElementList;
6
import org.eclipse.sapphire.modeling.ModelElementType;
7
import org.eclipse.sapphire.modeling.Value;
8
import org.eclipse.sapphire.modeling.ValueProperty;
9
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
10
import org.eclipse.sapphire.modeling.annotations.NonNullValue;
11
import org.eclipse.sapphire.modeling.annotations.Type;
12
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
13
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
14
15
@GenerateImpl
16
17
public interface IDiagramConnectionGeometry extends IModelElement 
18
{
19
	ModelElementType TYPE = new ModelElementType( IDiagramConnectionGeometry.class );
20
	
21
	// *** ConnectionId ***
22
	
23
	@XmlBinding( path = "id")
24
	@NonNullValue
25
26
	ValueProperty PROP_CONNECTION_ID = new ValueProperty( TYPE, "ConnectionId" );
27
28
    Value<String> getConnectionId();
29
    void setConnectionId( String name );
30
31
    // *** ConnectionBendpoints***
32
33
    @Type( base = IBendPoint.class )
34
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "bendpoint", type = IBendPoint.class ) )
35
    
36
    ListProperty PROP_CONNECTION_BENDPOINTS = new ListProperty( TYPE, "ConnectionBendPoints" );
37
    
38
    ModelElementList<IBendPoint> getConnectionBendpoints();
39
    
40
    
41
}
(-)src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramGeometry.java (+39 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.geometry;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ListProperty;
5
import org.eclipse.sapphire.modeling.ModelElementList;
6
import org.eclipse.sapphire.modeling.ModelElementType;
7
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
8
import org.eclipse.sapphire.modeling.annotations.Type;
9
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
10
import org.eclipse.sapphire.modeling.xml.annotations.XmlRootBinding;
11
12
@GenerateImpl
13
@XmlRootBinding( elementName = "diagram-geometry" )
14
15
public interface IDiagramGeometry extends IModelElement 
16
{
17
	ModelElementType TYPE = new ModelElementType( IDiagramGeometry.class );
18
	
19
    // *** DiagramNodeGeometries ***
20
21
    @Type( base = IDiagramNodeGeometry.class )
22
    
23
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "node", type = IDiagramNodeGeometry.class ) )
24
    
25
    ListProperty PROP_DIAGRAM_NODE_GEOMETRIES = new ListProperty( TYPE, "DiagramNodeGeometries" );
26
    
27
    ModelElementList<IDiagramNodeGeometry> getDiagramNodeGeometries();
28
	
29
    // *** DiagramConnectionGeometries ***
30
31
    @Type( base = IDiagramConnectionGeometry.class )
32
    
33
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "connection", type = IDiagramConnectionGeometry.class ) )
34
    
35
    ListProperty PROP_DIAGRAM_CONNECTION_GEOMETRIES = new ListProperty( TYPE, "DiagramConnectionGeometries" );
36
    
37
    ModelElementList<IDiagramConnectionGeometry> getDiagramConnectionGeometries();
38
39
}
(-)src/org/eclipse/sapphire/ui/diagram/geometry/IDiagramNodeGeometry.java (+87 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.geometry;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ListProperty;
5
import org.eclipse.sapphire.modeling.ModelElementList;
6
import org.eclipse.sapphire.modeling.ModelElementType;
7
import org.eclipse.sapphire.modeling.Value;
8
import org.eclipse.sapphire.modeling.ValueProperty;
9
import org.eclipse.sapphire.modeling.annotations.GenerateImpl;
10
import org.eclipse.sapphire.modeling.annotations.NonNullValue;
11
import org.eclipse.sapphire.modeling.annotations.Type;
12
import org.eclipse.sapphire.modeling.xml.annotations.CustomXmlValueBinding;
13
import org.eclipse.sapphire.modeling.xml.annotations.XmlBinding;
14
import org.eclipse.sapphire.modeling.xml.annotations.XmlListBinding;
15
import org.eclipse.sapphire.ui.diagram.geometry.internal.GeometryAttributeBinding;
16
17
@GenerateImpl
18
19
public interface IDiagramNodeGeometry extends IModelElement
20
{
21
	ModelElementType TYPE = new ModelElementType( IDiagramNodeGeometry.class );
22
	
23
	// *** NodeId ***
24
	
25
	@XmlBinding( path = "id")
26
	@NonNullValue
27
28
	ValueProperty PROP_NODE_ID = new ValueProperty( TYPE, "NodeId" );
29
30
    Value<String> getNodeId();
31
    void setNodeId( String name );
32
33
    // *** X ***
34
    
35
    @Type( base = Integer.class )
36
    @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "x"})
37
    
38
    ValueProperty PROP_X = new ValueProperty( TYPE, "X");
39
    
40
    Value<Integer> getX();
41
    void setX(Integer value);
42
	void setX(String value);
43
44
    // *** Y ***
45
    
46
    @Type( base = Integer.class )
47
    @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "y"})
48
49
    ValueProperty PROP_Y = new ValueProperty( TYPE, "Y");
50
    
51
    Value<Integer> getY();
52
    void setY(Integer value);
53
	void setY(String value);
54
    
55
    // *** Width ***
56
    
57
    @Type( base = Integer.class )
58
    @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "width"})
59
    
60
    ValueProperty PROP_WIDTH = new ValueProperty( TYPE, "Width");
61
    
62
    Value<Integer> getWidth();
63
    void setWidth(Integer value);
64
	void setWidth(String value);
65
	
66
    // *** Height ***
67
    
68
    @Type( base = Integer.class )
69
    @CustomXmlValueBinding( impl = GeometryAttributeBinding.class, params = {"gemometry", "height"})
70
    
71
    ValueProperty PROP_HEIGHT = new ValueProperty( TYPE, "Height");
72
    
73
    Value<Integer> getHeight();
74
    void setHeight(Integer value);
75
	void setHeight(String value);
76
	
77
    // *** EmbeddedConnectionGeometries ***
78
79
    @Type( base = IDiagramConnectionGeometry.class )
80
    
81
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "connection", type = IDiagramConnectionGeometry.class ) )
82
    
83
    ListProperty PROP_EMBEDDED_CONNECTION_GEOMETRIES = new ListProperty( TYPE, "EmbeddedConnectionGeometries" );
84
    
85
    ModelElementList<IDiagramConnectionGeometry> getEmbeddedConnectionGeometries();	
86
	
87
}
(-)src/org/eclipse/sapphire/ui/diagram/geometry/internal/GeometryAttributeBinding.java (+68 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.geometry.internal;
2
3
import org.eclipse.sapphire.modeling.IModelElement;
4
import org.eclipse.sapphire.modeling.ModelProperty;
5
import org.eclipse.sapphire.modeling.xml.XmlElement;
6
import org.eclipse.sapphire.modeling.xml.XmlValueBindingImpl;
7
8
public class GeometryAttributeBinding extends XmlValueBindingImpl
9
{
10
	private String modelPath = null;
11
	private String attrName = null;
12
	
13
	@Override
14
    public void init( final IModelElement element,
15
            final ModelProperty property,
16
            final String[] params )
17
	{
18
		super.init(element, property, params);
19
		if (params != null)
20
		{
21
			if (params.length > 1)
22
			{
23
				this.modelPath = params[0];
24
				this.attrName = params[1];
25
			}
26
			else if (params.length > 0) 
27
			{
28
				this.attrName = params[0];
29
			}
30
		}
31
	}
32
33
	@Override
34
	public String read() 
35
	{
36
		String attrVal = null;
37
		if (this.attrName != null)
38
		{
39
			XmlElement geometryEl = xml(false);
40
			if (geometryEl != null)
41
			{
42
				if (this.modelPath != null)
43
				{
44
					geometryEl = geometryEl.getChildElement(this.modelPath, false);
45
				}
46
				if (geometryEl != null)
47
				{
48
					attrVal = ( geometryEl.getAttributeText(this.attrName) );
49
				}
50
			}
51
		}
52
		return attrVal;
53
	}
54
55
	@Override
56
	public void write(String value) 
57
	{
58
		if (this.attrName != null)
59
		{
60
			XmlElement geometryEl = xml(true);
61
			if (this.modelPath != null)
62
			{
63
				geometryEl = geometryEl.getChildElement(this.modelPath, true);
64
			}
65
			geometryEl.setAttributeText( this.attrName, value, true );
66
		}		
67
	}
68
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/GraphitiFileService.java (+172 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti;
2
3
import java.io.IOException;
4
import java.io.PrintWriter;
5
import java.io.StringWriter;
6
import java.util.Collections;
7
import java.util.HashMap;
8
import java.util.HashSet;
9
import java.util.Map;
10
import java.util.Map.Entry;
11
import java.util.Set;
12
13
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IWorkspaceRunnable;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.Path;
19
import org.eclipse.emf.common.command.CommandStack;
20
import org.eclipse.emf.common.util.EList;
21
import org.eclipse.emf.common.util.URI;
22
import org.eclipse.emf.common.util.WrappedException;
23
import org.eclipse.emf.ecore.resource.Resource;
24
import org.eclipse.emf.ecore.resource.ResourceSet;
25
import org.eclipse.emf.transaction.RecordingCommand;
26
import org.eclipse.emf.transaction.Transaction;
27
import org.eclipse.emf.transaction.TransactionalEditingDomain;
28
import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
29
import org.eclipse.graphiti.mm.pictograms.Diagram;
30
import org.eclipse.graphiti.ui.editor.DiagramEditorFactory;
31
32
public class GraphitiFileService 
33
{
34
	public static TransactionalEditingDomain createEmfFileForDiagram(URI diagramResourceUri, final Diagram diagram) {
35
36
		// Create a resource set and EditingDomain
37
		final TransactionalEditingDomain editingDomain = DiagramEditorFactory.createResourceSetAndEditingDomain();
38
		final ResourceSet resourceSet = editingDomain.getResourceSet();
39
		// Create a resource for this file.
40
		final Resource resource = resourceSet.createResource(diagramResourceUri);
41
		final CommandStack commandStack = editingDomain.getCommandStack();
42
		commandStack.execute(new RecordingCommand(editingDomain) {
43
44
			@Override
45
			protected void doExecute() {
46
				resource.setTrackingModification(true);
47
				resource.getContents().add(diagram);
48
49
			}
50
		});
51
52
		save(editingDomain, Collections.<Resource, Map<?, ?>> emptyMap());
53
		return editingDomain;
54
	}
55
56
	private static void save(TransactionalEditingDomain editingDomain, Map<Resource, Map<?, ?>> options) {
57
		saveInWorkspaceRunnable(editingDomain, options);
58
	}
59
60
	private static void saveInWorkspaceRunnable(final TransactionalEditingDomain editingDomain, final Map<Resource, Map<?, ?>> options) {
61
62
		final Map<URI, Throwable> failedSaves = new HashMap<URI, Throwable>();
63
		final IWorkspaceRunnable wsRunnable = new IWorkspaceRunnable() {			
64
			public void run(final IProgressMonitor monitor) throws CoreException {
65
66
				final Runnable runnable = new Runnable() {
67
					
68
					public void run() {
69
						Transaction parentTx;
70
						if (editingDomain != null
71
								&& (parentTx = ((TransactionalEditingDomainImpl) editingDomain).getActiveTransaction()) != null) {
72
							do {
73
								if (!parentTx.isReadOnly()) {
74
									throw new IllegalStateException(
75
											"FileService.save() called from within a command (likely produces a deadlock)");
76
								}
77
							} while ((parentTx = ((TransactionalEditingDomainImpl) editingDomain).getActiveTransaction().getParent()) != null);
78
						}
79
80
						final EList<Resource> resources = editingDomain.getResourceSet().getResources();
81
						// Copy list to an array to prevent
82
						// ConcurrentModificationExceptions
83
						// during the saving of the dirty resources
84
						Resource[] resourcesArray = new Resource[resources.size()];
85
						resourcesArray = resources.toArray(resourcesArray);
86
						final Set<Resource> savedResources = new HashSet<Resource>();
87
						for (int i = 0; i < resourcesArray.length; i++) {
88
							// In case resource modification tracking is
89
							// switched on, we can check if a resource
90
							// has been modified, so that we only need to same
91
							// really changed resources; otherwise
92
							// we need to save all resources in the set
93
							final Resource resource = resourcesArray[i];
94
							if (resource.isModified()) {
95
								try {
96
									resource.save(options.get(resource));
97
									savedResources.add(resource);
98
								} catch (final Throwable t) {
99
									failedSaves.put(resource.getURI(), t);
100
								}
101
							}
102
						}
103
					}
104
				};
105
106
				try {
107
					editingDomain.runExclusive(runnable);
108
				} catch (final InterruptedException e) {
109
					throw new RuntimeException(e);
110
				}
111
				editingDomain.getCommandStack().flush();
112
			}
113
		};
114
		try {
115
			ResourcesPlugin.getWorkspace().run(wsRunnable, null);
116
			if (!failedSaves.isEmpty()) {
117
				throw new WrappedException(createMessage(failedSaves), new RuntimeException());
118
			}
119
		} catch (final CoreException e) {
120
			final Throwable cause = e.getStatus().getException();
121
			if (cause instanceof RuntimeException) {
122
				throw (RuntimeException) cause;
123
			}
124
			throw new RuntimeException(e);
125
		}
126
	}
127
128
	private static String createMessage(Map<URI, Throwable> failedSaves) {
129
		final StringBuilder buf = new StringBuilder("The following resources could not be saved:");
130
		for (final Entry<URI, Throwable> entry : failedSaves.entrySet()) {
131
			buf.append("\nURI: ").append(entry.getKey().toString()).append(", cause: \n").append(getExceptionAsString(entry.getValue()));
132
		}
133
		return buf.toString();
134
	}
135
136
	private static String getExceptionAsString(Throwable t) {
137
		final StringWriter stringWriter = new StringWriter();
138
		final PrintWriter printWriter = new PrintWriter(stringWriter);
139
		t.printStackTrace(printWriter);
140
		final String result = stringWriter.toString();
141
		try {
142
			stringWriter.close();
143
		} catch (final IOException e) {
144
			// $JL-EXC$ ignore
145
		}
146
		printWriter.close();
147
		return result;
148
	}
149
	
150
	public static IFile EmfResourceToIFile(Resource resource)
151
	{
152
		IFile ifile = null;
153
		
154
		URI uri = resource.getURI();
155
	    uri = resource.getResourceSet().getURIConverter().normalize(uri);
156
	    
157
	    String scheme = uri.scheme();
158
	    if ("platform".equals(scheme) && uri.segmentCount() > 1 &&
159
	    		"resource".equals(uri.segment(0)))
160
	    {
161
	    	StringBuffer platformResourcePath = new StringBuffer();
162
	    	for (int j = 1, size = uri.segmentCount(); j < size; ++j)
163
	    	{
164
	    		platformResourcePath.append('/');
165
	    		platformResourcePath.append(uri.segment(j));
166
	    	}
167
	    	return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformResourcePath.toString()));
168
	    }
169
		return ifile;
170
	}
171
172
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditor.java (+236 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.editor;
2
3
import java.util.Collection;
4
import java.util.HashSet;
5
import java.util.Iterator;
6
import java.util.List;
7
8
import org.eclipse.core.runtime.IProgressMonitor;
9
import org.eclipse.emf.transaction.RecordingCommand;
10
import org.eclipse.emf.transaction.TransactionalEditingDomain;
11
import org.eclipse.emf.transaction.util.TransactionUtil;
12
import org.eclipse.graphiti.features.IAddFeature;
13
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
14
import org.eclipse.graphiti.features.context.impl.AddContext;
15
import org.eclipse.graphiti.mm.algorithms.styles.Point;
16
import org.eclipse.graphiti.mm.pictograms.Anchor;
17
import org.eclipse.graphiti.mm.pictograms.Connection;
18
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
19
import org.eclipse.graphiti.mm.pictograms.Diagram;
20
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
21
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
22
import org.eclipse.graphiti.mm.pictograms.Shape;
23
import org.eclipse.graphiti.services.Graphiti;
24
import org.eclipse.graphiti.ui.editor.DiagramEditor;
25
import org.eclipse.sapphire.modeling.IModelElement;
26
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
27
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionTemplate;
28
import org.eclipse.sapphire.ui.diagram.editor.DiagramEmbeddedConnectionTemplate;
29
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper;
30
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper.Bounds;
31
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
32
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate;
33
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
34
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
35
36
@SuppressWarnings("restriction")
37
public class SapphireDiagramEditor extends DiagramEditor 
38
{
39
	private SapphireDiagramEditorPart diagramPart;
40
	
41
	public SapphireDiagramEditor(SapphireDiagramEditorPart diagramPart)
42
	{
43
		this.diagramPart = diagramPart;
44
	}
45
	
46
	public SapphireDiagramEditorPart getDiagramEditorPart()
47
	{
48
		return this.diagramPart;
49
	}
50
	
51
	@Override
52
	public void doSave(final IProgressMonitor monitor )
53
	{
54
		super.doSave(monitor);
55
		try
56
		{
57
			this.diagramPart.getDiagramGeometry().write();
58
		}
59
        catch( Exception e )
60
        {
61
            SapphireUiFrameworkPlugin.log( e );
62
        }		
63
	}
64
	
65
	public void syncDiagramWithModel()
66
	{
67
		final Diagram diagram = getDiagramTypeProvider().getDiagram();
68
		
69
		TransactionalEditingDomain ted = TransactionUtil.getEditingDomain(diagram);
70
		ted.getCommandStack().execute(new RecordingCommand(ted) 
71
		{
72
			protected void doExecute() 
73
			{		
74
				removeConnections(diagram);
75
				removeNodes(diagram);
76
				
77
				reconstructNodes(diagram);
78
				reconstructConnections(diagram);
79
			}
80
		});
81
	}
82
	
83
	private void removeConnections(final Diagram diagram) 
84
	{
85
		List<Connection> cons = diagram.getConnections();
86
		Iterator<Connection> consIt = cons.iterator();
87
		// don't cause ConcurrentModificationException
88
		Collection<Connection> allCons = new HashSet<Connection>();
89
		while (consIt.hasNext()) 
90
		{
91
			Connection con = consIt.next();
92
			allCons.add(con);
93
		}
94
		consIt = allCons.iterator();
95
		while (consIt.hasNext()) 
96
		{
97
			Connection con = consIt.next();			
98
			Graphiti.getPeService().deletePictogramElement(con);
99
		}		
100
	}
101
	
102
	private void removeNodes(final Diagram diagram)
103
	{
104
		List<Shape> containerShapes = diagram.getChildren();
105
		Iterator<Shape> shapeIt = containerShapes.iterator();
106
		// don't cause ConcurrentModificationException
107
		Collection<Shape> allShapes = new HashSet<Shape>();
108
		while (shapeIt.hasNext())
109
		{
110
			Shape shape = shapeIt.next();
111
			allShapes.add(shape);
112
		}
113
		shapeIt = allShapes.iterator();
114
		while (shapeIt.hasNext())
115
		{
116
			Shape containerShape = shapeIt.next();
117
			Graphiti.getPeService().deletePictogramElement(containerShape);
118
		}
119
	}
120
	
121
	private void reconstructNodes(final Diagram diagram)
122
	{
123
		// Add the nodes back to the diagram thus re-establishing mapping between
124
		// pictograms and business objects
125
		
126
		int nodeX = 50;
127
		int nodeY = 50;
128
		int xInc = 100;
129
		DiagramGeometryWrapper diagramGeometry = this.diagramPart.getDiagramGeometry();
130
		
131
		for (DiagramNodeTemplate nodeTemplate : this.diagramPart.getNodeTemplates())
132
		{
133
			for (DiagramNodePart nodePart : nodeTemplate.getDiagramNodes())
134
			{
135
				Bounds bounds = diagramGeometry.getNode(nodePart);
136
				if (bounds == null)
137
				{
138
					bounds = new Bounds(nodeX, nodeY, -1, -1);
139
					nodeX += xInc;
140
				}
141
				AddContext ctx = new AddContext();
142
				ctx.setNewObject(nodePart);
143
				ctx.setTargetContainer(diagram);
144
				ctx.setWidth(bounds.width);
145
				ctx.setHeight(bounds.height);
146
				ctx.setX(bounds.x);
147
				ctx.setY(bounds.y);
148
				IAddFeature ft = getDiagramTypeProvider().getFeatureProvider().getAddFeature(ctx);						
149
				ft.add(ctx);						
150
			}
151
			
152
			// add embedded connections
153
			DiagramEmbeddedConnectionTemplate embeddedConnTemplate = 
154
				nodeTemplate.getEmbeddedConnectionTemplate();
155
			if (embeddedConnTemplate != null)
156
			{
157
				for (DiagramConnectionPart connPart : embeddedConnTemplate.getDiagramConnections())
158
				{
159
					addConnection(connPart, diagramGeometry);
160
				}
161
			}
162
		}		
163
	}
164
	
165
	private void reconstructConnections(final Diagram diagram)
166
	{
167
		DiagramGeometryWrapper diagramGeometry = this.diagramPart.getDiagramGeometry();
168
		
169
		// add the top level connections back to the diagram
170
		for (DiagramConnectionTemplate connTemplate : this.diagramPart.getConnectionTemplates())
171
		{
172
			for (DiagramConnectionPart connPart : connTemplate.getDiagramConnections())
173
			{
174
				addConnection(connPart, diagramGeometry);
175
			}
176
		}		
177
	}
178
	
179
	private ContainerShape getContainerShape(Object bo)
180
	{
181
		ContainerShape containerShape = null;
182
		PictogramElement [] pictograms = 
183
			getDiagramTypeProvider().getFeatureProvider().getAllPictogramElementsForBusinessObject(bo);
184
		for (PictogramElement pictogram : pictograms)
185
		{
186
			if (pictogram instanceof ContainerShape)
187
			{
188
				containerShape = (ContainerShape)pictogram;
189
				break;
190
			}
191
		}
192
		return containerShape;
193
	}
194
	
195
	private Connection addConnection(DiagramConnectionPart connPart, DiagramGeometryWrapper diagramGeometry)
196
	{
197
		Connection conn = null;
198
		
199
		IModelElement endpoint1 = connPart.getEndpoint1();
200
		IModelElement endpoint2 = connPart.getEndpoint2();
201
		DiagramNodePart nodePart1 = this.diagramPart.getDiagramNodePart(endpoint1);
202
		DiagramNodePart nodePart2 = this.diagramPart.getDiagramNodePart(endpoint2);
203
		if (nodePart1 != null && nodePart2 != null)
204
		{
205
			ContainerShape sourceShape = getContainerShape(nodePart1);
206
			ContainerShape targetShape = getContainerShape(nodePart2);
207
			if (sourceShape != null && targetShape != null)
208
			{
209
				Anchor sourceAnchor = sourceShape.getAnchors().get(0);
210
				Anchor targetAnchor = targetShape.getAnchors().get(0);
211
				AddConnectionContext connCtx = new AddConnectionContext(sourceAnchor, targetAnchor);
212
				connCtx.setNewObject(connPart);
213
				IAddFeature fcfp = getDiagramTypeProvider().getFeatureProvider().getAddFeature(connCtx);
214
				
215
				conn = (Connection)fcfp.add(connCtx);
216
				if (conn instanceof FreeFormConnection && 
217
						diagramGeometry.getConnectionBendpoints(connPart) != null)
218
				{
219
					FreeFormConnection freeConn = (FreeFormConnection)conn;
220
					List<org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper.Point> bps = 
221
						diagramGeometry.getConnectionBendpoints(connPart);
222
					List<Point> bendpoints = freeConn.getBendpoints();
223
					int index = 0;
224
					for (org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper.Point pt : bps)
225
					{
226
						Point newPoint = Graphiti.getGaService().createPoint(pt.x, pt.y);										
227
						bendpoints.add(index++, newPoint);										
228
					}
229
				}
230
			}							
231
		}
232
		
233
		return conn;
234
	}
235
	
236
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorFactory.java (+120 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.editor;
2
3
import java.io.ByteArrayInputStream;
4
import java.io.IOException;
5
import java.util.Iterator;
6
7
import org.eclipse.core.resources.IFile;
8
import org.eclipse.core.resources.IFolder;
9
import org.eclipse.core.resources.IProject;
10
import org.eclipse.core.runtime.CoreException;
11
import org.eclipse.core.runtime.Path;
12
import org.eclipse.emf.common.util.EList;
13
import org.eclipse.emf.common.util.URI;
14
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.emf.ecore.resource.ResourceSet;
17
import org.eclipse.emf.transaction.TransactionalEditingDomain;
18
import org.eclipse.graphiti.mm.pictograms.Diagram;
19
import org.eclipse.graphiti.services.Graphiti;
20
import org.eclipse.graphiti.ui.editor.DiagramEditorFactory;
21
import org.eclipse.graphiti.ui.internal.services.GraphitiUiInternal;
22
import org.eclipse.graphiti.ui.services.GraphitiUi;
23
import org.eclipse.sapphire.modeling.util.internal.FileUtil;
24
import org.eclipse.sapphire.ui.diagram.graphiti.GraphitiFileService;
25
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
26
import org.eclipse.ui.IEditorInput;
27
import org.eclipse.ui.IFileEditorInput;
28
29
public class SapphireDiagramEditorFactory 
30
{
31
	public static final String SAPPHIRE_DIAGRAM_TYPE = "sapphireDiagram";
32
	
33
	public static SapphireDiagramEditorInput createEditorInput(IEditorInput otherInput) 
34
		throws CoreException
35
	{
36
		if (otherInput instanceof SapphireDiagramEditorInput)
37
		{
38
			return (SapphireDiagramEditorInput)otherInput;
39
		}
40
		else if (otherInput instanceof IFileEditorInput)
41
		{
42
			final IFileEditorInput fileInput = (IFileEditorInput) otherInput;
43
			final IFile file = fileInput.getFile();
44
			final IProject project = file.getProject();
45
			
46
			final IFolder diagramFolder = project.getFolder(".settings/diagrams/");
47
			String fileName = file.getName();
48
			if (fileName.endsWith(".xml"))
49
			{
50
				fileName = fileName.substring(0, fileName.indexOf(".xml"));
51
			}
52
			
53
			TransactionalEditingDomain domain = null;
54
			ResourceSet resourceSet = null;
55
			Diagram diagram = null;
56
			URI diagramFileUri = null;
57
			
58
			// create diagram file if it doesn't exist
59
			final IFile diagramFile = diagramFolder.getFile(fileName + ".xmi");
60
			if (!diagramFile.exists())
61
			{
62
				FileUtil.mkdirs( diagramFile.getParent().getLocation().toFile() );
63
				diagramFile.create( new ByteArrayInputStream(new byte[0]), true, null );
64
				
65
				// Create Diagram Obj
66
				diagram = Graphiti.getPeCreateService().createDiagram(
67
						SAPPHIRE_DIAGRAM_TYPE, fileName, 10, false);
68
				diagramFileUri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
69
				domain = GraphitiFileService.createEmfFileForDiagram(diagramFileUri, diagram);
70
			}
71
			else
72
			{			
73
				domain = DiagramEditorFactory.createResourceSetAndEditingDomain();
74
				resourceSet = domain.getResourceSet();
75
			
76
				diagramFileUri = GraphitiUiInternal.getEmfService().getFileURI(diagramFile, resourceSet);
77
				if (diagramFileUri != null)
78
				{
79
					final Resource resource = resourceSet.createResource(diagramFileUri);
80
					try
81
					{
82
						resource.load(null);
83
					}
84
					catch (IOException ie)
85
					{
86
						SapphireUiFrameworkPlugin.log(ie);
87
					}
88
					EList<EObject> objs = resource.getContents();
89
					Iterator<EObject> it = objs.iterator();					
90
					while (it.hasNext()) 
91
					{
92
						EObject obj = it.next();
93
						if ((obj == null) && !Diagram.class.isInstance(obj))
94
							continue;
95
						diagram = (Diagram)obj;
96
						break;
97
					}
98
				}				
99
			}
100
			// create diagram node position file if it doesn't exist
101
			IFile nodePosFile = diagramFile.getParent().getFile(new Path(fileName + ".np"));
102
			if (!nodePosFile.exists())
103
			{
104
				nodePosFile.create( new ByteArrayInputStream(new byte[0]), true, null );
105
			}
106
107
			// create sapphire diagram editor input
108
			if (diagram != null)
109
			{
110
				String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
111
				final SapphireDiagramEditorInput diagramEditorInput = 
112
					SapphireDiagramEditorInput.createEditorInput(diagram, domain, providerId, false);
113
				diagramEditorInput.setNodePositionFile(nodePosFile);
114
				return diagramEditorInput;
115
			}
116
		}
117
		return null;
118
	}
119
120
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorInput.java (+91 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.editor;
2
3
import org.eclipse.core.resources.IFile;
4
import org.eclipse.emf.common.util.URI;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.emf.ecore.resource.Resource;
7
import org.eclipse.emf.ecore.resource.ResourceSet;
8
import org.eclipse.emf.transaction.TransactionalEditingDomain;
9
import org.eclipse.graphiti.mm.pictograms.Diagram;
10
import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
11
12
public class SapphireDiagramEditorInput extends DiagramEditorInput 
13
{
14
	private Diagram diagram;
15
	private IFile nodePositionFile;
16
	
17
	public SapphireDiagramEditorInput(Diagram diagram, String diagramUriString,
18
			TransactionalEditingDomain domain, String providerId,
19
			boolean disposeEditingDomain) 
20
	{
21
		super(diagramUriString, domain, providerId, disposeEditingDomain);
22
		this.diagram = diagram;
23
	}
24
25
	public SapphireDiagramEditorInput(Diagram diagram, URI diagramUri,
26
			TransactionalEditingDomain domain, String providerId,
27
			boolean disposeEditingDomain) 
28
	{
29
		super(diagramUri, domain, providerId, disposeEditingDomain);
30
		this.diagram = diagram;
31
	}
32
	
33
	public Diagram getDiagram() 
34
	{
35
		return this.diagram;
36
	}	
37
	
38
	public TransactionalEditingDomain getEditingDomain() 
39
	{
40
		return this.editingDomain;
41
	}
42
	
43
	@SuppressWarnings("rawtypes")
44
	public Object getAdapter(Class adapter) 
45
	{
46
		if (EObject.class.isAssignableFrom(adapter)) 
47
		{
48
			return getDiagram();
49
		} 
50
		else if (Diagram.class.isAssignableFrom(adapter)) 
51
		{
52
			return getDiagram();
53
		}
54
		else if (TransactionalEditingDomain.class.isAssignableFrom(adapter)) 
55
		{
56
			return getEditingDomain();
57
		} 
58
		else if (ResourceSet.class.isAssignableFrom(adapter)) 
59
		{
60
			return getEditingDomain().getResourceSet();
61
		}		
62
		return null;
63
	}
64
	
65
	public IFile getNodePositionFile()
66
	{
67
		return this.nodePositionFile;
68
	}
69
	
70
	public void setNodePositionFile(IFile file)
71
	{
72
		this.nodePositionFile = file;
73
	}
74
	
75
	
76
	public static SapphireDiagramEditorInput createEditorInput(Diagram diagram, 
77
			TransactionalEditingDomain domain, String providerId, boolean disposeEditingDomain) 
78
	{
79
		final Resource resource = diagram.eResource();
80
		if (resource == null) {
81
			throw new IllegalArgumentException();
82
		}
83
		final String fragment = resource.getURIFragment(diagram);
84
		final URI fragmentUri = resource.getURI().appendFragment(fragment);
85
		SapphireDiagramEditorInput diagramEditorInput;
86
		diagramEditorInput = new SapphireDiagramEditorInput(diagram, fragmentUri,
87
				domain, providerId, disposeEditingDomain);
88
		return diagramEditorInput;
89
	}	
90
	
91
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/NoResizeConfiguration.java (+17 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IResizeConfiguration;
4
5
public class NoResizeConfiguration implements IResizeConfiguration 
6
{
7
	public boolean isVerticalResizeAllowed() 
8
	{
9
		return false;
10
	}
11
12
	public boolean isHorizontalResizeAllowed() 
13
	{
14
		return false;
15
	}
16
17
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddBendpointFeature.java (+33 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.context.IAddBendpointContext;
5
import org.eclipse.graphiti.features.impl.DefaultAddBendpointFeature;
6
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
7
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
8
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper;
9
import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider;
10
11
public class SapphireAddBendpointFeature extends DefaultAddBendpointFeature 
12
{
13
	public SapphireAddBendpointFeature(IFeatureProvider fp)
14
	{
15
		super(fp);
16
	}
17
	
18
	@Override
19
	public void addBendpoint(IAddBendpointContext context) 
20
	{
21
		super.addBendpoint(context);
22
		
23
		FreeFormConnection freeFormConnection = context.getConnection();
24
		Object bo = getBusinessObjectForPictogramElement(freeFormConnection);
25
		if (bo instanceof DiagramConnectionPart)
26
		{
27
			DiagramGeometryWrapper dg = 
28
				((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry();
29
			dg.addConnectionBendpoint((DiagramConnectionPart)bo, 
30
					context.getBendpointIndex(), context.getX(), context.getY());
31
		}		
32
	}	
33
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddConnectionFeature.java (+97 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IDirectEditingInfo;
4
import org.eclipse.graphiti.features.IFeatureProvider;
5
import org.eclipse.graphiti.features.context.IAddConnectionContext;
6
import org.eclipse.graphiti.features.context.IAddContext;
7
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
8
import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
9
import org.eclipse.graphiti.mm.algorithms.Polygon;
10
import org.eclipse.graphiti.mm.algorithms.Polyline;
11
import org.eclipse.graphiti.mm.algorithms.Text;
12
import org.eclipse.graphiti.mm.pictograms.Connection;
13
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
14
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
15
import org.eclipse.graphiti.services.Graphiti;
16
import org.eclipse.graphiti.services.IGaService;
17
import org.eclipse.graphiti.services.IPeCreateService;
18
import org.eclipse.graphiti.util.IColorConstant;
19
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
20
21
public class SapphireAddConnectionFeature extends AbstractAddFeature 
22
{
23
	public SapphireAddConnectionFeature(IFeatureProvider fp)
24
	{
25
		super(fp);
26
	}
27
	
28
	public boolean canAdd(IAddContext context) 
29
	{
30
		// return true if given business object is an DiagramConnectionPart
31
		// note, that the context must be an instance of IAddConnectionContext
32
		if (context instanceof IAddConnectionContext && 
33
				context.getNewObject() instanceof DiagramConnectionPart) 
34
		{
35
			return true;
36
		}
37
		return false;
38
	}
39
40
	public PictogramElement add(IAddContext context) 
41
	{
42
		IAddConnectionContext addConContext = (IAddConnectionContext) context;
43
		DiagramConnectionPart connectionPart = (DiagramConnectionPart) context.getNewObject();
44
45
		IPeCreateService peCreateService = Graphiti.getPeCreateService();
46
		// CONNECTION WITH POLYLINE
47
		Connection connection = peCreateService.createFreeFormConnection(getDiagram());
48
		connection.setStart(addConContext.getSourceAnchor());
49
		connection.setEnd(addConContext.getTargetAnchor());
50
51
		IGaService gaService = Graphiti.getGaService();
52
		Polyline polyline = gaService.createPolyline(connection);
53
		polyline.setForeground(manageColor(IColorConstant.BLACK));
54
		polyline.setLineWidth(1);
55
       
56
		// create link and wire it
57
		link(connection, connectionPart);
58
59
		// add dynamic text decorator for the reference name
60
		ConnectionDecorator textDecorator = peCreateService.createConnectionDecorator(connection, true, 0.5, true);
61
		Text text = gaService.createDefaultText(textDecorator);
62
		text.setForeground(manageColor(IColorConstant.BLACK));
63
		gaService.setLocation(text, 10, 0);		
64
		
65
		text.setValue(connectionPart.getLabel());
66
67
		// add static graphical decorators (composition and navigable)
68
		ConnectionDecorator cd;
69
		cd = peCreateService.createConnectionDecorator(connection, false, 1.0, true);
70
		createArrow(cd);
71
72
        // provide information to support direct-editing directly 
73
74
        // after object creation (must be activated additionally)
75
        IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
76
77
        // set container shape for direct editing after object creation
78
        directEditingInfo.setMainPictogramElement(connection);
79
80
        // set shape and graphics algorithm where the editor for
81
        // direct editing shall be opened after object creation
82
        directEditingInfo.setPictogramElement(textDecorator);
83
        directEditingInfo.setGraphicsAlgorithm(text);
84
		
85
		return connection;
86
	}
87
88
	private Polygon createArrow(GraphicsAlgorithmContainer gaContainer) 
89
	{
90
		Polygon polygon = Graphiti.getGaCreateService().createPolygon(gaContainer, new int[] { -8, 4, 0, 0, -8, -4, -5, 0 });
91
		polygon.setBackground(manageColor(IColorConstant.BLACK));
92
		//polygon.setStyle(StyleUtil.getStyleForADFView(getDiagram()));
93
		polygon.setFilled(true);
94
		return polygon;
95
	}
96
	
97
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireAddNodeFeature.java (+150 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IDirectEditingInfo;
4
import org.eclipse.graphiti.features.IFeatureProvider;
5
import org.eclipse.graphiti.features.context.IAddContext;
6
import org.eclipse.graphiti.features.impl.AbstractAddShapeFeature;
7
import org.eclipse.graphiti.mm.algorithms.Image;
8
import org.eclipse.graphiti.mm.algorithms.Polyline;
9
import org.eclipse.graphiti.mm.algorithms.Rectangle;
10
import org.eclipse.graphiti.mm.algorithms.Text;
11
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
12
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
13
import org.eclipse.graphiti.mm.pictograms.Diagram;
14
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
15
import org.eclipse.graphiti.mm.pictograms.Shape;
16
import org.eclipse.graphiti.services.Graphiti;
17
import org.eclipse.graphiti.services.IGaService;
18
import org.eclipse.graphiti.services.IPeCreateService;
19
import org.eclipse.graphiti.util.ColorConstant;
20
import org.eclipse.graphiti.util.IColorConstant;
21
import org.eclipse.sapphire.ui.def.ISapphirePartDef;
22
import org.eclipse.sapphire.ui.diagram.def.IDiagramLabelDef;
23
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef;
24
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeImageDef;
25
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper;
26
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
27
import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider;
28
29
public class SapphireAddNodeFeature extends AbstractAddShapeFeature 
30
{
31
    private static final IColorConstant CLASS_TEXT_FOREGROUND = new ColorConstant(51, 51, 153);
32
    private static final IColorConstant CLASS_FOREGROUND = new ColorConstant(255, 102, 0);
33
    private static final IColorConstant CLASS_BACKGROUND =  new ColorConstant(255, 204, 153);
34
	
35
	public SapphireAddNodeFeature(IFeatureProvider fp)
36
	{
37
		super(fp);
38
	}
39
	
40
	public boolean canAdd(IAddContext context) 
41
	{
42
		Object newObj = context.getNewObject();
43
		if (newObj instanceof DiagramNodePart && context.getTargetContainer() instanceof Diagram)
44
		{
45
			return true;
46
		}
47
		return false;
48
	}
49
50
	public PictogramElement add(IAddContext context)
51
	{
52
		DiagramNodePart nodePart = (DiagramNodePart)context.getNewObject();
53
		final Diagram targetDiagram = (Diagram) context.getTargetContainer();
54
		
55
        // define a default size for the shape
56
        IDiagramNodeDef nodeDef = (IDiagramNodeDef)nodePart.getDefinition();
57
        int width = nodeDef.getHint(ISapphirePartDef.HINT_WIDTH, -1);
58
        int height = nodeDef.getHint(ISapphirePartDef.HINT_HEIGHT, -1);
59
60
        // CONTAINER SHAPE WITH RECTANGLE
61
        IPeCreateService peCreateService = Graphiti.getPeCreateService();
62
        ContainerShape containerShape =  peCreateService.createContainerShape(targetDiagram, true);
63
        IGaService gaService = Graphiti.getGaService();
64
        
65
        // TODO clean this up
66
        // The temporary logic is to create a default rectangle if no icon is associated with the node
67
        if (nodeDef.getImage().element() == null)
68
        {
69
            // create and set graphics algorithm
70
            Rectangle rectangle = gaService.createRectangle(containerShape);
71
            rectangle.setForeground(manageColor(CLASS_FOREGROUND));
72
            rectangle.setBackground(manageColor(CLASS_BACKGROUND));
73
            rectangle.setLineWidth(2);
74
            gaService.setLocationAndSize(rectangle,
75
                context.getX(), context.getY(), width, height);
76
 
77
            // create link and wire it
78
            link(containerShape, nodePart);
79
        		
80
	        // SHAPE WITH LINE
81
	        {
82
	            // create shape for line
83
	            Shape shape = peCreateService.createShape(containerShape, false);
84
	 
85
	            // create and set graphics algorithm
86
	            Polyline polyline =
87
	                gaService.createPolyline(shape, new int[] { 0, 20, width, 20 });
88
	            polyline.setForeground(manageColor(CLASS_FOREGROUND));
89
	            polyline.setLineWidth(2);
90
	        }
91
        }
92
        else
93
        {
94
        	IDiagramNodeImageDef imageDef = nodeDef.getImage().element();
95
        	Rectangle rectangle = gaService.createRectangle(containerShape);
96
        	rectangle.setFilled(false);
97
        	rectangle.setLineVisible(false);
98
        	gaService.setLocationAndSize(rectangle, context.getX(), context.getY(), width, height);
99
        	
100
        	link(containerShape, nodePart);
101
        	
102
            // Shape with Image
103
            {
104
            	Shape shape = peCreateService.createShape(containerShape, false);
105
            	String imageId = imageDef.getImageId().getContent();
106
            	Image image = gaService.createImage(shape, imageId);
107
            	int imageX = imageDef.getHint("x", 0);
108
            	int imageY = imageDef.getHint("y", 0);
109
                int imageWidth = imageDef.getHint(ISapphirePartDef.HINT_WIDTH, width);
110
                int imageHeight = imageDef.getHint(ISapphirePartDef.HINT_HEIGHT, -1);
111
            	
112
    	        gaService.setLocationAndSize(image, imageX, imageY, imageWidth, imageHeight);
113
            }        	
114
        }
115
116
        if (nodeDef.getLabel().element() != null)
117
        {
118
            // create shape for text
119
            Shape shape = peCreateService.createShape(containerShape, false);
120
 
121
            // create and set text graphics algorithm
122
            Text text = gaService.createDefaultText(shape, nodePart.getLabel());
123
            text.setForeground(manageColor(CLASS_TEXT_FOREGROUND));
124
            text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
125
            text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
126
127
            IDiagramLabelDef labelDef = nodeDef.getLabel().element();
128
            int labelX = labelDef.getHint("x", 0);
129
        	int labelY = labelDef.getHint("y", 0);            
130
            int labelWidth = labelDef.getHint(ISapphirePartDef.HINT_WIDTH, width);
131
            int labelHeight = labelDef.getHint(ISapphirePartDef.HINT_HEIGHT, 15);
132
            
133
            gaService.setLocationAndSize(text, labelX, labelY, labelWidth, labelHeight);
134
 
135
            // create link and wire it
136
            link(shape, nodePart);            
137
        }
138
        
139
        // add a chopbox anchor to the shape
140
        peCreateService.createChopboxAnchor(containerShape);
141
        
142
        // Save the node bounds
143
        DiagramGeometryWrapper diagramGeometry = 
144
        	((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry();
145
        diagramGeometry.addNode(nodePart, context.getX(), context.getY(), width, height);
146
        
147
		return containerShape;
148
	}
149
150
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateConnectionFeature.java (+93 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
5
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
6
import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
7
import org.eclipse.graphiti.mm.pictograms.Anchor;
8
import org.eclipse.graphiti.mm.pictograms.Connection;
9
import org.eclipse.sapphire.ui.SapphirePart;
10
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
11
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionTemplate;
12
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
13
14
public class SapphireCreateConnectionFeature extends AbstractCreateConnectionFeature 
15
{
16
	private DiagramConnectionTemplate connectionTemplate;
17
	
18
	public SapphireCreateConnectionFeature(IFeatureProvider fp, DiagramConnectionTemplate connectionTemplate)
19
	{
20
		super(fp, connectionTemplate.getToolPaletteLabel(), connectionTemplate.getToolPaletteDesc());
21
		this.connectionTemplate = connectionTemplate;		
22
	}
23
	
24
	public boolean canCreate(ICreateConnectionContext context) 
25
	{
26
		// return true if both anchors belong to an IModelElement
27
		// and those model elements are not identical
28
		SapphirePart source = getEndpoint(context.getSourceAnchor());
29
		SapphirePart target = getEndpoint(context.getTargetAnchor());
30
		if (source instanceof DiagramNodePart && 
31
				target instanceof DiagramNodePart && source != target) 
32
		{
33
			return this.connectionTemplate.canCreateNewConnection((DiagramNodePart)source, 
34
					(DiagramNodePart)target);
35
		}
36
		return false;
37
	}
38
39
	public Connection create(ICreateConnectionContext context) 
40
	{
41
		Connection newConnection = null;
42
43
		// get model elements which should be connected
44
		SapphirePart source = getEndpoint(context.getSourceAnchor());
45
		SapphirePart target = getEndpoint(context.getTargetAnchor());
46
47
		if (source instanceof DiagramNodePart && target instanceof DiagramNodePart) 
48
		{
49
			DiagramNodePart sourceNode = (DiagramNodePart)source;
50
			DiagramNodePart targetNode = (DiagramNodePart)target;
51
			// create new business object
52
			DiagramConnectionPart connectionPart = 
53
				this.connectionTemplate.createNewDiagramConnection(sourceNode, targetNode);
54
55
			// add connection for business object
56
			AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
57
			addContext.setNewObject(connectionPart);
58
			newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);
59
			
60
	        // activate direct editing after object creation
61
	        getFeatureProvider().getDirectEditingInfo().setActive(true);
62
		}
63
64
		return newConnection;
65
	}
66
67
	public boolean canStartConnection(ICreateConnectionContext context) 
68
	{
69
		// return true if start anchor belongs to an IModelElement
70
		if (getEndpoint(context.getSourceAnchor()) instanceof DiagramNodePart) 
71
		{
72
			return true;
73
		}
74
		return false;
75
	}
76
77
	/**
78
	 * Returns the SapphirePart belonging to the anchor, or null if not available.
79
	 */
80
	private SapphirePart getEndpoint(Anchor anchor) 
81
	{
82
		if (anchor != null) 
83
		{
84
			Object obj = getBusinessObjectForPictogramElement(anchor.getParent());
85
			if (obj instanceof SapphirePart) 
86
			{
87
				return (SapphirePart) obj;
88
			}
89
		}
90
		return null;
91
	}
92
	
93
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateNodeFeature.java (+32 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.context.ICreateContext;
5
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
6
import org.eclipse.graphiti.mm.pictograms.Diagram;
7
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
8
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate;
9
10
public class SapphireCreateNodeFeature extends AbstractCreateFeature 
11
{
12
	private DiagramNodeTemplate nodeTemplate;
13
	
14
	public SapphireCreateNodeFeature(IFeatureProvider fp, DiagramNodeTemplate nodeTemplate)
15
	{
16
		super(fp, nodeTemplate.getToolPaletteLabel(), nodeTemplate.getToolPaletteDesc());
17
		this.nodeTemplate = nodeTemplate;		
18
	}
19
20
	public boolean canCreate(ICreateContext context) 
21
	{		
22
		return context.getTargetContainer() instanceof Diagram;
23
	}
24
25
	public Object[] create(ICreateContext context) 
26
	{
27
		DiagramNodePart nodePart = this.nodeTemplate.createNewDiagramNode();
28
		
29
		addGraphicalRepresentation(context, nodePart);
30
		return new Object[] { nodePart };
31
	}
32
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditConnectionFeature.java (+62 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.context.IDirectEditingContext;
5
import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature;
6
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
7
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
8
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
9
10
public class SapphireDirectEditConnectionFeature extends AbstractDirectEditingFeature 
11
{
12
	public SapphireDirectEditConnectionFeature(IFeatureProvider fp)
13
	{
14
		super(fp);
15
	}
16
	
17
	public int getEditingType() 
18
	{
19
		return TYPE_TEXT;
20
	}
21
22
	@Override
23
	public boolean canDirectEdit(IDirectEditingContext context) 
24
	{
25
		PictogramElement pe = (PictogramElement)context.getPictogramElement().eContainer();
26
		Object bo = getBusinessObjectForPictogramElement(pe);
27
		// support direct editing, if it is a DiagramConnectionPart, and the 
28
		// DiagramConnectionPart contains editable label
29
		if (bo instanceof DiagramConnectionPart && 
30
				((DiagramConnectionPart)bo).canEditLabel()) 
31
		{
32
			return true;
33
		}
34
		// direct editing not supported in all other cases
35
		return false;
36
	}
37
	
38
	public String getInitialValue(IDirectEditingContext context) 
39
	{
40
		PictogramElement pe = (PictogramElement)context.getPictogramElement().eContainer();
41
		Object bo = getBusinessObjectForPictogramElement(pe);
42
		if (bo instanceof DiagramConnectionPart)
43
		{
44
			DiagramConnectionPart connPart = (DiagramConnectionPart)bo;
45
			return connPart.getLabel();
46
		}
47
		return null;
48
	}
49
50
	public void setValue(String value, IDirectEditingContext context) 
51
	{
52
		PictogramElement pe = (PictogramElement)context.getPictogramElement().eContainer();
53
		Object bo = getBusinessObjectForPictogramElement(pe);
54
		if (bo instanceof DiagramConnectionPart)
55
		{
56
			DiagramConnectionPart connPart = (DiagramConnectionPart)bo;
57
			connPart.setLabel(value);
58
			updatePictogramElement(pe);
59
		}
60
	}
61
62
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireDirectEditNodeFeature.java (+103 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import java.util.Iterator;
4
5
import org.eclipse.graphiti.features.IFeatureProvider;
6
import org.eclipse.graphiti.features.context.IDirectEditingContext;
7
import org.eclipse.graphiti.features.impl.AbstractDirectEditingFeature;
8
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
9
import org.eclipse.graphiti.mm.algorithms.Text;
10
import org.eclipse.graphiti.mm.pictograms.Anchor;
11
import org.eclipse.graphiti.mm.pictograms.Connection;
12
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
13
import org.eclipse.graphiti.mm.pictograms.Shape;
14
import org.eclipse.graphiti.services.Graphiti;
15
import org.eclipse.sapphire.modeling.IModelElement;
16
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
17
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
18
19
public class SapphireDirectEditNodeFeature extends AbstractDirectEditingFeature 
20
{
21
	public SapphireDirectEditNodeFeature(IFeatureProvider fp)
22
	{
23
		super(fp);
24
	}
25
	
26
	public int getEditingType() 
27
	{
28
		return TYPE_TEXT;
29
	}
30
31
	@Override
32
	public boolean canDirectEdit(IDirectEditingContext context) 
33
	{
34
		PictogramElement pe = context.getPictogramElement();
35
		Object bo = getBusinessObjectForPictogramElement(pe);
36
		GraphicsAlgorithm ga = context.getGraphicsAlgorithm();
37
		// support direct editing, if it is a DiagramNodePart, and the user clicked
38
		// directly on the text and not somewhere else in the rectangle
39
		if (bo instanceof DiagramNodePart && ga instanceof Text) 
40
		{
41
			return ((DiagramNodePart)bo).canEditLabel();
42
		}
43
		// direct editing not supported in all other cases
44
		return false;
45
	}
46
47
	public String getInitialValue(IDirectEditingContext context) 
48
	{
49
		// return the current label of the node
50
		PictogramElement pe = context.getPictogramElement();
51
		DiagramNodePart nodePart = (DiagramNodePart)getBusinessObjectForPictogramElement(pe);
52
		return nodePart.getLabel();
53
	}
54
55
	public void setValue(String value, IDirectEditingContext context) 
56
	{
57
		PictogramElement pe = context.getPictogramElement();
58
				
59
		if (pe.eContainer() instanceof Shape)
60
		{
61
			DiagramNodePart nodePart = (DiagramNodePart)getBusinessObjectForPictogramElement(pe);
62
			nodePart.setLabel(value);
63
			IModelElement nodeElement = nodePart.getLocalModelElement();
64
			Shape nodeShape = (Shape)pe.eContainer();
65
			
66
			// go through all the connections associated with this bo and update them
67
			for (Iterator<Anchor> iter = nodeShape.getAnchors().iterator(); iter.hasNext();) 
68
			{
69
				Anchor anchor = iter.next();
70
				for (Iterator<Connection> iterator = Graphiti.getPeService().getAllConnections(anchor).iterator(); iterator.hasNext();) 
71
				{
72
					Connection connection = iterator.next();
73
					Object bo = getBusinessObjectForPictogramElement(connection);
74
					if (bo instanceof DiagramConnectionPart)
75
					{
76
						DiagramConnectionPart connectionPart = (DiagramConnectionPart)bo;
77
						IModelElement endpoint1 = connectionPart.getEndpoint1();
78
						IModelElement endpoint2 = connectionPart.getEndpoint2();
79
						if (endpoint1 == nodeElement)
80
						{
81
							connectionPart.refreshEndpoint1();
82
						}
83
						else if (endpoint2 == nodeElement)
84
						{
85
							connectionPart.refreshEndpoint2();
86
						}
87
					}
88
				}
89
			}
90
			
91
		}
92
				
93
		// Explicitly update the shape to display the new value in the diagram
94
		// Note, that this might not be necessary in future versions of Graphiti
95
		// (currently in discussion)
96
97
		// we know, that pe is the Shape of the Text, so its container is the
98
		// main shape of the node
99
		updatePictogramElement(((Shape)pe).getContainer());
100
101
	}
102
103
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveBendpointFeature.java (+36 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.context.IMoveBendpointContext;
5
import org.eclipse.graphiti.features.impl.DefaultMoveBendpointFeature;
6
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
7
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
8
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper;
9
import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider;
10
11
public class SapphireMoveBendpointFeature extends DefaultMoveBendpointFeature 
12
{
13
	public SapphireMoveBendpointFeature(IFeatureProvider fp)
14
	{
15
		super(fp);
16
	}
17
	
18
	@Override
19
	public boolean moveBendpoint(IMoveBendpointContext context) 
20
	{
21
		boolean ret = false;
22
		super.moveBendpoint(context);
23
		
24
		FreeFormConnection freeFormConnection = context.getConnection();
25
		Object bo = getBusinessObjectForPictogramElement(freeFormConnection);
26
		if (bo instanceof DiagramConnectionPart)
27
		{
28
			DiagramGeometryWrapper dg = 
29
				((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry();
30
			ret = dg.updateConnectionBendpoint((DiagramConnectionPart)bo, 
31
					context.getBendpointIndex(), context.getX(), context.getY());
32
		}		
33
		return ret;
34
	}
35
	
36
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireMoveNodeFeature.java (+31 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.context.IMoveShapeContext;
5
import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature;
6
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
7
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper;
8
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
9
import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider;
10
11
public class SapphireMoveNodeFeature extends DefaultMoveShapeFeature 
12
{
13
	public SapphireMoveNodeFeature(IFeatureProvider fp)
14
	{
15
		super(fp);
16
	}
17
	
18
	@Override
19
	protected void internalMove(IMoveShapeContext context) 
20
	{
21
		super.internalMove(context);
22
 		PictogramElement pe = context.getPictogramElement();
23
 		Object bo = getBusinessObjectForPictogramElement(pe);
24
 		if (bo instanceof DiagramNodePart)
25
 		{
26
			DiagramGeometryWrapper dg = 
27
				((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry();
28
			dg.updateNode((DiagramNodePart)bo, context.getX(), context.getY());
29
 		}
30
	}
31
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireRemoveBendpointFeature.java (+34 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.context.IRemoveBendpointContext;
5
import org.eclipse.graphiti.features.impl.DefaultRemoveBendpointFeature;
6
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
7
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
8
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper;
9
import org.eclipse.sapphire.ui.diagram.graphiti.providers.SapphireDiagramFeatureProvider;
10
11
public class SapphireRemoveBendpointFeature extends DefaultRemoveBendpointFeature 
12
{
13
	public SapphireRemoveBendpointFeature(IFeatureProvider fp)
14
	{
15
		super(fp);
16
	}
17
	
18
	@Override
19
	public void removeBendpoint(IRemoveBendpointContext context) 
20
	{
21
		super.removeBendpoint(context);
22
		
23
		FreeFormConnection freeFormConnection = context.getConnection();
24
		Object bo = getBusinessObjectForPictogramElement(freeFormConnection);
25
		if (bo instanceof DiagramConnectionPart)
26
		{
27
			DiagramGeometryWrapper dg = 
28
				((SapphireDiagramFeatureProvider)getFeatureProvider()).getDiagramGeometry();
29
			dg.removeConnectionBendpoint((DiagramConnectionPart)bo, context.getBendpointIndex());
30
		}
31
		
32
	}
33
34
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireResizeShapeFeature.java (+41 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.DefaultResizeConfiguration;
4
import org.eclipse.graphiti.features.IFeatureProvider;
5
import org.eclipse.graphiti.features.IResizeConfiguration;
6
import org.eclipse.graphiti.features.context.IResizeShapeContext;
7
import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
8
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
9
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
10
11
public class SapphireResizeShapeFeature extends DefaultResizeShapeFeature 
12
{
13
	public SapphireResizeShapeFeature(IFeatureProvider fp)
14
	{
15
		super(fp);
16
	}
17
	
18
	@Override
19
	public boolean canResizeShape(IResizeShapeContext context) 
20
	{
21
		PictogramElement pe = context.getPictogramElement();
22
 		Object bo = getBusinessObjectForPictogramElement(pe);
23
 		if (bo instanceof DiagramNodePart)
24
 		{
25
 			DiagramNodePart nodePart = (DiagramNodePart)bo;
26
 			return nodePart.canResizeShape();
27
 		}
28
 		return super.canResizeShape(context);
29
	}
30
	
31
	@Override
32
	public IResizeConfiguration getResizeConfiguration(IResizeShapeContext context) 
33
	{
34
		if (!canResizeShape(context))
35
		{
36
			return new NoResizeConfiguration();
37
		}
38
		return new DefaultResizeConfiguration();
39
	}
40
	
41
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateConnectionFeature.java (+94 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.IReason;
5
import org.eclipse.graphiti.features.context.IUpdateContext;
6
import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
7
import org.eclipse.graphiti.features.impl.Reason;
8
import org.eclipse.graphiti.mm.algorithms.Text;
9
import org.eclipse.graphiti.mm.pictograms.Connection;
10
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
11
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
12
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
13
14
public class SapphireUpdateConnectionFeature extends AbstractUpdateFeature 
15
{
16
	public SapphireUpdateConnectionFeature(IFeatureProvider fp)
17
	{
18
		super(fp);
19
	}
20
	
21
	public boolean canUpdate(IUpdateContext context) 
22
	{
23
		PictogramElement pe = context.getPictogramElement();
24
		Object bo = getBusinessObjectForPictogramElement(pe);
25
		return bo instanceof DiagramConnectionPart;
26
	}
27
28
	public IReason updateNeeded(IUpdateContext context) 
29
	{
30
		// retrieve name from pictogram model
31
		String pictogramName = null;
32
		PictogramElement pictogramElement = context.getPictogramElement();
33
		if (pictogramElement instanceof Connection) {
34
			Connection c = (Connection) pictogramElement;
35
			for (ConnectionDecorator cd : c.getConnectionDecorators()) {
36
				if (cd.getGraphicsAlgorithm() instanceof Text) {
37
					Text text = (Text) cd.getGraphicsAlgorithm();
38
					pictogramName = text.getValue();
39
				}
40
			}
41
		}
42
43
		// retrieve name from business model
44
		String businessName = null;
45
		Object bo = getBusinessObjectForPictogramElement(pictogramElement);
46
		if (bo instanceof DiagramConnectionPart) 
47
		{
48
			DiagramConnectionPart connPart = (DiagramConnectionPart)bo;
49
			businessName = connPart.getLabel();
50
		}
51
52
		// update needed, if names are different
53
		boolean updateNameNeeded = ((pictogramName == null && businessName != null) || (pictogramName != null && !pictogramName
54
				.equals(businessName)));
55
		if (updateNameNeeded) 
56
		{
57
			return Reason.createTrueReason("Name is out of date"); //$NON-NLS-1$
58
		} 
59
		else
60
		{
61
			return Reason.createFalseReason();
62
		}
63
	}
64
65
	public boolean update(IUpdateContext context) 
66
	{
67
		String businessName = null;
68
		PictogramElement pe = context.getPictogramElement();
69
		Object bo = getBusinessObjectForPictogramElement(pe);
70
		if (bo instanceof DiagramConnectionPart) 
71
		{
72
			DiagramConnectionPart connPart = (DiagramConnectionPart)bo;
73
			businessName = connPart.getLabel();
74
		}
75
		
76
		// Set name in pictogram model
77
		if (pe instanceof Connection) 
78
		{
79
			Connection c = (Connection) pe;
80
			for (ConnectionDecorator cd : c.getConnectionDecorators()) 
81
			{
82
				if (cd.getGraphicsAlgorithm() instanceof Text)
83
				{
84
					Text text = (Text) cd.getGraphicsAlgorithm();
85
					text.setValue(businessName);
86
					return true;
87
				}
88
			}
89
		}
90
		
91
		return false;
92
	}
93
94
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireUpdateNodeFeature.java (+94 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.features;
2
3
import org.eclipse.graphiti.features.IFeatureProvider;
4
import org.eclipse.graphiti.features.IReason;
5
import org.eclipse.graphiti.features.context.IUpdateContext;
6
import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
7
import org.eclipse.graphiti.features.impl.Reason;
8
import org.eclipse.graphiti.mm.algorithms.Text;
9
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
10
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
11
import org.eclipse.graphiti.mm.pictograms.Shape;
12
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
13
14
public class SapphireUpdateNodeFeature extends AbstractUpdateFeature 
15
{
16
	public SapphireUpdateNodeFeature(IFeatureProvider fp)
17
	{
18
		super(fp);
19
	}
20
	
21
	public boolean canUpdate(IUpdateContext context) 
22
	{
23
		Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
24
		return bo instanceof DiagramNodePart;
25
	}
26
27
	public IReason updateNeeded(IUpdateContext context) 
28
	{
29
		// retrieve name from pictogram model
30
		String pictogramName = null;
31
		PictogramElement pictogramElement = context.getPictogramElement();
32
		if (pictogramElement instanceof ContainerShape) 
33
		{
34
			ContainerShape cs = (ContainerShape) pictogramElement;
35
			for (Shape shape : cs.getChildren()) 
36
			{
37
				if (shape.getGraphicsAlgorithm() instanceof Text) {
38
					Text text = (Text) shape.getGraphicsAlgorithm();
39
					pictogramName = text.getValue();
40
				}
41
			}
42
		}
43
		// retrieve name from business model
44
		String businessName = null;
45
		Object bo = getBusinessObjectForPictogramElement(pictogramElement);
46
		if (bo instanceof DiagramNodePart) 
47
		{
48
			DiagramNodePart nodePart = (DiagramNodePart) bo;
49
			businessName = nodePart.getLabel();
50
		}
51
		// update needed, if names are different
52
		boolean updateNameNeeded = 
53
			((pictogramName == null && businessName != null) || 
54
					(pictogramName != null && !pictogramName.equals(businessName)));
55
		if (updateNameNeeded) 
56
		{
57
			return Reason.createTrueReason("Name is out of date"); //$NON-NLS-1$
58
		} 
59
		else 
60
		{
61
			return Reason.createFalseReason();
62
		}		
63
	}
64
65
	public boolean update(IUpdateContext context) 
66
	{
67
		// retrieve name from business model
68
		String businessName = null;
69
		PictogramElement pictogramElement = context.getPictogramElement();
70
		Object bo = getBusinessObjectForPictogramElement(pictogramElement);
71
		if (bo instanceof DiagramNodePart) {
72
			DiagramNodePart nodePart = (DiagramNodePart) bo;
73
			businessName = nodePart.getLabel();
74
		}
75
76
		// Set name in pictogram model
77
		if (pictogramElement instanceof ContainerShape) 
78
		{
79
			ContainerShape cs = (ContainerShape) pictogramElement;
80
			for (Shape shape : cs.getChildren()) 
81
			{
82
				if (shape.getGraphicsAlgorithm() instanceof Text) 
83
				{
84
					Text text = (Text) shape.getGraphicsAlgorithm();
85
					text.setValue(businessName);
86
					return true;
87
				}
88
			}
89
		}
90
91
		return false;
92
	}
93
94
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramFeatureProvider.java (+208 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.providers;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
7
import org.eclipse.graphiti.features.IAddBendpointFeature;
8
import org.eclipse.graphiti.features.IAddFeature;
9
import org.eclipse.graphiti.features.ICreateConnectionFeature;
10
import org.eclipse.graphiti.features.ICreateFeature;
11
import org.eclipse.graphiti.features.IDirectEditingFeature;
12
import org.eclipse.graphiti.features.IMoveBendpointFeature;
13
import org.eclipse.graphiti.features.IMoveShapeFeature;
14
import org.eclipse.graphiti.features.IRemoveBendpointFeature;
15
import org.eclipse.graphiti.features.IResizeShapeFeature;
16
import org.eclipse.graphiti.features.IUpdateFeature;
17
import org.eclipse.graphiti.features.context.IAddBendpointContext;
18
import org.eclipse.graphiti.features.context.IAddContext;
19
import org.eclipse.graphiti.features.context.IDirectEditingContext;
20
import org.eclipse.graphiti.features.context.IMoveBendpointContext;
21
import org.eclipse.graphiti.features.context.IMoveShapeContext;
22
import org.eclipse.graphiti.features.context.IRemoveBendpointContext;
23
import org.eclipse.graphiti.features.context.IResizeShapeContext;
24
import org.eclipse.graphiti.features.context.IUpdateContext;
25
import org.eclipse.graphiti.features.impl.IIndependenceSolver;
26
import org.eclipse.graphiti.mm.pictograms.Connection;
27
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
28
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
29
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
30
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
31
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionTemplate;
32
import org.eclipse.sapphire.ui.diagram.editor.DiagramGeometryWrapper;
33
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
34
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate;
35
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
36
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddBendpointFeature;
37
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddConnectionFeature;
38
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddNodeFeature;
39
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireCreateConnectionFeature;
40
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireCreateNodeFeature;
41
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireDirectEditConnectionFeature;
42
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireDirectEditNodeFeature;
43
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireMoveBendpointFeature;
44
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireMoveNodeFeature;
45
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireRemoveBendpointFeature;
46
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireResizeShapeFeature;
47
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireUpdateConnectionFeature;
48
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireUpdateNodeFeature;
49
50
public class SapphireDiagramFeatureProvider extends DefaultFeatureProvider 
51
{
52
	private SapphireDiagramEditorPart diagramPart;
53
	
54
	public SapphireDiagramFeatureProvider(IDiagramTypeProvider dtp, IIndependenceSolver solver)
55
	{
56
		super(dtp);
57
		this.setIndependenceSolver(solver);
58
	}
59
	
60
	public void setDiagramPart(SapphireDiagramEditorPart diagramPart)
61
	{
62
		this.diagramPart = diagramPart;
63
		
64
	}
65
	
66
	public SapphireDiagramEditorPart getDiagramPart()
67
	{
68
		return this.diagramPart;
69
	}
70
	
71
	public DiagramGeometryWrapper getDiagramGeometry()
72
	{
73
		return this.diagramPart.getDiagramGeometry();
74
	}
75
	
76
	@Override
77
	public IAddFeature getAddFeature(IAddContext context) 
78
	{
79
		Object obj = context.getNewObject();
80
		if (obj instanceof DiagramNodePart)
81
		{
82
			return new SapphireAddNodeFeature(this);
83
		}
84
		else if (obj instanceof DiagramConnectionPart)
85
		{
86
			return new SapphireAddConnectionFeature(this);
87
		}
88
		
89
		return super.getAddFeature(context);
90
	}
91
	
92
	@Override
93
	public ICreateFeature[] getCreateFeatures() 
94
	{
95
		List<DiagramNodeTemplate> nodeTemplates = this.diagramPart.getNodeTemplates();
96
		ICreateFeature[] features = new ICreateFeature[nodeTemplates.size()];
97
		int i = 0;
98
		for (DiagramNodeTemplate nodeTemplate : nodeTemplates)
99
		{
100
			SapphireCreateNodeFeature createNodeFeature = 
101
				new SapphireCreateNodeFeature(this, nodeTemplate);
102
			features[i++] = createNodeFeature;
103
		}
104
		return features;
105
	}	
106
	
107
	@Override
108
    public ICreateConnectionFeature[] getCreateConnectionFeatures() 
109
	{
110
		List<DiagramConnectionTemplate> connectionTemplates = this.diagramPart.getConnectionTemplates();
111
		List<ICreateConnectionFeature> features = 
112
			new ArrayList<ICreateConnectionFeature>(connectionTemplates.size());
113
		for (DiagramConnectionTemplate connectionTemplate : connectionTemplates)
114
		{
115
			SapphireCreateConnectionFeature createConnectionFeature = 
116
				new SapphireCreateConnectionFeature(this, connectionTemplate);
117
			features.add(createConnectionFeature);
118
		}
119
		
120
		// Add Embedded connection features
121
		List<DiagramNodeTemplate> nodeTemplates = this.diagramPart.getNodeTemplates();
122
		for (DiagramNodeTemplate nodeTemplate : nodeTemplates)
123
		{
124
			DiagramConnectionTemplate connTemplate = nodeTemplate.getEmbeddedConnectionTemplate();
125
			if (connTemplate != null)
126
			{
127
				SapphireCreateConnectionFeature createConnectionFeature = 
128
					new SapphireCreateConnectionFeature(this, connTemplate);
129
				features.add(createConnectionFeature);
130
			}
131
		}		
132
		return features.toArray(new ICreateConnectionFeature[0]);
133
	}
134
	
135
	@Override
136
	public IDirectEditingFeature getDirectEditingFeature(IDirectEditingContext context) 
137
	{
138
		PictogramElement pe = context.getPictogramElement();
139
		Object bo = getBusinessObjectForPictogramElement((PictogramElement) pe.eContainer());
140
		if (bo instanceof DiagramNodePart)
141
		{
142
			return new SapphireDirectEditNodeFeature(this);
143
		}
144
		else if (bo instanceof DiagramConnectionPart)
145
		{
146
			return new SapphireDirectEditConnectionFeature(this);
147
		}
148
		return super.getDirectEditingFeature(context);		
149
	}
150
	
151
	@Override
152
	public IUpdateFeature getUpdateFeature(IUpdateContext context) 
153
	{
154
		PictogramElement pe = context.getPictogramElement();
155
		if (pe instanceof ContainerShape) 
156
		{
157
			Object bo = getBusinessObjectForPictogramElement(pe);
158
			if (bo instanceof DiagramNodePart) 
159
			{
160
				return new SapphireUpdateNodeFeature(this);
161
			}
162
		}
163
		else if (pe instanceof Connection)
164
		{
165
			Object bo = getBusinessObjectForPictogramElement(pe);
166
			if (bo instanceof DiagramConnectionPart)
167
			{
168
				return new SapphireUpdateConnectionFeature(this);
169
			}
170
		}
171
		return super.getUpdateFeature(context);
172
	}
173
	
174
	@Override
175
	public IAddBendpointFeature getAddBendpointFeature(IAddBendpointContext context) 
176
	{
177
		IAddBendpointFeature ret = new SapphireAddBendpointFeature(this);
178
		return ret;
179
	}
180
	
181
	@Override
182
	public IRemoveBendpointFeature getRemoveBendpointFeature(IRemoveBendpointContext context) 
183
	{
184
		IRemoveBendpointFeature ret = new SapphireRemoveBendpointFeature(this);
185
		return ret;
186
	}
187
188
	@Override
189
	public IMoveBendpointFeature getMoveBendpointFeature(IMoveBendpointContext context) 
190
	{
191
		IMoveBendpointFeature ret = new SapphireMoveBendpointFeature(this);
192
		return ret;
193
	}
194
	
195
    @Override
196
    public IMoveShapeFeature getMoveShapeFeature(IMoveShapeContext context) 
197
    {
198
    	return new SapphireMoveNodeFeature(this);
199
    }
200
	
201
	@Override
202
	public IResizeShapeFeature getResizeShapeFeature(IResizeShapeContext context) 
203
	{
204
		IResizeShapeFeature ret = new SapphireResizeShapeFeature(this);
205
		return ret;
206
	}
207
	    
208
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramImageProvider.java (+23 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.providers;
2
3
import org.eclipse.graphiti.ui.platform.AbstractImageProvider;
4
5
public class SapphireDiagramImageProvider extends AbstractImageProvider 
6
{
7
	public SapphireDiagramImageProvider()
8
	{
9
		super();
10
	}
11
	
12
	@Override
13
	protected void addAvailableImages() 
14
	{
15
16
	}
17
	
18
	public void registerImage(String imageId, String imageFilePath)
19
	{
20
		this.addImageFilePath(imageId, imageFilePath);
21
	}
22
23
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramSolver.java (+45 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.providers;
2
3
import java.util.HashMap;
4
5
import org.eclipse.graphiti.features.impl.IIndependenceSolver;
6
import org.eclipse.sapphire.ui.SapphirePart;
7
8
public class SapphireDiagramSolver implements IIndependenceSolver 
9
{
10
	private HashMap<String, SapphirePart> keyToBOMap;
11
	private HashMap<SapphirePart, String> bOToKeyMap;
12
	private int counter = 0;
13
14
	public SapphireDiagramSolver()
15
	{
16
		this.keyToBOMap = new HashMap<String, SapphirePart>();
17
		this.bOToKeyMap = new HashMap<SapphirePart, String>();		
18
	}
19
	
20
	public String getKeyForBusinessObject(Object bo) 
21
	{
22
		if (bo instanceof SapphirePart)			
23
		{
24
			SapphirePart part = (SapphirePart)bo;
25
			if (this.bOToKeyMap.containsKey(bo))
26
			{
27
				return this.bOToKeyMap.get(bo);
28
			}
29
			String key = Integer.toString(this.counter++);
30
			this.keyToBOMap.put(key, part);
31
			this.bOToKeyMap.put(part, key);
32
			
33
			return key;
34
		}
35
		return null;
36
	}
37
38
	public Object getBusinessObjectForKey(String key) 
39
	{
40
		if (key == null)
41
			return null;
42
		return this.keyToBOMap.get(key);
43
	}
44
45
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramToolBehaviorProvider.java (+25 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.providers;
2
3
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
4
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
5
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
6
import org.eclipse.graphiti.tb.IContextButtonPadData;
7
8
9
public class SapphireDiagramToolBehaviorProvider extends DefaultToolBehaviorProvider 
10
{
11
	public SapphireDiagramToolBehaviorProvider(IDiagramTypeProvider dtp) 
12
	{
13
		super(dtp);
14
	}
15
16
	/**
17
	 * Override super class impl to not include "Remove"
18
	 */
19
	@Override
20
	protected void setGenericContextButtons(IContextButtonPadData data, PictogramElement pe, int identifiers) 
21
	{
22
		identifiers -= CONTEXT_BUTTON_REMOVE;
23
		super.setGenericContextButtons(data, pe, identifiers);
24
	}
25
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/providers/SapphireDiagramTypeProvider.java (+145 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.providers;
2
3
import java.io.File;
4
import java.io.IOException;
5
import java.net.URL;
6
import java.util.List;
7
8
import org.eclipse.core.runtime.FileLocator;
9
import org.eclipse.core.runtime.Path;
10
import org.eclipse.core.runtime.Platform;
11
import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
12
import org.eclipse.graphiti.mm.pictograms.Diagram;
13
import org.eclipse.graphiti.platform.IDiagramEditor;
14
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
15
import org.eclipse.graphiti.ui.internal.platform.ExtensionManager;
16
import org.eclipse.graphiti.ui.platform.IImageProvider;
17
import org.eclipse.graphiti.ui.services.GraphitiUi;
18
import org.eclipse.sapphire.ui.def.IImportDirective;
19
import org.eclipse.sapphire.ui.def.ISapphireUiDef;
20
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef;
21
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeImageDef;
22
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate;
23
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
24
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor;
25
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
26
import org.eclipse.ui.internal.util.BundleUtility;
27
import org.osgi.framework.Bundle;
28
29
public class SapphireDiagramTypeProvider extends AbstractDiagramTypeProvider 
30
{
31
	private SapphireDiagramEditorPart diagramPart;
32
	private SapphireDiagramFeatureProvider featureProvider;
33
	private IToolBehaviorProvider[] toolBehaviorProviders;
34
	
35
	public SapphireDiagramTypeProvider()
36
	{
37
		this.featureProvider = 
38
			new SapphireDiagramFeatureProvider(this, new SapphireDiagramSolver());
39
		setFeatureProvider(this.featureProvider);
40
	}
41
	
42
	public void setDiagramPart(SapphireDiagramEditorPart diagramPart)
43
	{
44
		this.diagramPart = diagramPart;
45
		this.featureProvider.setDiagramPart(diagramPart);		
46
	}
47
	
48
	public SapphireDiagramEditorPart getDiagramPart()
49
	{
50
		return this.diagramPart;
51
	}
52
	
53
	@Override
54
	public void init(Diagram diagram, IDiagramEditor diagramEditor)
55
	{
56
		super.init(diagram, diagramEditor);
57
		setDiagramPart(((SapphireDiagramEditor)diagramEditor).getDiagramEditorPart());
58
		ExtensionManager extManager = (ExtensionManager)GraphitiUi.getExtensionManager();
59
		IImageProvider imageProviders[] = extManager.getImageProviders();
60
		SapphireDiagramImageProvider sapphireImageProvider = null;
61
		for (IImageProvider imageProvider : imageProviders)
62
		{
63
			if (imageProvider instanceof SapphireDiagramImageProvider)
64
			{
65
				sapphireImageProvider = (SapphireDiagramImageProvider)imageProvider;
66
				break;
67
			}
68
		}
69
		if (sapphireImageProvider != null)
70
		{
71
			List<DiagramNodeTemplate> nodeTemplates = this.diagramPart.getNodeTemplates();
72
			for (DiagramNodeTemplate nodeTemplate : nodeTemplates)
73
			{
74
				IDiagramNodeDef nodeDef = nodeTemplate.getDefinition();
75
				if (nodeDef.getImage().element() != null)
76
				{
77
					IDiagramNodeImageDef imageDef = nodeDef.getImage().element();
78
					ISapphireUiDef uiDef = imageDef.nearest(ISapphireUiDef.class);
79
					String imageId = imageDef.getImageId().getContent();
80
					String imagePath = imageDef.getImagePath().getContent();
81
					
82
					String bundleId = resolveImageBundle(uiDef, imagePath);
83
					// Graphiti's image provider doesn't support images from different plugins.
84
					// See http://www.eclipse.org/forums/index.php?t=tree&th=201973&start=0&S=3813ad4d99f2ac8bd56a0072ffa6ebd9
85
					if (bundleId != null)
86
					{
87
						sapphireImageProvider.setPluginId(bundleId);
88
					}
89
					
90
					if (imageId != null && imagePath != null)
91
					{
92
						sapphireImageProvider.registerImage(imageId, imagePath);
93
					}
94
				}
95
			}
96
		}
97
	}
98
	
99
    @Override
100
    public IToolBehaviorProvider[] getAvailableToolBehaviorProviders() 
101
    {
102
        if (this.toolBehaviorProviders == null) 
103
        {
104
            this.toolBehaviorProviders =
105
                new IToolBehaviorProvider[] { new SapphireDiagramToolBehaviorProvider(this) };
106
        }
107
        return this.toolBehaviorProviders;
108
    }
109
	
110
    @Override
111
    public void postInit() 
112
    {    	
113
    	SapphireDiagramEditor sapphireEditor = (SapphireDiagramEditor)getDiagramEditor();
114
    	sapphireEditor.syncDiagramWithModel();
115
    	sapphireEditor.doSave(null);
116
    }
117
    
118
    private String resolveImageBundle(ISapphireUiDef def, String imagePath)
119
    {
120
    	try
121
    	{
122
	    	for (IImportDirective directive : def.getImportDirectives())
123
	    	{
124
	            final String bundleId = directive.getBundle().getText();
125
	            Bundle bundle = Platform.getBundle(bundleId);
126
	            URL url = BundleUtility.find(bundle, imagePath);
127
				URL locatedURL = FileLocator.toFileURL(url);
128
				if ("file".equalsIgnoreCase(locatedURL.getProtocol()))
129
				{
130
					String fullPath = new Path(locatedURL.getPath()).toOSString();
131
					File f = new File(fullPath);
132
					if (f.exists())
133
					{
134
						return bundleId;
135
					}
136
				}
137
	    	}
138
    	}
139
    	catch (IOException e)
140
    	{
141
    		SapphireUiFrameworkPlugin.log(e);
142
    	}
143
    	return null;
144
    }
145
}

Return to bug 330482