<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ticklish Techs &#187; JaDAL</title>
	<atom:link href="http://www.ticklishtechs.net/tag/jadal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ticklishtechs.net</link>
	<description>a mostly .NET but also some other cool techs blog</description>
	<lastBuildDate>Fri, 23 Jul 2010 06:07:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flow</title>
		<link>http://www.ticklishtechs.net/2009/01/05/flow/</link>
		<comments>http://www.ticklishtechs.net/2009/01/05/flow/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 06:49:00 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flow]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2009/01/05/flow/</guid>
		<description><![CDATA[It was very silent here in the past month. That was mainly because I was working on my diploma thesis until the end of September. After that I did my final exam and started working in Bonn. Now it is December and almost 2009. I’m sitting in a plane to Australia for holiday and have [...]]]></description>
			<content:encoded><![CDATA[<p>It was very silent here in the past month. That was mainly because I was working on my diploma thesis until the end of September. After that I did my final exam and started working in Bonn. Now it is December and almost 2009. I’m sitting in a plane to Australia for holiday and have much time to write articles. I will try to keep this blog alive and will write articles more frequently.</p>
<p>Today I will introduce <em><strong>Flow</strong></em>. With <em>Flow</em> you can model the behavior of nodes in a wireless sensor network (WSN) in a data driven and event driven manor. I developed <em>Flow</em> as part of my diploma thesis.</p>
<p><em>Flow</em> is build as a Visual Studio Addon (a VS Package) on top of the DSL-Tools containing three different domain specific languages to describe different parts of the software running on a sensor node. These different DSLs are working together and using most of the techniques I described earlier in this blog. E.g. my library JaDAL was initially build to support this diploma thesis.</p>
<p>You will find screenshots, more explanations and <em>Flow</em> itself on <a href="http://flow.irgendwie.net">http://flow.irgendwie.net</a>. While the webpage and the software are available in English the thesis itself is a pdf-document and can only be downloaded in a German version.</p>
<p>The software is fully working and if no wireless sensor network is available you can use a node simulator to evaluate <em>Flow</em>. The code is released under the new BSD license and also available for download.</p>
<h3>Screenshots:</h3>
<p>Dataflows modeled with <em>Flow</em> looks like that:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2009/01/dataflow.png"><img style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" title="dataflow" src="http://www.ticklishtechs.net/wp-content/uploads/2009/01/dataflow-thumb.png" border="0" alt="dataflow" width="456" height="191" /></a></p>
<p>The simulated sensor nodes are represented as Windows forms programmed by such dataflows:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2009/01/simulatednode.png"><img style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" title="simulatednode" src="http://www.ticklishtechs.net/wp-content/uploads/2009/01/simulatednode-thumb.png" border="0" alt="simulatednode" width="182" height="244" /></a></p>
<p>For more information just visit <a href="http://flow.irgendwie.net">http://flow.irgendwie.net</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2009/01/05/flow/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DirectiveProcessor for VSX</title>
		<link>http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/</link>
		<comments>http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 20:20:33 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[t4]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/</guid>
		<description><![CDATA[I created two DirectiveProcessor for Visual Studio to use in the T4 system. I added the classes to JaDAL hoping someone can use them in her project or use the code as an example when creating new DirectiveProcessors.
Let&#8217;s start with a short introduction to DirectiveProcessors. DirectiveProcessors are used in .tt-files to provide data to the [...]]]></description>
			<content:encoded><![CDATA[<p>I created two DirectiveProcessor for Visual Studio to use in the T4 system. I added the classes to JaDAL hoping someone can use them in her project or use the code as an example when creating new DirectiveProcessors.</p>
<p>Let&#8217;s start with a short introduction to DirectiveProcessors. DirectiveProcessors are used in .tt-files to provide data to the template. The DirectiveProcessor can take parameters from the declaration in the .tt-file and adds some code to the compiled template. This code (often properties) can be used from within the template. For example the DSL Tools are generating one DirectiveProcessor for each DSL model. In a template form the DSL Tools you will see a line like the following:</p>
<p><span style="background: gold">&lt;#@</span><span style="color: red;"> Language1 </span><span style="color: red;">processor=</span>&#8220;<span style="color: blue;">Language1DirectiveProcessor</span>&#8221;<br />
<span style="color: red;">requires=</span>&#8220;<span style="color: blue;">fileName=&#8217;Sample.mydsl1&#8242;</span>&#8221; <span style="background: gold">#&gt;</span></p>
<p>This line uses the <code>Language1DirectiveProcessor</code> and provides it with one parameter (<code>fileName</code>). The DirectiveProcessor adds code to the template to open the given file and creates (in this case) a <code>ExampleModel</code>-property to use in the template code.</p>
<p>I created two DirectiveProcessors to use the data of simple Xml-files and Visual Studio Project files in the templates. The code of the two DirectiveProcessors is very straight forward and maybe one could advance it (e.g. make it compatible with templates written in Visual Basic).</p>
<h3>Using the XmlFileDirectiveProcessor</h3>
<p>Add a line like the following to your .tt-file:</p>
<p><span style="background: gold">&lt;#@</span><span style="color: red;"> XmlFile processor=</span>&#8220;<span style="color: blue;">XmlFileDirectiveProcessor</span>&#8221; <span style="color: red;">FileName=</span>&#8220;<span style="color: blue;">example.xml</span>&#8221; <span style="background: gold">#&gt;</span></p>
<p>Inside this template you can access the (full qualified) filename via the <code>this.XmlFileName</code>-Property and the Content of this file (as a <code>XDocument</code>) via the <code>this.XmlFile</code>-Property.</p>
<h3>Using the VsProjectFileDirectiveProcessor</h3>
<p>Add this line to your template:</p>
<p><span style="background: gold">&lt;#@</span><span style="color: red;"> ProjectFile processor=</span>&#8220;<span style="color: blue;">VsProjectFileDirectiveProcessor</span>&#8221; <span style="color: red;">FileName=</span>&#8220;<span style="color: #0000ff;">x.csproj</span>&#8221; <span style="background: gold">#&gt;</span></p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>A property named <code>this.ProjectFile</code> will be added to the template. This property provides you with an instance of the <code>VsProjectFile</code>-class containing the project file contents. This class contains only very little functionality (feel free to add some more and submit it back to me!). Just take a look at the source code of this class. The method <code>GetAllFiles()</code> returns a string array of all files found in the project (supporting C++ and C# project files &#8211; .vcproj and .csproj).</p>
<h3>Setup</h3>
<p>An entry in the registry is needed to allow the T4 system to find custom DirectiveProcessors. Just add the following entries to your registry and don&#8217;t forget to point to the right location of the <code>JaDAL.dll</code>.</p>
<p>[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0Exp\<br />
Configuration\TextTemplating\DirectiveProcessors\VsProjectFileDirectiveProcessor]<br />
&#8220;Class&#8221;=&#8221;BenjaminSchroeter.Dsl.DirectiveProcessors.VsProjectFileDirectiveProcessor&#8221;<br />
&#8220;CodeBase&#8221;=&#8221;D:\\JaDAL\\bin\\Debug\\JaDAL.dll&#8221;</p>
<p>[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0Exp\<br />
Configuration\TextTemplating\DirectiveProcessors\XmlFileDirectiveProcessor]<br />
&#8220;Class&#8221;=&#8221;BenjaminSchroeter.Dsl.DirectiveProcessors.XmlFileDirectiveProcessor&#8221;<br />
&#8220;CodeBase&#8221;=&#8221;D:\\JaDAL\\bin\\Debug\\JaDAL.dll&#8221;</p>
<p>These registry keys are for the Experimental Hive of Visual Studio. To register the DirectiveProcessors for the normal Visual Studio instance the registry key starts with HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0<br />
\TextTemplating\DirectiveProcessors\</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/10/15/directiveprocessor-for-vsx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom restrictions for Domain Properties</title>
		<link>http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/</link>
		<comments>http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/#comments</comments>
		<pubDate>Mon, 26 May 2008 09:43:47 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/</guid>
		<description><![CDATA[In To restrict dynamically the usage of Domain Properties in DSL Models I described a way to restrict the usage of certain domain properties by the user. You can define different modes for your editor and thus allow or prevent the usage of domain properties via attributes on your domain classes. The technique is described [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/">To restrict dynamically the usage of Domain Properties in DSL Models</a> I described a way to restrict the usage of certain domain properties by the user. You can define different modes for your editor and thus allow or prevent the usage of domain properties via attributes on your domain classes. The technique is described in the linked article and the code is released as part of <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a>.</p>
<p>This is a pretty static way to control the domain properties. You have to define a few modes and decide at design time the visible and active properties for each mode. Sometimes you need a more dynamic way: So I introduced another attribute <code>CustomRestrictedPropertyAttribute</code> and an interface <code>ISupportsUserRestrictions</code>. If this attribute is present, the library will call the <code>GetRestriction()</code> method of this interface and your user code can decide whenever the domain property will be visible, hidden or read only.</p>
<p>I built a small example: a domain class contains a few properties: <em>CustomPropery</em>, <em>CustomPropertyVisible</em> and <em>CustomPropertyReadOnly</em>. The two flags cause the first property to be visible, hidden or read only in the properties window. </p>
<pre class="code">[<span style="color: #2b91af">CustomRestrictedProperty</span>(<span style="color: #a31515">&quot;CustomProperty&quot;</span>)]
<span style="color: blue">partial class </span><span style="color: #2b91af">ExampleElement </span>: <span style="color: #2b91af">ISupportsUserRestrictions
</span>{
    <span style="color: blue">public </span><span style="color: #2b91af">Restriction </span>GetRestriction(<span style="color: blue">string </span>property)
    {
        <span style="color: blue">if </span>(property == <span style="color: #a31515">&quot;CustomProperty&quot;</span>)
        {
            <span style="color: blue">if </span>(!<span style="color: blue">this</span>.CustomPropertyVisible)
                <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.Hidden;

            <span style="color: blue">if </span>(<span style="color: blue">this</span>.CustumPropertyReadOnly)
                <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.ReadOnly;

            <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.Full;
        }

        <span style="color: blue">return </span><span style="color: #2b91af">Restriction</span>.Full;
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/properties.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="168" alt="properties" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/properties-thumb.png" width="490" border="0" /></a> </p>
<p>This example can be downloaded as part of the <a href="http://www.codeplex.com/JaDAL/SourceControl/ListDownloadableCommits.aspx">JaDAL source code</a>. Currently you have to catch the code directly from the Source Code tab at <a href="http://www.codeplex.com">CodePlex</a> since it isn&#8217;t part of the latest Release yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/26/custom-restrictions-for-domain-properties/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JaDAL &#8211; Just another DSL-Tools Addon Library</title>
		<link>http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/</link>
		<comments>http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/#comments</comments>
		<pubDate>Wed, 21 May 2008 10:43:31 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/</guid>
		<description><![CDATA[Over the time I build some libraries that enhance the Microsoft DSL Tools framework and post them here. I wrote a number of articles and for many of them I provided a download with source code or examples. 
However we all know: zip files are a bad version management system!
I decided to put all these [...]]]></description>
			<content:encoded><![CDATA[<p>Over the time I build some libraries that enhance the <a href="http://msdn.com/vsx">Microsoft DSL Tools framework</a> and post them here. I wrote <a href="http://www.ticklishtechs.net/tag/dsl/">a number of articles</a> and for many of them I provided a download with source code or examples. </p>
<p><em>However we all know: zip files are a bad version management system!</em></p>
<p>I decided to put all these code together and compose a single library with addons for the DSL Tools, name it &#8220;<a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a>&#8221; and publish it at <a href="http://www.codeplex.com">CodePlex</a>. I will continue to write articles here, but now you can always find the latest code at CodePlex. </p>
<p>If you are interested in my work with the DSL Tools, just take a look at <a href="http://www.codeplex.com/JaDAL">JaDAL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/21/jadal-just-another-dsl-tools-addon-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connectors between compartment shape entries with DSL Tools &#8211; Version 2</title>
		<link>http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/</link>
		<comments>http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/#comments</comments>
		<pubDate>Wed, 21 May 2008 01:13:38 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/</guid>
		<description><![CDATA[Few months ago I wrote a series of articles and released a library to create connectors between the entries of compartment shapes in Microsoft DSL Tools. In the meantime I found a setting that wasn&#8217;t working with my library and now it is time for version 2. I will release this new version as part [...]]]></description>
			<content:encoded><![CDATA[<p>Few months ago I wrote a <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">series of articles</a> and released a library to create connectors between the entries of compartment shapes in Microsoft DSL Tools. In the meantime I found a setting that wasn&#8217;t working with my library and now it is time for version 2. I will release this new version as part of <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> on <a href="http://www.codeplex.com">CodePlex</a>.</p>
<p>If you don&#8217;t have any idea what I&#8217;m talking about please take a look at (at least) the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first part</a> of the series, but be careful and DO NOT read the second part! The second part contains obsolete information that will be corrected here. <a href="http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/">Part 3</a> and <a href="http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/">part 4</a> describe the inside of the library and they are still valid for the new version.</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/sample.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="226" alt="sample" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/sample-thumb.png" width="440" border="0" /></a> </p>
<h3>Changes from version 1 to 2</h3>
<p>In the original version you have to decide (using the xml file) for the target and source of the connection to be mapped to a compartment or a regular shape. I thought this wouldn&#8217;t be an issue since you must know the mapping of your classes. I believed it until I created my DSL with the use of inheritance and some base class that can be mapped to regular or compartment shapes. For this base class I couldn&#8217;t create a mapping that goes from a regular or a compartment shape to a regular or compartment shape. </p>
<p>I removed this constraint and in version 2 you needn&#8217;t care about it. The library can handle all these cases (even the trivial mapping from regular to regular shape). And even the best: it turned out that removing this constraint made the code much clearer and simpler (both the code of the library itself and the code you have to write). Before this change there were many different cases (first regular to compartment, then compartment to regular, then compartment to compartment and at the end regular to regular which throws an exception) and now everything works the same way.</p>
<p><em>Lesson learned: If you can do something in an abstract and general way, don&#8217;t create different cases and handle only some of them!</em></p>
<h3>And again: the user guide</h3>
<p>In the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">2nd part</a> of this series I presented a user guide with a step by step walkthrough of creating a DSL using the compartment mapping. I will now create the same DSL with version 2. Most steps are still the same but I repeat them for completeness. The main difference is the xml file format at step 7 and the class you have to write yourself in steps 9 to 11.</p>
<p>You will find this example (and a more advanced one) in the release download over at CodePlex.</p>
<ol>
<li>You need <a href="http://code.msdn.microsoft.com/TTxGen">TTxGen</a> to generate some code from my templates. See <a href="http://www.ticklishtechs.net/2008/02/28/codegeneration-with-codesmith-and-orcas-t4/">my article</a> for more information and a workaround for an installation problem.       </li>
<li>I assume you have a DSL solution and at least two <em>Domain Classes</em> mapped to two compartment shapes and two more <em>Domain Classes</em> used as entries of the compartment shapes created. In my example these classes are called <code>Parent1</code>, <code>Entry1</code>, <code>Parent2</code> and <code>Entry2</code>.       <br />The entries need a unique identifier. You could use a name property for this, but there will be some difficulties if the user creates two entries in one shape with the same name, so I will use a guid. (Don&#8217;t forget to create a new guid in the constructor or another proper place.)       </li>
<li>Create a <em>Reference Relationship</em> from <code>Parent1</code> to <code>Parent2</code>. This will be automatically named <code>Parent1ReferencesParent2</code>. We will use this reference to present the relationship from one entry to another. I would like to create <em>Reference Relationships</em> from this relationship to the entries, but relationships of relationships are not supported. We have to store the guids of the entries in the relationship and add two <em>Domain Properties</em> for this purpose to it. I named them <code>fromEntry</code> and <code>toEntry</code>.       <br /><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/02/dsldefinition.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="298" alt="DslDefinition" src="http://www.ticklishtechs.net/wp-content/uploads/2008/02/dsldefinition-thumb.png" width="440" border="0" /></a>&#160; </li>
<li>Set the <code>Allows Duplicates</code> property of the <code>Parent1ReferencesParent2</code> relationship to <code>true</code>.       </li>
<li>Set the <code>Is Custom</code> property of the <em>Connection Builder</em> (<code>Parent1ReferencesParent2Builder</code>) in the <em>DSL Explorer</em> to <code>true</code>.       </li>
<li>Add a reference to <code>JaDAL.dll</code> to both the <code>Dsl</code> and <code>DslPackage</code> project.       </li>
<li>Add a new xml file (in my example <code>CompartmentMappings.xml</code>) to your solution and write the following code in it:
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot; <span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">CompartmentMappings </span><span style="color: red">xmlns:xsi</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://www.w3.org/2001/XMLSchema-instance</span>&quot;
 <span style="color: red">xsi:noNamespaceSchemaLocation</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentMappings.xsd</span>&quot;
 <span style="color: red">namespace</span><span style="color: blue">=</span>&quot;<span style="color: blue">BenjaminSchroeter.CompartmentMapping</span>&quot;<span style="color: blue">&gt;

  &lt;</span><span style="color: #a31515">Connection </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent1ReferencesParent2</span>&quot;
    <span style="color: red">allowSelfReference</span><span style="color: blue">=</span>&quot;<span style="color: blue">true</span>&quot;
    <span style="color: red">suppressEntryDeletePropagation</span><span style="color: blue">=</span>&quot;<span style="color: blue">false</span>&quot;<span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">Source </span><span style="color: red">allowHead</span><span style="color: blue">=</span>&quot;<span style="color: blue">false</span>&quot;<span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">DomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent1</span>&quot; <span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">EntryDomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Entry1</span>&quot;<span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">Source</span><span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">Target </span><span style="color: red">allowHead</span><span style="color: blue">=</span>&quot;<span style="color: blue">true</span>&quot;<span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">DomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent2</span>&quot;<span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">EntryDomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Entry2</span>&quot;<span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">Target</span><span style="color: blue">&gt;

    &lt;</span><span style="color: #a31515">Connector </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Connector</span>&quot;<span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">Connection</span><span style="color: blue">&gt;

  &lt;</span><span style="color: #a31515">CompartmentShape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentShape1</span>&quot;<span style="color: blue">/&gt;
  &lt;</span><span style="color: #a31515">CompartmentShape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentShape2</span>&quot;<span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">CompartmentMappings</span><span style="color: blue">&gt;</span></pre>
<p>(If you place the xsd file in the same directory you get IntelliSense and error checking for free.)</p>
</li>
<li>Place the <code>CompartmentMappings.tt</code> file in the same directory, right-click on the xml file and choose <em>Generate xGen Template</em>. A <code>CompartmentMappings_xGen.tt</code> file will be created below the xml file and there you have to add the following lines:
<pre class="code"><span style="background: gold">&lt;#@</span><span style="color: red"> ParentFileInjector processor=</span>&quot;<span style="color: blue">TTxGenDirectiveProcessor</span>&quot;
    <span style="color: red">requires=</span>&quot;<span style="color: blue">fileName='CompartmentMappings.xml'</span>&quot; <span style="background: gold">#&gt;
&lt;#@</span><span style="color: red"> </span><span style="color: brown">include </span><span style="color: red">file=</span>&quot;<span style="color: blue">CompartmentMappings.tt</span>&quot; <span style="background: gold">#&gt;</span></pre>
<p>(Be sure you use the right xml file name here.)</p>
</li>
<li>Now you have to write some code by yourself. In the generated cs file (<code>CompartmentMappings_xGen.cs</code>) there will be a class named <code>Parent1ReferencesParent2BuilderInstance </code>with three missing methods you have to override. Create a partial class in a new file and implement these methods (see 10 and 11).
<p></li>
<li>Implement the <code>CreateElementLink()</code> method in this file. Here you have to add code to store the selected compartment entries for source and target in the properties of the relationship (see 3).
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">ElementLink </span>CreateElementLink
    (<span style="color: #2b91af">Parent1 </span>source,
     <span style="color: #2b91af">SelectedCompartmentPartType </span>sourcePartType,
     <span style="color: #2b91af">Entry1 </span>sourceEntry,
     <span style="color: #2b91af">Parent2 </span>target,
     <span style="color: #2b91af">SelectedCompartmentPartType </span>targetPartType,
     <span style="color: #2b91af">Entry2 </span>targetEntry)
{
    <span style="color: #2b91af">Parent1ReferencesParent2 </span>result;
    result = <span style="color: blue">new </span><span style="color: #2b91af">Parent1ReferencesParent2</span>(source, target);
    <span style="color: blue">if</span>(sourcePartType== <span style="color: #2b91af">SelectedCompartmentPartType</span>.Head)
        <span style="color: green">// use a empty guid for the Head
        </span>result.fromEntry = <span style="color: #2b91af">Guid</span>.Empty;
    <span style="color: blue">else
        </span>result.fromEntry = sourceEntry.Guid;

    <span style="color: blue">if</span>(targetPartType== <span style="color: #2b91af">SelectedCompartmentPartType</span>.Head)
        <span style="color: green">// use a empty guid for the Head
        </span>result.toEntry = <span style="color: #2b91af">Guid</span>.Empty;
    <span style="color: blue">else
        </span>result.toEntry = targetEntry.Guid;

    <span style="color: blue">return </span>result;
}</pre>
<p>    <a href="http://11011.net/software/vspaste"></a></li>
<li>In the <code>CreateElementLink()</code> method you have stored the source and target entry information somewhere; my library does not know about this location. So we need two additional methods to compare an entry with a relationship and answer the question &quot;Is this entry the source of a given relationship?&quot; and the same for the target. These code resists in the same file:
<pre class="code"><span style="color: blue">public override bool </span>IsEntryConnectionSource
    (<span style="color: #2b91af">Entry1 </span>entry,
     <span style="color: #2b91af">Parent1ReferencesParent2 </span>connection)
{
    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return </span>connection.fromEntry.Equals(<span style="color: #2b91af">Guid</span>.Empty);

    <span style="color: blue">return </span>connection.fromEntry.Equals(entry.Guid);
}

<span style="color: blue">public override bool </span>IsEntryConnectionTarget
    (<span style="color: #2b91af">Entry2 </span>entry,
     <span style="color: #2b91af">Parent1ReferencesParent2 </span>connection)
{
    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return </span>connection.toEntry.Equals(<span style="color: #2b91af">Guid</span>.Empty);

    <span style="color: blue">return </span>connection.toEntry.Equals(entry.Guid);
}</pre>
<p>Always care for <code>entry == null</code>, this will be used to check whether the head of the shape is meant. Even if you do not allow the head to be source or target this method will be called with a <code>null</code> parameter from time to time.</p>
</li>
<li>Create a <code>partial class</code> for your <em>Domain Model </em>(<code>CompartmentMappingExampleDomainModel</code>) and add the following methods.
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">Type</span>[] GetCustomDomainModelTypes()
{
  <span style="color: blue">return </span><span style="color: #2b91af">CompartmentMappingUtil</span>.AllCompartmentMappingRules(<span style="color: blue">this</span>);
}</pre>
<p>(If you have already some custom rules, you can use an overloaded version of the <code>AllCompartmentMappingRules()</code> method.)</p>
</li>
<li>
<p>In the <code>DslPackage</code> project create a <code>partial class</code> for the generated <em>Command Set</em> and add the following code:</p>
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">MenuCommand</span>&gt; GetMenuCommands()
{
    <span style="color: blue">return </span><span style="color: #2b91af">CompartmentMappingUtil</span>.RemoveRerouteCommand
                                (<span style="color: blue">base</span>.GetMenuCommands());
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
</li>
</ol>
<p>That&#8217;s all. The mapping from compartment entry to compartment entry should be working after compiling the solution.</p>
<h3>Advanced Features</h3>
<p>As I mention above you can mix compartment and regular shapes. You only need to create a DSL with these shapes and configure the xml file another way. As you see, inside the <code>&lt;Connection&gt;</code> element there is no longer a reference to the diagram elements, only the domain classes are used here. Obviously if you use inheritance all your classes need to have the same base class for <code>&lt;DomainClass&gt;</code> itself and for <code>&lt;EntryDomainClass&gt;</code>. If the concrete class is mapped to a compartment shape, the compartment mappings, otherwise a mapping of regular shapes, will be used.</p>
<p>If one of source or target is always a regular shape, please use <code>ModelElement</code> for <code>&lt;EntryDomainClass&gt;</code>.</p>
<p>At the bottom of the xml file you have to list all shapes that play a role in your mapping. Use the xml elements <code>&lt;CompartmentShape&gt;</code> and <code>&lt;RegularShape&gt;</code> therefore.</p>
<p>Inside your <code>Parent1ReferencesParent2BuilderInstance</code> class you can override some more methods to allow or forbid the creation of connectors. I think the names and signatures speak for themselves:</p>
<ul>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptAsCompartmentSource (SOURCE_ELEMENT candidate,   <span style="color: #2b91af">SelectedCompartmentPartType </span>partType,   SOURCE_COMPARTMENT_ENTRY candidateEntry)</pre>
</li>
<p>  <a href="http://11011.net/software/vspaste"></a></p>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptAsCompartmentTarget (TARGET_ELEMENT candidate,   <span style="color: #2b91af">SelectedCompartmentPartType </span>partType,   TARGET_COMPARTMENT_ENTRY candidateEntry)</pre>
</li>
<p>  <a href="http://11011.net/software/vspaste"></a></p>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptAsCompartmentSourceAndTarget  (SOURCE_ELEMENT sourceElement, <span style="color: #2b91af">  SelectedCompartmentPartType </span>sourcePartType,   SOURCE_COMPARTMENT_ENTRY sourceEntry,   TARGET_ELEMENT targetElement, <span style="color: #2b91af">  SelectedCompartmentPartType </span>targetPartType,   TARGET_COMPARTMENT_ENTRY targetEntry)</pre>
</li>
</ul>
<h3>Advanced Sample</h3>
<p>In addition to the sample above I build a second one. There I want to create mappings form some <em>Inputs</em> to some <em>Outputs</em>, where one of these <em>Inputs</em> or <em>Outputs</em> can be an entry of a compartment shape or a whole regular shape. This regular shape contains a property <em>Kind</em> that makes the shape to an <em>Input </em>or an <em>Output</em> (to show you the use of the <code>CanAcceptAs...</code> methods).</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advancedsample.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="207" alt="advancedsample" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advancedsample-thumb.png" width="440" border="0" /></a> </p>
<p>The DSL model looks like this:</p>
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advanceddslmodel.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="268" alt="advanceddslmodel" src="http://www.ticklishtechs.net/wp-content/uploads/2008/05/advanceddslmodel-thumb.png" width="444" border="0" /></a> </p>
<p>The project with all sources is part of the samples in the JaDAL download.</p>
<h3>Download</h3>
<p>The compartment mapping library and both samples are part of <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> which you can download from <a href="http://www.codeplex.com">CodePlex</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Preventing model elements from being deleted</title>
		<link>http://www.ticklishtechs.net/2008/05/15/preventing-model-elements-from-being-deleted/</link>
		<comments>http://www.ticklishtechs.net/2008/05/15/preventing-model-elements-from-being-deleted/#comments</comments>
		<pubDate>Thu, 15 May 2008 16:21:22 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/05/15/preventing-model-elements-from-being-deleted/</guid>
		<description><![CDATA[One would think, it is a simple feature in the DSL Tools framework to allow and forbid the deletion of model elements, but it isn&#8217;t.
There are a few posts in the DSL Forum and it seems there are even a few methods to forbid the deletion. But every single solution has its pros and cons [...]]]></description>
			<content:encoded><![CDATA[<p>One would think, it is a simple feature in the DSL Tools framework to allow and forbid the deletion of model elements, but it isn&#8217;t.</p>
<p>There are a few posts in the DSL Forum and it seems there are even a few methods to forbid the deletion. But every single solution has its pros and cons and you have to write a little bit of code yourself. Just take a look at the following postings:</p>
<ul>
<li><a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=73606&amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=73606&amp;SiteID=1">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=73606&amp;SiteID=1</a> </li>
<li><a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=780425&amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=780425&amp;SiteID=1">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=780425&amp;SiteID=1</a> </li>
</ul>
<p>One solution is to throw an exception from within a DeletingRule, but I personally don&#8217;t like this. It means, the user is able to click on a <em>delete </em>menu item and then an error message box pops up. This is not a good user experience!</p>
<p>I think the best would be to hide the &quot;delete&quot; commands from the menus. If you disable the commands, the delete key isn&#8217;t working, too. But there are two places where the user can find such a &quot;delete&quot; command for the model elements: on the design surface of the DSL Editor and on the items of the DSL Explorer (and further more: the DSL Explorer has a &quot;delete&quot; and a &quot;delete all&quot; command on different tree nodes). You have to handle both cases.</p>
<p>I would just like to have somewhere a <code>bool CanDelete()</code> method that is called every time the menu is shown and asks my component whether to allow the deletion or not.</p>
<p><strong>Now the good news: I added this Method and wrote a little piece of code for it!</strong></p>
<p>First I created a very simple Interface</p>
<pre class="code"><span style="color: blue">public interface </span><span style="color: #2b91af">IDynamicCanDelete
</span>{
    <span style="color: blue">bool </span>CanDelete();
}</pre>
<p>With this interface you can add the missing method to your shapes or model elements. I recommend to implement this method in the model elements since the model explorer knows nothing about your shapes and cannot call this method if implemented in the shape classes. You don&#8217;t need to implement this method for every model element, but only for those you want to forbid deletion. Just return <code>false</code> or implement some logic based on the model element state.</p>
<p>If this feature would be part of DSL Tools that is all you need to do. Though since it is only an addition to it, you have to connect some methods with my library:</p>
<ul>
<li>In the <code>DslPackage</code> project add a partial class for your <code>MyLanguageCommandSet</code> and override the following method:</li>
<pre class="code"><span style="color: blue">protected override void </span>ProcessOnStatusDeleteCommand
                                   (<span style="color: #2b91af">MenuCommand </span>command)
{
    OnStatusDeleteCommandLogic.ForEditor(command,
                    <span style="color: blue">this</span>.CurrentDocumentSelection,
                    <span style="color: blue">base</span>.ProcessOnStatusDeleteCommand);
}</pre>
<li>
<p>In the same project add a partial class for your <code>MyLanguageExplorer</code> and override two methods:</p>
<pre class="code"><span style="color: blue">protected override void </span>ProcessOnStatusDeleteCommand
                                    (<span style="color: #2b91af">MenuCommand </span>cmd)
{
    OnStatusDeleteCommandLogic.ForExplorerDelete(cmd,
                  <span style="color: blue">this</span>.SelectedElement,
                  <span style="color: blue">base</span>.ProcessOnStatusDeleteCommand);
}

<span style="color: blue">protected override void </span>ProcessOnStatusDeleteAllCommand
                                        (<span style="color: #2b91af">MenuCommand </span>cmd)
{
    OnStatusDeleteCommandLogic.ForExplorerDeleteAll(cmd,
                 <span style="color: blue">this</span>.ObjectModelBrowser.SelectedNode,
                 <span style="color: blue">base</span>.ProcessOnStatusDeleteAllCommand);
}</pre>
</li>
<p>  <a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></ul>
<p>That&#8217;s all, but what&#8217;s happening inside the <code>OnStatusDeleteCommandLogic</code> class? I&#8217;m looking for the selected elements (that are shapes in the editor or TreeNodes in the DSL Explorer) and check whether they implement the <code>IDynamicCanDelete</code> interface. If there is this interface I will call the <code>CanDelete()</code> method and if it returns <code>false</code> the delete menu command will be disabled and set to invisible.</p>
<p>For the Editor I will check the shape and the corresponding model element. If there are multiple elements selected only one must report <code>false</code> to disable the command.</p>
<p>The DSL Explorer provides a <em>Delete All</em> command on some nodes. For this command I will check all children but not the grandchildren.</p>
<p>For more details please take a look at the source code.</p>
<div class="wlWriterSmartContent" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:c837f8ad-3efc-45ff-94ce-9a617ead3c9f" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<p><strike>Download </strike><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/05/candelete.zip"><strike>the files</strike></a></p>
</div>
<h3>Update</h3>
<p>This code is now part of the <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> project. Please download the current version from that page. The download over at <a href="http://www.codeplex.com">CodePlex</a> contains the source code described here, an example DSL language and the library as a binary. Future enhancements of the code will be published there, too.</p>
<h3>Additional bug fix for the explorer</h3>
<p>DuncanP mentioned at the end of his <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=780425&amp;SiteID=1">article</a> a small bug in the behavior of the model explorer. This bug can make the &#8220;Delete All&#8221; command visible when you don&#8217;t want it to be. He described an idea for a bug fix. I can find the same wrong behavior in the current release for Visual Studio 2008 and implemented a bug fix the way DuncanP pointed out:</p>
<p>Add the following code in the <code>MyLanguageExplorer</code> class</p>
<pre class="code"><span style="color: blue">public override void </span>AddCommandHandlers(<span style="color: #2b91af">IMenuCommandService </span>menuCommandService)
{
    <span style="color: blue">base</span>.AddCommandHandlers(menuCommandService);

    <span style="color: #2b91af">MenuCommand </span>deleteAllCommand =
        menuCommandService.FindCommand
            (<span style="color: #2b91af">CommonModelingCommands</span>.ModelExplorerDeleteAll);
    <span style="color: blue">this</span>.ObjectModelBrowser.AfterSelect +=
        <span style="color: blue">delegate
            </span>{
                ProcessOnStatusDeleteAllCommand(deleteAllCommand);
            };
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/05/15/preventing-model-elements-from-being-deleted/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>To restrict dynamically the usage of Domain Properties in DSL Models</title>
		<link>http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/</link>
		<comments>http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 21:10:33 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/</guid>
		<description><![CDATA[What&#8217;s the matter?
If you define Domain Properties on your Domain Classes and Shapes, you can configure the way a user of your DSL can interact with this Domain Properties. With the properties Is Browsable and Is UI Read Only you can hide a property from the Properties Window, make it read only or give the [...]]]></description>
			<content:encoded><![CDATA[<h3>What&#8217;s the matter?</h3>
<p>If you define <em>Domain Properties</em> on your <em>Domain Classes</em> and <em>Shapes</em>, you can configure the way a user of your DSL can interact with this <em>Domain Properties</em>. With the properties <em>Is Browsable </em>and <em>Is UI Read Only</em> you can hide a property from the Properties Window, make it read only or give the user full access to it.</p>
<p>But I want to change this behavior of certain Domain Properties dynamically at runtime!    <br />Why the heck would someone need this? I don&#8217;t know, but I can tell why I need it: I&#8217;m designing a DSL with two types of users in mind. The DSL should look the same to both users, but one user can edit the whole DSL and change every property while the other user is not allowed to do so. Some properties will be disabled (read only) and some other properties will be invisible to the second user.</p>
<p>Another scenario could be a simple and advanced mode for some DSL Editor and the user can switch between these modes in some options dialog.</p>
<h3>How do you use it?</h3>
<p>First I want to describe the using of my library. If you are not interested in understanding how it works, you can use the library after reading this section.</p>
<p>First you have to define an enumeration with the modes your editor should support. The enumeration can contain more then two elements if you need more modes. The special Value 0 is used for the editor in the way you defined it within the DSL Tools. You should define your properties with <em>Is Browsable </em>set to <code>true</code> and <em>Is UI Read Only </em>set to <code>false</code>.</p>
<pre class="code"><span style="color: blue">public enum </span><span style="color: #2b91af">RestrictionModes
</span>{
    Original = 0,
    Simple,
    Advanced
}</pre>
<p>Than you can provide your <em>Domain Classes </em>and the <em>Domain Model </em>with the <code>RestrictedProperty</code>-Attribute to configure the different properties:</p>
<pre class="code">[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Simple,
                    <span style="color: #a31515">&quot;P1&quot;</span>, <span style="color: #2b91af">Restriction</span>.Hidden)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Simple,
                    <span style="color: #a31515">&quot;P2&quot;</span>, <span style="color: #2b91af">Restriction</span>.ReadOnly)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Simple,
                    <span style="color: #a31515">&quot;P3&quot;</span>, <span style="color: #2b91af">Restriction</span>.ReadOnly)]

[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Advanced,
                    <span style="color: #a31515">&quot;P1&quot;</span>, <span style="color: #2b91af">Restriction</span>.Full)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Advanced,
                    <span style="color: #a31515">&quot;P2&quot;</span>, <span style="color: #2b91af">Restriction</span>.Full)]
[<span style="color: #2b91af">RestrictedProperty</span>((<span style="color: blue">int</span>)<span style="color: #2b91af">RestrictionModes</span>.Advanced,
                    <span style="color: #a31515">&quot;P3&quot;</span>, <span style="color: #2b91af">Restriction</span>.ReadOnly)]
<span style="color: blue">partial class </span><span style="color: #2b91af">ExampleModel
</span>{
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The <code>ExampleModel</code> has three properties (<code>P1</code>, <code>P2</code>, <code>P3</code>) and in the original DSL Editor these properties are all writable. Properties that are not mentioned by the attributes will work as defined. </p>
<p>If the Restriction Mode is set to <code>RestrictionModes.Advanced</code> two of them are fully assessable (in fact you do not need to create Attributes to set the properties to <code>Restriction.Full</code> since this is the default value) and one is read only. In the <code>RestrictionModes.Simple</code>-case one property will be hidden and two are read only.</p>
<p>You can assign these attribute to each class that shows properties in the Properties Window. That are Model Elements, Shapes, Connectors and the Model itself.</p>
<p>After that you have to create a <code>partial</code> class for your <code>Package</code> and &quot;activate&quot; my library for each Class that uses these attributes:</p>
<pre class="code"><span style="color: blue">partial class </span><span style="color: #2b91af">RestrictPropertiesTestPackage
</span>{
 <span style="color: blue">protected override void </span>Initialize()
 {
<span style="color: #2b91af">  UserRestrictionProvider</span>.RegisterRestrictedElement&lt;<span style="color: #2b91af">ExampleElement</span>&gt;();
  <span style="color: #2b91af">UserRestrictionProvider</span>.RegisterRestrictedElement&lt;<span style="color: #2b91af">ExampleModel</span>&gt;();

  <span style="color: blue">base</span>.Initialize();
 }}</pre>
<p>Or use the shorter way to add all classes with one line of code. This will use reflection to find the classes.</p>
<pre class="code"><span style="color: #2b91af">UserRestrictionProvider
 </span>.RegisterAllRestrictedElements    &lt;<span style="color: #2b91af">RestrictPropertiesExampleDiagram</span>&gt;();</pre>
<p>Now there is only one step left: how to change the mode. Each <code>Store</code> (that is the class where the Elements of a Model are stored in memory) is mapped to one Restriction Mode. So you can define one mode for each <code>Store</code> and so one mode for each <code>Model</code> or <code>Diagram</code>. The <code>Store</code> can be accessed from each <code>ModelElement</code>, so as a key for this purpose it is a great value. There is a <code>UserRestrictionProvider</code> class with two <code>static</code> methods:</p>
<ul>
<li>
<pre class="code"><span style="color: blue">public static void </span>SetRestrictionMode(<span style="color: #2b91af">Store </span>store, <span style="color: blue">int </span>mode)</pre>
</li>
<li>
<pre class="code"><span style="color: blue">public static int </span>GetRestrictionMode(<span style="color: #2b91af">Store </span>store)</pre>
</li>
</ul>
<p>You can use these methods whenever you want to change the Restriction Mode. For the demo project I used a <em>Domain Property</em> of the Diagram with <em>Custom Storage.</em></p>
<h3>How does it work?</h3>
<p>With the <code>UserRestrictionProvider.RegisterRestrictedElement()</code>method I register a special <a title="TypeDescriptionProvider Class" href="http://msdn2.microsoft.com/57y792w8.aspx">TypeDescriptionProvider</a> to the global Component Model (via the <a title="TypeDescriptor..::.AddProvider Method " href="http://msdn2.microsoft.com/8dtk2wwz.aspx">TypeDescriptor.AddProvider()</a> method). This new Provider is be asked from the IDE whenever a list of all properties of a particular object is needed. At this point it is easy to remove some properties form the original list (this properties are not be shown in the Properties Windows) or make them read only (see the <code>ReadOnlyPropertyDescriptor</code> class in my code).</p>
<p>For more in depth information feel free to take a look at the source code.</p>
<h3>&#8230;but beware</h3>
<p>All these property restrictions <strong>effect only the properties windows</strong>. The properties can be changed and accessed by code and via other elements of the DSL Designer (for example TextDecorators and the DSL Explorer).</p>
<h3><strike>Download</strike></h3>
<p><strike>In the zip file you will find all described classes in one project and an example DSL project.</strike></p>
</p>
<div class="wlWriterSmartContent" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:97ecb1ea-90a4-4953-9c57-8995ca4f1190" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<p><strike>Download: </strike><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/04/restrictpropertiesexample.zip"><strike>Source code and example</strike></a></p>
</div>
<h3>Update</h3>
<p>This code is now part of the <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> project. Please download the current version from that page. The download over at <a href="http://www.codeplex.com">CodePlex</a> contains the source code described here, an example DSL language and the library as a binary. Future enhancements of the code will be published there, too.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finding and removing a default command in DSL Tools (part 4 of Compartment Mappings)</title>
		<link>http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/</link>
		<comments>http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 20:25:57 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/</guid>
		<description><![CDATA[[Update (2008-05-21): This code is now hosted at CodePlex as part of JaDAL. And a follow-up article was published.]
Previously on&#8230;
This article is part of a series. A table of contents can be found at the end of the first article. Part 2 contains a user guide and in part 3 I showed most of the [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update (2008-05-21): </strong>This code is now hosted at CodePlex as part of <a href="http://www.codeplex.com/JaDAL">JaDAL</a>. And a <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">follow-up article</a> was published.]</p>
<h3>Previously on&#8230;</h3>
<p>This article is part of a series. A table of contents can be found at the end of the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first article</a>. <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">Part 2</a> contains a user guide and in <a href="http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/">part 3</a> I showed most of the internals of the library.</p>
<h3>The &quot;Reroute&quot; command</h3>
<p>For each connector there is a command named &quot;Reroute&quot; in the context menu of the DSL editor. Now I have to remove this command for the compartment entry mappings. If the user would use it, the layout of my connectors will be destroyed. Unfortunately I did not find an option, an extension point or anything else where I could change or handle this particular command or the context menu of the connectors.</p>
<h3>The generated code</h3>
<p>First I looked at the generated code of my <code>Dsl</code> and <code>DslPackage</code> project. There is a <code>GeneratedVSCT.vsct</code> file. In <code>vsct</code> files the commands are defined, but in this one I could not find anything with &quot;Reroute&quot;. Then I searched for the string &quot;Reroute&quot; in all files and found nothing.</p>
<h3>The DSL binaries</h3>
<p>I found no documentation for this command and&#160; was a little desperate. I needed to find the place where it comes from. I searched the whole VS SDK folder (text and binary files) for the string &quot;reroute&quot;. A promising hint was found in the Microsoft.VisualStudio.Modeling.Sdk.Shell.dll file. Now let&#8217;s go to the <a href="http://www.aisto.com/roeder/dotnet/">Reflector</a> and take a deeper look inside.</p>
<p>After a while I found the <a title="CommandSet Class" href="http://msdn2.microsoft.com/bb163614.aspx">Microsoft.VisualStudio.Modeling.Shell.CommandSet</a> class. And hey, in the msdn documentation article for this class there is also the <em>Reroute Line </em>command mentioned. With this knowledge one can easily find the generated <code>CommandSet.cs</code> file as part of the <code>DslPackage</code>. In this file there are two classes <code>AbcCommandSetBase</code> and <code>AbcCommandSet</code> where <code>Abc</code> is the name of you DSL project. </p>
<p>The design pattern of this classes is called <em>double derived</em> and can be found quiet often within the generated DSL code. The <code>...Base</code> class stays abstract and derives from a class defined in the Microsoft Visual Studio SDK libraries, in this case from the <a title="CommandSet Class" href="http://msdn2.microsoft.com/bb163614.aspx">CommandSet</a> class I found above. All code created by the code generator is added to this <code>...Base </code>class. The other class derives from the <code>...Base</code> class and is empty &#8211; all parts of the project uses this one. Since it is declared with the <code>partial</code> keyword, the user can override ALL methods and change the behavior of all aspects of this class.</p>
<p>And that is what we are going to do: override the <code>GetMenuCommands()</code> method and remove the reroute command:</p>
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">MenuCommand</span>&gt; GetMenuCommands()
{
  <span style="color: green">// get the base list
  </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">MenuCommand</span>&gt; cmds = <span style="color: blue">base</span>.GetMenuCommands();
  <span style="color: green">// find the reroute command
  </span><span style="color: #2b91af">MenuCommand </span>rerouteCommand = cmds.First(
    c =&gt; c.CommandID == <span style="color: #2b91af">CommonModelingCommands</span>.RerouteLine);
  <span style="color: green">// if found, remove it
  </span><span style="color: blue">if </span>(rerouteCommand != <span style="color: blue">null</span>)
      cmds.Remove(rerouteCommand); 

  <span style="color: green">// and return the changed list
  </span><span style="color: blue">return </span>cmds;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>That&#8217;s it. Pretty easy, but you have to discover where to add this logic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Connectors between compartment shape entries with DSL Tools &#8211; part 3</title>
		<link>http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/</link>
		<comments>http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 17:42:14 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/</guid>
		<description><![CDATA[[Update (2008-05-21): This code is now hosted at CodePlex as part of JaDAL. And a follow-up article was published.]
Previously on&#8230;
This article is part of a series. The table of contents can be found at the end of the first article. In that article you can also find a brief overview. In the second part there [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update (2008-05-21): </strong>This code is now hosted at CodePlex as part of <a href="http://www.codeplex.com/JaDAL">JaDAL</a>. And a <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">follow-up article</a> was published.]</p>
<h3>Previously on&#8230;</h3>
<p>This article is part of a series. The table of contents can be found at the end of the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first article</a>. In that article you can also find a brief overview. In the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">second part</a> there is a short user guide and a download link of the source code and binaries.</p>
<h3>How does it all work?</h3>
<p>I don&#8217;t want to explain every single detail of my code. If you want to go that deep, you have to read the source code yourself and maybe you will find some comments. I will only show you the fundamental parts of the CompartmentMapping library.</p>
<p>There are a few things you have to consider to achieve the aim of the library:</p>
<ol>
<li>When creating a connector from <em>Shape A</em> to <em>Shape B</em> how should I get and store the <em>Compartment Entry</em> information for the <em>Reference Relationship</em>? </li>
<li>After that, the connector representing this relationship must be drawn in such a way that it seems to be a connector from one entry to another. </li>
<li>What can a user do to destroy the layout of my connectors? And even more important: how can I prevent him from doing so? </li>
<li>If the user deletes a <em>compartment entry</em> that is part of a relationship, the relationship needs to be deleted, too. </li>
</ol>
<h3>The Connection Builder</h3>
<p>There is the concept of <em>Connection Builders</em> used by the DSL Tools. While your day to day use of DSL, you don&#8217;t have to worry about <em>Connection Builders</em> since they will be generated by the DSL Tools code generator. But you can turn this generation off and provide your implementation of a <em>Connection Builder </em>for a certain relationship. (see number 5 in the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">user guide</a>). </p>
<p>A <em>Connection Builder</em> is a static class and will be assigned to a connection toolbar item of your editor. This class contains four interesting methods:</p>
<ol>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptSource(<span style="color: #2b91af">ModelElement</span>)</pre>
</li>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptTarget(<span style="color: #2b91af">ModelElement</span>)</pre>
</li>
<li>
<pre class="code"><span style="color: blue">bool </span>CanAcceptSourceAndTarget(<span style="color: #2b91af">ModelElement</span>, <span style="color: #2b91af">ModelElement</span>)</pre>
</li>
<li>
<pre class="code"><span style="color: #2b91af">ElementLink </span>Connect(<span style="color: #2b91af">ModelElement</span>, <span style="color: #2b91af">ModelElement</span>)</pre>
</li>
</ol>
<p>The first two methods are used to determine if a particular <code>ModelElement</code> can act as source or target of you connection. For example you can check the <code>ModelElement</code> for a certain property to be set and only allow elements with this property as source and with another property as target, or whatever. </p>
<p>With&#160; <code>CanAcceptSourceAndTarget()</code> you can check whenever a concrete combination of source and target <code>ModelElements</code> is allowed to be connected by your relationship. </p>
<p>Last but not least with the <code>Connect()</code> method you have to create this new relationship for the two selected <code>ModelElements</code>.</p>
<p>In such a <em>Connection Builder</em> I will add the logic to check not only the model elements but also the selected entry inside the <em>Compartment Shape</em>. At this point I will mix the model representation (containing of <em>Domain Classes</em> and <em>Relationships</em>) and the graphical appearance (containing of <em>Shapes </em>and <em>Connectors</em>) but there is no better way at this time since the DSL Tools can only create connectors from shape to shape.</p>
<p>The first problem I ran into: How to get the shape of the model element in the <em>Connection Builder</em> if the only parameter is the <code>ModelElement?</code> I used the <a title="PresentationViewsSubject..::.GetPresentation Method " href="http://msdn2.microsoft.com/bb128952.aspx">PresentationViewsSubject.GetPresentation()</a> method and I&#8217;m hoping it will always work. The architecture is build in such a way, that one <code>ModelElement</code> can have multiple shapes, but I didn&#8217;t saw such a configuration until now, so I assume there will be only one shape.</p>
<p>After holding the shape in my hand I need to know something about the selected <em>Compartment Entry</em>. This becomes a little bit complicated, too: Sometimes I need the entry right below the mouse cursor (for <code>CanAcceptSource()</code>) and sometimes the entry that was below the mouse when the user pressed the mouse button. Of course a <em>Compartment Shape</em> doesn&#8217;t provide any of that information. Take a look at <code>CompartmentMouseTrack</code> and <code>ICompartmentMouseActionTrackable</code> in the CompartmentMapping library and you will see in which way I handle mouse events of the shape to track all these mouse actions for the <em>Compartment Shapes</em> that are under the control of my library.</p>
<p>With all these new information my <code>CompartmentMappingBuilderBase</code> can decide to allow or permit the creation of a connection. With some <code>virtual</code> methods, it can delegate&#160; more details of this decision to your code (see the advanced options <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/">here</a>).</p>
<ol><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></ol>
<h3>How to trick the routing algorithm of DSL Tools</h3>
<p>With the <em>Connection Builder</em> one can create relationships in the domain model but the connector inside the visual representation of your model will still be routed from shape to shape and won&#8217;t give you a proper understanding of the entry to entry relationship. So we have to change the routing in a way that the start and endpoints of the connector will be glued near to the entry on one side of the shape.</p>
<p>This will be done with an <a title="AddRule Class" href="http://msdn2.microsoft.com/bb141674.aspx">AddRule</a> (<code>CompartmentMappingAddRuleBase</code>) every time a new connector will be added to the diagram (and when opening a saved diagram). </p>
<p>After determination the favored points on the shape outline you can set them to the connector with the <a title="BinaryLinkShapeBase..::.FromEndPoint Property " href="http://msdn2.microsoft.com/bb135134.aspx">FromEndPoint</a> and <a title="BinaryLinkShapeBase..::.ToEndPoint Property " href="http://msdn2.microsoft.com/bb135144.aspx">ToEndPoint</a> properties. Don&#8217;t forget to change the <a title="BinaryLinkShapeBase..::.FixedFrom Property " href="http://msdn2.microsoft.com/bb135132.aspx">FixedFrom</a> and <a title="BinaryLinkShapeBase..::.FixedTo Property " href="http://msdn2.microsoft.com/bb135133.aspx">FixedTo</a> to <code>VGFixedCode.Caller</code> as well.</p>
<h3>Don&#8217;t get tricked by the routing algorithm</h3>
<p>If you change the start and endpoints of a connector in the <em><u>AddRule</u></em> these values aren&#8217;t set forever.&#160; The user could collapse and expand the compartment shape or use the &quot;Reroute&quot; command that is visible in the context menu of every connector. He could also move the connector or only the start and endpoints on the shape outline. If he deletes one entry that was shown above an entry with a connection this entry moves closer to the top and the connection should do the same.</p>
<p>With a few lines of code, we can forbid the user to change the routing of a connectors. In the connector class the <code>CanManuallyRoute</code> property simply have to return <code>false</code>.</p>
<p>Every time the size of the shape changes (see <a title="NodeShape..::.OnAbsoluteBoundsChanged Method " href="http://msdn2.microsoft.com/bb128708.aspx">OnAbsoluteBoundsChanged event</a>) I will recalculate the connection points of all connectors assigned to this shape. This event will handle a bunch of cases for me: insertion and deletion of other entries, expanding and collapsing of the whole shape and singe compartment lists and renaming of entries which can cause reordering of the compartment list.</p>
<h3>Delete propagation</h3>
<p>The delete propagation is an easy requirement. I just added a <a title="DeletingRule Class" href="http://msdn2.microsoft.com/bb142028.aspx">DeletingRule</a> that keep track of the deletion of certain <em>Compartment Entries</em> and if one is deleted it looks for <em>Compartment Mapping Relationships</em> and deletes them. </p>
<p>It is a little bit challenging to find the relationships coming from the entry. If you want to know more details take a look at the <code>CompartmentEntryDeletingRuleBase</code> source code.</p>
<h3>Upcoming article</h3>
<p>In the <a href="http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/">last article</a> of this series I will explain the way of removing the &quot;Reroute&quot; command from the connector context menu. The actual code consist only of a few lines, but the way I found the point to do it can be interesting for someone because the &quot;Reroute&quot; command is not proper documented anywhere.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Connectors between compartment shape entries with DSL Tools &#8211; part 2</title>
		<link>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/</link>
		<comments>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 22:05:02 +0000</pubDate>
		<dc:creator>Benjamin Schröter</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[JaDAL]]></category>
		<category><![CDATA[orcas]]></category>
		<category><![CDATA[visual studio]]></category>
		<category><![CDATA[vsx]]></category>

		<guid isPermaLink="false">http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/</guid>
		<description><![CDATA[[Update (2008-05-21): This code is now hosted at CodePlex as part of JaDAL. And a follow-up article was published.]
Previously on&#8230;
This article is part of a series. A table of contents can be found at the end of the first article. In that article you can also find a brief overview.

User guide
If you read this article [...]]]></description>
			<content:encoded><![CDATA[<p>[<strong>Update (2008-05-21): </strong>This code is now hosted at CodePlex as part of <a href="http://www.codeplex.com/JaDAL">JaDAL</a>. And a <a href="http://www.ticklishtechs.net/2008/05/21/connectors-between-compartment-shape-entries-with-dsl-tools-version-2/">follow-up article</a> was published.]</p>
<h3>Previously on&#8230;</h3>
<p>This article is part of a series. A table of contents can be found at the end of the <a href="http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-1/">first article</a>. In that article you can also find a brief overview.</p>
<ul></ul>
<h3>User guide</h3>
<p>If you read this article to this point you will properly use or at least evaluate the CompartmentMapping library. I will provide you with a step-by-step tutorial. There are pretty some steps, but its the shortest way I could imagine to create my solution. Please give it a try. <img src='http://www.ticklishtechs.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<ol>
<li>You need <a href="http://code.msdn.microsoft.com/TTxGen">TTxGen</a> to generate some code from my templates. See <a href="http://www.ticklishtechs.net/2008/02/28/codegeneration-with-codesmith-and-orcas-t4/">my last article</a> for more information and a workaround for an installation problem.       </li>
<li>I assume you have a DSL solution and at least two <em>Domain Classes</em> mapped to two compartment shapes and two more <em>Domain Classes</em> used as entries of the compartment shapes created. In my example these classes are called <code>Parent1</code>, <code>Entry1</code>, <code>Parent2</code> and <code>Entry2</code>.       <br />The entries need a unique identifier. You could use a name property for this, but there will be some difficulties if the user creates two entries in one shape with the same name, so I will use a guid. (Don&#8217;t forget to create a new guid in the constructor or another proper place.)       </li>
<li>Create a <em>Reference Relationship</em> from <code>Parent1</code> to <code>Parent2</code>. This will be automatically named <code>Parent1ReferencesParent2</code>. We will use this reference to present the relationship from one entry to the other. I would like to create <em>Reference Relationships</em> from this relationship to the entries, but relationships of relationships are not supported. We have to store the guids of the entries in the relationship and add two <em>Domain Properties</em> for this purpose to it. I named them <code>fromEntry</code> and <code>toEntry</code>.       <br /><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/02/dsldefinition.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="298" alt="DslDefinition" src="http://www.ticklishtechs.net/wp-content/uploads/2008/02/dsldefinition-thumb.png" width="440" border="0" /></a>&#160; </li>
<li>Set the <code>Allows Duplicates</code> property of the <code>Parent1ReferencesParent2</code> relationship to <code>true</code>.       </li>
<li>Set the <code>Is Custom</code> property of the <em>Connection Builder</em> (<code>Parent1ReferencesParent2Builder</code>) in the <em>DSL Explorer</em> to <code>true</code>.       </li>
<li>Add a reference to <code>CompartmentMapping.dll</code> to both the <code>Dsl</code> and <code>DslPackage</code> project.       </li>
<li>Add a new xml file (in my example <code>CompartmentMappings.xml</code>) to your solution and write the following code in it:
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot; <span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">CompartmentConnections
    </span><span style="color: red">xmlns:xsi</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://www.w3.org/2001/XMLSchema-instance</span>&quot;
    <span style="color: red">xsi:noNamespaceSchemaLocation</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentMappings.xsd</span>&quot;
    <span style="color: red">namespace</span><span style="color: blue">=</span>&quot;<span style="color: blue">BenjaminSchroeter.CompartmentMappingExample</span>&quot; <span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">CompartmentConnection</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">CompartmentSource</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">DomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent1</span>&quot;<span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">EntryDomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Entry1</span>&quot;<span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">Shape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentShape1</span>&quot; <span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">CompartmentSource</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">CompartmentTarget</span><span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">DomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent2</span>&quot; <span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">EntryDomainClass </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Entry2</span>&quot; <span style="color: blue">/&gt;
      &lt;</span><span style="color: #a31515">Shape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">CompartmentShape2</span>&quot; <span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">CompartmentTarget</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Connection </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Parent1ReferencesParent2</span>&quot;<span style="color: blue">&gt;
      &lt;</span><span style="color: #a31515">Shape </span><span style="color: red">name</span><span style="color: blue">=</span>&quot;<span style="color: blue">Connector</span>&quot; <span style="color: blue">/&gt;
    &lt;/</span><span style="color: #a31515">Connection</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">CompartmentConnection</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">CompartmentConnections</span><span style="color: blue">&gt;</span></pre>
<p>(If you place the xsd file in the same directory you get IntelliSense and error checking for free.)</p>
</li>
<li>Place the <code>CompartmentConnections.tt</code> file in the same directory and right-click on the xml file and choose <em>Generate xGen Template</em>. A <code>CompartmentMappings_xGen.tt</code> file will be created below the xml file and there you have to add the following lines:
<pre class="code"><span style="background: gold">&lt;#@</span><span style="color: red"> ParentFileInjector processor=</span>&quot;<span style="color: blue">TTxGenDirectiveProcessor</span>&quot;
    <span style="color: red">requires=</span>&quot;<span style="color: blue">fileName='CompartmentMappings.xml'</span>&quot; <span style="background: gold">#&gt;
&lt;#@</span><span style="color: red"> </span><span style="color: brown">include </span><span style="color: red">file=</span>&quot;<span style="color: blue">CompartmentConnections.tt</span>&quot; <span style="background: gold">#&gt;</span></pre>
<p>(Be sure you use the right xml file name here.)</p>
<p>Now press the <em>Transform All Templates</em> Button in the <em>Solution Explorer </em>to generate the the code from this template.</p>
</li>
<li>Now you have to write code by yourself (nearly by yourself, the frames are generated, too). Take a look at the generated cs file <code>CompartmentConnections_xGen.cs</code>.
<p>At the top you will find commented code. Copy this code to a new cs file and remove the comments. All code you will write for the compartment mappings you will write in this file.</p>
</li>
<li>Complete the <code>CreateElementLink()</code> method in this file. Here you have to add code to store the selected compartment entries for source and target in the properties of the relationship (see 3).
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">ElementLink </span>CreateElementLink(<span style="color: #2b91af">Parent1 </span>source,
  <span style="color: #2b91af">SelectedCompartmentPartType </span>sourcePartType,
  <span style="color: #2b91af">Entry1 </span>sourceEntry,
  <span style="color: #2b91af">Parent2 </span>target,
  <span style="color: #2b91af">SelectedCompartmentPartType </span>targetPartType,
  <span style="color: #2b91af">Entry2 </span>targetEntry)
{
    <span style="color: #2b91af">Parent1ReferencesParent2 </span>result =
        <span style="color: blue">new </span><span style="color: #2b91af">Parent1ReferencesParent2</span>(source, target);
<strong>    result.fromEntry = sourceEntry.Guid;
    result.toEntry = targetEntry.Guid;</strong>
    <span style="color: blue">return </span>result;
}</pre>
</li>
<li>In the <code>CreateElementLink()</code> method you have stored the source and target entry information somewhere; my library does not know about this location. So we need two more methods to compare an entry with a relationship and answer the question &quot;Is this entry the source of a given relationship?&quot; and the same for the target. These code resists in the same file:
<pre class="code"><span style="color: blue">public override bool </span>IsEntryConnectionSource
    (<span style="color: #2b91af">Entry1 </span>entry, <span style="color: #2b91af">Parent1ReferencesParent2 </span>connection)
{
<strong>    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return false</span>;
    <span style="color: blue">return </span>connection.fromEntry.Equals(entry.Guid);</strong>
}
<span style="color: blue">public override bool </span>IsEntryConnectionTarget
    (<span style="color: #2b91af">Entry2 </span>entry, <span style="color: #2b91af">Parent1ReferencesParent2 </span>connection)
{
<strong>    <span style="color: blue">if </span>(entry == <span style="color: blue">null</span>)
        <span style="color: blue">return false</span>;
    <span style="color: blue">return </span>connection.toEntry.Equals(entry.Guid);</strong>
}</pre>
<p>Always care for <code>entry == null</code> this will be used to check whether the head of the shape is meant. Even if you do not allow the head as source or target this method will be called with a <code>null</code> parameter from time to time.</p>
</li>
<li>Create a <code>partial class</code> for your <em>Domain Model </em>(<code>CompartmentMappingExampleDomainModel</code>) and add the following methods.
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">Type</span>[] GetCustomDomainModelTypes()
{
  <span style="color: blue">return </span><span style="color: #2b91af">CompartmentMappingUtil</span>.AllCompartmentMappingRules(<span style="color: blue">this</span>);
}</pre>
<p>(If you have already some custom rules, you can use an overloaded version of the <code>AllCompartmentMappingRules()</code> method.)</p>
</li>
<li>
<p>In the <code>DslPackage</code> project create a <code>partial class</code> for the generated <em>Command Set</em> and add the following code:</p>
<pre class="code"><span style="color: blue">protected override </span><span style="color: #2b91af">IList</span>&lt;<span style="color: #2b91af">MenuCommand</span>&gt; GetMenuCommands()
{
    <span style="color: blue">return </span><span style="color: #2b91af">CompartmentMappingUtil</span>.RemoveRerouteCommand
                                (<span style="color: blue">base</span>.GetMenuCommands());
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
</li>
</ol>
<p>That&#8217;s all. Only 13 steps, a few settings and conventions and 10 lines of C# code to write. I know it is not very easy but I think it is ok. And the best: as you will see it is working.</p>
<p>Now compile and start you solution. You can now create connectors from one entry of the <code>Parent1</code> shape to an entry of the <code>Parent2</code> shape. Great &#8211; isn&#8217;t it?</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="319" alt="mapping" src="http://www.ticklishtechs.net/wp-content/uploads/2008/02/mapping.png" width="462" border="0" />&#160;</p>
<p>Take a look at the properties in the <em>Properties window</em> when selecting a connector. You see the guids of the corresponding entries and can use them in your code when working with this connections for code generation or whatever you need to do.</p>
<h3>Advanced options</h3>
<p>There are some more options besides the basics described above to configure and extend the compartment mappings.</p>
<p>Some of them can easily turned on in the xml file:</p>
<ul>
<li>For <code>CompartmentSource</code> and <code>CompartmentTarget</code> you can specify an attribute called <code>allowHeadAsSource</code> (and <code>allowHeadAsTarget</code> respectively) and set it to <code>true</code>, to allow the head of the compartment shape as source or target. Remember, if you do this the <code>CreateElementLink()</code> method will be called with <code>null</code> values for the entries and you have to handle this. </li>
<li>On the <code>Connection</code> element there are two more optional attributes, too.
<p>If you set <code>allowSelfReference</code> to <code>true</code> the user can create connections from one entry of one shape to another (or the same) entry of the same shape (source = target). This makes only sense if you specify <code>CompartmentSource</code> and <code>CompartmentTarget</code> to be the same <em>Domain Class </em>and the same shape.</p>
<p>With the <code>suppressEntryDeletePropagation</code> attribute set to <code>true</code> you suppress the deletion of the connection when a corresponding compartment entry is deleted. Be careful with this setting: Wrong connections will remain in your model and produce ugly diagrams.</p>
</li>
<li>One of source and target can be a regular shape (that is a geometry or image shape and not a compartment shape). Replace either <code>CompartmentSource</code> with <code>Source</code> or <code>CompartmentTarget</code> with <code>Target</code>. For these elements you don&#8217;t need to define a <code>EntryDomainClass</code> element since regular shapes do not have entries. </li>
</ul>
<p>You can add even more code to the C# file from step 9 to 11. There are two more methods you can override: <code>CanAcceptAsCompartmentSource()</code> and <code>CanAcceptAsCompartmentSourceAndTarget()</code>. If you do so, the DSL editor will ask your code while the user moves the mouse over shapes when creating the connection to identify the current shape and entry as a valid source or target in you scenario. It is pretty much the same pattern as used in the DSL Tools itself. But remember, this method will be called very often und should have a very short running time.</p>
<h3><stroke>Download</stroke></h3>
<p><stroke>The archive contains the library both as a compiled dll and as source code and the Example DSL created in this article.</stroke></p>
<h3>Update</h3>
<p>This code is now part of the <a href="http://www.codeplex.com/JaDAL">JaDAL &#8211; Just another DSL-Tools Addon Library</a> project. Please download the current version from that page. The download over at <a href="http://www.codeplex.com">CodePlex</a> contains the source code described here, an example DSL language and the library as a binary. Future enhancements of the code will be published there, too.</p>
<div class="wlWriterSmartContent" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:1f1d4156-e123-40e6-bec0-9bfe126fbf7e" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<p><a href="http://www.ticklishtechs.net/wp-content/uploads/2008/03/compartmentmapping.zip" target="_blank">CompartmentMapping.zip</a></p>
</div>
<h3>Upcoming articles</h3>
<p><a href="http://www.ticklishtechs.net/2008/03/01/connectors-between-compartment-shape-entries-with-dsl-tools-part-3/">Part 3</a> and <a href="http://www.ticklishtechs.net/2008/03/01/finding-and-removing-a-default-command-in-dsl-tools-part-4-of-compartment-mappings/">part 4</a> of this series will give an in depth view into the internals of the library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ticklishtechs.net/2008/02/29/connectors-between-compartment-shape-entries-with-dsl-tools-part-2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
