|
/********************************************************************
* FulcrumWeb RAD Framework - Fulcrum of your business *
* Copyright (c) 2002-2009 FulcrumWeb, ALL RIGHTS RESERVED *
* *
* THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED *
* FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE *
* COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE *
* AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT *
* AND PERMISSION FROM FULCRUMWEB. CONSULT THE END USER LICENSE *
* AGREEMENT FOR INFORMATION ON ADDITIONAL RESTRICTIONS. *
********************************************************************/
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Framework.Silverlight.Client.AppServer;
namespace Framework.Silverlight.Client
{
/// <summary>
/// Provides logic for creating and initializing Section
/// UI items using information from Sections metadata.
/// </summary>
public class CxSectionUiProvider
{
/// <summary>
/// Returns list of the UI items which will are initialized by section metadata.
/// </summary>
/// <param name="sectionsMetadata">The list of CxSection items for UI items initializing.</param>
/// <returns>List of the UI items that are initialized using CxSectionMetadata metadata.</returns>
public List<Control> GetUiItemsList(IEnumerable<CxSection> sectionsMetadata)
{
List<Control> items = new List<Control>();
foreach (CxSection section in sectionsMetadata)
{
if (section.SectionMetadata.Visible)
items.Add(GetUiItem(section));
}
return items;
}
//----------------------------------------------------------------------------
/// <summary>
/// Returns UI item that will be initialized by section metadata.
/// </summary>
/// <param name="sectionMetadata">The CxSection item for UI item initializing.</param>
/// <returns>Instance of UI item that initialized using section metadata.</returns>
public Control GetUiItem(CxSection sectionMetadata)
{
Control uiInstance = CreateUiItem(sectionMetadata);
InitUiItem(uiInstance, sectionMetadata);
return uiInstance;
}
//----------------------------------------------------------------------------
/// <summary>
/// Creates UI item using section metadata.
/// </summary>
/// <param name="sectionMetadata">The instance of CxSection for UI item creating.</param>
/// <returns>Instance of UI item that created by CxSection .</returns>
protected virtual Control CreateUiItem(CxSection sectionMetadata)
{
return new CxToolBoxItem();
}
//----------------------------------------------------------------------------
/// <summary>
/// Initializes UI item using section metadata.
/// </summary>
/// <param name="uiItem">The instance of UI item that need
/// to initialize by section metadata. </param>
/// <param name="sectionMetadata">The istance of CxSection for UI item initializing.</param>
protected virtual void InitUiItem(Control uiItem, CxSection sectionMetadata)
{
CxToolBoxItem item = (CxToolBoxItem) uiItem;
item.Text = sectionMetadata.SectionMetadata.Text;
item.SectionId = sectionMetadata.SectionMetadata.Id;
if (!string.IsNullOrEmpty(sectionMetadata.SectionMetadata.ImageId))
{
string imageId = sectionMetadata.SectionMetadata.ImageId.ToUpper();
CxClientImageMetadata image;
if (!CxAppContext.Instance.ImagesMetadata.TryGetValue(imageId, out image))
throw new ExApplicationException(string.Format("Image <{0}> was not present in the images metadata", imageId));
IxImageProvider imageProvider = (IxImageProvider) CxTypeActivator.CreateInstance(image.ProviderClassId);
item.Image.Source = new BitmapImage(new Uri(imageProvider[image.ImageIndex], UriKind.RelativeOrAbsolute));
}
CxTreeItemUiProvider treeItemUiProvider = new CxTreeItemUiProvider();
CxTreeView treeView = new CxTreeView();
treeItemUiProvider.Tree = treeView;
//treeView.tvMain.EnableLines = true;
foreach (CxTreeItem treeItem in sectionMetadata.TreeItems)
{
if (treeItem.TreeItemMetadata.Visible)
{
CxNode node = (CxNode) treeItemUiProvider.GetUiItem(treeItem);
treeView.tvMain.Nodes.Add(node);
item.TreeView = treeView;
}
}
treeItemUiProvider.Tree = null;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.