index > Visual Studio Team System - Domain-Specific Language Tools > Decorator for Compartments

Decorator for Compartments


Hi,

I would like to know if there is any way to have something like an IconDecorator on a Compartment (Microsoft.VisualStudio.Modeling.Diagrams.Compartment) ?

The result should be similar to say the Icons that are used to represent the different kind of Decorators in the Dsl Tool itself.

Regards,

Rasmus Oudal Edberg




/Rasmus
Rasmus Oudal Edberg

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
Rasmus Oudal Edberg
reply 2

You can use google to search for other answers

 

More Articles

Label Editing (how to prevent)
Inheritance Restriction?
What can be created with DSL?
Keeping separate models in step
How To Navigate over Links
Minor gotcha in the Adding a Compartment Shape walkthrough
Can we host DSL designer in a custom host application?
Odd results experimenting with shapes and connectors
DSL Tools May 2005 with VSTS July CTP?
Dynamically determining link type
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

how can i get a reference to a modelelem…
Split (T4) code in more than 1 text temp…
Decorator for Compartments
academic distribution of a DSL
Custom Storage setting...
Error crearting DSL prokject
Transform Model to DSL
Reference relationships without graphica…
Persistence in XML
How to Add context menu to shapes
Changing type of element using property …
filtering reference dropdowns in the pro…
Codegen templates selected at build time
Label Editing (how to prevent)
Generating Code From a Model Walkthrough

Hot Articles

How to add or remove template files in t…
Xsd To DslDefinition.dsl transformation
Package Load Failure - ...TextTemplating…
How to migrate / implement CustomStorage…
What is the best way to present 3 value …
Error : Value cannot be null ,Parameter …
Installing June 2006 VS SDK CTP side-by-…
Abstract classes in minimal language
Reflecting domain property value on shap…
Catch On Properties Change Event
Migrating between languages
HELP!!!...There is no: File > Export …
Fail to load Designer package
blog post suggestions: mdfddt/mdfomt fil…
Accessing the domain model using code

Recommend Articles

Diagram Size
2 problems with V1 release
DSL Setup project fails to compile
How are new objects created in a DSL?
Package Load Failure Again
How to intercept shape double-click event
Embedding Relationships and Inheritence
How to add Text template and make availa…
Enable/Disable property OnValueChanging/…
connections restrictions between shapes …
Why the f$%^&* does the DSL tools as…
Keeping separate models in step
DSL Tools / VS.NET RTM
DMD -> DD
Rules don't seem to be called with sdk 2…