Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » Creating custom connection bindings(How to create a custom connection binding for unique xml schema)
Creating custom connection bindings [message #1709277] Fri, 25 September 2015 14:39 Go to next message
Justin Albright is currently offline Justin AlbrightFriend
Messages: 10
Registered: September 2015
Junior Member
I am attempting to create a connection binding for my diagram page and am having some trouble getting it to work. I am using the following code sample as my test case for now.
<application done='file_write'>
  <instance component='file_read'>
    <property name='filename' value='test.input'/>
    <property name='granularity' value='4'/>
    <property name='messageSize' value='16'/>
  </instance>
  <instance component='bias' connect='file_write'>
    <property name='biasValue' value='0x01020304'/>
  </instance>
  <instance component='file_write'>
    <property name='filename' value='test.outputwrong'/>
  </instance>
  <connection>
    <port instance='file_read' name='out' xferrole='flowcontrol'/>
    <port instance='bias' name='in'/>
  </connection>
</application>

I have been able to create a custom DiagramConnectionPart and custom ConnectionService for the "connect" attribute of the instance elements following some guidance from this project - https://github.com/tomas-milata/jbosstools-javaee.

I am now trying to figure out how to make the connection element bindings. I know that the default connection bindings could work, but I'm not sure how to specify the endpoints because each endpoint ends up being its own port element in the list of ports associated with the connection. I have attempted to create custom parts like I did for the connect attribute, however connection elements and their ports know nothing about the instance nodes that I am attempting to connect.

Any suggestions would be greatly appreciated.
Re: Creating custom connection bindings [message #1709283 is a reply to message #1709277] Fri, 25 September 2015 15:24 Go to previous messageGo to next message
Shenxue Zhou is currently offline Shenxue ZhouFriend
Messages: 60
Registered: July 2009
Member
Have you looked at Sapphire Diagram Samples? The simplest diagram sample is the Map sample. It specifies two types of connections: embedded connections and top level connections. Both types of connection bindings are specified in the sample. I suspect you'll only need the top level connection like the high way route in the Map sample. Connection needs to be bound to a list property like the Routes property in Map sample:

public interface Map extends Element
{
ElementType TYPE = new ElementType( Map.class );

// *** Locations ***

@Type( base = Location.class )
@XmlListBinding( mappings = @XmlListBinding.Mapping( element = "location", type = Location.class ) )

ListProperty PROP_LOCATIONS = new ListProperty( TYPE, "Locations" );

ElementList<Location> getLocations();

// ** Method: findLocation

@DelegateImplementation( MapMethods.class )

Location findLocation( String name );

// ** Method: hasLocation

@DelegateImplementation( MapMethods.class )

boolean hasLocation( String name );

// *** Routes ***

@Type( base = Route.class )
@XmlListBinding( mappings = @XmlListBinding.Mapping( element = "route", type = Route.class ) )

ListProperty PROP_ROUTES = new ListProperty( TYPE, "Routes" );

ElementList<Route> getRoutes();

}

The two endpoints of the connection binding are the two ElementReference properties in the Route element which reference to the Locations. Locations will be used to create diagram nodes.

Hope that helps.

Shenxue
Re: Creating custom connection bindings [message #1709287 is a reply to message #1709283] Fri, 25 September 2015 15:58 Go to previous messageGo to next message
Justin Albright is currently offline Justin AlbrightFriend
Messages: 10
Registered: September 2015
Junior Member
I have been using the Map sample as a guide for developing my diagram editor and I did notice that the highway routes were very similar to what I was attempting to do. Where I get caught up is when I got to specify the endpoints because my Connection interface is
public interface Connection extends Element {
	ElementType TYPE = new ElementType( Connection.class );
	
	// *** Name ***
	@XmlBinding(path = "@name")
	@Label(standard = "Name")
	
	ValueProperty PROP_NAME = new ValueProperty(TYPE, "Name");

	Value<String> getName();
	void setName(String value);
	
	// *** Transport ***
	@XmlBinding( path = "@transport" )
	@Label( standard = "Transport" )
	
	ValueProperty PROP_TRANSPORT = new ValueProperty( TYPE, "Transport" );
	
	Value<String> getProperty();
	void setProperty( String value );
	
	// *** Ports ***
	@Type( base = ConnectionPort.class )
	@XmlListBinding( mappings = { @XmlListBinding.Mapping( element = "port", type = ConnectionPort.class ) } )
	@Label( standard = "Ports" )
				
	ListProperty PROP_PORTS = new ListProperty( TYPE, "Ports" );
				
	ElementList<ConnectionPort> getPorts();
}


With the ConnectionPort interface as follows...
public interface ConnectionPort extends Element {
	ElementType TYPE = new ElementType( ConnectionPort.class );
	
	// *** Name ***
	@XmlBinding(path = "@name")
	@Label(standard = "Name")
	@Required 
	
	ValueProperty PROP_NAME = new ValueProperty(TYPE, "Name");

	Value<String> getName();
	void setName(String value);
	
	// *** Instance ***
	@Reference( target = Instance.class )
	@ElementReference(list = "/Instances", key = "Component")
	@XmlBinding(path = "@instance")
	@Label(standard = "Instance")
	@Required
	@MustExist
	
	ValueProperty PROP_INSTANCE = new ValueProperty(TYPE, "Instance");

	ReferenceValue<String, Instance> getInstance();
	void setInstance(String value);
}


My connection binding looks like...
<connection-binding>
            <connection-id>ConnectionElementConnection</connection-id>
            <property>Connections</property>
            <endpoint1>
                <property>Ports</property>
                <value>endpoint 1</value>
            </endpoint1>
            <endpoint2>
                <property>Ports</property>
                <value>endpoint2</value>
            </endpoint2>
 </connection-binding>


When I launch I get this exception...
java.lang.ClassCastException: org.eclipse.sapphire.ListProperty cannot be cast to org.eclipse.sapphire.ValueProperty. I am assuming this related to using the Port list property as the endpoint property. Is there a way I can restructure my interfaces or modify the property value inside the connection binding endpoints to allow this to work.


*** Update: No longer get the above exception because I was able to modify the connection binding endpoint property to be Ports/Instance, however now I get another exception - java.lang.IllegalArgumentException
at org.eclipse.sapphire.ElementImpl.property(ElementImpl.java:372).

[Updated on: Fri, 25 September 2015 16:14]

Report message to a moderator

Re: Creating custom connection bindings [message #1709293 is a reply to message #1709287] Fri, 25 September 2015 16:28 Go to previous messageGo to next message
Shenxue Zhou is currently offline Shenxue ZhouFriend
Messages: 60
Registered: July 2009
Member
You should have a root model element, let's call it "Application". This would be similar to the Map element in the Map sample. In the "Application" element, you define a list property "Components" for the components, similar to the "Locations" property in the Map element. Then you define a list property "Ports" for the connection binding. Ports would be a list based off your "Connection" interface. And in the "Connection" interface, you define two value properties: FromPort and ToPort, similar to the FromLocation and ToLocation property in the Route interface of the Map Sample, using element reference.

The connection binding will need to use the "Ports" list property of the root element "Application". Keep in mind you don't need a "top" element for the connection (e.g., your Connection interface). Instead, start with a root element which represents the entire diagram. That is the place where you define list property for the nodes and list property for the connection.

Shenxue
Re: Creating custom connection bindings [message #1709298 is a reply to message #1709293] Fri, 25 September 2015 17:46 Go to previous messageGo to next message
Justin Albright is currently offline Justin AlbrightFriend
Messages: 10
Registered: September 2015
Junior Member
If I create the FromPort and ToPort elements in the Connection interface and then reference each back to the Instances I can make a successful connection. However, this does not conform to the xml schema I have to adhere to for the framework. Is there a way to make these elements there for the connection binding, but hidden in the xml so that it does not get shown and I can manually add in the proper port elements in my custom ConnectionService?
Re: Creating custom connection bindings [message #1709305 is a reply to message #1709287] Fri, 25 September 2015 20:30 Go to previous messageGo to next message
Shenxue Zhou is currently offline Shenxue ZhouFriend
Messages: 60
Registered: July 2009
Member
If you don't want the connections to show up in the model xml file, you can get rid of @XmlBinding on your FromPort and ToPort properties. Also get rid of the @XmlListBinding on the Connection list property of your root element. The custom connection service is launched only when you create a new connection. For connections that should be shown when you open the diagram, you still need a way to fill the corresponding connection list property. I recommend that you use a custom list binding for that list property. Please take a look at Sapphire Calendar Sample and its CalendarResource class to get an idea on how to create a custom list binding. When you instantiate your model in your editor, something similiar to this line:

this.modelCalendarIntegrated = org.eclipse.sapphire.samples.calendar.integrated.ICalendar.TYPE.instantiate( new CalendarResource( this.modelCalendar, this.modelContacts ) );

Make your Resource class extend from RootXmlResource class. Override its "protected PropertyBinding createBinding( final Property property )" method to return a "LayeredListPropertyBinding" for the connection list property. For other properties, call super.createBinding(). Please refer to CalendarResource class for details.

I suspect this should be sufficient. You probably don't need a custom connection service once you have the binding working.
Re: Creating custom connection bindings [message #1709478 is a reply to message #1709305] Mon, 28 September 2015 18:36 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Reading through this thread... Is the issue here that the schema for the connection uses a list of <port> elements rather than distinctly-named elements? Presumably it's a list that must be size two. If that's correct, you should be able to achieve what you need either by keeping the model the same and writing a custom ConnectionService or by modifying the model to have ToPort/FromPort properties and using custom binding to read/write the list in xml. Which way you go on this depends on whether you want to preserve the list-nature of the endpoint specification in the model layer.
Re: Creating custom connection bindings [message #1709634 is a reply to message #1709478] Tue, 29 September 2015 18:13 Go to previous message
Justin Albright is currently offline Justin AlbrightFriend
Messages: 10
Registered: September 2015
Junior Member
Thank you both for your responses. I ended up adding this connection type to my existing custom ConnectionService that I already had in place for the connect attribute. It is working as I expect and I was able to retain the schema, which is something I was not able to change.
Previous Topic:Using ListProperty for attribute of an element
Next Topic:How To Use Context When Creating New Diagram Node
Goto Forum:
  


Current Time: Tue Apr 23 05:32:38 GMT 2024

Powered by FUDForum. Page generated in 0.03175 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top