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 (+10 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
149
  
159
  
150
</plugin>
160
</plugin>
(-)sdef/MapEditor.sdef (+65 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
      <property>Destinations</property>
18
      <label>${ Name == null ? "&lt;Destination&gt;" : Name }</label>
19
    </node>
20
    <connection>
21
      <id>connections</id>
22
      <tool-palette-label>Route</tool-palette-label>
23
      <tool-palette-desc>Map Route</tool-palette-desc>
24
      <property>Routes</property>
25
      <label>${ Distance == null ? "&lt;Distance&gt;" : Distance }</label>
26
      <endpoint1>
27
        <property>FromDestination</property>
28
        <value>${Name}</value>
29
        <type>NONE</type>
30
      </endpoint1>
31
      <endpoint2>
32
        <property>ToDestination</property>
33
        <value>${Name}</value>
34
        <type>ARROW</type>
35
      </endpoint2>
36
    </connection>
37
  </diagram-page>
38
  
39
  <editor-page>
40
    <id>overview</id>
41
    <page-name>Overview</page-name>
42
    <page-header-text>Overview</page-header-text>
43
    <root-node>
44
      <node>
45
        <label>Destinations</label>
46
        <section>
47
          <description>Destinations in the map</description>
48
          <content>
49
            <property-editor>Destinations</property-editor>
50
          </content>
51
        </section>
52
      </node>
53
      <node>
54
        <label>Routes</label>
55
        <section>
56
          <description>Routes in the map</description>
57
          <content>
58
            <property-editor>Routes</property-editor>
59
          </content>
60
        </section>
61
      </node>
62
    </root-node>
63
  </editor-page>
64
</definition>
65
    
(-)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 (+74 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.Path;
5
import org.eclipse.sapphire.modeling.IModelElement;
6
import org.eclipse.sapphire.modeling.xml.RootXmlResource;
7
import org.eclipse.sapphire.samples.map.IMap;
8
import org.eclipse.sapphire.ui.SapphireEditor;
9
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
10
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor;
11
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditorInput;
12
import org.eclipse.sapphire.ui.editor.views.masterdetails.MasterDetailsPage;
13
import org.eclipse.sapphire.ui.xml.XmlEditorResourceStore;
14
import org.eclipse.ui.PartInitException;
15
import org.eclipse.ui.part.FileEditorInput;
16
import org.eclipse.wst.sse.ui.StructuredTextEditor;
17
18
public class MapEditor extends SapphireEditor 
19
{
20
	private IMap modelMap;
21
	private StructuredTextEditor mapSourceEditor;
22
	private SapphireDiagramEditorPart mapDiagramPart;
23
	private MasterDetailsPage mapOverviewPage;
24
	
25
    public MapEditor()
26
    {
27
        super( "org.eclipse.sapphire.samples" );
28
    }
29
30
	@Override
31
	protected void createSourcePages() throws PartInitException 
32
	{
33
		this.mapSourceEditor = new StructuredTextEditor();
34
		this.mapSourceEditor.setEditorPart(this);
35
        final FileEditorInput rootEditorInput = (FileEditorInput) getEditorInput();
36
        
37
        int index = addPage( this.mapSourceEditor, rootEditorInput );
38
        setPageText( index, "map.xml" );
39
	}
40
41
	@Override
42
	protected IModelElement createModel() 
43
	{
44
		this.modelMap = IMap.TYPE.instantiate(new RootXmlResource(new XmlEditorResourceStore(this, this.mapSourceEditor)));
45
		return this.modelMap;
46
	}
47
48
	@Override
49
	protected void createDiagramPages() throws PartInitException
50
	{
51
		IPath path = new Path( "org.eclipse.sapphire.samples/sdef/MapEditor.sdef/diagram" );
52
		this.mapDiagramPart = new SapphireDiagramEditorPart(this, this.modelMap, path);
53
		SapphireDiagramEditor diagramEditor = this.mapDiagramPart.getDiagramEditor();
54
		SapphireDiagramEditorInput diagramEditorInput = this.mapDiagramPart.getDiagramEditorInput();
55
		addPage(0, diagramEditor, diagramEditorInput);
56
		setPageText( 0, "Diagram" );
57
		setPageId(this.pages.get(0), "Diagram");
58
	}
59
	
60
	@Override
61
	protected void createFormPages() throws PartInitException 
62
	{
63
		IPath path = new Path( "org.eclipse.sapphire.samples/sdef/MapEditor.sdef/overview" );
64
		this.mapOverviewPage = new MasterDetailsPage(this, this.modelMap, path);
65
        addPage(1, this.mapOverviewPage);
66
        setPageText(1, "Overview");
67
        setPageId(this.pages.get(1), "Overview");		
68
	}
69
70
	public IMap getMap()
71
	{
72
		return this.modelMap;
73
	}
74
}
(-)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 (+19 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
      </diagramTypeProvider>
44
   </extension>
45
     
27
</plugin>
46
</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 (+91 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
    @Label( standard = "label" )
66
    @XmlBinding( path = "label" )
67
    
68
    ValueProperty PROP_LABEL = new ValueProperty( TYPE, "Label" );
69
    
70
    Value<String> getLabel();
71
    void setLabel( String label );
72
    
73
    // *** Endpoint1 ***
74
    
75
    @Type( base = IDiagramConnectionEndpointDef.class )
76
    @XmlBinding( path = "endpoint1" )
77
78
    ElementProperty PROP_ENDPOINT_1 = new ElementProperty( TYPE, "Endpoint1" );
79
    
80
    ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint1();
81
82
    // *** Endpoint2 ***
83
    
84
    @Type( base = IDiagramConnectionEndpointDef.class )
85
    @XmlBinding( path = "endpoint2" )
86
87
    ElementProperty PROP_ENDPOINT_2 = new ElementProperty( TYPE, "Endpoint2" );
88
    
89
    ModelElementHandle<IDiagramConnectionEndpointDef> getEndpoint2();
90
    
91
}
(-)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/IDiagramNodeDef.java (+70 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 IDiagramNodeDef 
14
15
	extends ISapphirePartDef
16
	
17
{
18
	ModelElementType TYPE = new ModelElementType( IDiagramNodeDef.class );
19
	
20
    // *** Id ***
21
    
22
    @Label( standard = "ID" )
23
    @XmlBinding( path = "id" )
24
    
25
    ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" );
26
    
27
    Value<String> getId();
28
    void setId( String id );
29
    
30
    // *** ToolPaletteLabel ***
31
    
32
    @Label( standard = "tool palette label" )
33
    @XmlBinding( path = "tool-palette-label" )
34
    
35
    ValueProperty PROP_TOOL_PALETTE_LABEL = new ValueProperty( TYPE, "ToolPaletteLabel" );
36
    
37
    Value<String> getToolPaletteLabel();
38
    void setToolPaletteLabel( String paletteLabel );
39
    
40
    // *** ToolPaletteDesc ***
41
    
42
    @Label( standard = "tool palette description" )
43
    @XmlBinding( path = "tool-palette-desc" )
44
    
45
    ValueProperty PROP_TOOL_PALETTE_DESC = new ValueProperty( TYPE, "ToolPaletteDesc" );
46
    
47
    Value<String> getToolPaletteDesc();
48
    void setToolPaletteDesc( String paletteDesc );
49
50
    // *** Property ***
51
    
52
    @Label( standard = "property" )
53
    @XmlBinding( path = "property" )
54
    
55
    ValueProperty PROP_PROPERTY = new ValueProperty( TYPE, "Property" );
56
    
57
    Value<String> getProperty();
58
    void setProperty( String property );
59
        
60
    // *** Label ***
61
    
62
    @Label( standard = "label" )
63
    @XmlBinding( path = "label" )
64
    
65
    ValueProperty PROP_LABEL = new ValueProperty( TYPE, "Label" );
66
    
67
    Value<String> getLabel();
68
    void setLabel( String label );
69
	
70
}
(-)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 (+177 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 definition;
19
	private IModelElement modelElement;
20
	private String label;
21
	private IDiagramConnectionEndpointDef endpoint1Def;
22
	private IDiagramConnectionEndpointDef endpoint2Def;
23
	private IModelElement endpoint1Model;
24
	private IModelElement endpoint2Model;
25
	private Function endpoint1Function;
26
	private Function endpoint2Function;
27
	
28
	public DiagramConnectionPart(DiagramConnectionTemplate connectionTemplate)
29
	{
30
		this.connectionTemplate = connectionTemplate;
31
	}
32
	
33
    @Override
34
    protected void init()
35
    {
36
        super.init();
37
        
38
        this.definition = (IDiagramConnectionDef)super.definition;
39
        this.modelElement = getModelElement();
40
        Function labelFunction = initExpression
41
        ( 
42
            this.definition.getLabel().getLocalizedText(), 
43
            new Runnable()
44
            {
45
                public void run()
46
                {
47
                }
48
            }
49
        );
50
        this.label = (String)labelFunction.value();
51
        labelFunction.dispose();
52
        
53
        this.endpoint1Def = this.definition.getEndpoint1().element();
54
        this.endpoint2Def = this.definition.getEndpoint2().element();
55
        this.endpoint1Model = processEndpoint(this.endpoint1Def);
56
        this.endpoint2Model = processEndpoint(this.endpoint2Def);
57
        this.endpoint1Function = initExpression
58
        (
59
        	this.endpoint1Model, 
60
        	this.endpoint1Def.getValue().getContent(), 
61
            new Runnable()
62
        	{
63
	            public void run()
64
	            {
65
	            	refreshEndpoint1();
66
	            }
67
        	}
68
        );
69
        this.endpoint2Function = initExpression
70
        (
71
        	this.endpoint2Model, 
72
        	this.endpoint2Def.getValue().getContent(), 
73
            new Runnable()
74
        	{
75
	            public void run()
76
	            {
77
	            	refreshEndpoint2();
78
	            }
79
        	}
80
        );
81
    }
82
    
83
    public DiagramConnectionTemplate getDiagramConnectionTemplate()
84
    {
85
    	return this.connectionTemplate;
86
    }
87
    
88
    public IModelElement getLocalModelElement()
89
    {
90
        return this.modelElement;
91
    }    
92
    
93
    public IModelElement getEndpoint1()
94
    {
95
    	return this.endpoint1Model;
96
    }
97
    
98
    public IModelElement getEndpoint2()
99
    {
100
    	return this.endpoint2Model;
101
    }
102
103
    public String getLabel()
104
	{
105
		return this.label;
106
	}
107
    
108
	@Override
109
	public void render(SapphireRenderingContext context)
110
	{
111
		throw new UnsupportedOperationException();
112
	}
113
	
114
	public void refreshEndpoint1()
115
	{
116
		if (this.endpoint1Function != null)
117
		{
118
			Object value = this.endpoint1Function.value();
119
			String property = this.endpoint1Def.getProperty().getContent();
120
			setModelProperty(this.modelElement, property, value);
121
		}		
122
	}
123
	
124
	public void refreshEndpoint2()
125
	{
126
		if (this.endpoint2Function != null)
127
		{
128
			Object value = this.endpoint2Function.value();
129
			String property = this.endpoint2Def.getProperty().getContent();
130
			setModelProperty(this.modelElement, property, value);
131
		}		
132
	}
133
	
134
	private IModelElement processEndpoint(IDiagramConnectionEndpointDef endpointDef)
135
	{
136
		String propertyName = endpointDef.getProperty().getContent();
137
		ModelProperty modelProperty = resolve(this.modelElement, propertyName);
138
        if (!(modelProperty instanceof ValueProperty))
139
        {
140
        	throw new RuntimeException( "Property " + propertyName + " not a ValueProperty");
141
        }
142
        ValueProperty property = (ValueProperty)modelProperty;
143
		Value<?> valObj = this.modelElement.read(property);
144
		if (!(valObj instanceof ReferenceValue))
145
		{
146
			throw new RuntimeException( "Property " + propertyName + " value not a reference");
147
		}
148
		ReferenceValue<?> refVal = (ReferenceValue<?>)valObj;
149
		Object targetObj = refVal.resolve();
150
		if (!(targetObj instanceof IModelElement))
151
		{
152
			throw new RuntimeException( "Target not an IModelElement");
153
		}
154
		return (IModelElement)targetObj;
155
	}
156
	
157
    private void setModelProperty(final IModelElement modelElement, 
158
			String propertyName, Object value)
159
	{
160
		if (propertyName != null)
161
		{
162
			final ModelElementType type = modelElement.getModelElementType();
163
			final ModelProperty property = type.getProperty( propertyName );
164
			if( property == null )
165
			{
166
				throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
167
			}
168
			if (!(property instanceof ValueProperty))
169
			{
170
				throw new RuntimeException( "Property " + propertyName + " not a ValueProperty");
171
			}
172
		
173
			modelElement.write((ValueProperty)property, value);
174
		}    	
175
	}
176
	
177
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramConnectionTemplate.java (+186 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.el.Function;
16
import org.eclipse.sapphire.modeling.el.FunctionContext;
17
import org.eclipse.sapphire.modeling.el.ModelElementFunctionContext;
18
import org.eclipse.sapphire.modeling.el.parser.ExpressionLanguageParser;
19
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionDef;
20
import org.eclipse.sapphire.ui.diagram.def.IDiagramConnectionEndpointDef;
21
import org.eclipse.sapphire.ui.internal.SapphireUiFrameworkPlugin;
22
23
public class DiagramConnectionTemplate 
24
{
25
	private SapphireDiagramEditorPart diagramEditor;
26
	private IDiagramConnectionDef definition;
27
	private IModelElement modelElement;	
28
	private ModelProperty modelProperty;
29
	private String toolPaletteLabel;
30
	private String toolPaletteDesc;
31
	
32
	private List<DiagramConnectionPart> diagramConnections;
33
	    
34
    public DiagramConnectionTemplate(final SapphireDiagramEditorPart diagramEditor, 
35
    		IDiagramConnectionDef definition, IModelElement modelElement)
36
    {
37
    	this.diagramEditor = diagramEditor;
38
    	this.modelElement = modelElement;
39
    	this.definition = definition;
40
    	
41
        this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent();
42
        this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent();
43
        
44
        this.diagramConnections = new ArrayList<DiagramConnectionPart>();
45
        
46
        String propertyName = this.definition.getProperty().getContent();
47
        this.modelProperty = resolve(this.modelElement, propertyName);
48
        if (this.modelProperty instanceof ListProperty)
49
        {
50
        	ListProperty listProperty = (ListProperty)this.modelProperty;
51
        	ModelElementList<?> list = this.modelElement.read(listProperty);
52
            for( IModelElement listEntryModelElement : list )
53
            {
54
            	DiagramConnectionPart connection = new DiagramConnectionPart(this);
55
            	connection.init(this.diagramEditor, listEntryModelElement, definition, 
56
            			Collections.<String,String>emptyMap());
57
            	this.diagramConnections.add(connection);
58
            }
59
        }
60
        else if (this.modelProperty instanceof ElementProperty)
61
        {
62
        	ElementProperty elementProperty = (ElementProperty)this.modelProperty;
63
        	if (this.modelElement.read(elementProperty) != null)
64
        	{
65
	        	IModelElement localModelElement = this.modelElement.read(elementProperty).element();
66
	        	DiagramConnectionPart connection = new DiagramConnectionPart(this);
67
	        	connection.init(this.diagramEditor, localModelElement, definition, 
68
	        			Collections.<String,String>emptyMap());
69
	        	
70
	        	this.diagramConnections.add(connection);
71
        	}
72
        }
73
    }
74
    
75
    public List<DiagramConnectionPart> getDiagramConnections()
76
    {
77
    	return this.diagramConnections;
78
    }
79
    
80
    public String getToolPaletteLabel()
81
    {
82
    	return this.toolPaletteLabel;
83
    }
84
    
85
    public String getToolPaletteDesc()
86
    {
87
    	return this.toolPaletteDesc;
88
    }
89
    
90
    public DiagramConnectionPart createNewDiagramConnection(DiagramNodePart srcNode, 
91
    														DiagramNodePart targetNode)
92
    {
93
    	IModelElement newElement = null;
94
    	if (this.modelProperty instanceof ListProperty)
95
    	{
96
    		ListProperty listProperty = (ListProperty)this.modelProperty;
97
    		ModelElementList<?> list = this.modelElement.read(listProperty);
98
    		newElement = list.addNewElement();
99
    	}
100
    	else if (this.modelProperty instanceof ElementProperty)
101
    	{
102
    		// TODO what if the element property does exist?
103
    		ElementProperty elementProperty = (ElementProperty)this.modelProperty;
104
    		newElement = this.modelElement.read(elementProperty).element(true);
105
    	}
106
    	
107
    	IDiagramConnectionEndpointDef srcAnchorDef = this.definition.getEndpoint1().element();
108
    	String srcProperty = srcAnchorDef.getProperty().getContent();
109
    	String srcExpr = srcAnchorDef.getValue().getContent();
110
    	Function srcFunc = getNodeReferenceFunction(srcNode, srcExpr);
111
    	Object srcValue = srcFunc.value();
112
    	srcFunc.dispose();
113
    	setModelProperty(newElement, srcProperty, srcValue);
114
    	
115
    	IDiagramConnectionEndpointDef targetAnchorDef = this.definition.getEndpoint2().element();
116
    	String targetProperty = targetAnchorDef.getProperty().getContent();
117
    	String targetExpr = targetAnchorDef.getValue().getContent();
118
    	Function targetFunc = getNodeReferenceFunction(targetNode, targetExpr);
119
    	Object targetValue = targetFunc.value();
120
    	targetFunc.dispose();
121
    	setModelProperty(newElement, targetProperty, targetValue);
122
    	
123
    	DiagramConnectionPart newConn = new DiagramConnectionPart(this);
124
    	newConn.init(this.diagramEditor, newElement, this.definition, 
125
    			Collections.<String,String>emptyMap());
126
    	this.diagramConnections.add(newConn);
127
    	return newConn;
128
    }
129
    
130
    private ModelProperty resolve(final IModelElement modelElement, 
131
    		String propertyName)
132
    {
133
    	if (propertyName != null)
134
    	{
135
	        final ModelElementType type = modelElement.getModelElementType();
136
	        final ModelProperty property = type.getProperty( propertyName );
137
	        if( property == null )
138
	        {
139
	            throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
140
	        }
141
	        return property;
142
    	}    
143
        return null;
144
    }
145
146
    private void setModelProperty(final IModelElement modelElement, 
147
    								String propertyName, Object value)
148
    {
149
    	if (propertyName != null)
150
    	{
151
	        final ModelElementType type = modelElement.getModelElementType();
152
	        final ModelProperty property = type.getProperty( propertyName );
153
	        if( property == null )
154
	        {
155
	            throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
156
	        }
157
	        if (!(property instanceof ValueProperty))
158
	        {
159
	        	throw new RuntimeException( "Property " + propertyName + " not a ValueProperty");
160
	        }
161
	        		
162
	        modelElement.write((ValueProperty)property, ((Value<?>)value).getContent());
163
    	}    	
164
    }
165
    
166
    private Function getNodeReferenceFunction(final DiagramNodePart nodePart,
167
    											final String expression)
168
    {
169
        final FunctionContext context = new ModelElementFunctionContext( nodePart.getLocalModelElement() );
170
        Function result = null;
171
        
172
        if( expression != null )
173
        {
174
            try
175
            {
176
                result = ExpressionLanguageParser.parse( context, expression );
177
            }
178
            catch( Exception e )
179
            {
180
                SapphireUiFrameworkPlugin.log( e );
181
                result = null;
182
            }
183
        }
184
        return result;
185
    }
186
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodePart.java (+102 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
import org.eclipse.sapphire.ui.SapphirePart;
12
import org.eclipse.sapphire.ui.SapphireRenderingContext;
13
import org.eclipse.sapphire.ui.diagram.def.IDiagramNodeDef;
14
15
public class DiagramNodePart extends SapphirePart 
16
{
17
	private DiagramNodeTemplate nodeTemplate;
18
	private IDiagramNodeDef definition;
19
	private IModelElement modelElement;
20
	private String label;
21
	private Function labelFunction;
22
	private ValueProperty labelProperty;
23
	
24
	public DiagramNodePart(DiagramNodeTemplate nodeTemplate)
25
	{
26
		this.nodeTemplate = nodeTemplate;
27
	}
28
	
29
    @Override
30
    protected void init()
31
    {
32
        super.init();
33
        
34
        this.definition = (IDiagramNodeDef)super.definition;
35
        this.modelElement = getModelElement();
36
        this.labelFunction = initExpression
37
        ( 
38
            this.definition.getLabel().getLocalizedText(), 
39
            new Runnable()
40
            {
41
                public void run()
42
                {
43
                	refreshLabel();
44
                }
45
            }
46
        );
47
        refreshLabel();
48
        this.labelProperty = FunctionUtil.getFunctionProperty(this.modelElement, this.labelFunction);
49
        if (this.labelProperty == null)
50
        {
51
        	throw new RuntimeException( "Label function does not contain a property.");
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
		return this.label;
74
	}
75
76
	public void setLabel(String newValue)
77
	{
78
		if (this.labelProperty != null)
79
		{
80
			this.modelElement.write(this.labelProperty, newValue);
81
			refreshLabel();
82
		}
83
	}
84
	
85
    private void refreshLabel()
86
    {        
87
        if( this.labelFunction != null )
88
        {
89
            this.label = (String) this.labelFunction.value();
90
        }
91
        
92
        if( this.label == null )
93
        {
94
        	this.label = "#null#";
95
        }
96
        else
97
        {
98
        	this.label = this.label.trim();
99
        }        
100
    }
101
	
102
}
(-)src/org/eclipse/sapphire/ui/diagram/editor/DiagramNodeTemplate.java (+120 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.IDiagramNodeDef;
14
15
public class DiagramNodeTemplate 
16
{
17
	private SapphireDiagramEditorPart diagramEditor;
18
	private IDiagramNodeDef definition;
19
	private IModelElement modelElement;	
20
	private ModelProperty modelProperty;
21
	private String toolPaletteLabel;
22
	private String toolPaletteDesc;
23
	
24
	private List<DiagramNodePart> diagramNodes;
25
	    
26
    public DiagramNodeTemplate(final SapphireDiagramEditorPart diagramEditor, IDiagramNodeDef definition, IModelElement modelElement)
27
    {
28
    	this.diagramEditor = diagramEditor;
29
    	this.modelElement = modelElement;
30
    	this.definition = definition;
31
    	
32
        this.toolPaletteLabel = this.definition.getToolPaletteLabel().getContent();
33
        this.toolPaletteDesc = this.definition.getToolPaletteDesc().getContent();
34
        
35
        this.diagramNodes = new ArrayList<DiagramNodePart>();
36
        
37
        String propertyName = this.definition.getProperty().getContent();
38
        this.modelProperty = resolve(this.modelElement, propertyName);
39
        if (this.modelProperty instanceof ListProperty)
40
        {
41
        	ListProperty listProperty = (ListProperty)this.modelProperty;
42
        	ModelElementList<?> list = this.modelElement.read(listProperty);
43
            for( IModelElement listEntryModelElement : list )
44
            {
45
            	DiagramNodePart node = new DiagramNodePart(this);
46
            	node.init(this.diagramEditor, listEntryModelElement, definition, 
47
            			Collections.<String,String>emptyMap());
48
            	this.diagramNodes.add(node);
49
            }
50
        }
51
        else if (this.modelProperty instanceof ElementProperty)
52
        {
53
        	ElementProperty elementProperty = (ElementProperty)this.modelProperty;
54
        	if (this.modelElement.read(elementProperty) != null)
55
        	{
56
	        	IModelElement localModelElement = this.modelElement.read(elementProperty).element();
57
	        	DiagramNodePart node = new DiagramNodePart(this);
58
	        	node.init(this.diagramEditor, localModelElement, definition, 
59
	        			Collections.<String,String>emptyMap());
60
	        	
61
	        	this.diagramNodes.add(node);
62
        	}
63
        }
64
    }
65
    
66
    public List<DiagramNodePart> getDiagramNodes()
67
    {
68
    	return this.diagramNodes;
69
    }
70
    
71
    public String getToolPaletteLabel()
72
    {
73
    	return this.toolPaletteLabel;
74
    }
75
    
76
    public String getToolPaletteDesc()
77
    {
78
    	return this.toolPaletteDesc;
79
    }
80
    
81
    public DiagramNodePart createNewDiagramNode()
82
    {
83
    	IModelElement newElement = null;
84
    	if (this.modelProperty instanceof ListProperty)
85
    	{
86
    		ListProperty listProperty = (ListProperty)this.modelProperty;
87
    		ModelElementList<?> list = this.modelElement.read(listProperty);
88
    		newElement = list.addNewElement();
89
    	}
90
    	else if (this.modelProperty instanceof ElementProperty)
91
    	{
92
    		// TODO what if the element property does exist?
93
    		ElementProperty elementProperty = (ElementProperty)this.modelProperty;
94
    		newElement = this.modelElement.read(elementProperty).element(true);
95
    	}
96
    	DiagramNodePart newNode = new DiagramNodePart(this);
97
    	newNode.init(this.diagramEditor, newElement, this.definition, 
98
    			Collections.<String,String>emptyMap());
99
    	this.diagramNodes.add(newNode);
100
    	return newNode;
101
    }
102
    
103
    private ModelProperty resolve(final IModelElement modelElement, 
104
    		String propertyName)
105
    {
106
    	if (propertyName != null)
107
    	{
108
	        final ModelElementType type = modelElement.getModelElementType();
109
	        final ModelProperty property = type.getProperty( propertyName );
110
	        
111
	        if( property == null )
112
	        {
113
	            throw new RuntimeException( "Could not find property " + propertyName + " in " + type.getQualifiedName() );
114
	        }
115
	        return property;
116
    	}    
117
        return null;
118
    }
119
    
120
}
(-)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 (+198 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.runtime.CoreException;
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 List<DiagramNodeTemplate> nodeTemplates;
37
    private List<DiagramConnectionTemplate> connectionTemplates;
38
    private SapphireDiagramEditorInput diagramInput;
39
    private SapphireDiagramEditor diagramEditor;
40
	
41
	public SapphireDiagramEditorPart(final SapphireEditor editor,
42
								final IModelElement rootModelElement,
43
								final IPath pageDefinitionLocation )
44
	{
45
		this(editor, rootModelElement, pageDefinitionLocation, null);
46
	}
47
48
	public SapphireDiagramEditorPart(final SapphireEditor editor,
49
								final IModelElement rootModelElement,
50
								final IPath pageDefinitionLocation,
51
								String pageName )
52
	{
53
		this.editor = editor;
54
		this.rootModelElement = rootModelElement;
55
56
        final String bundleId = pageDefinitionLocation.segment( 0 );
57
        final String pageId = pageDefinitionLocation.lastSegment();
58
        final String relPath = pageDefinitionLocation.removeFirstSegments( 1 ).removeLastSegments( 1 ).toPortableString();
59
        
60
        final ISapphireUiDef def = SapphireUiDefFactory.load( bundleId, relPath );
61
        
62
        for( IDiagramPageDef pg : def.getDiagramPageDefs() )
63
        {
64
            if( pageId.equals( pg.getId().getText() ) )
65
            {
66
                this.diagramPageDef = pg;
67
                break;
68
            }
69
        }
70
                
71
        this.nodeTemplates = new ArrayList<DiagramNodeTemplate>();
72
        ModelElementList<IDiagramNodeDef> nodeDefs = this.diagramPageDef.getDiagramNodeDefs();
73
        
74
        for (IDiagramNodeDef nodeDef : nodeDefs)
75
        {
76
        	DiagramNodeTemplate nodeTemplate = new DiagramNodeTemplate(this, nodeDef, this.rootModelElement);
77
        	this.nodeTemplates.add(nodeTemplate);
78
        }
79
        
80
        this.connectionTemplates = new ArrayList<DiagramConnectionTemplate>();
81
        ModelElementList<IDiagramConnectionDef> connectionDefs = this.diagramPageDef.getDiagramConnectionDefs();
82
        for (IDiagramConnectionDef connectionDef : connectionDefs)
83
        {
84
        	DiagramConnectionTemplate connectionTemplate = new DiagramConnectionTemplate(this, connectionDef, this.rootModelElement);
85
        	this.connectionTemplates.add(connectionTemplate);
86
        }       
87
        
88
        initializeDiagramEditor();
89
	}
90
91
	private void initializeDiagramEditor()
92
	{
93
        try
94
        {
95
        	this.diagramInput = SapphireDiagramEditorFactory.createEditorInput(this.editor.getEditorInput());
96
        }
97
        catch( CoreException e )
98
        {
99
            SapphireUiFrameworkPlugin.log( e );
100
        }
101
    	this.diagramEditor = new SapphireDiagramEditor(this);
102
	}
103
	
104
	public SapphireDiagramEditorInput getDiagramEditorInput()
105
	{
106
		return this.diagramInput;
107
	}
108
	
109
	public SapphireDiagramEditor getDiagramEditor()
110
	{
111
		return this.diagramEditor;
112
	}
113
	
114
	public List<DiagramNodeTemplate> getNodeTemplates()
115
	{
116
		return this.nodeTemplates;
117
	}
118
	
119
	public List<DiagramConnectionTemplate> getConnectionTemplates()
120
	{
121
		return this.connectionTemplates;
122
	}
123
	
124
	public ISapphirePart getParentPart() 
125
	{	
126
		return this.editor;
127
	}
128
129
	public <T> T getNearestPart(Class<T> partType) {
130
		// TODO Auto-generated method stub
131
		return null;
132
	}
133
134
	public IModelElement getModelElement() 
135
	{	
136
		return this.rootModelElement;
137
	}
138
139
	public IStatus getValidationState() {
140
		// TODO Auto-generated method stub
141
		return null;
142
	}
143
144
	public IContext getDocumentationContext() {
145
		// TODO Auto-generated method stub
146
		return null;
147
	}
148
149
	public SapphireImageCache getImageCache() {
150
		// TODO Auto-generated method stub
151
		return null;
152
	}
153
154
	public void addListener(SapphirePartListener listener) {
155
		// TODO Auto-generated method stub
156
		
157
	}
158
159
	public void removeListener(SapphirePartListener listener) {
160
		// TODO Auto-generated method stub
161
		
162
	}
163
164
	public void dispose() {
165
		// TODO Auto-generated method stub
166
		
167
	}
168
169
	public ISapphirePartDef getDefinition() 
170
	{	
171
		return this.diagramPageDef;
172
	}
173
174
	public Set<String> getActionContexts() {
175
		// TODO Auto-generated method stub
176
		return null;
177
	}
178
179
	public String getMainActionContext() {
180
		// TODO Auto-generated method stub
181
		return null;
182
	}
183
184
	public SapphireActionGroup getActions() {
185
		// TODO Auto-generated method stub
186
		return null;
187
	}
188
189
	public SapphireActionGroup getActions(String context) {
190
		// TODO Auto-generated method stub
191
		return null;
192
	}
193
194
	public SapphireAction getAction(String id) {
195
		// TODO Auto-generated method stub
196
		return null;
197
	}
198
}
(-)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 (+21 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.editor;
2
3
import org.eclipse.gef.DefaultEditDomain;
4
import org.eclipse.graphiti.ui.editor.DiagramEditor;
5
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
6
7
public class SapphireDiagramEditor extends DiagramEditor 
8
{
9
	private SapphireDiagramEditorPart diagramPart;
10
	
11
	public SapphireDiagramEditor(SapphireDiagramEditorPart diagramPart)
12
	{
13
		this.diagramPart = diagramPart;
14
		DefaultEditDomain ded = new DefaultEditDomain( this );
15
	}
16
	
17
	public SapphireDiagramEditorPart getDiagramEditorPart()
18
	{
19
		return this.diagramPart;
20
	}
21
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/editor/SapphireDiagramEditorFactory.java (+119 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.ui.IEditorInput;
26
import org.eclipse.ui.IFileEditorInput;
27
28
public class SapphireDiagramEditorFactory 
29
{
30
	public static final String SAPPHIRE_DIAGRAM_TYPE = "sapphireDiagram";
31
	
32
	public static SapphireDiagramEditorInput createEditorInput(IEditorInput otherInput) 
33
		throws CoreException
34
	{
35
		if (otherInput instanceof SapphireDiagramEditorInput)
36
		{
37
			return (SapphireDiagramEditorInput)otherInput;
38
		}
39
		else if (otherInput instanceof IFileEditorInput)
40
		{
41
			final IFileEditorInput fileInput = (IFileEditorInput) otherInput;
42
			final IFile file = fileInput.getFile();
43
			final IProject project = file.getProject();
44
			
45
			final IFolder diagramFolder = project.getFolder(".settings/diagrams/");
46
			String fileName = file.getName();
47
			if (fileName.endsWith(".xml"))
48
			{
49
				fileName = fileName.substring(0, fileName.indexOf(".xml"));
50
			}
51
			
52
			TransactionalEditingDomain domain = null;
53
			ResourceSet resourceSet = null;
54
			Diagram diagram = null;
55
			URI diagramFileUri = null;
56
			
57
			// create diagram file if it doesn't exist
58
			final IFile diagramFile = diagramFolder.getFile(fileName + ".xmi");
59
			if (!diagramFile.exists())
60
			{
61
				FileUtil.mkdirs( diagramFile.getParent().getLocation().toFile() );
62
				diagramFile.create( new ByteArrayInputStream(new byte[0]), true, null );
63
				
64
				// Create Diagram Obj
65
				diagram = Graphiti.getPeCreateService().createDiagram(
66
						SAPPHIRE_DIAGRAM_TYPE, fileName, 10, false);
67
				diagramFileUri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
68
				domain = GraphitiFileService.createEmfFileForDiagram(diagramFileUri, diagram);
69
			}
70
			else
71
			{			
72
				domain = DiagramEditorFactory.createResourceSetAndEditingDomain();
73
				resourceSet = domain.getResourceSet();
74
			
75
				diagramFileUri = GraphitiUiInternal.getEmfService().getFileURI(diagramFile, resourceSet);
76
				if (diagramFileUri != null)
77
				{
78
					final Resource resource = resourceSet.createResource(diagramFileUri);
79
					try
80
					{
81
						resource.load(null);
82
					}
83
					catch (IOException ie)
84
					{
85
						ie.printStackTrace();
86
					}
87
					EList<EObject> objs = resource.getContents();
88
					Iterator<EObject> it = objs.iterator();					
89
					while (it.hasNext()) 
90
					{
91
						EObject obj = it.next();
92
						if ((obj == null) && !Diagram.class.isInstance(obj))
93
							continue;
94
						diagram = (Diagram)obj;
95
						break;
96
					}
97
				}				
98
			}
99
			// create diagram node position file if it doesn't exist
100
			IFile nodePosFile = diagramFile.getParent().getFile(new Path(fileName + ".np"));
101
			if (!nodePosFile.exists())
102
			{
103
				nodePosFile.create( new ByteArrayInputStream(new byte[0]), true, null );
104
			}
105
106
			// create sapphire diagram editor input
107
			if (diagram != null)
108
			{
109
				String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
110
				final SapphireDiagramEditorInput diagramEditorInput = 
111
					SapphireDiagramEditorInput.createEditorInput(diagram, domain, providerId, false);
112
				diagramEditorInput.setNodePositionFile(nodePosFile);
113
				return diagramEditorInput;
114
			}
115
		}
116
		return null;
117
	}
118
119
}
(-)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/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 (+114 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.Polyline;
8
import org.eclipse.graphiti.mm.algorithms.Rectangle;
9
import org.eclipse.graphiti.mm.algorithms.Text;
10
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
11
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
12
import org.eclipse.graphiti.mm.pictograms.Diagram;
13
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
14
import org.eclipse.graphiti.mm.pictograms.Shape;
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.ColorConstant;
19
import org.eclipse.graphiti.util.IColorConstant;
20
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
21
22
public class SapphireAddNodeFeature extends AbstractAddShapeFeature 
23
{
24
    private static final IColorConstant CLASS_TEXT_FOREGROUND = new ColorConstant(51, 51, 153);
25
    private static final IColorConstant CLASS_FOREGROUND = new ColorConstant(255, 102, 0);
26
    private static final IColorConstant CLASS_BACKGROUND =  new ColorConstant(255, 204, 153);
27
	
28
	public SapphireAddNodeFeature(IFeatureProvider fp)
29
	{
30
		super(fp);
31
	}
32
	
33
	public boolean canAdd(IAddContext context) 
34
	{
35
		Object newObj = context.getNewObject();
36
		if (newObj instanceof DiagramNodePart && context.getTargetContainer() instanceof Diagram)
37
		{
38
			return true;
39
		}
40
		return false;
41
	}
42
43
	public PictogramElement add(IAddContext context)
44
	{
45
		DiagramNodePart nodePart = (DiagramNodePart)context.getNewObject();
46
		final Diagram targetDiagram = (Diagram) context.getTargetContainer();
47
		
48
        // CONTAINER SHAPE WITH RECTANGLE
49
        IPeCreateService peCreateService = Graphiti.getPeCreateService();
50
        ContainerShape containerShape =  peCreateService.createContainerShape(targetDiagram, true);
51
52
        // define a default size for the shape
53
        int width = 100;
54
        int height = 50; 
55
        IGaService gaService = Graphiti.getGaService();
56
        {
57
            // create and set graphics algorithm
58
            Rectangle rectangle = gaService.createRectangle(containerShape);
59
            rectangle.setForeground(manageColor(CLASS_FOREGROUND));
60
            rectangle.setBackground(manageColor(CLASS_BACKGROUND));
61
            rectangle.setLineWidth(2);
62
            gaService.setLocationAndSize(rectangle,
63
                context.getX(), context.getY(), width, height);
64
 
65
            // create link and wire it
66
            link(containerShape, nodePart);
67
        }
68
		
69
        // SHAPE WITH LINE
70
        {
71
            // create shape for line
72
            Shape shape = peCreateService.createShape(containerShape, false);
73
 
74
            // create and set graphics algorithm
75
            Polyline polyline =
76
                gaService.createPolyline(shape, new int[] { 0, 20, width, 20 });
77
            polyline.setForeground(manageColor(CLASS_FOREGROUND));
78
            polyline.setLineWidth(2);
79
        }
80
 
81
        // SHAPE WITH TEXT
82
        {
83
            // create shape for text
84
            Shape shape = peCreateService.createShape(containerShape, false);
85
 
86
            // create and set text graphics algorithm
87
            Text text = gaService.createDefaultText(shape, nodePart.getLabel());
88
            text.setForeground(manageColor(CLASS_TEXT_FOREGROUND));
89
            text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
90
            text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
91
            //text.getFont().setBold(true);
92
            gaService.setLocationAndSize(text, 0, 0, width, 20);
93
 
94
            // create link and wire it
95
            link(shape, nodePart);
96
            
97
			// provide information to support direct-editing directly
98
			// after object creation (must be activated additionally)
99
			final IDirectEditingInfo directEditingInfo = getFeatureProvider().getDirectEditingInfo();
100
			// set container shape for direct editing after object creation
101
			directEditingInfo.setMainPictogramElement(containerShape);
102
			// set shape and graphics algorithm where the editor for
103
			// direct editing shall be opened after object creation
104
			directEditingInfo.setPictogramElement(shape);
105
			directEditingInfo.setGraphicsAlgorithm(text);            
106
        }
107
        
108
        // add a chopbox anchor to the shape
109
        peCreateService.createChopboxAnchor(containerShape);
110
        
111
		return null;
112
	}
113
114
}
(-)src/org/eclipse/sapphire/ui/diagram/graphiti/features/SapphireCreateConnectionFeature.java (+92 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
				source instanceof DiagramNodePart && source != target) 
32
		{
33
			return true;
34
		}
35
		return false;
36
	}
37
38
	public Connection create(ICreateConnectionContext context) 
39
	{
40
		Connection newConnection = null;
41
42
		// get model elements which should be connected
43
		SapphirePart source = getEndpoint(context.getSourceAnchor());
44
		SapphirePart target = getEndpoint(context.getTargetAnchor());
45
46
		if (source instanceof DiagramNodePart && target instanceof DiagramNodePart) 
47
		{
48
			DiagramNodePart sourceNode = (DiagramNodePart)source;
49
			DiagramNodePart targetNode = (DiagramNodePart)target;
50
			// create new business object
51
			DiagramConnectionPart connectionPart = 
52
				this.connectionTemplate.createNewDiagramConnection(sourceNode, targetNode);
53
54
			// add connection for business object
55
			AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
56
			addContext.setNewObject(connectionPart);
57
			newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);
58
			
59
	        // activate direct editing after object creation
60
	        getFeatureProvider().getDirectEditingInfo().setActive(true);
61
		}
62
63
		return newConnection;
64
	}
65
66
	public boolean canStartConnection(ICreateConnectionContext context) 
67
	{
68
		// return true if start anchor belongs to an IModelElement
69
		if (getEndpoint(context.getSourceAnchor()) instanceof DiagramNodePart) 
70
		{
71
			return true;
72
		}
73
		return false;
74
	}
75
76
	/**
77
	 * Returns the EClass belonging to the anchor, or null if not available.
78
	 */
79
	private SapphirePart getEndpoint(Anchor anchor) 
80
	{
81
		if (anchor != null) 
82
		{
83
			Object obj = getBusinessObjectForPictogramElement(anchor.getParent());
84
			if (obj instanceof SapphirePart) 
85
			{
86
				return (SapphirePart) obj;
87
			}
88
		}
89
		return null;
90
	}
91
	
92
}
(-)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/SapphireDirectEditNodeFeature.java (+105 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 IADFView, 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 true;
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 name of the EClass
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
		// set the new id for the adf view
58
		PictogramElement pe = context.getPictogramElement();
59
				
60
		if (pe.eContainer() instanceof Shape)
61
		{
62
			DiagramNodePart nodePart = (DiagramNodePart)getBusinessObjectForPictogramElement(pe);
63
			String oldValue = nodePart.getLabel();
64
			nodePart.setLabel(value);
65
			IModelElement nodeElement = nodePart.getLocalModelElement();
66
			Shape nodeShape = (Shape)pe.eContainer();
67
			
68
			// go through all the connections associated with this bo and update them
69
			for (Iterator<Anchor> iter = nodeShape.getAnchors().iterator(); iter.hasNext();) 
70
			{
71
				Anchor anchor = iter.next();
72
				for (Iterator<Connection> iterator = Graphiti.getPeService().getAllConnections(anchor).iterator(); iterator.hasNext();) 
73
				{
74
					Connection connection = iterator.next();
75
					Object bo = getBusinessObjectForPictogramElement(connection);
76
					if (bo instanceof DiagramConnectionPart)
77
					{
78
						DiagramConnectionPart connectionPart = (DiagramConnectionPart)bo;
79
						IModelElement endpoint1 = connectionPart.getEndpoint1();
80
						IModelElement endpoint2 = connectionPart.getEndpoint2();
81
						if (endpoint1 == nodeElement)
82
						{
83
							connectionPart.refreshEndpoint1();
84
						}
85
						else if (endpoint2 == nodeElement)
86
						{
87
							connectionPart.refreshEndpoint2();
88
						}
89
					}
90
				}
91
			}
92
			
93
		}
94
				
95
		// Explicitly update the shape to display the new value in the diagram
96
		// Note, that this might not be necessary in future versions of Graphiti
97
		// (currently in discussion)
98
99
		// we know, that pe is the Shape of the Text, so its container is the
100
		// main shape of the adf view
101
		updatePictogramElement(((Shape)pe).getContainer());
102
103
	}
104
105
}
(-)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 (+124 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.providers;
2
3
import java.util.List;
4
5
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
6
import org.eclipse.graphiti.features.IAddFeature;
7
import org.eclipse.graphiti.features.ICreateConnectionFeature;
8
import org.eclipse.graphiti.features.ICreateFeature;
9
import org.eclipse.graphiti.features.IDirectEditingFeature;
10
import org.eclipse.graphiti.features.IUpdateFeature;
11
import org.eclipse.graphiti.features.context.IAddContext;
12
import org.eclipse.graphiti.features.context.IDirectEditingContext;
13
import org.eclipse.graphiti.features.context.IUpdateContext;
14
import org.eclipse.graphiti.features.impl.IIndependenceSolver;
15
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
16
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
17
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
18
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionPart;
19
import org.eclipse.sapphire.ui.diagram.editor.DiagramConnectionTemplate;
20
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart;
21
import org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate;
22
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
23
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddConnectionFeature;
24
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireAddNodeFeature;
25
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireCreateConnectionFeature;
26
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireCreateNodeFeature;
27
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireDirectEditNodeFeature;
28
import org.eclipse.sapphire.ui.diagram.graphiti.features.SapphireUpdateNodeFeature;
29
30
public class SapphireDiagramFeatureProvider extends DefaultFeatureProvider 
31
{
32
	private SapphireDiagramEditorPart diagramPart;
33
	
34
	public SapphireDiagramFeatureProvider(IDiagramTypeProvider dtp, IIndependenceSolver solver)
35
	{
36
		super(dtp);
37
		this.setIndependenceSolver(solver);
38
	}
39
	
40
	public void setDiagramPart(SapphireDiagramEditorPart diagramPart)
41
	{
42
		this.diagramPart = diagramPart;
43
		
44
	}
45
	
46
	public SapphireDiagramEditorPart getDiagramPart()
47
	{
48
		return this.diagramPart;
49
	}
50
	
51
	@Override
52
	public IAddFeature getAddFeature(IAddContext context) 
53
	{
54
		Object obj = context.getNewObject();
55
		if (obj instanceof DiagramNodePart)
56
		{
57
			return new SapphireAddNodeFeature(this);
58
		}
59
		else if (obj instanceof DiagramConnectionPart)
60
		{
61
			return new SapphireAddConnectionFeature(this);
62
		}
63
		
64
		return super.getAddFeature(context);
65
	}
66
	
67
	@Override
68
	public ICreateFeature[] getCreateFeatures() 
69
	{
70
		List<DiagramNodeTemplate> nodeTemplates = this.diagramPart.getNodeTemplates();
71
		ICreateFeature[] features = new ICreateFeature[nodeTemplates.size()];
72
		int i = 0;
73
		for (DiagramNodeTemplate nodeTemplate : nodeTemplates)
74
		{
75
			SapphireCreateNodeFeature createNodeFeature = 
76
				new SapphireCreateNodeFeature(this, nodeTemplate);
77
			features[i++] = createNodeFeature;
78
		}
79
		return features;
80
	}	
81
	
82
	@Override
83
    public ICreateConnectionFeature[] getCreateConnectionFeatures() 
84
	{
85
		List<DiagramConnectionTemplate> connectionTemplates = this.diagramPart.getConnectionTemplates();
86
		ICreateConnectionFeature[] features = new ICreateConnectionFeature[connectionTemplates.size()];
87
		int i = 0;
88
		for (DiagramConnectionTemplate connectionTemplate : connectionTemplates)
89
		{
90
			SapphireCreateConnectionFeature createConnectionFeature = 
91
				new SapphireCreateConnectionFeature(this, connectionTemplate);
92
			features[i++] = createConnectionFeature;
93
		}
94
		return features;
95
	}
96
	
97
	@Override
98
	public IDirectEditingFeature getDirectEditingFeature(IDirectEditingContext context) 
99
	{
100
		PictogramElement pe = context.getPictogramElement();
101
		Object bo = getBusinessObjectForPictogramElement((PictogramElement) pe.eContainer());
102
		if (bo instanceof DiagramNodePart)
103
		{
104
			return new SapphireDirectEditNodeFeature(this);
105
		}
106
		
107
		return super.getDirectEditingFeature(context);		
108
	}
109
	
110
	@Override
111
	public IUpdateFeature getUpdateFeature(IUpdateContext context) 
112
	{
113
		PictogramElement pictogramElement = context.getPictogramElement();
114
		if (pictogramElement instanceof ContainerShape) 
115
		{
116
			Object bo = getBusinessObjectForPictogramElement(pictogramElement);
117
			if (bo instanceof DiagramNodePart) 
118
			{
119
				return new SapphireUpdateNodeFeature(this);
120
			}
121
		}
122
		return super.getUpdateFeature(context);
123
	}	
124
}
(-)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/SapphireDiagramTypeProvider.java (+38 lines)
Added Link Here
1
package org.eclipse.sapphire.ui.diagram.graphiti.providers;
2
3
import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
4
import org.eclipse.graphiti.mm.pictograms.Diagram;
5
import org.eclipse.graphiti.platform.IDiagramEditor;
6
import org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPart;
7
import org.eclipse.sapphire.ui.diagram.graphiti.editor.SapphireDiagramEditor;
8
9
public class SapphireDiagramTypeProvider extends AbstractDiagramTypeProvider 
10
{
11
	private SapphireDiagramEditorPart diagramPart;
12
	private SapphireDiagramFeatureProvider featureProvider;
13
	
14
	public SapphireDiagramTypeProvider()
15
	{
16
		this.featureProvider = 
17
			new SapphireDiagramFeatureProvider(this, new SapphireDiagramSolver());
18
		setFeatureProvider(this.featureProvider);
19
	}
20
	
21
	public void setDiagramPart(SapphireDiagramEditorPart diagramPart)
22
	{
23
		this.diagramPart = diagramPart;
24
		this.featureProvider.setDiagramPart(diagramPart);		
25
	}
26
	
27
	public SapphireDiagramEditorPart getDiagramPart()
28
	{
29
		return this.diagramPart;
30
	}
31
	
32
	@Override
33
	public void init(Diagram diagram, IDiagramEditor diagramEditor)
34
	{
35
		super.init(diagram, diagramEditor);
36
		setDiagramPart(((SapphireDiagramEditor)diagramEditor).getDiagramEditorPart());
37
	}
38
}

Return to bug 330482