Beispiel #1
0
        private void OnDragOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            object sourceItem = DragDropPayloadManager.GetDataFromObject(e.Data, __dragSource);

            TreeListViewRow      destinationRow  = (e.OriginalSource as TreeListViewRow) ?? (e.OriginalSource as FrameworkElement).ParentOfType <TreeListViewRow>();
            GridViewScrollViewer destinationTree = (e.OriginalSource as GridViewScrollViewer) ?? (e.OriginalSource as FrameworkElement).ParentOfType <GridViewScrollViewer>();

            if (destinationRow != null && destinationRow.Item != sourceItem)
            {
                e.Effects = !IsChildOf(destinationRow, sourceItem) ? DragDropEffects.Move : DragDropEffects.None;
                if (e.Effects == DragDropEffects.Move)
                {
                    DragDropPayloadManager.SetData(e.Data, __dragTarget, destinationRow.Item);
                }
            }
            else if (destinationTree != null)
            {
                DragDropPayloadManager.SetData(e.Data, __dragTarget, string.Empty);
            }
            else
            {
                e.Effects = DragDropEffects.None;
            }

            e.Handled = true;
        }
        public void AssociateWithTemplate(TreeListViewRow destination)
        {
            try
            {
                foreach (var templateItem in TemplateViewModelLocator.GetTemplateVM().SelectedItems)
                {
                    switch (Globals.DraggedItem.Type)
                    {
                    case "Property":
                        foreach (var propertyItem in PropertyViewModelLocator.GetPropertyVM().SelectedItems)
                        {
                            TemplateAssociationModel templateAssociationItem = new TemplateAssociationModel
                            {
                                ID                = Guid.NewGuid(),
                                IsNew             = true,
                                IsChanged         = false,
                                IsDeleted         = false,
                                Project_ID        = Globals.Project_ID,
                                Template_ID       = templateItem.ID,
                                AssociationType   = Globals.DraggedItem.Type,
                                ChildAssociations = new TD.ObservableItemCollection <TemplateAssociationModel>(),
                            };
                            templateAssociationItem.Association_ID     = propertyItem.ID;
                            templateAssociationItem.Name               = propertyItem.PropertyName;
                            templateAssociationItem.Description        = propertyItem.Description;
                            templateAssociationItem.AssociationType_ID = propertyItem.PropertyType_ID;
                            templateAssociationItem.Value              = propertyItem.Value;

                            foreach (var childItem in propertyItem.ChildProperties)
                            {
                                TemplateAssociationModel templateAssociationChildItem = new TemplateAssociationModel
                                {
                                    IsNew           = true,
                                    IsChanged       = false,
                                    IsDeleted       = false,
                                    AssociationType = "Property",
                                    ID                 = Guid.NewGuid(),
                                    Project_ID         = Globals.Project_ID,
                                    Template_ID        = templateItem.ID,
                                    Association_ID     = childItem.ID,
                                    Name               = childItem.PropertyName,
                                    Description        = childItem.Description,
                                    AssociationType_ID = childItem.PropertyType_ID,
                                    Value              = childItem.Value,
                                    ChildAssociations  = new TD.ObservableItemCollection <TemplateAssociationModel>()
                                };
                                templateAssociationItem.ChildAssociations.Add(templateAssociationChildItem);
                            }
                            TemplateAssociations.Add(templateAssociationItem);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                RadWindow.Alert(ex.Message);
            }
            //}
        }
        private void ContextMenu_OnOpened(object sender, RoutedEventArgs e)
        {
            
            TreeListViewRow item = this.ContextMenu.GetClickedElement<TreeListViewRow>();
            if (item != null) 
            {
                LayerList.SelectedItem = (LayerTreeNode)item.DataContext;
            }

        }
        public void AssociateWithObject(TreeListViewRow destination)
        {
            try
            {
                // Associate all selected objects
                foreach (var objectItem in ObjectViewModelLocator.GetObjectVM().SelectedItems)
                {
                    // With all selected requirements (m:n)
                    foreach (var requirementItem in RequirementViewModelLocator.GetRequirementVM().SelectedItems)
                    {
                        ObjectRequirementModel objectRequirementItem = new ObjectRequirementModel
                        {
                            IsNew              = true,
                            IsChanged          = false,
                            IsDeleted          = false,
                            Project_ID         = Globals.Project_ID,
                            Object_ID          = objectItem.ID,
                            Requirement_ID     = requirementItem.ID,
                            RequirementType_ID = requirementItem.RequirementType_ID,
                            ArticleNo          = requirementItem.ArticleNo,
                            ArticleHeader      = requirementItem.ArticleHeader,
                            //RequirementType = Globals.DraggedItem.Type,
                            ChildRequirements = new TD.ObservableItemCollection <ObjectRequirementModel>(),
                        };

                        foreach (var childItem in requirementItem.ChildRequirements)
                        {
                            ObjectRequirementModel objectRequirementChildItem = new ObjectRequirementModel
                            {
                                IsNew              = true,
                                IsChanged          = false,
                                IsDeleted          = false,
                                Project_ID         = Globals.Project_ID,
                                Object_ID          = objectRequirementItem.Object_ID,
                                Requirement_ID     = childItem.ID,
                                RequirementType_ID = childItem.RequirementType_ID,
                                //objectFunctionalityChildItem.FunctionParent_ID = childItem.Parent_ID;
                                ArticleNo         = childItem.ArticleNo,
                                ArticleHeader     = childItem.ArticleHeader,
                                ChildRequirements = new TD.ObservableItemCollection <ObjectRequirementModel>()
                            };
                            objectRequirementItem.ChildRequirements.Add(objectRequirementChildItem);
                        }
                        ;

                        ObjectRequirements.Add(objectRequirementItem);
                    }
                }
            }
            catch (Exception ex)
            {
                RadWindow.Alert(ex.Message);
            }
        }
Beispiel #5
0
        private void OnDragInitialize(object sender, DragInitializeEventArgs e)
        {
            TreeListViewRow sourceRow = (e.OriginalSource as TreeListViewRow) ?? (e.OriginalSource as FrameworkElement).ParentOfType <TreeListViewRow>();

            if (sourceRow != null)
            {
                IDragPayload dataObject = DragDropPayloadManager.GeneratePayload(null);
                DragDropPayloadManager.SetData(dataObject, __dragSource, sourceRow.Item);
                e.Data = dataObject;
            }
        }
        private void ShowObject(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            TreeListViewRow item = this.ContextMenu.GetClickedElement<TreeListViewRow>();
            MessageArgs arg=new MessageArgs();

            ZoomToObjEvent _event = new ZoomToObjEvent(UnityEventType.ZoomToObjEvent);
            
            _event.path = (item.DataContext as LayerTreeNode)?.path;
            string _str = JsonConvert.SerializeObject(_event);
            arg.message = _str;
            viewModel.SendMessageListener(this, arg);
        }
        //TODO: fix hard code
        private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            if (e.Data != null && e.AllowedEffects != DragDropEffects.None)
            {
                var             treeListViewName = (sender as RadTreeListView).Name;
                TreeListViewRow destination      = e.OriginalSource as TreeListViewRow ?? (e.OriginalSource as FrameworkElement).ParentOfType <TreeListViewRow>();
                switch (treeListViewName)
                {
                case "ObjectTreeListView":
                    ObjectViewModelLocator.GetObjectVM().MoveSelection(destination);
                    break;

                case "TemplateTreeListView":
                    TemplateViewModelLocator.GetTemplateVM().MoveSelection(destination);
                    break;

                case "PropertyTreeListView":
                    PropertyViewModelLocator.GetPropertyVM().MoveSelection(destination);
                    break;

                case "ObjectAssociationTreeListView":
                    ObjectAssociationViewModel objectAssociationViewModel = ObjectAssociationViewModelLocator.GetObjectAssociationVM();
                    objectAssociationViewModel.AssociateWithObject(destination);
                    objectAssociationViewModel.FilteredObjectAssociations.View.Refresh();
                    break;

                case "ObjectRequirementTreeListView":
                    ObjectRequirementViewModel objectRequirementViewModel = ObjectRequirementViewModelLocator.GetObjectRequirementVM();
                    objectRequirementViewModel.AssociateWithObject(destination);
                    objectRequirementViewModel.FilteredObjectRequirements.View.Refresh();
                    break;

                case "TemplateAssociationTreeListView":
                    TemplateAssociationViewModel templateAssociationViewModel = TemplateAssociationViewModelLocator.GetTemplateAssociationVM();
                    templateAssociationViewModel.AssociateWithTemplate(destination);
                    templateAssociationViewModel.FilteredTemplateAssociations.View.Refresh();
                    break;

                case "TemplateRequirementTreeListView":
                    TemplateRequirementViewModel templateRequirementViewModel = TemplateRequirementViewModelLocator.GetTemplateRequirementVM();
                    templateRequirementViewModel.AssociateWithTemplate(destination);
                    templateRequirementViewModel.FilteredTemplateRequirements.View.Refresh();
                    break;

                case "RequirementTreeListView":
                    RequirementViewModelLocator.GetRequirementVM().MoveSelection(destination);
                    break;
                }
            }
        }
        private bool IsChildOf(TreeListViewRow dropTarget, object originalSource)
        {
            var currentElement = dropTarget;

            while (currentElement != null)
            {
                if (currentElement.Item == originalSource)
                {
                    return(true);
                }

                currentElement = currentElement.ParentRow;
            }

            return(false);
        }
Beispiel #9
0
        public override Style SelectStyle(object item, DependencyObject container)
        {
            TreeListViewRow row = container as TreeListViewRow;

            if (item is Club)
            {
                Club parent = item as Club;
                if (parent.Players.Count > 1)
                {
                    Dispatcher.BeginInvoke(new Action(() => row.IsExpanded = true));
                    return(ExpandedStyle);
                }
                else
                {
                    Dispatcher.BeginInvoke(new Action(() => row.IsExpanded = false));
                    return(CollapseStyle);
                }
            }
            return(null);
        }
Beispiel #10
0
        public void AssociateWithObject(TreeListViewRow destination)
        {
            try
            {
                foreach (var objectItem in ObjectViewModelLocator.GetObjectVM().SelectedItems)
                {
                    switch (Globals.DraggedItem.Type)
                    {
                    case "Template":
                        foreach (var templateItem in TemplateViewModelLocator.GetTemplateVM().SelectedItems)
                        {
                            ObjectAssociationModel objectAssociationItem = new ObjectAssociationModel
                            {
                                IsNew             = true,
                                IsChanged         = false,
                                IsDeleted         = false,
                                ID                = Guid.NewGuid(),
                                Project_ID        = Globals.Project_ID,
                                Object_ID         = objectItem.ID,
                                AssociationType   = Globals.DraggedItem.Type,
                                Value             = "",
                                ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>(),
                            };
                            objectAssociationItem.Association_ID     = templateItem.ID;
                            objectAssociationItem.Name               = templateItem.TemplateName;
                            objectAssociationItem.Description        = templateItem.Description;
                            objectAssociationItem.AssociationType_ID = templateItem.TemplateType_ID;

                            foreach (var childItem in templateItem.ChildTemplates)
                            {
                                ObjectAssociationModel objectAssociationChildItem = new ObjectAssociationModel
                                {
                                    IsNew              = true,
                                    IsChanged          = false,
                                    IsDeleted          = false,
                                    ID                 = Guid.NewGuid(),
                                    AssociationType    = "Template",
                                    Project_ID         = Globals.Project_ID,
                                    Object_ID          = objectItem.ID,
                                    Association_ID     = childItem.ID,
                                    Name               = childItem.TemplateName,
                                    Description        = childItem.Description,
                                    AssociationType_ID = childItem.TemplateType_ID,
                                    Value              = "",
                                    ChildAssociations  = new TD.ObservableItemCollection <ObjectAssociationModel>()
                                };
                                objectAssociationItem.ChildAssociations.Add(objectAssociationChildItem);
                                LoadTemplateProperties(objectAssociationChildItem);
                            }
                            ;
                            ObjectAssociations.Add(objectAssociationItem);
                            LoadTemplateProperties(objectAssociationItem);
                        }
                        break;

                    case "Property":
                        foreach (var propertyItem in PropertyViewModelLocator.GetPropertyVM().SelectedItems)
                        {
                            ObjectAssociationModel objectAssociationItem = new ObjectAssociationModel
                            {
                                IsNew             = true,
                                IsChanged         = false,
                                IsDeleted         = false,
                                ID                = Guid.NewGuid(),
                                Project_ID        = Globals.Project_ID,
                                Object_ID         = objectItem.ID,
                                AssociationType   = Globals.DraggedItem.Type,
                                Value             = "",
                                ChildAssociations = new TD.ObservableItemCollection <ObjectAssociationModel>(),
                            };

                            objectAssociationItem.Association_ID     = propertyItem.ID;
                            objectAssociationItem.Name               = propertyItem.PropertyName;
                            objectAssociationItem.Description        = propertyItem.Description;
                            objectAssociationItem.AssociationType_ID = propertyItem.PropertyType_ID;

                            foreach (var childItem in propertyItem.ChildProperties)
                            {
                                ObjectAssociationModel objectAssociationChildItem = new ObjectAssociationModel
                                {
                                    IsNew              = true,
                                    IsChanged          = false,
                                    IsDeleted          = false,
                                    AssociationType    = "Property",
                                    Project_ID         = Globals.Project_ID,
                                    Object_ID          = objectItem.ID,
                                    Association_ID     = childItem.ID,
                                    Name               = childItem.PropertyName,
                                    Description        = childItem.Description,
                                    AssociationType_ID = childItem.PropertyType_ID,
                                    Value              = "",
                                    ChildAssociations  = new TD.ObservableItemCollection <ObjectAssociationModel>()
                                };
                                objectAssociationItem.ChildAssociations.Add(objectAssociationChildItem);
                            }
                            ObjectAssociations.Add(objectAssociationItem);
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                RadWindow.Alert(ex.Message);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Method triggered by the TreeListViewDragDropBehavior Class. Takes care of moving on item in the tree, which can be from
        /// any level to any level
        /// </summary>
        /// <param name="destination"></param>
        public void MoveSelection(TreeListViewRow destination) // Collection<ObjectModel> selectedItems, ObjectModel destination )
        {
            if (destination != null)
            {
                ObjectModel destinationItem = (destination.DataContext) as ObjectModel;
                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 <ObjectModel> selectedItems = new TD.ObservableItemCollection <ObjectModel>();
                    foreach (ObjectModel item in SelectedItems)
                    {
                        selectedItems.Add(item);
                    }

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

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

                        TreeListViewDropPosition relativeDropPosition = (TreeListViewDropPosition)destination.GetValue(RadTreeListView.DropPositionProperty);
                        destination.UpdateLayout();
                        // 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.ChildObjects.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;
                                Objects.Insert(Objects.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 = GetObject(destinationItem.Parent_ID);
                                // Insert the item before or after the destination item in the ChildObject collection of the parent of the destination
                                if (relativeDropPosition == TreeListViewDropPosition.Before)
                                {
                                    parentSourceItem.ChildObjects.Insert(parentSourceItem.ChildObjects.IndexOf(destinationItem), item);
                                }
                                else
                                {
                                    parentSourceItem.ChildObjects.Insert(parentSourceItem.ChildObjects.IndexOf(destinationItem) + 1, item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    RadWindow.Alert(new DialogParameters()
                    {
                        Header  = "Error",
                        Content = "Error while moving object\n" + ex.Message
                    });
                }
            }
        }
		private bool IsChildOf(TreeListViewRow dropTarget, object originalSource)
		{
			var currentElement = dropTarget;
			while (currentElement != null)
			{
				if (currentElement.Item == originalSource)
				{
					return true;
				}

				currentElement = currentElement.ParentRow;
			}

			return false;
		}
Beispiel #13
0
        /// <summary>
        /// Method triggered by the TreeListViewDragDropBehavior Class. Takes care of moving on item in the tree, which can be from
        /// any level to any level
        /// </summary>
        /// <param name="destination"></param>
        public void MoveSelection(TreeListViewRow destination) // Collection<PropertyModel> selectedItems, PropertyModel destination )
        {
            if (destination != null)
            {
                PropertyModel destinationItem = (destination.DataContext) as PropertyModel;
                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 <PropertyModel> selectedItems = new TD.ObservableItemCollection <PropertyModel>();
                    foreach (PropertyModel item in SelectedItems)
                    {
                        selectedItems.Add(item);
                    }

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

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

                        TreeListViewDropPosition relativeDropPosition = (TreeListViewDropPosition)destination.GetValue(RadTreeListView.DropPositionProperty);
                        destination.UpdateLayout();
                        // 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.ChildProperties.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;
                                Properties.Insert(Properties.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 = GetProperty(destinationItem.Parent_ID);
                                // Insert the item before or after the destination item in the ChildObject collection of the parent of the destination
                                if (relativeDropPosition == TreeListViewDropPosition.Before)
                                {
                                    parentSourceItem.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem), item);
                                }
                                else
                                {
                                    parentSourceItem.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem) + 1, item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    RadWindow.Alert(ex.Message);
                }
            }
            //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<PropertyModel> selectedItems = new TD.ObservableItemCollection<PropertyModel>();
            //    foreach (PropertyModel item in SelectedItems)
            //    {
            //        selectedItems.Add(item);
            //    }

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

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


            //        if (destination != null)
            //        {
            //            TreeListViewDropPosition relativeDropPosition = (TreeListViewDropPosition)destination.GetValue(RadTreeListView.DropPositionProperty);
            //            PropertyModel destinationItem = (destination.DataContext) as PropertyModel;
            //            // 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.ChildProperties.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;
            //                    Properties.Insert(Properties.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 = GetProperty(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.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem), item);
            //                    else
            //                        parentSourceItem.ChildProperties.Insert(parentSourceItem.ChildProperties.IndexOf(destinationItem) + 1, item);
            //                }
            //            }

            //        }
            //        else // destination is null, i.e. below the tree
            //        {
            //            item.Parent_ID = null;
            //            Properties.Add(item);
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    RadWindow.Alert(ex.Message);
            //}
        }