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

Bug 335642

Summary: [diagram] improve color and line style api
Product: z_Archived Reporter: Konstantin Komissarchik <konstantin>
Component: SapphireAssignee: Shenxue Zhou <shenxue.zhou>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Patch v1
none
Patch V2 konstantin: iplog+

Description Konstantin Komissarchik CLA 2011-01-27 20:02:33 EST
A recent change added support for setting line style and color on diagram connections. This was done using hints facilities. I am actually trying to phase out the reliance on hints. We loose a lot of expressive power by not treating these settings as explicit properties and the syntax in the sdef file isn't very convenient.

Let's add LineStyle and LineColor properties to IDiagramConnectionDef. 

LineStyle property can use the existing LineStyle enum. You will not need LineStyle.getLineStyle(<string>) method any more. Use @EnumSerialization annotation on enum items to set how enums are to be converted to string form.

LineColor property needs a corresponding Color object. You will need to register a value serialization service since this will be a completely custom value type. There are plenty of examples of how to do this. See basic types like Integer in the modeling plugin. The parseColor function would live in the serializer. The Color class cannot use SWT's RGB class. It should contain the color triplet directly. The rendering layer can construct RGB objects as necessary.

Both LineStyle class and the to-be-created Color class should live in the root sapphire.ui package since they are in principle more generic than diagram feature.
Comment 1 Shenxue Zhou CLA 2011-02-01 16:09:11 EST
Created attachment 188088 [details]
Patch v1
Comment 2 Konstantin Komissarchik CLA 2011-02-01 16:21:41 EST
A few issues...

1. ColorSerializationService needs encode implementation. The default implementation uses toString(), but you haven't implemented toString() on Color either.

2. LineStyle.getLineStyle() static method should be removed. This sort of translation should happen via serialization service. For enums, the serialization service is supplied by the system. You would write something like this... element.service( MyProperty, ValueSerializationService.class ).decode( str )

3. There is a commented-out color hint line in MapEditor.sdef with old syntax. Should this line be removed?

Also, please name your patches "Patch v1", "Patch v2", etc. This makes it simpler to sort out what's going on. A detail description of the content should go in the accompanying comment rather than attachment title.
Comment 3 Shenxue Zhou CLA 2011-02-01 17:25:34 EST
Created attachment 188097 [details]
Patch V2

Patch v2 to address the above issues
Comment 4 Konstantin Komissarchik CLA 2011-02-01 19:55:00 EST
Released patch v2. There was one other problem that I noticed in ColorSerializationService, but I just fixed it up myself. The issue is that the decode method isn't supposed to throw exceptions. It should return null instead. I have also updated javadoc of ValueSerializationService to state as much.
Comment 5 Konstantin Komissarchik CLA 2011-06-09 16:37:50 EDT
Closing. This can be considered verified as Shenxue has submitted the patch and I reviewed the code and behavior before releasing.