// Copyright (C) 2013 João Pedro Correia - All Rights Reserved
// Code under the terms of the GPLv2 license
// URL: http://flowstudio.codeplex.com

namespace FlowStudio.ViewModel.Data
{
    using System.Activities.Presentation.Model;

    public class OutlineActivityBuilderItem : OutlineRootHolderItem
    {
        private readonly string displayText;

        public OutlineActivityBuilderItem(ModelItem rootItem)
            : base(rootItem)
        {
            // Get display text

            var nameProperty = rootItem.Properties.Find("Name");

            if (nameProperty != null)
            {
                var name = nameProperty.ComputedValue as string;

                if (name != null && !string.IsNullOrEmpty(name))
                {
                    displayText = name;
                }
            }

            displayText = displayText ?? rootItem.Name;

            // Traverse implementation

            var implementationProperty = rootItem.Properties.Find("Implementation");

            if (implementationProperty != null)
            {
                InnerItems.Add(new OutlineActivityItem(implementationProperty.Value));
            }
        }

        public override string DisplayText
        {
            get { return displayText; }
        }
    }
}
