コード例 #1
0
        /// <summary>
        ///     Gets all <see cref="Unit">Units</see> along the hierarchy or the current unit if it is a leaf in the hierarchy.
        /// </summary>
        /// <param name="unit">The <see cref="UnitBase" /> to start with.</param>
        /// <returns>All <see cref="Unit">Units</see> that were found along the hierarchy.</returns>
        public static IEnumerable <IUnitDecorator> GetUnitsAlongHierarchy(IUnitDecorator unit)
        {
            IEnumerable <IUnitDecorator> result;

            if (unit is UnitDecorator ||
                (unit is MultiSelectionUnitDecorator && !((MultiSelectionUnitDecorator)unit).DecoratesHigherUnit))
            {
                result = LinqExtensions.FromSingle(unit);
            }
            else if (unit is HigherUnitDecorator)
            {
                result =
                    ((HigherUnitDecorator)unit).Subordinates.Cast <IUnitDecorator>().SelectMany(GetUnitsAlongHierarchy);
            }
            else if (unit is MultiSelectionUnitDecorator)
            {
                result = ((MultiSelectionUnitDecorator)unit).Subordinates.SelectMany(GetUnitsAlongHierarchy);
            }
            else
            {
                result = Enumerable.Empty <UnitDecorator>();
            }

            return(result);
        }
コード例 #2
0
        private static bool HasUnitTypeChanged(IUnitDecorator oldUnit, IUnitDecorator newUnit)
        {
            bool hasUnitTypeChanged = (oldUnit is UnitDecorator) ^ (newUnit is UnitDecorator);
            bool isOneUnitNull      = (oldUnit == null) ^ (newUnit == null);

            return(hasUnitTypeChanged || isOneUnitNull);
        }
コード例 #3
0
        /// <summary>
        ///     Gets all <see cref="Unit">Units</see> along the hierarchy or the current unit if it is a leaf in the hierarchy.
        /// </summary>
        /// <param name="unit">The <see cref="UnitBase" /> to start with.</param>
        /// <returns>All <see cref="Unit">Units</see> that were found along the hierarchy.</returns>
        public static IEnumerable<IUnitDecorator> GetUnitsAlongHierarchy(IUnitDecorator unit)
        {
            IEnumerable<IUnitDecorator> result;

            if (unit is UnitDecorator ||
                (unit is MultiSelectionUnitDecorator && !((MultiSelectionUnitDecorator)unit).DecoratesHigherUnit))
            {
                result = LinqExtensions.FromSingle(unit);
            }
            else if (unit is HigherUnitDecorator)
            {
                result =
                    ((HigherUnitDecorator)unit).Subordinates.Cast<IUnitDecorator>().SelectMany(GetUnitsAlongHierarchy);
            }
            else if (unit is MultiSelectionUnitDecorator)
            {
                result = ((MultiSelectionUnitDecorator)unit).Subordinates.SelectMany(GetUnitsAlongHierarchy);
            }
            else
            {
                result = Enumerable.Empty<UnitDecorator>();
            }

            return result;
        }
コード例 #4
0
        /// <summary>
        ///     Adds a unit.
        /// </summary>
        public void AddUnit()
        {
            IUnitDecorator newUnit = RootUnit.AddNewUnit();

            SelectedUnit = newUnit;
            ActivateItem(Items.FirstOrDefault());

            OnModelChanged();
        }
コード例 #5
0
        /// <summary>
        ///     Adds a hierarchy level.
        /// </summary>
        public void AddHierarchyLevel()
        {
            IUnitDecorator newHierarchyLevel = RootUnit.AddNewHigherUnit();

            SelectedUnit = newHierarchyLevel;
            ActivateItem(Items.FirstOrDefault());

            OnModelChanged();
        }
コード例 #6
0
        /// <summary>
        ///     Moves a unit to a new location within the hierarchy.
        /// </summary>
        /// <param name="unit">The moved unit.</param>
        /// <param name="target">The new suprtior of the unit.</param>
        public void MoveUnitInHierarchy(IUnitDecorator unit, HigherUnitDecorator target)
        {
            if (unit.Superior != null)
            {
                if (unit.Superior == target)
                {
                    return;
                }

                unit.Superior.RemoveSubordinate((UnitBase)unit);
            }

            target.AddSubordinate((UnitBase)unit);

            SelectedUnit = unit;

            RootUnit.Subordinates.Refresh();

            OnModelChanged();
        }
コード例 #7
0
        private void DropTreeDrop(object sender, DragEventArgs e)
        {
            Contract.Requires(e.Data != null);

            IUnitDecorator droppedUnitDecorator = null;

            if (e.Data.GetDataPresent(typeof(UnitDecorator)))
            {
                droppedUnitDecorator = e.Data.GetData(typeof(UnitDecorator)) as UnitDecorator;
            }
            else if (e.Data.GetDataPresent(typeof(HigherUnitDecorator)))
            {
                droppedUnitDecorator = e.Data.GetData(typeof(HigherUnitDecorator)) as HigherUnitDecorator;
            }

            if (droppedUnitDecorator != null)
            {
                var treeViewItem = FindAnchestor <TreeViewItem>((DependencyObject)e.OriginalSource);

                HigherUnitDecorator dropTarget = ViewModel.RootUnit;

                if (treeViewItem != null)
                {
                    dropTarget = treeViewItem.Header as HigherUnitDecorator;

                    if (dropTarget == null)
                    {
                        return;
                    }
                }

                Contract.Assume(dropTarget != null);

                if (droppedUnitDecorator == dropTarget)
                {
                    return;
                }

                ViewModel.MoveUnitInHierarchy(droppedUnitDecorator, dropTarget);
            }
        }
コード例 #8
0
 private void OnDossierChanged()
 {
     SelectedUnit = Dossier.RootUnit.Subordinates.Cast <IUnitDecorator>().FirstOrDefault();
 }