/// <inheritdoc />
        protected override void BuildPartUI(VisualElement parent)
        {
            if (m_Model is IVariableDeclarationModel variableDeclarationModel)
            {
                m_Field = GraphElementFactory.CreateUI <GraphElement>(m_OwnerElement.View, m_OwnerElement.CommandDispatcher,
                                                                      variableDeclarationModel, blackboardVariablePartCreationContext);

                if (m_Field == null)
                {
                    return;
                }

                m_Field.AddToClassList(ussClassName);
                m_Field.AddToClassList(m_ParentClassName.WithUssElement(PartName));
                m_Field.viewDataKey = m_Model.Guid + "__" + Blackboard.persistenceKey;

                m_Field.AddToView(m_OwnerElement.View);

                if (m_Field is BlackboardField blackboardField)
                {
                    blackboardField.NameLabel.RegisterCallback <ChangeEvent <string> >(OnFieldRenamed);
                }

                if (parent is BlackboardRow row)
                {
                    row.FieldSlot.Add(m_Field);
                }
                else
                {
                    parent.Add(m_Field);
                }
            }
        }
        public void UpdatePorts(IEnumerable <IPortModel> ports, IModelView view, CommandDispatcher commandDispatcher)
        {
            var uiPorts        = this.Query <Port>().ToList();
            var portViewModels = ports?.ToList() ?? new List <IPortModel>();

            // Check if we should rebuild ports
            bool rebuildPorts = false;

            if (uiPorts.Count != portViewModels.Count)
            {
                rebuildPorts = true;
            }
            else
            {
                int i = 0;
                foreach (var portModel in portViewModels)
                {
                    if (!Equals(uiPorts[i].PortModel, portModel))
                    {
                        rebuildPorts = true;
                        break;
                    }

                    i++;
                }
            }

            if (rebuildPorts)
            {
                foreach (var visualElement in Children())
                {
                    if (visualElement is Port port)
                    {
                        port.RemoveFromView();
                    }
                }

                Clear();

                foreach (var portModel in portViewModels)
                {
                    var ui = GraphElementFactory.CreateUI <Port>(view, commandDispatcher, portModel);
                    Debug.Assert(ui != null, "GraphElementFactory does not know how to create UI for " + portModel.GetType());
                    Add(ui);

                    ui.AddToView(view);
                }
            }
            else
            {
                foreach (var port in uiPorts)
                {
                    port.UpdateFromModel();
                }
            }

            this.PrefixEnableInClassList(portCountClassNamePrefix, portViewModels.Count.ToString());
        }
Пример #3
0
        /// <inheritdoc />
        public override void OnSelectionChanged(IEnumerable <SearcherItem> items)
        {
            if (m_DetailsPanel == null)
            {
                return;
            }

            var itemsList = items.ToList();

            if (!itemsList.Any())
            {
                return;
            }

            var searcherItem = itemsList.First();

            m_DetailsTitle.text = searcherItem.Name;

            var graphView = SearcherService.GraphView;

            foreach (var graphElement in graphView.GraphElements.ToList())
            {
                graphView.RemoveElement(graphElement);
            }

            if (!m_Scrollview.Contains(graphView))
            {
                m_Scrollview.Add(graphView);

                var eventCatcher = new VisualElement();
                eventCatcher.RegisterCallback <MouseDownEvent>(e => e.StopImmediatePropagation());
                eventCatcher.RegisterCallback <MouseMoveEvent>(e => e.StopImmediatePropagation());
                m_Scrollview.Add(eventCatcher);
                eventCatcher.StretchToParentSize();
            }

            var elements = CreateGraphElements(searcherItem).ToList();

            foreach (var element in elements.Where(element => element is INodeModel || element is IStickyNoteModel))
            {
                var node = GraphElementFactory.CreateUI <GraphElement>(graphView, graphView.CommandDispatcher, element);
                if (node != null)
                {
                    node.style.position = Position.Relative;
                    graphView.AddElement(node);
                }
            }

            OnGraphElementsCreated(searcherItem, elements);
        }
        Edge CreateGhostEdge(IGraphModel graphModel)
        {
            GhostEdgeModel ghostEdge;

            if (m_GhostEdgeViewModelCreator != null)
            {
                ghostEdge = m_GhostEdgeViewModelCreator.Invoke(graphModel);
            }
            else
            {
                ghostEdge = new GhostEdgeModel(graphModel);
            }

            var ui = GraphElementFactory.CreateUI <Edge>(GraphView, m_CommandDispatcher, ghostEdge);

            return(ui);
        }
        void Update(IStateObserver observer, GraphToolState state)
        {
            using (var observation = observer.ObserveState(state.ModelInspectorState))
            {
                var rebuildType = observation.UpdateType;

                if (rebuildType == UpdateType.Complete)
                {
                    m_SidePanelInspectorContainer.Clear();
                    if (state.ModelInspectorState.EditedNode != null)
                    {
                        m_SidePanelTitle.text = (state.ModelInspectorState.EditedNode as IHasTitle)?.Title ?? "Node Inspector";
                        m_Inspector           = GraphElementFactory.CreateUI <ModelUI>(this, CommandDispatcher, state.ModelInspectorState.EditedNode);
                        if (m_Inspector != null)
                        {
                            m_SidePanelInspectorContainer.Add(m_Inspector);
                        }
                    }
                    else
                    {
                        m_Inspector           = null;
                        m_SidePanelTitle.text = "Node Inspector";
                    }
                }
            }

            using (var gvObservation = observer.ObserveState(state.GraphViewState))
            {
                var rebuildType = gvObservation.UpdateType;

                if (rebuildType != UpdateType.None)
                {
                    m_SidePanelTitle.text = (state.ModelInspectorState.EditedNode as IHasTitle)?.Title ?? "Node Inspector";
                    m_Inspector?.UpdateFromModel();
                }
            }
        }
Пример #6
0
        /// <inheritdoc />
        protected override void UpdatePartFromModel()
        {
            if (m_Model is IBlackboardGraphModel graphProxyElement)
            {
                foreach (var row in m_Rows)
                {
                    row.RemoveFromView();
                }
                m_Rows.Clear();

                Blackboard.Highlightables.Clear();

                foreach (var sectionName in graphProxyElement.SectionNames)
                {
                    // PF FIXME: implement partial rebuild, like for PortContainer
                    m_Sections[sectionName].Clear();

                    var variableDeclarationModels = graphProxyElement.GetSectionRows(sectionName);
                    foreach (var vdm in variableDeclarationModels)
                    {
                        var ui = GraphElementFactory.CreateUI <GraphElement>(m_OwnerElement.View, m_OwnerElement.CommandDispatcher, vdm);

                        if (ui == null)
                        {
                            continue;
                        }

                        m_Sections[sectionName].Add(ui);
                        ui.AddToView(m_OwnerElement.View);
                        m_Rows.Add(ui);

                        Blackboard.Highlightables.AddRange(vdm.GetAllUIs(m_OwnerElement.View).OfType <IHighlightable>());
                    }
                }
            }
        }