Controlling the DGML Double-Click


You folks are making it quite easy to come up with blog ideas. I just sit and wait for questions to come in. If more than one question comes in on the same topic, I’m going to post it! So here’s another.

I’ve recently been asked a few times how to control what happens when the user double-clicks on a node in a DGML document. The answer is actually quite simple. All you need to do is add a Property node with the appropriate information to your DGML document and away you go.

Here’s a very basic DGML doc:

<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes>
  </Nodes>
  <Links>
  </Links>
  <Categories>
  </Categories>
</DirectedGraph>

 

Of course, the diagram is currently blank. Now add a node:

<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes>
    <Node Id="1" Label="Let's go to Microsoft" />
  </Nodes>
  <Links>
  </Links>
  <Categories>
  </Categories>
</DirectedGraph>

That DGML creates a graph that looks like this:

 image

And if you right click on that node, the context menu looks like this:

image

And if you double-click on it, nothing happens.

Now let’s add the markup that will actually take us to http://www.microsoft.com. Add the following markup:

<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes>
    <Node Id="1" Label="Let's go to Microsoft" Microsoft="Doesn't Matter"/>
  </Nodes>
  <Links>
  </Links>
  <Categories>
  </Categories>
  <Properties>
    <Property Id="Microsoft" IsReference="True" ReferenceTemplate="http://www.microsoft.com"/>
  </Properties>
</DirectedGraph>

Notice the addition of the Property node, the Id value ( “Microsoft” ), the fact that the IsReference attribute is set to “True”, and the ReferenceTemplate

attribute is set the URL of the Microsoft home site.

You should also notice that we added a new attribute to our existing Node called “Microsoft”, which is the Id of the Property node we just created, the value of that attribute doesn’t matter in this case. More on that in a minute.

But at this point, the diagram has changed visibly. The label of the node is now underlined:

 image

And sure enough, if you double-click the node, blamo, off to Microsoft we go, with the web page showing up right inside VS.

Now if you right-click on this node, you’ll also see an additional menu item called “Goto”, with “Microsoft” as a sub menu:

image

Cool!

There is an additional part to this functionality that I need to also mention. Imagine you want a DGML node to represent a new Test Case, or perhaps reference a Work Item that you have previously created. That is also quite doable.

To link to a Test Case, you’ll need to use a URL in the format defined in this blog post. It’ll look something like this:

mtm://server:8080/tfs/ProjectCollection/p:Project/testing/testcase/open?id=67

Notice the last bit of that URL is the ID of the Test Case to link to.

Here’s the DGML code to link our node to a Test Case:

<DirectedGraph xmlns="http://schemas.microsoft.com/vs/2009/dgml">
  <Nodes>
    <Node Id="1" Label="Let's go to a Test Case" TestCase="67"/>
  </Nodes>
  <Links>
  </Links>
  <Categories>
  </Categories>
  <Properties>
    <Property Id="TestCase" IsReference="True" ReferenceTemplate="mtm://server:8080/tfs/ProjectCollection/p:Project/testing/testcase/open?id={0}"/>
  </Properties>
</DirectedGraph>

Notice that in the Property node, I replace the “67” from the URL above with “{0}”. I also changed the Id value to “TestCase”, and then added the TestCase attribute

to our node with the value of “67”.

Now if you double click or right-click and select “Goto->TestCase”, the new Microsoft Test and Lab Manager will popup and show you the Test Case with Id 67!

This same technique will work with TSWA links as well. The thing to keep in mind is that the ReferenceTemplate property is literally a template, instantiated with the values of the properties attached to the actual nodes.

I hope all this was clear, but if not, feel free to ping me.

Cameron

Comments (4)

  1. Anonymous says:

    Interesting. So what if I want to have multiple arguments in the template e.g. {0}{1}{2}. Is this possible. since you state the template is instantiated with the assigend properties, the interesting point would be, how do you determine the position of the argument? or is this the position in the list of attributes in the properties node?

  2. No, that’s not possible. Only one parameter can be passed. However, you can have many Property nodes associated with a Node element.

  3. Anonymous says:

    Is it possible to open a work item in Visual Studio instead of Test Manager? If so, what is the syntax of the ReferenceTemplate attribute?

    Thanks in advance.

  4. Unfortunately no, but you can bring it up in the web access to TFS…