Use Case
| • | You want to display an Application Component in a dockable, pinnable, hideable window. |
Relevant Architecture
Relevant Types
| • | ApplicationComponent |
| • | IShelf |
| • | Shelf |
Sample Code
using ClearCanvas.Common;
using ClearCanvas.Desktop;
using ClearCanvas.Desktop.Actions;
using ClearCanvas.Desktop.Tools;
// ... (other using namespace statements here)
namespace MyPlugin.Basics
{
[ButtonAction("open", "global-toolbars/MyTools/ShowMyComponentAsShelf", "ShowMyComponent")]
[IconSet("open", IconScheme.Colour, "Icons.MyToolSmall.png", "Icons.MyToolMedium.png", "Icons.MyToolLarge.png")]
// ... (other action attributes here)
[ExtensionOf(typeof (DesktopToolExtensionPoint))]
public class MyShelfTool : Tool<IDesktopToolContext>
{
private IShelf _shelf;
public void ShowMyComponent()
{
MyComponent component = new MyComponent();
_shelf = ApplicationComponent.LaunchAsShelf(
this.Context.DesktopWindow,
component,
"shelf caption",
ShelfDisplayHint.DockLeft);
_shelf.Closed += Shelf_Closed;
}
/// <summary>
/// Event handler for IShelf.Closed
/// </summary>
private void Shelf_Closed(object sender, ClosedEventArgs e)
{
_shelf.Closed -= Shelf_Closed;
_shelf = null;
}
}
// your component's view extension point class
[ExtensionPoint()]
public class MyComponentViewExtensionPoint : ExtensionPoint<IApplicationComponentView> {}
// your component
[AssociateView(typeof (MyComponentViewExtensionPoint))]
public class MyComponent : ApplicationComponent
{
// your component code here
}
}
Remarks
A shelf is a construct in which an ApplicationComponent can run, typically independent of other components running as workspaces or shelves, but of course you can listen for workspace activation events and change the shelf component depending on what kind of component is in the currently active workspace. For a more thorough discussion on Shelves and the application architecture, please see the section on the Desktop architecture.
To launch an ApplicationComponent as a shelf, simply call the static launcher method ApplicationComponent.LaunchAsShelf. This creates a new IShelf object and, if you keep this reference, you can listen for events such as the user activating or closing the shelf, or even trigger a close programmatically. Listening for the shelf being closed is illustrated in the sample code above. The sample uses the simple component MyComponent and its corresponding view MyComponentViewExtensionPoint, but you should use your own component, or an existing component such as the ExtensionBrowserComponent. The LaunchAsShelf method takes a number of different parameters, such as a hint as to where to show the shelf, if it tries to auto-hide, etc. There is also another parameter to set the name of the shelf so that the shelf display settings can be persisted (however, displayed shelves must have unique names, so you must implement a check so you don't try to open another shelf with the same name).
Examples in Code Base
| • | ClearCanvas.Desktop.ExtensionBrowser.ExtensionBrowserTool |