/// <summary> /// Creates the DAO. /// </summary> public void CreateDAO() { if (rbNone.Checked) { return; } if (rbSelect.Checked) { ClassImplementation port = cbDAO.SelectedItem as ClassImplementation; port.AssociatedEntity = _entity; } else if (rbNew.Checked) { ClassImplementation port = new ClassImplementation(_dataAccessLayer.Store); port.Name = txtDAOName.Text; port.RootName = _entity.RootName; port.AssociatedEntity = _entity; _dataAccessLayer.Classes.Add(port); UnplacedModelHelper.RegisterNewModel(_dataAccessLayer.Store, port); } }
// Ajout de l'élément /// <summary> /// Alerts listeners that a rule has been used. /// </summary> /// <param name="e">An ElementAddedEventArgs that contains the event data.</param> public override void ElementAdded(ElementAddedEventArgs e) { // Test the element ParentShapeContainsNestedChildShapes link = e.ModelElement as ParentShapeContainsNestedChildShapes; if (link == null) { return; } if (link.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.IsSerializing || link.Store.InUndoRedoOrRollback) { return; } // Création d'une référence multi-couches. On essaye de positionner tous les éléments dans le même axe double X = UnplacedModelHelper.GetInitialPosition(link.Store); List <NodeShape> unplacedShapes = UnplacedModelHelper.GetUnplacedShapes(link.Store); if (unplacedShapes != null && X != 0.0) { foreach (NodeShape shape in unplacedShapes) { RectangleD rec = shape.AbsoluteBounds; rec.X = Math.Min(X, shape.ParentShape.AbsoluteBoundingBox.Right - rec.Width); rec.Y = ((NodeShape)shape.ParentShape).AbsoluteBounds.Top + 0.15; shape.AbsoluteBounds = rec; } return; } if (link.NestedChildShapes.ModelElement is ISortedLayer) { SoftwareComponentShape shape = link.ParentShape as SoftwareComponentShape; if (shape != null) { shape.ArrangeShapes(); return; } } LayerPackageShape lps = link.ParentShape as LayerPackageShape; if (lps != null) { lps.ArrangeShapes(); return; } if ((link.NestedChildShapes.ModelElement is ServiceContract || link.NestedChildShapes.ModelElement is ClassImplementation || link.NestedChildShapes.ModelElement is Process) && link.NestedChildShapes.BoundingBox.X == 0.0) { X = ((NodeShape)link.ParentShape).AbsoluteBounds.X; double Y = ((NodeShape)link.ParentShape).AbsoluteBounds.Y + 0.15; foreach (PresentationElement pel in link.ParentShape.NestedChildShapes) { NodeShape child = pel as NodeShape; if (child != null && child.AbsoluteBounds.Right > X) { Y = child.AbsoluteBounds.Top; X = child.AbsoluteBounds.Right; } } NodeShape shape = (NodeShape)link.NestedChildShapes; RectangleD rec = shape.AbsoluteBounds; rec.X = X + 0.15; rec.Y = Y; shape.AbsoluteBounds = rec; } }
/// <summary> /// Execution du wizard /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="DSLFactory.Candle.SystemModel.Strategies.StrategyElementElementAddedEventArgs"/> instance containing the event data.</param> public void RunWizard(ModelElement sender, StrategyElementElementAddedEventArgs e) { CandleElement elem = e.ModelElement as CandleElement; txtRootName.Text = elem.RootName; if (elem is ServiceContract) // Ce cas est désactivé (voir selection du wizard) { _layer = ((ServiceContract)e.ModelElement).Layer; txtName.Text = StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_layer, elem.RootName); } else { _layer = ((ClassImplementation)e.ModelElement).Layer; _iLayer = ((ClassImplementation)e.ModelElement).Layer.LayerPackage.InterfaceLayer; txtName.Text = StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_layer, elem.RootName); if (_iLayer == null) { txtContractName.Visible = false; } else { txtContractName.Text = StrategyManager.GetInstance(_layer.Store).NamingStrategy.CreateElementName(_iLayer, txtName.Text); } } if (elem is ServiceContract || ((ClassImplementation)elem).Layer.LayerPackage.InterfaceLayer == null) { lblContractName.Visible = false; txtContractName.Visible = false; txtContractName.Text = null; } lblHeader.Text = String.Format(lblHeader.Text, _layer.Name); groupBox1.Text = _layer.Namespace; if (!s_dontShow) { e.UserCancel = (ShowDialog() == DialogResult.Cancel); if (e.UserCancel) { return; } s_dontShow = ckDontShow.Checked; } // Ici on force les noms des classes donc on ne veut pas que la régle basée sur la modification // du RootName s'execute. On l'indique dans le contexte de la transaction if ( !elem.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.ContainsKey( "CustomizableElementChangeRule_Enabled")) { elem.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo.Add( "CustomizableElementChangeRule_Enabled", false); } elem.Name = txtName.Text; using (Transaction transaction = elem.Store.TransactionManager.BeginTransaction("Set root name")) { // Force la transaction pour que la règle s'execute tout de suite et qu'on puisse // forcer le nom ensuite elem.RootName = txtRootName.Text; transaction.Commit(); } // Si c'est une classe, on essaye de créer son interface ClassImplementation clazz = elem as ClassImplementation; if (clazz != null && _iLayer != null && !String.IsNullOrEmpty(txtContractName.Text)) { if (clazz.Contract == null) { // On regarde si l'interface n'existe pas clazz.Contract = _iLayer.ServiceContracts.Find( delegate(ServiceContract c) { return(c.Name == txtContractName.Text); }); if (clazz.Contract == null) { clazz.Contract = new ServiceContract(clazz.Store); clazz.Contract.RootName = txtRootName.Text; clazz.Layer.LayerPackage.InterfaceLayer.ServiceContracts.Add(clazz.Contract); UnplacedModelHelper.RegisterNewModel(clazz.Store, clazz.Contract); // Si la classe courante utilise un seul contract, on le recopie IList <ClassUsesOperations> links = ClassUsesOperations.GetLinksToServicesUsed(clazz); if (links.Count == 1) { ServiceContract contract = links[0].TargetService as ServiceContract; if (contract != null) { TypeWithOperations.CopyOperations(contract, clazz.Contract); } else { ExternalServiceContract externalContract = links[0].TargetService as ExternalServiceContract; if (externalContract != null) { TypeWithOperations.CopyOperations(externalContract.ReferencedServiceContract, clazz.Contract); } } } } } using (Transaction transaction = elem.Store.TransactionManager.BeginTransaction("Set root name")) { // Force la transaction pour que la règle s'execute tout de suite et qu'on puisse // forcer le nom ensuite clazz.Contract.RootName = elem.RootName; transaction.Commit(); } if (clazz.Contract.Name != txtContractName.Text) { clazz.Contract.Name = txtContractName.Text; } } e.CancelBubble = true; }