Use Case
| • | You want to display an Application Component in a workspace (for example, in a separate tab, like the DICOM image viewer). |
Relevant Architecture
Relevant Types
| • | ApplicationComponent |
| • | IWorkspace |
| • | Workspace |
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/ShowMyComponentAsWorkspace", "ShowMyComponent")]
[IconSet("open", IconScheme.Colour, "Icons.MyToolSmall.png", "Icons.MyToolMedium.png", "Icons.MyToolLarge.png")]
// ... (other action attributes here)
[ExtensionOf(typeof (DesktopToolExtensionPoint))]
public class MyWorkspaceTool : Tool<IDesktopToolContext>
{
private IWorkspace _workspace;
public void ShowMyComponent()
{
MyComponent component = new MyComponent();
_workspace = ApplicationComponent.LaunchAsWorkspace(
this.Context.DesktopWindow,
component,
"workspace caption");
_workspace.Closed += Workspace_Closed;
}
/// <summary>
/// Event handler for IWorkspace.Closed
/// </summary>
private void Workspace_Closed(object sender, ClosedEventArgs e)
{
_workspace.Closed -= Workspace_Closed;
_workspace = 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 workspace is the highest level construct at which an ApplicationComponent can run – it exists directly on the DesktopWindow, and typically has no relationship with other components running as a workspace, although other components running as shelves may operate on the workspace components. For a more thorough discussion on Workspaces and the application architecture, please see the section on the Desktop architecture.
To launch an ApplicationComponent as a workspace, simply call the static launcher method ApplicationComponent.LaunchAsWorkspace. This creates a new IWorkspace object and, if you keep this reference, you can listen for events such as the user activating or closing the workspace, or even trigger a close programmatically. Listening for the workspace 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 ImageViewerComponent.
Examples in Code Base
| • | ClearCanvas.ImageViewer.Explorer.Dicom.OpenStudyTool |