public void GenerateChildren(GraphViewModel owner, NodeViewModel parent, List <INodePresenter> nodePresenters)
 {
     foreach (var child in CombineChildren(nodePresenters))
     {
         if (ShouldConstructViewModel(child))
         {
             Type type      = null;
             var  typeMatch = true;
             foreach (var childPresenter in child)
             {
                 if (type == null)
                 {
                     type = childPresenter.Type;
                 }
                 else if (type != childPresenter.Type && type.IsAssignableFrom(childPresenter.Type))
                 {
                     type = childPresenter.Type;
                 }
                 else if (type != childPresenter.Type)
                 {
                     typeMatch = false;
                     break;
                 }
             }
             if (typeMatch)
             {
                 CreateNodeViewModel(owner, parent, child.First().Type, child);
             }
         }
     }
 }
Exemple #2
0
        protected internal NodeViewModel([NotNull] GraphViewModel ownerViewModel, NodeViewModel parent, [NotNull] string baseName, Type nodeType, [NotNull] List <INodePresenter> nodePresenters)
            : base(ownerViewModel.ServiceProvider)
        {
            owner = ownerViewModel;
            Type  = nodeType;

            if (baseName == null)
            {
                throw new ArgumentException("baseName and index can't be both null.");
            }

            Name = EscapeName(baseName);

            this.nodePresenters = nodePresenters;
            foreach (var nodePresenter in nodePresenters)
            {
                nodePresenter.ValueChanging += ValueChanging;
                nodePresenter.ValueChanged  += ValueChanged;
                nodePresenter.AttachedProperties.PropertyUpdated += AttachedPropertyUpdated;
            }

            UpdateViewModelProperties();

            parent?.AddChild(this);
        }
        protected virtual NodeViewModel CreateNodeViewModel([NotNull] GraphViewModel owner, NodeViewModel parent, Type nodeType, [NotNull] List <INodePresenter> nodePresenters, bool isRootNode = false)
        {
            // TODO: properly compute the name
            var viewModel = new NodeViewModel(owner, parent, nodePresenters.First().Name, nodeType, nodePresenters);

            if (isRootNode)
            {
                owner.RootNode = viewModel;
            }
            viewModel.Refresh();
            return(viewModel);
        }
 public NodeViewModelValueChangedArgs(GraphViewModel viewModel, NodeViewModel node)
 {
     ViewModel = viewModel;
     Node      = node;
 }
        public NodeViewModel CreateGraph(GraphViewModel owner, Type rootType, IEnumerable <INodePresenter> rootNodes)
        {
            var rootViewModelNode = CreateNodeViewModel(owner, null, rootType, rootNodes.ToList(), true);

            return(rootViewModelNode);
        }