Navigation:  I Want To... > Basics >

Create a dialog box

Previous pageReturn to chapter overviewNext page

Use Case

You want to display an Application Component in a dialog box.

Relevant Architecture

Interaction between Application Components and the Desktop

Relevant Types

ApplicationComponent
DialogBox

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/ShowMyComponentAsDialogBox""ShowMyComponent")]

   [IconSet("open", IconScheme.Colour, "Icons.MyToolSmall.png""Icons.MyToolMedium.png""Icons.MyToolLarge.png")]

   // ... (other action attributes here)

   [ExtensionOf(typeof (DesktopToolExtensionPoint))]

   public class MyDialogBoxTool : Tool<IDesktopToolContext>

   {

      public void ShowMyComponent()

      {

         MyComponent component = new MyComponent();

         SimpleComponentContainer container = new SimpleComponentContainer(component);

         ApplicationComponentExitCode exitCode;

         exitCode = ApplicationComponent.LaunchAsDialog(

            this.Context.DesktopWindow,

            container,

            "dialog caption");

 

         if (exitCode == ApplicationComponentExitCode.Accepted)

         {

            // user clicked OK (or equivalent button)

         }

      }

   }

 

   // 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 dialog box is a construct in which an ApplicationComponent can run, typically to gather additional information before proceeding on to continue some overall work operation.  In the Framework, dialog boxes are always modal, which means that the dialog box must be closed before the user can continue on with his/her work.  For a more thorough discussion on dialog boxes and the application architecture, please see the section on the Desktop architecture.

To launch an ApplicationComponent as a dialog box, simply call the static launcher method ApplicationComponent.LaunchAsDialog.  This shows a dialog box and waits for the user to close it.  The method returns an ApplicationComponentExitCode, which can be tested to determine if an error happened in the component, if the user cancelled the dialog, or if the user accepted whatever the dialog was about.  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 views (i.e. the GUI layer) for most components do not provide OK and Cancel buttons in order to make the component reusable (you don't usually see OK and Cancel at the bottom of a shelf or workspace) so the component can be wrapped in a SimpleComponentContainer which provides the OK and Cancel buttons (as above in the sample code).

Examples in Code Base

ClearCanvas.ImageViewer.Configuration.ServerTree.AddServerTool