Esempio n. 1
0
        public TreeNodeViewModel(Element element, TreeNodeViewModel parent)
        {
            _element = element;
            _parent = parent;

            IsExpanded = true; //defaults

            _children = new ObservableCollection<TreeNodeViewModel>(
                    (from child in _element.Children
                     select new TreeNodeViewModel(child, this))
                     .ToList<TreeNodeViewModel>());

            if (_children.Count > 0)
                hasChildren = true;
            else
                hasChildren = false;
        }
Esempio n. 2
0
        private Element createValueElement(XmlReader reader)
        {
            Element e = new Element();
            e.Name = reader.Value;
            e.Value = reader.Value;
            e.Type = ElementType.InstanceValue;

            return e;
        }
Esempio n. 3
0
        private Element createModelElement(XmlReader reader)
        {
            Element e = new Element();
            e.Name = reader.Name;
            e.Value = reader.Value;
            e.Type = ElementType.ModelElement;

            return e;
        }
Esempio n. 4
0
        private void getElementListFromNotation(XmlNode notation)
        {
            if ((!notation.HasChildNodes) && (!String.IsNullOrEmpty(notation.Value)))
            {
                Element e = new Element();
                //e.Name = notation.ParentNode.Name;
                //e.Value = notation.InnerText;
                e.Value = notation.ParentNode.Name;

                ///this part is different in visualfucntion and visual element
                //e.Name = notation.InnerText; //visual element
                e.Name = notation.ParentNode.Name; //visual function

                //e.Address = getRelativeAddress(Data,notation.Name);
                e.Address = getFullAddress(notation);
                elementList.Add(e);
            }
            else
                foreach (XmlNode x in notation.ChildNodes)
                    getElementListFromNotation(x);
        }
Esempio n. 5
0
 public TreeNodeViewModel(Element element)
     : this(element, null)
 {
 }
Esempio n. 6
0
        //public void createRunPopup()
        //{
        //    //clear previous popUp
        //    if (showList == true)
        //    {
        //        showList = false;
        //        OnPropertyChanged("showList");
        //    }
        //    else
        //    {
        //        elementList.Clear();
        //        if (Data == null)
        //        {
        //            loadDataFromXaml();
        //        }
        //        //else
        //        //{
        //        getElementListFromNotation(Data);
        //        //}
        //        OnPropertyChanged("elementList");
        //        showList = true;
        //        OnPropertyChanged("showList");
        //    }
        //}
        private void getElementListFromNotation(XmlNode notation, bool isPlaceHolder)
        {
            if ((!notation.HasChildNodes) && (!String.IsNullOrEmpty(notation.Value)))
            {

                Element e = new Element();
                e.Name = notation.ParentNode.Name;
                e.Value = notation.InnerText;
                e.IsPlaceHolder = isPlaceHolder;
                //e.Value = notation.ParentNode.Name;
                //e.Name = notation.InnerText;

                //e.Address = getRelativeAddress(Data,notation.Name);
                e.Address = getFullAddress(notation);
                //elementList.Add(e);
                MyItemsHost.Items.Add(e);

            }
            else
                if (!notation.Name.Equals("IsPlaceHolder"))//if notation is placeholder attribute, ignore it
                {
                    XmlNode node = notation.Attributes["IsPlaceHolder"]; //if xml element has isplaceholder attribute
                    bool checkPlaceHolder = false;

                    if (node != null)
                        checkPlaceHolder = true;

                    foreach (XmlNode x in notation.ChildNodes)
                        getElementListFromNotation(x, checkPlaceHolder);
                }
        }
Esempio n. 7
0
        /*public override void ItemElement_MouseMove(object sender, MouseEventArgs e)
        {

            if (e.LeftButton != MouseButtonState.Pressed)
            {
                elementDragStartPoint = null;
            }

            if (elementDragStartPoint.HasValue)
            {
                Point pos = e.GetPosition(this);

                if ((SystemParameters.MinimumHorizontalDragDistance <=
                    Math.Abs((double)(pos.X - elementDragStartPoint.Value.X))) ||
                    (SystemParameters.MinimumVerticalDragDistance <=
                    Math.Abs((double)(pos.Y - elementDragStartPoint.Value.Y))))
                {
                    if ((e.Source as ContentPresenter) != null)
                    {
                        Element ele = (e.Source as ContentPresenter).Content as Element;

                        if (ele.Address.ToLower().Contains("arg"))
                        {
                            MessageBox.Show("Only conditions can be dragged!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            e.Handled = true;
                        }
                        else
                        {
                            //MessageBox.Show("Name: "+ele.Name + "  Value: "+ele.Value);

                            VisualConditionDragObject eleDrag = new VisualConditionDragObject();
                            eleDrag.Condition = this;
                            eleDrag.element = ele;

                            XmlNode condXml = getConditionCode();

                            DataObject dataObject = new DataObject("VisualConditionDragObject", eleDrag);

                            if (dataObject != null)
                            {
                                DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
                            }

                            e.Handled = true;
                        }
                    }
                }
            }
        }*/
        //ToDo -> what?
        public override void VisualBase_RightClick(object sender, MouseButtonEventArgs e)
        {
            //clear previous popUp
            if (showList == true)
            {
                showList = false;
                OnPropertyChanged("showList");
            }
            else
            {
                elementList.Clear();

                if (Data != null)
                {
                    XmlNode args = Data.SelectSingleNode("args");

                    foreach (XmlNode arg in args.ChildNodes)
                    {
                        Element el = new Element();
                        el.Value = arg.Name;
                        el.Name = arg.InnerText; //visual Condition
                        el.Address = getFullAddress(arg.FirstChild);//bizzare way, the full address works with parents, so for now temporarily work like this -> arg1, etc. need to have value for now

                        elementList.Add(el);
                    }

                    XmlNode conditions = Data.SelectSingleNode("conditions");

                    foreach (XmlNode xcond in conditions.ChildNodes)
                    {
                        XmlNode temp = xcond;
                        Element el = new Element();

                        if (xcond.Name.Contains("condition"))
                        {
                            temp = xcond.SelectSingleNode("expression");
                            el.Name = temp.InnerText; //visual Condition
                        }
                        else
                            el.Name = "Otherwise";

                        el.Value = temp.Name;
                        //el.Name = temp.InnerText; //visual Condition
                        el.Address = getFullAddress(temp.FirstChild);
                        elementList.Add(el);
                    }
                }
                else
                    ShowStatus("Data is null -> VisualConditions.VisualBase_RightClick(...)",ReportIcon.Error);

                OnPropertyChanged("elementList");
                showList = true;
                OnPropertyChanged("showList");
            }
            e.Handled = true;
        }
Esempio n. 8
0
 public TreeViewViewModel(Element rootElement)
 {
     this.initiate(rootElement);
 }
Esempio n. 9
0
        public void processVisual_VisualNotationDrop(VisualElement source, DependencyObject pWindow)
        {
            if (pWindow is Mapper)//double check
            {
                (pWindow as Mapper).ReportStatusBar.ShowStatus("Mapping " + source.Data.Name + " -> " + this.Data.Name, ReportIcon.Info);

                XSLTTemplate tem = new XSLTTemplate();
                Element header = new Element();
                header.Name = source.Data.Name;

                tem.HeaderNode = new TreeNodeViewModel(header);
                tem.TemplateXmlNode = this.Data.Clone() as XmlNode;

                (pWindow as Mapper).NewTemplate = tem;
                (pWindow as Mapper).sourceData = source.Data;

                //for reverse
                this.ReverseData = source.Data.Clone() as XmlNode;
                this.templateVMR.TemplateName = this.Data.Name.Clone() as string;

                (pWindow as Mapper).NewTemplateR = this.templateVMR;
                (pWindow as Mapper).NewTemplateR.TemplateName = templateVMR.TemplateName.Clone() as string;

                //suggester initiation
                source.abstractTree.prepare();
                this.abstractTree.prepare();
                (pWindow as Mapper).mapperSuggester = new Suggester(source.abstractTree, this.abstractTree);

                (pWindow as Mapper).updateSuggestions((pWindow as Mapper).mapperSuggester.getSuggestionsAsStrings((pWindow as Mapper).mapperSuggester.imFeelingLucky()), false);

                //MessageBox.Show("Reverse Data: \n\n"+ReverseData.OuterXml);
                //maybe do this for source as well
                //make sure it does not overright the model to visualisation reverse code

                //move elements to Mapper rule designer
                (pWindow as CONVErT.Mapper).RuleDesignerCanvas.Children.Clear();

                (pWindow as CONVErT.Mapper).LHS = source.Clone() as VisualElement;
                (pWindow as CONVErT.Mapper).RHS = this.Clone() as VisualElement;

                (pWindow as CONVErT.Mapper).LHS.Content = (pWindow as Mapper).renderer.render((pWindow as CONVErT.Mapper).LHS);
                (pWindow as CONVErT.Mapper).RHS.Content = (pWindow as Mapper).renderer.render((pWindow as CONVErT.Mapper).RHS);

                Canvas.SetTop((pWindow as CONVErT.Mapper).LHS, 40);
                Canvas.SetLeft((pWindow as CONVErT.Mapper).LHS, 40);

                Canvas.SetTop((pWindow as CONVErT.Mapper).RHS, 40);
                Canvas.SetLeft((pWindow as CONVErT.Mapper).RHS, 470);

                (pWindow as CONVErT.Mapper).RuleDesignerCanvas.Children.Add((pWindow as CONVErT.Mapper).LHS);
                (pWindow as CONVErT.Mapper).RuleDesignerCanvas.Children.Add((pWindow as CONVErT.Mapper).RHS);

                //log event
                (pWindow as Mapper).logger.log("\"" + source.Data.Name + "\" was dropped on \"" + this.Data.Name + "\"", ReportIcon.OK);
                (pWindow as Mapper).RuleDesignStatusBar.ShowStatus("Rule : " + source.Data.Name + " -> " + this.Data.Name, ReportIcon.Info);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Processing based on On-Demand approach
        /// </summary>
        /// <param name="strFile"></param>
        /// <returns></returns>
        private TreeNodeViewModel processXml(string strFile)
        {
            Element root = new Element();//root element
            TreeNodeViewModel rootNode = null;

            try
            {
                using (var reader = XmlReader.Create(strFile))
                {
                    //reader.MoveToContent();

                    //pass any whitespace or useless element
                    while (reader.NodeType != XmlNodeType.Element)
                        reader.Read();

                    //first element
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        //create starting element
                        root = createModelElement(reader);
                        rootNode = new TreeNodeViewModel(root);

                        if ((reader.NodeType == XmlNodeType.Element) && (reader.HasAttributes || !reader.IsEmptyElement))
                            rootNode.hasChildren = true;
                        else if (reader.IsEmptyElement || reader.NodeType == XmlNodeType.Text)
                            rootNode.hasChildren = false;

                    }
                    else
                        MessageBox.Show("First element of Model file is not an XML Element","Exception",MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (XmlException e)
            {
                Console.WriteLine("error occured: " + e.Message);
            }

            return rootNode;
        }
Esempio n. 11
0
        private Element populateNode(XmlNode inXmlNode, Element node)
        {
            if (inXmlNode.NodeType == XmlNodeType.Element)
            {
                if (inXmlNode.Attributes.Count > 0)
                {
                    foreach (XmlAttribute attr in inXmlNode.Attributes)
                    {
                        Element attNode = new Element();
                        attNode.Value = attr.Value;
                        attNode.Name = attr.Name;
                        attNode.Type = ElementType.ModelAttribute;

                        node.Children.Add(attNode);

                    }
                }

            }

            // Loop through the XML nodes until the leaf is reached.
            // Add the nodes to the TreeView during the looping process.
            if (inXmlNode.HasChildNodes)
            {
                node.Name = inXmlNode.Name;
                node.Type = ElementType.ModelElement;

                XmlNodeList nodeList = inXmlNode.ChildNodes;

                foreach (XmlNode xNode in nodeList)
                {
                    Element temp = new Element();

                    populateNode(xNode, temp);
                    node.Children.Add(temp);
                }

            }

            else
            {
                // Here you need to pull the data from the XmlNode based on the
                // type of node, whether attribute values are required, and so forth.
                if (inXmlNode.NodeType == XmlNodeType.Element)
                {
                    node.Name = inXmlNode.Name;
                    node.Type = ElementType.ModelElement;
                    node.Value = inXmlNode.Value;
                }
                else
                {
                    String value = (inXmlNode.Value);

                    if (!value.Equals(""))
                    {
                        node.Type = ElementType.InstanceValue;
                        node.Name = value;
                        node.Value = value;
                    }
                }
            }

            return node;
        }
Esempio n. 12
0
        private void initiate(Element rootElement)
        {
            _rootElement = new TreeNodeViewModel(rootElement);

            FirstChild = new Collection<TreeNodeViewModel>(
                new TreeNodeViewModel[]
                {
                    _rootElement
                });
        }
Esempio n. 13
0
        private Element createElementFromXMLNode(XmlNode xnode)
        {
            try
            {
                // Initialize Elements
                Element root = new Element();

                // Populate the TreeView with nodes
                populateNode(xnode, root);

                return root;
            }
            catch (XmlException xmlEx)
            {
                System.Windows.MessageBox.Show(xmlEx.Message);
                return null;
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
                return null;
            }
        }
Esempio n. 14
0
        private Element createElementFromXMLFile(String filename)
        {
            try
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings();
                readerSettings.IgnoreComments = true;
                using (XmlReader reader = XmlReader.Create(filename, readerSettings))
                {
                    // SECTION 1. Create a DOM Document and load the XML data into it.
                    XmlDocument dom = new XmlDocument();
                    dom.Load(reader);

                    // SECTION 2. Initialize Elements
                    Element root = new Element();

                    // SECTION 3. Populate the TreeView with the DOM nodes.
                    populateNode(dom.DocumentElement, root);

                    return root;
                }
            }
            catch (XmlException xmlEx)
            {
                System.Windows.MessageBox.Show(xmlEx.Message);
                return null;
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
                return null;
            }
        }