private void addTGGLinkVariableCopyToRule(EA.Connector connectorToBeCopied)
        {
            EA.Element newSource = newElementIdToNewElement[oldElementIdToNewElementId[connectorToBeCopied.ClientID]];
            EA.Element newTarget = newElementIdToNewElement[oldElementIdToNewElementId[connectorToBeCopied.SupplierID]];

            EA.Connector newConnector = newSource.Connectors.AddNew("", connectorToBeCopied.Type) as EA.Connector;
            newConnector.Stereotype       = TGGModelingMain.TggLinkVariableStereotype;
            newConnector.ClientEnd.Role   = connectorToBeCopied.ClientEnd.Role;
            newConnector.SupplierEnd.Role = connectorToBeCopied.SupplierEnd.Role;
            newConnector.SupplierID       = newTarget.ElementID;
            newConnector.ClientID         = newSource.ElementID;
            newConnector.Update();
            if (connectorToBeCopied.Stereotype == TGGModelingMain.TggLinkVariableStereotype)
            {
                foreach (EA.ConnectorTag tag in connectorToBeCopied.TaggedValues)
                {
                    EA.ConnectorTag newTag = newConnector.TaggedValues.AddNew(tag.Name, "") as EA.ConnectorTag;
                    if (!checkBoxExactCopy.Checked)
                    {
                        newTag.Value = tag.Value.Replace("create", "check_only");
                        newTag.Notes = tag.Notes.Replace("\"bindingOperator\" value=\"create", "\"bindingOperator\" value=\"check_only");
                    }
                    else
                    {
                        newTag.Value = tag.Value;
                        newTag.Notes = tag.Notes;
                    }
                    newTag.Update();
                }
            }
            EA.DiagramLink newDiagramLink = newRuleDiagram.DiagramLinks.AddNew("", newConnector.Type) as EA.DiagramLink;
            newDiagramLink.ConnectorID = newConnector.ConnectorID;
            newDiagramLink.Update();
            if (connectorToBeCopied.Stereotype != TGGModelingMain.TggLinkVariableStereotype)
            {
                LinkDialogueEntry linkEntry = new LinkDialogueEntry();
                linkEntry.direction = LinkDialogueEntryDirection.RIGHT;
                linkEntry.CorrespondingConnectorGuid = connectorToBeCopied.ConnectorGUID;
                if (newConnector.ClientEnd.Role != "")
                {
                    linkEntry.supplierRoleName = newConnector.ClientEnd.Role;
                }
                else if (newConnector.SupplierEnd.Role != "")
                {
                    linkEntry.supplierRoleName = newConnector.SupplierEnd.Role;
                }
                TGGLinkVariable tggLv = new TGGLinkVariable(repository.GetConnectorByID(newConnector.ConnectorID), repository);
                tggLv.linkDialogueEntry = linkEntry;
                if (!checkBoxExactCopy.Checked)
                {
                    tggLv.BindingOperator = SDMModeling.SDMExportWrapper.patterns.BindingOperator.CREATE;
                }
                tggLv.saveTreeToEATaggedValue(true);
            }
        }
        private LinkDialogueEntry computeLinkDialogEntry(String sourceOrTarget, List <SQLConnector> refs)
        {
            SQLConnector foundRef = null;

            foreach (SQLConnector con in refs)
            {
                if (con.ClientEnd.Role == sourceOrTarget || con.SupplierEnd.Role == sourceOrTarget)
                {
                    foundRef = con;
                }
            }
            LinkDialogueEntry newEntry = new LinkDialogueEntry();

            newEntry.direction                  = LinkDialogueEntryDirection.RIGHT;
            newEntry.supplierRoleName           = sourceOrTarget;
            newEntry.CorrespondingConnectorGuid = foundRef.ConnectorGUID;
            return(newEntry);
        }
        private Boolean createCorrespondenceObjectWithLinks(EA.Repository Repositorya, EA.EventProperties Info)
        {
            DateTime      t1         = DateTime.Now;
            SQLRepository Repository = new SQLRepository(Repositorya, false);

            EA.Diagram curDiagram = Repository.GetCurrentDiagram();

            int tggPackageId = EAUtil.getOutermostPackage(curDiagram, Repository).PackageID;

            BindingOperator newBindingOperator = BindingOperator.CHECK_ONLY;

            SQLElement clientOv   = Repository.GetElementByID(int.Parse(Info.Get("ClientID").Value.ToString()));
            SQLElement supplierOv = Repository.GetElementByID(int.Parse(Info.Get("SupplierID").Value.ToString()));

            EA.Element ruleClass = Repository.GetOriginalRepository().GetElementByID(clientOv.ParentID);

            SQLElement clientClassifier   = Repository.GetElementByID(clientOv.ClassifierID);
            SQLElement supplierClassifier = Repository.GetElementByID(supplierOv.ClassifierID);

            //compute domains of source and target classifiers
            DomainType clientDomain   = TGGModelingUtil.getDomainOfObjectVariable(Repository, new TGGObjectVariable(clientOv, Repository));
            DomainType supplierDomain = TGGModelingUtil.getDomainOfObjectVariable(Repository, new TGGObjectVariable(supplierOv, Repository));

            //get possible correspondence classes with connectors
            Dictionary <int, List <SQLConnector> > possibleCorrespondencesLinkWithConnectors = computeCorrespondencesWithLinks(clientClassifier, supplierClassifier, Repository, tggPackageId);

            //check for existing bindingOperator
            SQLTaggedValue bindingOperatorTag = EAEcoreAddin.Util.EAUtil.findTaggedValue(clientOv, ObjectVariable.BindingOperatorTaggedValueName);

            if (bindingOperatorTag != null)
            {
                newBindingOperator = (BindingOperator)Enum.Parse(typeof(BindingOperator), bindingOperatorTag.Value.ToUpper());
            }

            //create new correspondence ov
            EA.Element tggCorrespondenceObject = ruleClass.Elements.AddNew("", Main.EAObjectType) as EA.Element;
            tggCorrespondenceObject.Update();

            //dont know what this line does :)
            EA_OnNotifyContextItemModified(Repository.GetOriginalRepository(), tggCorrespondenceObject.ElementGUID, EA.ObjectType.otElement);

            //create connector from correspondence object to client ov
            EA.Connector connectorToClient = tggCorrespondenceObject.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector;
            connectorToClient.SupplierID = clientOv.ElementID;

            connectorToClient.Direction = "Unspecified";
            connectorToClient.Update();
            tggCorrespondenceObject.Connectors.Refresh();

            //create connector from correspondence object to supplier ov
            EA.Connector connectorToTarget = tggCorrespondenceObject.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector;
            connectorToTarget.SupplierID = supplierOv.ElementID;
            connectorToTarget.Direction  = "Unspecified";
            connectorToTarget.Update();
            tggCorrespondenceObject.Connectors.Refresh();

            createCorrespondenceDiagramObject(curDiagram, Repository.GetOriginalRepository(), clientOv.getRealElement(), supplierOv.getRealElement(), tggCorrespondenceObject);

            SelectCorrespondenceObject selectCorr = new SelectCorrespondenceObject(possibleCorrespondencesLinkWithConnectors, Repository.GetElementByID(tggCorrespondenceObject.ElementID), Repository, newBindingOperator, clientClassifier, supplierClassifier, clientOv, supplierOv);

            if (selectCorr.DialogResult == DialogResult.Cancel)
            {
                return(true);
            }

            //compute correct linkDialogueEntries so the rolenames can be set correctly

            LinkDialogueEntry sourceEntry = computeLinkDialogEntry("source", possibleCorrespondencesLinkWithConnectors[selectCorr.selectedCorrespondenceLinkId]);
            LinkDialogueEntry targetEntry = computeLinkDialogEntry("target", possibleCorrespondencesLinkWithConnectors[selectCorr.selectedCorrespondenceLinkId]);

            TGGLinkVariable sourceLv = new TGGLinkVariable(Repository.GetConnectorByID(connectorToClient.ConnectorID), Repository);

            sourceLv.BindingOperator = newBindingOperator;

            TGGLinkVariable targetLv = new TGGLinkVariable(Repository.GetConnectorByID(connectorToTarget.ConnectorID), Repository);

            targetLv.BindingOperator = newBindingOperator;

            if (clientDomain == DomainType.SOURCE && supplierDomain == DomainType.TARGET)
            {
                sourceLv.linkDialogueEntry = sourceEntry;
                targetLv.linkDialogueEntry = targetEntry;
            }
            else if (clientDomain == DomainType.TARGET && supplierDomain == DomainType.SOURCE)
            {
                sourceLv.linkDialogueEntry = targetEntry;
                targetLv.linkDialogueEntry = sourceEntry;
            }
            else
            {
                sourceLv.linkDialogueEntry = sourceEntry;
                targetLv.linkDialogueEntry = targetEntry;
            }
            sourceLv.saveTreeToEATaggedValue(true);
            targetLv.saveTreeToEATaggedValue(true);


            Repository.ReloadDiagram(curDiagram.DiagramID);



            return(true);
        }