I found the solution myself and thought I would share my approach. The solution I'm working on is based on the ClassDiagram template, so the code below should be familiar to anyone who have used that template.
What I did was set the ClassShape to "Generate Double Derived" and I created a new partial class and intercepted the call to GetCompartmentMappings and here added ImageGetter for the two different kind of compartments. The full class i listed below.
public partial class ClassShape : ClassShapeBase { /// <summary> /// Gets an array of CompartmentMappings for all compartments displayed on this shape /// (including compartment maps defined on base shapes). /// </summary> /// <param name="melType">The type of the DomainClass that this shape is mapped to</param> /// <returns></returns> protected override DslDiagrams::CompartmentMapping[] GetCompartmentMappings(global::System.Type melType) { if (melType == null) throw new global::System.ArgumentNullException("melType");
CompartmentMapping[] mappings = base.GetCompartmentMappings(melType);
foreach (CompartmentMapping mapping in mappings) { ElementListCompartmentMapping elemMap = mapping as ElementListCompartmentMapping;
if (elemMap != null) { if (elemMap.CompartmentId == "AttributesCompartment") { elemMap.ImageGetter = AttributeDisplayImageGetter; } if (elemMap.CompartmentId == "OperationsCompartment") { elemMap.ImageGetter = OperationDisplayImageGetter; } } }
return mappings; }
//This will deliver custom images to operations public Image OperationDisplayImageGetter(ModelElement element) { Assembly a = Assembly.GetExecutingAssembly(); Stream imgStream = a.GetManifestResourceStream("ABC.Tools.CustomResources.AttributeTool.bmp"); return Image.FromStream(imgStream); }
//This will deliver custom images to attributes public Image AttributeDisplayImageGetter(ModelElement element) { Assembly a = Assembly.GetExecutingAssembly(); Stream imgStream = a.GetManifestResourceStream("ABC.Tools.CustomResources.OperationTool.bmp"); return Image.FromStream(imgStream); } }
/Rasmus |