public SelectCorrespondenceObject(Dictionary <int, List <SQLConnector> > possibleCorrespondencesLinkWithConnectors, SQLElement corrObject, SQLRepository repository, BindingOperator bO, SQLElement clientClassifier, SQLElement supplierClassifier, SQLElement clientOv, SQLElement supplierOv) { InitializeComponent(); this.sqlRepository = repository; this.repository = sqlRepository.GetOriginalRepository(); this.StartPosition = FormStartPosition.CenterScreen; this.possibleCorrespondencesLinkWithConnectors = possibleCorrespondencesLinkWithConnectors; this.corrObject = corrObject; this.clientOv = clientOv; this.supplierOv = supplierOv; DomainType clientDomain = TGGModelingUtil.getDomainOfEClass(sqlRepository, clientClassifier); DomainType supplierDomain = TGGModelingUtil.getDomainOfEClass(sqlRepository, supplierClassifier); if (clientDomain == DomainType.SOURCE && supplierDomain == DomainType.TARGET) { this.clientClassifier = clientClassifier; this.supplierClassifier = supplierClassifier; } else if (clientDomain == DomainType.TARGET && supplierDomain == DomainType.SOURCE) { this.clientClassifier = supplierClassifier; this.supplierClassifier = clientClassifier; } else { this.clientClassifier = clientClassifier; this.supplierClassifier = supplierClassifier; } this.bo = bO; foreach (int possibleCorrClassID in this.possibleCorrespondencesLinkWithConnectors.Keys) { SQLElement possibleCorrClass = sqlRepository.GetElementByID(possibleCorrClassID); this.comboBoxCorrClasses.Items.Add(possibleCorrClass.Name); } checkBoxCreateNew.Checked = false; if (this.clientClassifier != null && this.supplierClassifier != null) { textBoxObjectName.Text = this.clientOv.Name + "To" + this.supplierOv.Name.Substring(0, 1).ToUpper() + this.supplierOv.Name.Substring(1, this.supplierOv.Name.Length - 1); } textBoxLinkName.Text = this.clientClassifier.Name + "To" + this.supplierClassifier.Name; if (this.comboBoxCorrClasses.Items.Count > 0) { this.comboBoxCorrClasses.SelectedIndex = 0; } ShowDialog(); }
private static Boolean createTGGLink(EA.Repository Repository, EA.EventProperties Info, TGGModelingMain modelingMain) { SQLRepository sqlRep = new SQLRepository(Repository, false); int clientID = int.Parse(Info.Get("ClientID").Value.ToString()); int supplierID = int.Parse(Info.Get("SupplierID").Value.ToString()); SQLElement client = sqlRep.GetElementByID(clientID); SQLElement supplier = sqlRep.GetElementByID(supplierID); DomainType clientDomain = TGGModelingUtil.getDomainOfEClass(sqlRep, client); DomainType supplierDomain = TGGModelingUtil.getDomainOfEClass(sqlRep, supplier); SQLElement source = null; SQLElement target = null; if (clientDomain == DomainType.SOURCE || supplierDomain == DomainType.TARGET) { source = client; target = supplier; } else if (clientDomain == DomainType.TARGET || supplierDomain == DomainType.SOURCE) { source = supplier; target = client; } else { //could not define the domains, this is an arbitrary choice source = client; target = supplier; } EA.Diagram curDiagram = Repository.GetCurrentDiagram(); EA.Package tggPackage = Repository.GetPackageByID(curDiagram.PackageID); EA.Element tggLink = tggPackage.Elements.AddNew(source.Name + "To" + target.Name, Main.EAClassType) as EA.Element; tggLink.StereotypeEx = TGGModelingMain.TggCorrespondenceTypeStereotype; tggLink.Update(); modelingMain.EA_OnNotifyContextItemModified(Repository, tggLink.ElementGUID, EA.ObjectType.otElement); EA.Connector connectorToSource = tggLink.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector; connectorToSource.SupplierID = source.ElementID; connectorToSource.Direction = Main.EASourceTargetDirection; connectorToSource.SupplierEnd.Role = "source"; connectorToSource.SupplierEnd.Navigable = "Navigable"; connectorToSource.SupplierEnd.Cardinality = "1"; connectorToSource.SupplierEnd.IsNavigable = true; connectorToSource.Update(); tggLink.Connectors.Refresh(); modelingMain.EA_OnNotifyContextItemModified(Repository, connectorToSource.ConnectorGUID, EA.ObjectType.otConnector); EA.Connector connectorToTarget = tggLink.Connectors.AddNew("", ECOREModelingMain.EReferenceConnectorType) as EA.Connector; connectorToTarget.SupplierID = target.ElementID; connectorToTarget.Direction = Main.EASourceTargetDirection; connectorToTarget.SupplierEnd.Role = "target"; connectorToTarget.SupplierEnd.Cardinality = "1"; connectorToTarget.SupplierEnd.Navigable = "Navigable"; connectorToTarget.SupplierEnd.IsNavigable = true; connectorToTarget.Update(); tggLink.Connectors.Refresh(); modelingMain.EA_OnNotifyContextItemModified(Repository, connectorToTarget.ConnectorGUID, EA.ObjectType.otConnector); //create a new diagram object Repository.SaveDiagram(curDiagram.DiagramID); EA.DiagramObject sourceDiagObj = null; EA.DiagramObject targetDiagObj = null; curDiagram.DiagramObjects.Refresh(); foreach (EA.DiagramObject diagObj in curDiagram.DiagramObjects) { if (diagObj.ElementID == source.ElementID) { sourceDiagObj = diagObj; } else if (diagObj.ElementID == target.ElementID) { targetDiagObj = diagObj; } if (sourceDiagObj != null && targetDiagObj != null) { continue; } } int sourceLeft = (sourceDiagObj == null) ? 0 : sourceDiagObj.left; int sourceRight = (sourceDiagObj == null) ? 0 : sourceDiagObj.right; int sourceBottom = (sourceDiagObj == null) ? 0 : sourceDiagObj.bottom; int sourceTop = (sourceDiagObj == null) ? 0 : sourceDiagObj.top; int targetLeft = (targetDiagObj == null) ? 0 : targetDiagObj.left; int targetRight = (targetDiagObj == null) ? 0 : targetDiagObj.right; int targetBottom = (targetDiagObj == null) ? 0 : targetDiagObj.bottom; int targetTop = (targetDiagObj == null) ? 0 : targetDiagObj.top; EA.DiagramObject tggLinkDiagObj = curDiagram.DiagramObjects.AddNew("", "") as EA.DiagramObject; tggLinkDiagObj.ElementID = tggLink.ElementID; tggLinkDiagObj.Update(); tggLinkDiagObj.left = (sourceLeft + targetLeft) / 2; tggLinkDiagObj.right = (sourceRight + targetRight) / 2; tggLinkDiagObj.bottom = (sourceBottom + targetBottom) / 2; tggLinkDiagObj.top = (sourceTop + targetTop) / 2; tggLinkDiagObj.Update(); curDiagram.DiagramObjects.Refresh(); Repository.ReloadDiagram(curDiagram.DiagramID); tggPackage.Elements.Refresh(); return(true); }