Inheritance: GraphItemConfiguration
        private void SelectReferenceItem(NodeConfigSectionBase section, NodeConfigSectionBase section1)
        {
            if (section.AddCommandType != null)
            {
            }

            var menu = new SelectionMenu();


            if (section1.AllowDuplicates)
            {
                menu.ConvertAndAdd(section1.GenericSelector(GraphItem).ToArray().OfType <IItem>(), _ =>
                {
                    GraphItem.AddReferenceItem(_ as TData, section1);
                });


                //InvertGraphEditor.WindowManager.InitItemWindow(section1.GenericSelector(GraphItem).ToArray(),
                //    (selected) => { GraphItem.AddReferenceItem(selected, section1); });
            }
            else
            {
                menu.ConvertAndAdd(section1.GenericSelector(GraphItem).Where(
                                       p =>
                                       !GraphItem.PersistedItems.OfType <GenericReferenceItem>()
                                       .Select(x => x.SourceIdentifier)
                                       .Contains(p.Identifier)).ToArray().OfType <IItem>(), _ =>
                {
                    GraphItem.AddReferenceItem(_ as TData, section1);
                });
            }

            InvertApplication.SignalEvent <IShowSelectionMenu>(_ => _.ShowSelectionMenu(menu));
        }
        private void CreateNewSectionItem(NodeConfigSectionBase section1, DiagramNodeViewModel vm)
        {
            var item = Activator.CreateInstance(section1.SourceType) as GenericNodeChildItem;

            item.Node = vm.GraphItemObject as GraphNode;
            DiagramViewModel.CurrentRepository.Add(item);
            item.Name = item.Repository.GetUniqueName(section1.Name);

            OnAdd(section1, item);

            if (typeof(ITypedItem).IsAssignableFrom(section1.SourceType))
            {
                InvertApplication.Execute(new SelectTypeCommand()
                {
                    PrimitiveOnly     = false,
                    AllowNone         = false,
                    IncludePrimitives = true,
                    Item = item as ITypedItem,
                    OnSelectionFinished = () =>
                    {
                        item.IsSelected = true;
                        item.IsEditing  = true;
                    }
                });
            }
            else
            {
                item.IsEditing = true;
            }
        }
 private void OnAdd(NodeConfigSectionBase section, NodeConfigSectionBase section1, DiagramNodeViewModel vm)
 {
     if (section1.AllowAdding && section1.ReferenceType != null && !section1.HasPredefinedOptions)
     {
         SelectReferenceItem(section, section1);
     }
     else
     {
         if (section1.GenericSelector != null && section1.HasPredefinedOptions)
         {
             SelectFromOptions(section1, vm);
         }
         else
         {
             CreateNewSectionItem(section1, vm);
         }
     }
 }
        private void SelectFromOptions(NodeConfigSectionBase section1, DiagramNodeViewModel vm)
        {
            InvertGraphEditor.WindowManager.InitItemWindow(section1.GenericSelector(GraphItem).ToArray(),
                                                           (selected) =>
            {
                var item = selected as GenericNodeChildItem;

                item.Node = vm.GraphItemObject as GraphNode;
                DiagramViewModel.CurrentRepository.Add(item);
                if (section1.OnAdd != null)
                {
                    section1.OnAdd(item);
                }
                else
                {
                    item.Name = item.Repository.GetUniqueName(section1.Name);
                }

                item.IsEditing = true;
                OnAdd(section1, item);
            });
        }
示例#5
0
 private void SelectReferenceItem(NodeConfigSectionBase section, NodeConfigSectionBase section1)
 {
     if (section.AddCommandType != null)
     {
     }
     if (section1.AllowDuplicates)
     {
         InvertGraphEditor.WindowManager.InitItemWindow(section1.GenericSelector(GraphItem).ToArray(),
                                                        (selected) => { GraphItem.AddReferenceItem(selected, section1); });
     }
     else
     {
         InvertGraphEditor.WindowManager.InitItemWindow(
             section1.GenericSelector(GraphItem).ToArray()
             .Where(
                 p =>
                 !GraphItem.PersistedItems.OfType <GenericReferenceItem>()
                 .Select(x => x.SourceIdentifier)
                 .Contains(p.Identifier)),
             (selected) => { GraphItem.AddReferenceItem(selected, section1); });
     }
 }
 protected override void OnAdd(NodeConfigSectionBase configSection, GenericNodeChildItem item)
 {
     base.OnAdd(configSection, item);
     
 }
 protected virtual void OnAdd(NodeConfigSectionBase configSection, GenericNodeChildItem item)
 {
 }
        private void AddSection(NodeConfigSectionBase section)
        {
            //if (DiagramViewModel != null && DiagramViewModel.CurrentRepository.CurrentFilter.IsAllowed(null, section.SourceType)) return;
            var section1 = section as NodeConfigSectionBase;

            if (!IsVisible(section.Visibility))
            {
                return;
            }

            if (!string.IsNullOrEmpty(section.Name))
            {
                var header = new GenericItemHeaderViewModel()
                {
                    Name          = section.Name,
                    NodeViewModel = this,
                    NodeConfig    = NodeConfig,
                    SectionConfig = section1,
                };
                //if (section.AttributeInfo != null)
                //{
                //    header.IsNewLine = inputConfig.AttributeInfo.IsNewRow;
                //}
                //else
                //{
                //    header.IsNewLine = true;
                //}

                header.AddCommand = section1.AllowAdding ? new LambdaCommand("Add Item", () =>
                {
                    OnAdd(section, section1, this);
                }) : null;


                ContentItems.Add(header);
            }

            if (section1.GenericSelector != null && section1.ReferenceType == null)
            {
                foreach (var item in section1.GenericSelector(GraphItem).OfType <IDiagramNodeItem>().OrderBy(p => p.Order))
                {
                    if (section.SourceType.IsAssignableFrom(item.GetType()))
                    {
                        var vm            = GetDataViewModel(item) as GraphItemViewModel;
                        var itemViewModel = vm as ItemViewModel;
                        if (itemViewModel != null)
                        {
                            itemViewModel.IsEditable = section1.IsEditable;
                            ApplyInputConfiguration(section, item, vm.InputConnector, section.AllowMultipleInputs);
                            ApplyOutputConfiguration(section, item, vm.OutputConnector, section.AllowMutlipleOutputs);
                        }

                        if (vm == null)
                        {
                            InvertApplication.LogError(
                                string.Format(
                                    "Couldn't find view-model for {0} in section {1} with child type {2}",
                                    item.GetType(), section1.Name, section1.SourceType.Name));
                            continue;
                        }

                        vm.DiagramViewModel = DiagramViewModel;
                        ContentItems.Add(vm);
                    }
                    else
                    {
                        InvertApplication.LogError(string.Format("Types do not match {0} and {1}", section.SourceType,
                                                                 item.GetType()));
                    }
                }
            }
            else
            {
                foreach (var item in GraphItem.PersistedItems)
                {
                    if (section.SourceType.IsAssignableFrom(item.GetType()))
                    {
                        var vm = GetDataViewModel(item) as ItemViewModel;


                        if (vm == null)
                        {
                            InvertApplication.LogError(string.Format("Couldn't find view-model for {0}", item.GetType()));
                            continue;
                        }
                        vm.IsEditable       = section1.IsEditable;
                        vm.DiagramViewModel = DiagramViewModel;
                        if (section1.HasPredefinedOptions)
                        {
                            vm.IsEditable = false;
                        }
                        ApplyInputConfiguration(section, item, vm.InputConnector, section.AllowMultipleInputs);
                        ApplyOutputConfiguration(section, item, vm.OutputConnector, section.AllowMutlipleOutputs);
                        ContentItems.Add(vm);
                    }
                }
            }
        }
示例#9
0
        private GraphItemConfiguration CreateSectionConfiguration(PropertyInfo property, Section section)
        {
            var sectionConfig = new NodeConfigSectionBase
            {
                Name           = section.Name,
                IsProxy        = section is ProxySection,
                Visibility     = section.Visibility,
                SourceType     = property.PropertyType.GetGenericParameter(),
                AddCommandType = section.AddCommandType
            };

            var referenceSection = section as ReferenceSection;

            if (referenceSection != null)
            {
                sectionConfig.AllowDuplicates = referenceSection.AllowDuplicates;
                sectionConfig.AllowAdding     = !referenceSection.Automatic;
                sectionConfig.ReferenceType   = referenceSection.ReferenceType ??
                                                sectionConfig.SourceType.GetGenericParameter() ?? property.PropertyType.GetGenericParameter();
                sectionConfig.IsEditable           = referenceSection.Editable;
                sectionConfig.HasPredefinedOptions = referenceSection.HasPredefinedOptions;

                if (sectionConfig.ReferenceType == null)
                {
                    throw new Exception(string.Format("Reference Section on property {0} doesn't have a valid ReferenceType.", property.Name));
                }

                //sectionConfig.GenericSelector = (node) =>
                //{

                //};
            }
            if (sectionConfig.IsProxy || referenceSection == null)
            {
                var property1 = property;

                if (sectionConfig.IsProxy)
                {
                    sectionConfig.AllowAdding = false;
                }

                sectionConfig.GenericSelector = (node) =>
                {
                    var enumerator = property1.GetValue(node, null) as IEnumerable;
                    if (enumerator == null)
                    {
                        return(null);
                    }
                    return(enumerator.Cast <IGraphItem>());
                };
            }
            else if (referenceSection != null)
            {
                var possibleSelectorProperty = NodeType.GetProperty("Possible" + property.Name);
                if (possibleSelectorProperty != null)
                {
                    sectionConfig.GenericSelector = (node) =>
                    {
                        var propertyN  = NodeType.GetProperty("Possible" + property.Name);
                        var enumerator = propertyN.GetValue(node, null) as IEnumerable;

                        if (enumerator == null)
                        {
                            return(null);
                        }
                        return(enumerator.OfType <IGraphItem>());
                    };
                }
                else
                {
                    sectionConfig.GenericSelector = (node) =>
                    {
                        return(node.Repository.AllOf <IGraphItem>().Where(p => referenceSection.ReferenceType.IsAssignableFrom(p.GetType())));
                    };
                }
            }
            return(sectionConfig);
        }
示例#10
0
        private GraphItemConfiguration CreateSectionConfiguration(PropertyInfo property, Section section)
        {
            var sectionConfig = new NodeConfigSectionBase
            {
                Name = section.Name,
                IsProxy = section is ProxySection,
                Visibility = section.Visibility,
                SourceType = property.PropertyType.GetGenericParameter(),
                AddCommandType = section.AddCommandType
            };

            var referenceSection = section as ReferenceSection;
            if (referenceSection != null)
            {
                sectionConfig.AllowDuplicates = referenceSection.AllowDuplicates;
                sectionConfig.AllowAdding = !referenceSection.Automatic;
                sectionConfig.ReferenceType = referenceSection.ReferenceType ??
                                              sectionConfig.SourceType.GetGenericParameter() ?? property.PropertyType.GetGenericParameter();
                sectionConfig.IsEditable = referenceSection.Editable;
                sectionConfig.HasPredefinedOptions = referenceSection.HasPredefinedOptions;
                
                if (sectionConfig.ReferenceType == null)
                {
                    throw new Exception(string.Format("Reference Section on property {0} doesn't have a valid ReferenceType.", property.Name));
                }

                //sectionConfig.GenericSelector = (node) =>
                //{

                //};
            }
            if (sectionConfig.IsProxy || referenceSection == null)
            {

                var property1 = property;
                
                if (sectionConfig.IsProxy)
                sectionConfig.AllowAdding = false;

                sectionConfig.GenericSelector = (node) =>
                {
                    var enumerator = property1.GetValue(node, null) as IEnumerable;
                    if (enumerator == null) return null;
                    return enumerator.Cast<IGraphItem>();

                };
            }
            else if (referenceSection != null)
            {
              

                var possibleSelectorProperty = NodeType.GetProperty("Possible" + property.Name);
                if (possibleSelectorProperty != null)
                {
                    
                
                    sectionConfig.GenericSelector = (node) =>
                    {
                        var propertyN = NodeType.GetProperty("Possible" + property.Name);
                        var enumerator = propertyN.GetValue(node, null) as IEnumerable;
                        
                        if (enumerator == null) return null;
                        return enumerator.OfType<IGraphItem>();

                    };
                }
                else
                {
                    sectionConfig.GenericSelector = (node) =>
                    {
                        return node.Repository.AllOf<IGraphItem>().Where(p => referenceSection.ReferenceType.IsAssignableFrom(p.GetType()));
                    };

                }

            }
            return sectionConfig;
        }
示例#11
0
        internal void AddReferenceItem(GenericReferenceItem[] mirrorItems, IGraphItem item, NodeConfigSectionBase mirrorSection)
        {
            var current = mirrorItems.FirstOrDefault(p => p.SourceIdentifier == item.Identifier);

            if (current != null && !mirrorSection.AllowDuplicates)
            {
                return;
            }

            var newMirror = Activator.CreateInstance(mirrorSection.SourceType) as GenericReferenceItem;

            newMirror.Node = this;
            Node.Repository.Add(newMirror);
            newMirror.SourceIdentifier = item.Identifier;


            //Node.Project.AddItem(newMirror);
        }
示例#12
0
 public void AddReferenceItem(IGraphItem item, NodeConfigSectionBase mirrorSection)
 {
     AddReferenceItem(PersistedItems.Where(p => p.GetType() == mirrorSection.ReferenceType).Cast <GenericReferenceItem>().ToArray(), item, mirrorSection);
 }