Exemplo n.º 1
0
        public void AddSibling()
        {
            {
                // Instanciate a new requirement
                RequirementModel requirementItem = new RequirementModel
                {
                    ID                 = Guid.NewGuid(),
                    Project_ID         = Globals.Project_ID,
                    ArticleNo          = "xxx",
                    ArticleHeader      = "New Article",
                    Version            = "",
                    IsChanged          = false,
                    IsNew              = true,
                    RequirementType_ID = TypeViewModelLocator.GetTypeVM().GetTypeGroupID("Requirement"),
                    ChildRequirements  = new TD.ObservableItemCollection <RequirementModel>()
                };

                // If no item has been selected, put the object in the root of the tree
                if (SelectedItem == null)
                {
                    requirementItem.Parent_ID = null;//
                    Requirements.Add(requirementItem);
                }
                // If the selected item is in the root, put the new object in the root also
                else if (SelectedItem.Parent_ID == null)
                {
                    requirementItem.Parent_ID = null;
                    Requirements.Insert(Requirements.IndexOf(SelectedItem) + 1, requirementItem);
                }
                // Otherwise het the parent object and add the new object as a child
                else
                {
                    RequirementModel parentItem = GetRequirement(SelectedItem.Parent_ID);
                    requirementItem.Parent_ID = SelectedItem.Parent_ID;
                    parentItem.ChildRequirements.Insert(parentItem.ChildRequirements.IndexOf(SelectedItem) + 1, requirementItem);
                }

                IsChanged = true;
            }
        }
Exemplo n.º 2
0
        public void MoveSelection(TreeListViewRow destination)
        {
            if (destination != null)
            {
                RequirementModel destinationItem = (destination.DataContext) as RequirementModel;
                try
                {
                    // Setup a private collection with the selected items only. This is because the SelectedItems that are part of the view model collection
                    // will change as soon as we start removing and adding objects
                    TD.ObservableItemCollection <RequirementModel> selectedItems = new TD.ObservableItemCollection <RequirementModel>();
                    foreach (RequirementModel item in SelectedItems)
                    {
                        selectedItems.Add(item);
                    }

                    foreach (RequirementModel item in selectedItems)
                    {
                        // find the original parent of the object that's moved
                        RequirementModel parentSourceItem = GetRequirement(item.Parent_ID);

                        // If the parent is in the root level
                        if (parentSourceItem == null)
                        {
                            // Remove the item in the root level
                            Requirements.Remove(item);
                        }
                        else
                        {
                            // Otherwise remove the item from the child collection
                            parentSourceItem.ChildRequirements.Remove(item);
                        }

                        TreeListViewDropPosition relativeDropPosition = (TreeListViewDropPosition)destination.GetValue(RadTreeListView.DropPositionProperty);

                        // If put on top of destination
                        if (relativeDropPosition == TreeListViewDropPosition.Inside)
                        {
                            // the Parent_ID of the item will become the ID of the destination
                            item.Parent_ID = destinationItem.ID;
                            destinationItem.ChildRequirements.Add(item);
                        }
                        // If put before or after the destination
                        else
                        {
                            // if the desitination is in the root collection
                            if (destinationItem.Parent_ID == null)
                            {
                                // The parent_ID of the item will also be null
                                item.Parent_ID = null;
                                Requirements.Insert(Requirements.IndexOf(destinationItem), item);
                            }
                            else
                            {
                                // otherwise the Parent_ID of the item will be the same as that of the destination item
                                item.Parent_ID = destinationItem.Parent_ID;
                                // find the Parent of the destination item
                                parentSourceItem = GetRequirement(destinationItem.Parent_ID);
                                // Insert the item above the destination item in the ChildObject collection of the parent of the destination
                                if (relativeDropPosition == TreeListViewDropPosition.Before)
                                {
                                    parentSourceItem.ChildRequirements.Insert(parentSourceItem.ChildRequirements.IndexOf(destinationItem), item);
                                }
                                else
                                {
                                    parentSourceItem.ChildRequirements.Insert(parentSourceItem.ChildRequirements.IndexOf(destinationItem) + 1, item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    RadWindow.Alert(ex.Message);
                }
            }
        }