GuntherLenz

I am reading certain diagram elements from an exisiting assembly via reflection and display the relevant concepts within my model. Becasaus these elements are defined somewhere else I do not want the user of the DSL to be able to delete and/or change these elements.

Disabling the delete command on certain elements was straight forward, but to disable the "Add" element command seems to be non-trivial. Perhaps I am missing something but the only post I found disabled the add command for all elements, which is not what I want to do.....(post http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=780425&SiteID=1 )

Anybody out there who knows how to do that




Re: Visual Studio Extensibility Hiding "add" command on certain shape elements

Patrick Tseng MSFT

Hi Gunther,

This is a little bit complicated and I will do my best to explain it.

All your sub menu "Addxxx" are calc'ed on the fly based on whether a child item can be added into the parent or not. E.g. In the ClassDiagram based language; If you RMA the class shape, the logic first find out all the nest childshapes and ask ModelElement ModelClass object to see if it can be merged into it.

You can try this by setting brk point in ModelClass.CanMerge (in your DomainClasses.cs file) . It will be called when you RMA on the class shape. Inside this method, rootElement is the domain class which is asked to be merged into the ModelClass object.

For your need, you would need to set your domain class to be double derived (This is so that a FooBase and Foo is gen'ed for you.). Override CanMerge in Foo class to be


protected override bool CanMerge(DslModeling:: ProtoElementBase rootElement, DslModeling::ElementGroupPrototype elementGroupPrototype)

{

if ( elementGroupPrototype == null ) throw new global:: System.ArgumentNullException("elementGroupPrototype");

if (rootElement != null)
{
DslModeling:: DomainClassInfo rootElementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(rootElement.DomainClassId);

// Add your logic here to see whether this domain class can be added into your Foo object,

}

}

return base.CanMerge( ...);

}

Did I answer your question






Re: Visual Studio Extensibility Hiding "add" command on certain shape elements

GuntherLenz

Hi Patrick,

ok, I am not really sure if I understand this.

Let's say I have a Domain class foo which is embedding domain class bar.

Now foo is mapped to a compartment shape fooShape. The compartment is called bars and maps to the domain class bar.

In my scenario I read some assembly and create a foo instance with some bar instances embedded. The whole thing is shown on the diagram in form a fooShape instance. I want to disable the add bar on the compartment of fooshape.

Now I create a double dervied class of foo or foo shape, or foo, or bar






Re: Visual Studio Extensibility Hiding "add" command on certain shape elements

Edward Bakker

Gunther,

You will double derive foo and implement the code example in the foo class.

Edward





Re: Visual Studio Extensibility Hiding "add" command on certain shape elements

GuntherLenz

Hi Edward,

thanks... it works .

3 lines of code, sounds easy if you know where to put them.....

Cheers,

Gunther