private void OnChildGroupAdded(object sender, ListEventArgs <FilteredGroup <IImageSet> > e)
        {
            ImageSetTreeGroupItem newGroupItem = new ImageSetTreeGroupItem(e.Item, this, _tree.Binding);

            _tree.Items.Add(newGroupItem);
            OnUpdated();
        }
 /// <summary>
 /// Constructor that allows a custom binding to be supplied.
 /// </summary>
 /// <param name="imageSets"></param>
 /// <param name="primaryStudyInstanceUid"></param>
 /// <param name="binding"></param>
 public ImageSetTree(ObservableList <IImageSet> imageSets, string primaryStudyInstanceUid, ImageSetTreeItemBinding binding)
 {
     _primaryStudyInstanceUid = primaryStudyInstanceUid;
     _imageSetGroups          = new ImageSetGroups(imageSets);
     _internalTree            = new ImageSetTreeGroupItem(_imageSetGroups.Root, new StudyDateComparer(), binding);
     UpdateInternalTreeRoot();
     _internalTree.Updated += OnInternalTreeUpdated;
 }
        private void OnChildGroupRemoved(object sender, ListEventArgs <FilteredGroup <IImageSet> > e)
        {
            ImageSetTreeGroupItem groupItem = FindGroupItem(e.Item);

            if (groupItem != null)
            {
                _tree.Items.Remove(groupItem);
                groupItem.Dispose();
                OnUpdated();
            }
        }
        private void ExpandTo(IImageSetTreeItem item)
        {
            ImageSetTreeGroupItem parent = item.Parent;

            while (parent != _internalTreeRoot)
            {
                parent.IsExpanded = true;
                parent            = parent.Parent;
            }

            _internalTreeRoot.IsExpanded = true;
        }
        private void OnChildGroupChanged(object sender, ListEventArgs <FilteredGroup <IImageSet> > e)
        {
            if (_changingGroupItem != null)
            {
                int replaceIndex = _tree.Items.IndexOf(_changingGroupItem);
                if (replaceIndex >= 0)
                {
                    _tree.Items[replaceIndex] = new ImageSetTreeGroupItem(e.Item, this, _tree.Binding);
                    OnUpdated();
                }

                _changingGroupItem.Dispose();
                _changingGroupItem = null;
            }
        }
        private ImageSetTreeGroupItem FindGroupItem(FilteredGroup <IImageSet> filteredGroup)
        {
            ImageSetTreeGroupItem groupItem = CollectionUtils.SelectFirst(_tree.Items,
                                                                          delegate(IImageSetTreeItem treeItem)
            {
                if (treeItem is ImageSetTreeGroupItem)
                {
                    return(((ImageSetTreeGroupItem)treeItem)._group == filteredGroup);
                }
                else
                {
                    return(false);
                }
            }) as ImageSetTreeGroupItem;

            return(groupItem);
        }
        private void UpdateInternalTreeRoot()
        {
            ImageSetTreeGroupItem treeRoot = _internalTree;

            while (treeRoot.GetItems().Count == 0)
            {
                ReadOnlyCollection <ImageSetTreeGroupItem> childGroupItems = treeRoot.GetGroupItems();
                int nonEmptyChildGroupItems = 0;
                foreach (ImageSetTreeGroupItem childGroupItem in childGroupItems)
                {
                    if (childGroupItem.GetAllItems().Count > 0)
                    {
                        ++nonEmptyChildGroupItems;
                    }
                }

                if (nonEmptyChildGroupItems == 1)
                {
                    treeRoot = childGroupItems[0];
                }
                else
                {
                    break;
                }
            }

            bool treeChanged = (_internalTreeRoot != treeRoot);

            _internalTreeRoot = treeRoot;
            UpdateSelection(false);
            ExpandToSelection();

            if (treeChanged)
            {
                OnTreeChanged();
            }
        }
 private void OnChildGroupChanging(object sender, ListEventArgs <FilteredGroup <IImageSet> > e)
 {
     _changingGroupItem = FindGroupItem(e.Item);
 }
 private ImageSetTreeGroupItem(FilteredGroup <IImageSet> group, ImageSetTreeGroupItem parent, ITreeItemBinding binding)
     : this(group, parent._imageSetComparer, binding)
 {
     _parent = parent;
 }
 internal ImageSetTreeItem(IImageSet imageSet, ImageSetTreeGroupItem parent)
 {
     _imageSet = imageSet;
     _parent   = parent;
 }