/// <summary> /// This function implements the action to be perfomed when a suggestion is accepted /// </summary> /// <param name="sg">Suggestion to be accepted</param> /// <returns></returns> public bool acceptSuggestion(Suggestion sg) { VisualElement vs = new VisualElement(); VisualElement vt = new VisualElement(); if ((sourceVisualElements.Count > 0) && (targetVisualElements.Count > 0)) { vs = findVisualElementInListByAddress(sourceVisualElements, sg.LHS); vt = findVisualElementInListByAddress(targetVisualElements, sg.RHS); if ((vs != null)&&(vt != null))// source and target notations exist { //update weights in Suggester this.mapperSuggester.retrieveSuggestion(sg.SuggestionString, "ACCEPT"); vs = vs.Clone() as VisualElement; //duplicate element not to mess with original one. vt = vt.Clone() as VisualElement; //duplicate vt.processVisual_VisualNotationDrop(vs,this); //like dropping a visual element on another in Mapper return true; } else if ((vs == null) && (vt == null))// source and target notations do not exist { //look for internal elements of the visualisation //when this happens, I have my source and target visualisations in LHS and RHS if ((NewTemplate != null) && (NewTemplateR != null)) { bool check = true; string targetMatch = sg.RHS; string sourceMatch = sg.LHS; string targetElementValue = ""; string sourceElementValue = ""; AbstractTreeLatticeNode lhsNode = LHS.abstractTree.getAbstractNodeAtAddress(NewTemplate.TemplateName + "/" + sg.LHS); if ((lhsNode != null) && (lhsNode.Values.Count > 0)) { sourceElementValue = lhsNode.Values[0]; } AbstractTreeLatticeNode rhsNode = RHS.abstractTree.getAbstractNodeAtAddress(NewTemplateR.TemplateName + "/" + sg.RHS); if ((rhsNode != null) && (rhsNode.Values.Count > 0)) { targetElementValue = rhsNode.Values[0]; } if (!String.IsNullOrEmpty(targetElementValue)) this.NewTemplate.updateXmlNodeByExactValue(targetMatch, sourceMatch, targetElementValue); else { check = false; ReportStatusBar.ShowStatus("Problem is finding element -> Target element value in Mapper.acceptSuggestion(...)", ReportIcon.Error); } //for reverse if (!String.IsNullOrEmpty(sourceElementValue)) this.NewTemplateR.updateXmlNodeByExactValue(sourceMatch, targetMatch, sourceElementValue); else { check = false; ReportStatusBar.ShowStatus("Problem is finding reverse element -> Source element value in Mapper.acceptSuggestion(...)", ReportIcon.Error); } if (check == true) { //update weights in Suggester Suggestion sgTemp = new Suggestion(lhsNode.Address, rhsNode.Address, this);//the previouse suggestion has been alltered and the visual element name is removed, therefore a new one is temporarily generated. this.mapperSuggester.retrieveSuggestion(sgTemp.SuggestionString, "ACCEPT"); } return check; } } } //if we are here then the suggestion is for internal elements //or there is an error -> mapping notation to internal elements or vice versa return false; }
public ToolboxItem(VisualElement v) { //create with values read from a file visualElement = (v.Clone() as VisualElement); visualBase = null; visualElement.Content = xamlRenderer.render(visualElement); this.Content = visualElement;//20/6/2012 }
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); } }