Custom Toolbox Items

[NOTE: This post is part of a blog series, the start of which is here.]

When defining layer diagrams for your organization, or various other modeling concepts and diagrams that you want to make available to your team, you can of course simply check in those diagrams to your version control system, such as Team Foundation Server. But another mechanism we have enabled in the product that can easily be overlooked is the ability to create custom toolbox items from existing diagrams ( UML or Layer ), and then make those available through the VSIX mechanism also new in Visual Studio 2010.

In this post, I’m going to walk you through the steps needed to create a couple different custom toolbox items. ( I’ll talk about the new VSIX capabilities in another post. )

Let’s create a Layer Diagram ( I discuss the basics of what the Layer Diagram is about here ) that can be used as the pattern for a new toolbox item that will appear whenever a Layer Diagram is present in the VS document well.

 

1) Select the “Architecture->New Diagram…” menu item.

 image

2) Select the “Layer Diagram” in the Add New Diagram dialog, and give the diagram the “PresentationLayer” name:

image

3) If you are following along exactly, this will prompt you for the name of a new modeling project. Let’s give the project the name of “CustomToolBoxItems”:

image

Cool. Now the new layer diagram and modeling project show up inside Visual Studio.

What we’re going to do now is replicate a layer diagram that is found in the second edition of the Patterns & Practices Architecture Guide. Specifically, the layer diagram described in Chapter 6: Presentation Layer Guidelines.

4) Create the following layer diagram:

image

Tips & Tricks, plus a Beta2 BUG ALERT:

I cut a quick video to include with this post to show a couple of suggestions / tips on how to quickly build the diagram above, as well as call out some funky behavior in the Beta2 build that has since been corrected. Here’s that video.

One thing I failed to mention in the video is that you can navigate in and out of nested layers by holding the Shift-> to get the tab to go to inner layers, and Shift-< to go to containers.

5) Save the PresentationLayer.layerdiagram

At this point, you need to create a directory in your %userprofile%\my Documents\Visual Studio 2010 directory.

6) Start a command prompt and cd to %userprofile%\my Documents\Visual Studio 2010

7) Create a directory called “Team Architecture”

8) cd into the “Team Architecture” directory and create another directory called “Custom Toolbox Items”

9) Copy your “PresentationLayer.*” files from your modeling project to the “Custom Toolbox Items” directory.

Here’s an image of my command line actions of steps 5-9:

image

Ok, we’re almost there. Before we exit Visual Studio, do take notice of the current toolbox window, which should look something like this:

image

10) Exit and then restart Visual Studio, and create a new modeling project.

11) Create a new layer diagram

Once the new layer diagram is visible, your toolbox should look something like this:

image

At this point, you can select the “PresentationLayer” toolbox item and drop into your new layer diagram. You should see the exact same diagram that we created in the step 4!

Now this is great, but we also give you the ability to control how these new toolbox items are displayed and organized. Enter the .tbxinfo file.

12) Create a file called “MyCustomItems.tbxinfo” in the “Custom Toolbox Items” directory we created in step 8.

13) Open that file in Visual Studio, and paste the following code:

<?xml version="1.0" encoding="utf-8" ?>
<customToolboxItems xmlns="https://schemas.microsoft.com/visualstudio/2010/TeamArchitect/CustomToolboxItems">
  <customToolboxItem fileName="PresentationLayer.layerdiagram">
    <displayName>
      <value>Presentation Layer Pattern</value>
    </displayName>
    <tabName>
      <value>Patterns &amp; Practices</value>
    </tabName>
    <image>
      <bmp fileName="cloudservice.ico"/>
    </image>
    <f1Keyword>
      <value>PLayerHelp</value>
    </f1Keyword>
    <tooltip>
      <value>Create the Presentation Layer As mentioned In Pattern And Practices' Architecture Guidance v2</value>
    </tooltip>
  </customToolboxItem>
</customToolboxItems>

 

Once you save that file, exit Visual Studio, open a modeling project and open a layer diagram, you’ll see the following:

 image

NOTE:

As you play around with these custom tool box items, it is possible that you’ll start to see toolbox items from past experiments. If you start to see things your aren’t expecting, right click in the toolbox and select “Reset Toolbox”:

image 

That’s it! You can experiment with adding more custom toolbox items created by using layer diagrams, and you can do the exact same thing with any of the UML diagrams as well. This is a great way to get started with Design Patterns or any other template you’d like to make more accessible with your engineering team.

Enjoy!

Cameron

 

[NOTE: This post is part of a blog series, the start of which is here.]