Welcome Guest, you are in: Login

FDOT Wiki

RSS RSS

GisFramework



Search the wiki
»

Component Base

RSS
Modified on Monday, 18 July 2011 10:20 AM by 156.75.200.132 Categorized as Components
All components that are used in the framework must implement the interface IComponentBase. A abstract class ComponentBase has been created to ease the implementation if inheriting from other classes is unnecessary. All components are required to provide an BitmapImage for an icon as well as a HelpView. There are two methods in the interface: Initialize and Execute. Initialize is called only one time when the application is initally loading. Execute is called anytime the component is clicked in the toolbar or it's hotkey has been entered.

Table of Contents [Hide/Show]


IComponentBase
         Properties
         Methods
         Sample Implementation
ComponentBase
         Properties
         Concrete Methods
         Abstract Methods
         Sample Implementation
See Also


IComponentBase

Only components that implement IComponentBase will be able to be loaded into the framework.

Properties

NameTypeDescription
HelpViewDependencyObjectThis is a UIElement that will be displayed in the helpview for the component. It can be anything from a Textblock to an usercontrol.
ComponentConfigurationApplicationComponentConfigurationThis is the configuration that has been defined for the component.
IconBitmapImageThe icon that is used in the toolbar in the application. The icon is displayed at a size of 24X24 pixels.
IsExecutingboolUsed to tell the framework if the component is currently executing.
IsInitializedboolUsed by the framework to tell if the component has already been initialized.

Methods

NameDescription
Execute()Called when the component is clicked in the toolbar. The logic for what should kick off when the component is executed should be placed in this method.
Initialize(IDictionary customSettings)Initialize is called when the component is loaded in the application. This will only occur once.

Sample Implementation


 public class SampleComponent:IComponentBase
    {
        public void Initialize(IDictionary<string, string> customSettings)
        {
            IsInitialized = true;
        }

        public void Execute()
        {
            // Do Something
        }

        public BitmapImage Icon
        {
            get { return ResourceHelper.GetBitmap("Assets/Images/sample.png"); }
        }

        public bool IsInitialized { get; private set; }

        public ApplicationComponentConfiguration ComponentConfiguration { get; set; }

        public bool IsExecuting { get; private set; }

        public DependencyObject HelpView
        {
            get { return new TextBlock {Text = "Help Text"}; }
        }
    }

ComponentBase

Most components that are being developed on the framework should inherit from ComponentBase. This base class reduces the boilerplate code that is required for a component. All that a developer needs to do is implement the abstract methods OnExecute and GetIconResourceUri.

Properties

NameTypeVirtualDescription
ComponentConfigurationApplicationComponentConfigurationfalseThis is the configuration that has been defined for the component.
HelpViewDependencyObjecttrueThis is a UIElement that will be displayed in the helpview for the component. It can be anything from a Textblock to an usercontrol
IconBitmapImagefalseThe icon that is used in the toolbar in the application. The icon is displayed at a size of 24X24 pixels.
IsExecutingboolfalseUsed to tell the framework if the component is currently executing.
IsInitializedboolfalseUsed by the framework to tell if the component has already been initialized.
SettingsViewModelobjectfalseThis is a viewModel that used by the component to expose component level user settings.

Concrete Methods

ameReturn TypeVirtual Description
CreateChildWindow(object viewModel)GenericDialogViewModelfalseShows the viewModel with a generated view with the onError method already wired up.
Execute()voidfalseCalled when the component is clicked in the toolbar. The logic for what should kick off when the component is executed should be placed in this method.
GetImageFromResource(string uriString)BitmapImagefalseThis is a helper method to get a bitmapImager from a uri.
Initialize(IDictionary customSettings)voidfalseInitialize is called when the component is loaded in the application. This will only occur once.
OnError(ErrorEventArgs errorEventArgs)voidtrueIf an exception occurs on Execute for the component this method gives the component a chance to handle the exception. If the exception is not handled then the exception will bubble up to the user.
OnInitialize(IDictionary customSettings)voidtrueThis method can be overridding so the component can perform an action at the time of initialization of the component.

Abstract Methods

NameReturn TypeDescription
GetIconResourceUri()stringUsed to set the uri for the icon for the component.
OnExecute()voidCalled when the component is clicked in the toolbar. The logic for what should kick off when the component is executed should be placed in this method.

Sample Implementation


    [Export(typeof(IComponentBase))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class SampleComponent : ComponentBase
    {
        protected override void OnExecute()
        {
	//Do Something
        }
        protected override string GetIconResourceUri()
        {
            return "/FDOT.GIS.Framework.Samples;component/Assets/Images/sample.png";
        }
    }

See Also

Any Questions or Comments? Email
Some of the icons created by FamFamFam.