Пример #1
0
        public static void SelectItem(ItemsControl items, IHierarchyObject item)
        {
            ItemsControl itemsControl = items;
            var          viewItems    = new Stack <IHierarchyObject>();

            while (item != null)
            {
                viewItems.Push(item);
                item = item.Parent;
            }

            IHierarchyObject parentViewItem = null;

            while (viewItems.Count > 0)
            {
                var viewItem = viewItems.Pop();

                itemsControl = BringViewItemToView(items, itemsControl, parentViewItem, viewItem);
                if (itemsControl == null)
                {
                    break;
                }

                parentViewItem = viewItem;
            }

            // If the desired selection is found, select it
            var desiredSelection = itemsControl as TreeViewItem;

            if (desiredSelection != null)
            {
                desiredSelection.IsSelected = true;
                desiredSelection.Focus();
            }
        }
Пример #2
0
        /// <summary>
        /// Cette méthode permet de couper un élément sélectionné dans le treeview
        /// Lorsqu'on clique sur le menu contextuelle cut,
        /// la variable CurrentCutObjet prend la valeur de l'élément selectionné
        /// et une copie de cette dernière est placé dans le presse-papier.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCutNode(object sender, RoutedEventArgs e)
        {
            IHierarchyObject selectedItem = (IHierarchyObject)this.SelectedItem;

            CurrentCutObject = selectedItem;
            Util.ClipbordUtil.SetHierarchyObject(CurrentCutObject.GetCopy());
        }
Пример #3
0
        public bool IsNameInUse(IHierarchyObject newItem, IHierarchyObject root = null)
        {
            if (root == null)
            {
                root = this.Root;
            }



            Type typeConteneur = this.GetRendererDataType();



            foreach (IHierarchyObject child in root.GetItems())
            {
                if (child == newItem)
                {
                    return(true);
                }
                else
                {
                    IsNameInUse(newItem, child);
                }
            }
            return(false);
        }
Пример #4
0
 /// <summary>
 /// Met à jour un fils
 /// </summary>
 /// <param name="child"></param>
 public void UpdateChild(IHierarchyObject child)
 {
     childrenListChangeHandler.AddUpdated((Role)child);
     bubbleSortDesc(childrenListChangeHandler.Items);
     UpdateParents();
     OnPropertyChanged("childrenListChangeHandler.Items");
 }
Пример #5
0
        /// <summary>
        /// Cette methode permet la copie d'un élément sélectionné dans le treeview
        /// Après la séléction de l'objet, un copie de cet objet est placée dans le presse-papiers
        /// en attente d'être collé.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnCopyNode(object sender, RoutedEventArgs e)
        {
            IHierarchyObject selectedItem = (IHierarchyObject)this.SelectedItem;
            IHierarchyObject copy         = selectedItem.GetCopy();

            Util.ClipbordUtil.SetHierarchyObject(copy);
        }
Пример #6
0
        private IHierarchyObject PreviousSibling(IHierarchyObject item)
        {
            if (item == null)
            {
                return(null);
            }
            var parent = item.GetParent();

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

            IHierarchyObject previous = null;

            foreach (var child in parent.GetAllChildren())
            {
                if (child.Equals(item))
                {
                    return(previous);
                }
                previous = child;
            }
            Debug.Assert(false);
            return(null);
        }
Пример #7
0
        private IHierarchyObject NextSibling(IHierarchyObject item)
        {
            if (item == null)
            {
                return(null);
            }
            var parent = item.GetParent();

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

            bool found = false;

            foreach (var child in parent.GetAllChildren())
            {
                if (found)
                {
                    return(child);
                }
                if (child.Equals(item))
                {
                    found = true;
                }
            }
            Debug.Assert(found);
            return(null);
        }
        public static IHierarchyObject GetCommonAncestor(this IHierarchyObject source, IHierarchyObject other)
        {
            if (object.ReferenceEquals(other, source)) {
                return source;

            } else if (other.IsAncestorOf(source)) {
                return other;

            } else if (other.IsDescendentOf(source)) {
                return source;

            } else {
                // Scan the hierarchy
                foreach (IHierarchyObject ancestor in GetAncestors(other)) {
                    // Check the ancestry - skip the starting instance; we already
                    // performed that check
                    if (ancestor.ParentObject != null
                        && ancestor.ParentObject.IsAncestorOf(source)) {

                        return ancestor.ParentObject;
                    }
                }

                return null;

            }
        }
Пример #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public IHierarchyObject GetChildByName(string name)
 {
     if (this.entity != null)
     {
         int pos = 0;
         foreach (Attribute attribute in this.entity.attributeListChangeHandler.Items)
         {
             attribute.SetPosition(pos);
             if (attribute.name.ToUpper().Equals(name.ToUpper()))
             {
                 return(attribute);
             }
             pos++;
         }
     }
     foreach (Attribute attribute in childrenListChangeHandler.Items)
     {
         if (attribute.name.ToUpper().Equals(name.ToUpper()))
         {
             return(attribute);
         }
         IHierarchyObject ob = attribute.GetChildByName(name);
         if (ob != null)
         {
             return(ob);
         }
     }
     return(null);
 }
Пример #10
0
        /// <summary>
        /// Retire un fils
        /// </summary>
        /// <param name="child"></param>
        public void RemoveChild(IHierarchyObject child)
        {
            foreach (IHierarchyObject item in childrenListChangeHandler.Items)
            {
                if (item.GetPosition() > child.GetPosition())
                {
                    item.SetPosition(item.GetPosition() - 1);
                    childrenListChangeHandler.AddUpdated((Attribute)item);
                }
            }
            child.SetPosition(-1);
            Attribute Child = (Attribute)child;

            if (Child.valueListChangeHandler.Items.Count > 0)
            {
                AttributeValue root = Child.valueListChangeHandler.Items[0].parent;
                for (int i = root.GetItems().Count - 1; i >= 0; i--)
                {
                    AttributeValue value = root.childrenListChangeHandler.Items[i];
                    root.RemoveChild(value);
                }
                Child.removeDefaultValue();
            }
            childrenListChangeHandler.AddDeleted(Child);
            UpdateParents();
        }
Пример #11
0
        private static ItemsControl BringViewItemToView(
            DispatcherObject dispatcher,
            ItemsControl itemsControl,
            IHierarchyObject parentViewItem,
            IHierarchyObject viewItem)
        {
            // Access the custom VSP that exposes BringIntoView
            var itemsHost = FindVisualChild <MyVirtualizingStackPanel>(itemsControl);

            if (itemsHost == null)
            {
                Logger.LogError("Can't find itemsHost for itemsControl.");
                return(null);
            }

            var index = (parentViewItem == null ? 0 : parentViewItem.Children.ToList().IndexOf(viewItem));

            if (index >= itemsControl.Items.Count)
            {
                Logger.LogError("Can't find child of itemsHost.");
                return(null);
            }

            // Due to virtualization, BringIntoView may not predict the offset correctly the first time.
            return(TryAction(
                       dispatcher,
                       () => itemsHost.BringIntoView(index),
                       () => (ItemsControl)itemsControl.ItemContainerGenerator.ContainerFromIndex(index),
                       10));
        }
Пример #12
0
 private IHierarchyObject FirstChild(IHierarchyObject item)
 {
     if (item == null)
     {
         return(null);
     }
     return(item.GetAllChildren().FirstOrDefault());
 }
Пример #13
0
 /// <summary>
 /// Rajoute un fils
 /// </summary>
 /// <param name="child"></param>
 public void AddChild(IHierarchyObject child)
 {
     child.SetPosition(childrenListChangeHandler.Items.Count + 1);
     child.SetParent(this);
     childrenListChangeHandler.AddNew((PresentationSlideItem)child);
     UpdateParents();
     OnPropertyChanged("childrenListChangeHandler.Items");
 }
Пример #14
0
 /// <summary>
 /// Rajoute un fils
 /// </summary>
 /// <param name="child"></param>
 public void AddChild(IHierarchyObject child)
 {
     child.SetPosition(childrenListChangeHandler.Items.Count);
     child.SetParent(this);
     childrenListChangeHandler.AddNew((PeriodInterval)child);
     UpdateParents();
     OnPropertyChanged("childrenListChangeHandler.Items");
 }
Пример #15
0
 /// <summary>
 /// Rajoute un fils
 /// </summary>
 /// <param name="child"></param>
 public void AddChild(IHierarchyObject child)
 {
     child.SetPosition(childrenListChangeHandler.Items.Count);
     child.SetParent(this);
     childrenListChangeHandler.AddNew((Role)child);
     bubbleSortDesc(childrenListChangeHandler.Items);
     UpdateParents();
     OnPropertyChanged("childrenListChangeHandler.Items");
 }
Пример #16
0
        /// <summary>
        /// Cette méthode permet de coller un objet précédement copier ou couper.
        /// A cet effet on vérifie si le Paste vient après un Cut(si CurrentCutObject!=null) ou un Copy,
        /// puis on met dans le presse-papiers une copie de l'élément coupé ou copié.
        /// On affecte un nouveau parent à l'élément coupé/copié.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPasteNode(object sender, RoutedEventArgs e)
        {
            IHierarchyObject parent;
            IHierarchyObject newItem = null;

            if (CurrentParent == null)
            {
                parent = this.Root;
            }
            else
            {
                parent = (IHierarchyObject)this.SelectedItem;
            }

            if (CurrentCutObject != null)
            {
                CurrentCutObject.GetParent().ForgetChild(CurrentCutObject);
                newItem = CurrentCutObject;
                IHierarchyObject copy = CurrentCutObject.GetCopy();
                Util.ClipbordUtil.SetHierarchyObject(copy);
                if (CurrentCutObject == parent)
                {
                    CurrentCutObject = null;
                    return;
                }
                CurrentCutObject = null;
            }
            else
            {
                Console.WriteLine(this.GetClipbordDataFormat());

                /*
                 * newItem = Util.ClipbordUtil.GetHierarchyObject(this.GetClipbordDataFormat());
                 * if(newItem != null)
                 * Util.ClipbordUtil.SetHierarchyObject(newItem.GetCopy());*/
            }

            if (newItem == null)
            {
                return;
            }
            if (parent != null && CanCreateSubNode)
            {
                parent.AddChild(newItem);
                parent.UpdateParents();
            }
            else
            {
                this.Root.AddChild(newItem);
            }
            SelectItem(this, newItem);
            if (Change != null)
            {
                Change();
            }
        }
Пример #17
0
 /// <summary>
 /// Cette methode permet la copie d'un élément sélectionné dans le treeview
 /// Après la séléction de l'objet, un copie de cet objet est placée dans le presse-papiers
 /// en attente d'être collé.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnCopyNode(object sender, RoutedEventArgs e)
 {
     Kernel.Domain.Measure measure = GetSelectedMeasure();
     if (measure != null)
     {
         IHierarchyObject copy = measure.GetCopy();
         Kernel.Util.ClipbordUtil.SetHierarchyObject(copy);
     }
     CurrentCutObject = null;
 }
Пример #18
0
 private void RefreshParent(IHierarchyObject item)
 {
     if (item != null)
     {
         foreach (IHierarchyObject child in item.GetItems())
         {
             child.SetParent(item);
             RefreshParent(child);
         }
     }
 }
Пример #19
0
 /// <summary>
 /// Oublier un fils
 /// </summary>
 /// <param name="child"></param>
 public void ForgetChild(IHierarchyObject child)
 {
     foreach (IHierarchyObject item in childrenListChangeHandler.Items)
     {
         if (item.GetPosition() > child.GetPosition())
         {
             item.SetPosition(item.GetPosition() - 1);
         }
     }
     child.SetPosition(-1);
     childrenListChangeHandler.forget((AttributeValue)child);
 }
Пример #20
0
 /// <summary>
 /// Oublier un fils
 /// </summary>
 /// <param name="child"></param>
 public void ForgetChild(IHierarchyObject child)
 {
     foreach (IHierarchyObject item in childrenListChangeHandler.Items)
     {
         if (item.GetPosition() > child.GetPosition())
         {
             item.SetPosition(item.GetPosition() - 1);
         }
     }
     child.SetPosition(-1);
     childrenListChangeHandler.forget((PresentationSlideItem)child);
 }
Пример #21
0
 /// <summary>
 /// Retire un fils
 /// </summary>
 /// <param name="child"></param>
 public void RemoveChild(IHierarchyObject child)
 {
     foreach (IHierarchyObject item in childrenListChangeHandler.Items)
     {
         if (item.GetPosition() > child.GetPosition())
         {
             item.SetPosition(item.GetPosition() - 1);
         }
     }
     child.SetPosition(-1);
     childrenListChangeHandler.AddDeleted((BGroup)child);
 }
Пример #22
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="root"></param>
 public void DisplayRoot(IHierarchyObject root)
 {
     if (root == null)
     {
         this.ItemsSource = null;
     }
     else
     {
         RefreshParent(root);
         //this.ItemsSource = this.Root.GetItems();
         this.ItemsSource = new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
     }
 }
Пример #23
0
        /// <summary>
        /// Returns the item (or null) directly following <paramref name="item"/> in
        /// "previous sibling, parent" order.
        /// </summary>
        public IHierarchyObject GetPreviousItem(IHierarchyObject item)
        {
            if (item == null)
            {
                return(null);
            }

            // a
            //   b
            //     c
            //     d
            // e
            //
            // Return "b" is we are on "c"
            // Return "d" if we are on "e"
            // Return "e" if we are on "a"
            // Return "a" if we are on "b"
            //
            var result = PreviousSibling(item);

            if (result == null)
            {
                var parent = item.GetParent();
                if (parent != null)
                {
                    return(parent);
                }
                // "a" case: get the very last child at the bottom of the tree
                while (true)
                {
                    Debug.Assert(item != null);
                    var last = LastChild(item);
                    if (last == null)
                    {
                        return(item);
                    }
                    item = last;
                }
            }

            while (true)
            {
                Debug.Assert(result != null);
                var last = LastChild(result);
                if (last == null)
                {
                    return(result);
                }
                result = last;
            }
        }
Пример #24
0
 /// <summary>
 /// Retire un fils
 /// </summary>
 /// <param name="child"></param>
 public void RemoveChild(IHierarchyObject child)
 {
     foreach (IHierarchyObject item in childrenListChangeHandler.Items)
     {
         if (item.GetPosition() > child.GetPosition())
         {
             item.SetPosition(item.GetPosition() - 1);
             childrenListChangeHandler.AddUpdated((AttributeValue)item);
         }
     }
     child.SetPosition(-1);
     childrenListChangeHandler.AddDeleted((AttributeValue)child);
     UpdateParents();
 }
        public static bool IsAncestorOf(this IHierarchyObject source, IHierarchyObject descendant)
        {
            if (descendant == null) { return false; }

            // Scan the hierarchy
            IEnumerator<IHierarchyObject> e = GetAncestors(descendant).GetEnumerator();

            while (e.MoveNext()) {
                if (e.Current == source)
                    return true;
            }

            return false;
        }
Пример #26
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IHierarchyObject GetCopy()
        {
            Role role = new Role();

            role.name      = "Copy Of " + this.name;
            role.IsDefault = false;
            role.parent    = null;
            foreach (Role child in this.childrenListChangeHandler.Items)
            {
                IHierarchyObject copy = child.GetCopy();
                role.AddChild(copy);
            }
            return(role);
        }
Пример #27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="root"></param>
 public void DisplayRoot(IHierarchyObject root)
 {
     this.Root = root;
     //this.ItemsSource = new ObservableCollection<IHierarchyObject>();
     if (this.Root == null)
     {
         this.ItemsSource = null;
     }
     else
     {
         RefreshParent(this.Root);
         this.ItemsSource = this.Root.GetItems();
     }
 }
Пример #28
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IHierarchyObject GetCopy()
        {
            PeriodName periodName = new PeriodName();

            periodName.name     = "Copy Of " + this.name;
            periodName.position = -1;
            periodName.parent   = null;
            foreach (PeriodName child in this.childrenListChangeHandler.Items)
            {
                IHierarchyObject copy = child.GetCopy();
                periodName.AddChild(copy);
            }
            return(periodName);
        }
Пример #29
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IHierarchyObject GetCopy()
        {
            PresentationSlideItem slide = new PresentationSlideItem();

            slide.name     = "Copy Of " + this.name;
            slide.position = -1;
            slide.parent   = null;

            foreach (PresentationSlideItem child in this.childrenListChangeHandler.Items)
            {
                IHierarchyObject copy = child.GetCopy();
                slide.AddChild(copy);
            }
            return(slide);
        }
Пример #30
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IHierarchyObject GetCopy()
        {
            AttributeValue value = new AttributeValue();

            value.name      = "Copy Of " + this.name;
            value.position  = -1;
            value.parent    = null;
            value.IsDefault = this.IsDefault;
            foreach (AttributeValue child in this.childrenListChangeHandler.Items)
            {
                IHierarchyObject copy = child.GetCopy();
                value.AddChild(copy);
            }
            return(value);
        }
Пример #31
0
        /// <summary>
        /// Cette méthode permet de désactiver un menuItem dans le cas
        /// où l'opération associée à ce menuItem n'est pas possible pour
        /// le noeud courant.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnContextMenuOpening(ContextMenuEventArgs e)
        {
            IHierarchyObject selectedItem = (IHierarchyObject)this.SelectedItem;

            this.NewMenuItem.IsEnabled      = this.Root != null;
            this.EditMenuItem.IsEnabled     = this.Root != null && selectedItem != null && CurrentParent != null;
            this.CutMenuItem.IsEnabled      = this.Root != null && selectedItem != null && CurrentParent != null;
            this.CopyMenuItem.IsEnabled     = this.Root != null && selectedItem != null && CurrentParent != null;
            this.PasteMenuItem.IsEnabled    = this.Root != null && selectedItem != null && !Util.ClipbordUtil.IsClipBoardEmpty();
            this.DeleteMenuItem.IsEnabled   = this.Root != null && selectedItem != null && CurrentParent != null;
            this.MoveUpMenuItem.IsEnabled   = this.Root != null && selectedItem != null && selectedItem.GetPosition() > 0 && CurrentParent != null;
            this.MoveDownMenuItem.IsEnabled = this.Root != null && selectedItem != null && selectedItem.GetPosition() < selectedItem.GetParent().GetItems().Count - 1 && CurrentParent != null;
            this.IndentMenuItem.IsEnabled   = this.Root != null && selectedItem != null && selectedItem.GetPosition() > 0 && CurrentParent != null;
            this.OutdentMenuItem.IsEnabled  = this.Root != null && selectedItem != null && selectedItem.GetParent() != null && selectedItem.GetParent() != Root && CurrentParent != null;
        }
Пример #32
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IHierarchyObject GetCopy()
        {
            BGroup group = new BGroup();

            group.name       = "Copy Of " + this.name;
            group.subjectTyp = this.subjectTyp;
            group.position   = -1;
            group.parent     = null;
            foreach (BGroup child in this.childrenListChangeHandler.Items)
            {
                IHierarchyObject copy = child.GetCopy();
                group.AddChild(copy);
            }
            return(group);
        }
        public static bool IsDescendentOf(this IHierarchyObject source, IHierarchyObject ancestor)
        {
            if (ancestor == null) { return false; }

            return ancestor.IsAncestorOf(source);
        }