Example #1
0
        /// <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;
        }