示例#1
0
        public bool acceptSuggestion(Suggestion sg)
        {
            if (visEl != null)
            {
                //update weights in Suggester
                this.visualiserSuggester.retrieveSuggestion(sg.SuggestionString, "ACCEPT");

                if (sg.RHS.Equals(visEl.Data.Name))// map to Visual element
                {
                    AbstractTreeLatticeNode atln = sourceASTL.getAbstractNodeAtAddress(sg.LHS);

                    if (atln != null)
                    {
                        XmlNode tx = atln.ToXML();
                        TreeViewViewModel tv = new TreeViewViewModel(tx);
                        visEl.processVisual_TreeNodeDrop(tv.Root, atln.Address); //like dropping a TreeNode on visEl
                        reportMessage("Suggestion \"" + sg.ToString() + "\" applied", ReportIcon.OK);
                        return true;
                    }
                }
                else //map to internal elements
                {

                    AbstractLattice sourceLattice = new AbstractLattice(visEl.ReverseData);
                    AbstractTreeLatticeNode lownode = sourceLattice.Root.findInChildrenByName(sg.LHS);

                    //MessageBox.Show("Source: " + sg.LHS);

                    if (lownode != null)
                    {
                        string lhs = visEl.abstractTree.findRelativeAddress(sourceLattice.Root, lownode);

                        if (!String.IsNullOrEmpty(lhs))
                        {
                            string rhs = sg.RHS;
                            //if (rhs.StartsWith(visEl.abstractTree.Root.Name))
                            //  rhs = rhs.Substring(visEl.abstractTree.Root.Name.Length+1);

                            //MessageBox.Show("in sugg\n\nSource: " + lhs + "\nTarget: " + rhs);

                            XmlNode tx = sourceLattice.Root.ToXML();
                            TreeViewViewModel tv = new TreeViewViewModel(tx);
                            TreeNodeViewModel tn = tv.findInTreeByName(sg.LHS);
                            if (tn != null)//which should be
                                //MessageBox.Show("in sugg: " + tv.Root.ToXML().OuterXml);
                                if (visEl.processElement_TreeNodeDrop(lhs, rhs, tn) == true)
                                {//like dropping a tree node on element of the list
                                    reportMessage("Suggestion \"" + sg.ToString() + "\" applied", ReportIcon.OK);
                                    return true;
                                }
                            //MessageBox.Show("in sugg\n\n"+visEl.templateVM.TemplateXmlNode.OuterXml + "\n\n" + visEl.templateVMR.TemplateXmlNode.OuterXml);
                        }

                        return false;
                    }
                }

                reportMessage("Could not find suggestion in source model", ReportIcon.Error);
                return false;

            }
            else//else will never happen
            {
                reportMessage("No visual element to apply suggestions to", ReportIcon.Error);
                return false;
            }
        }
        public void loadTreeView(string fileName)
        {
            ModelTree = new TreeViewViewModel(fileName);

            this.DataContext = ModelTree;
        }