// Lors de la création d'un element, on va afficher un wizard que l'utilisateur peut annuler. // TIPS permet d'intercepter la création d'un enfant /// <summary> /// Execution d'un wizard lors de la création d'un élément /// </summary> /// <param name="element">The element.</param> /// <param name="defaultWizard">The default wizard.</param> /// <returns></returns> public bool ExecuteWizard(ModelElement element, IStrategyWizard defaultWizard) { if (!(element is ICustomizableElement)) { return(true); } try { StrategyElementElementAddedEventArgs e = new StrategyElementElementAddedEventArgs(element); foreach (StrategyBase strategy in GetStrategies(false)) { IStrategyAddElementInterceptor sa = strategy as IStrategyAddElementInterceptor; if (sa == null) { continue; } IStrategyWizard wizard = sa.GetWizard(element); if (wizard != null) { wizard.RunWizard(this, e); if (e.UserCancel) { return(false); } if (e.CancelBubble) { break; } } } if (!e.CancelBubble && defaultWizard != null) { defaultWizard.RunWizard(this, e); if (e.UserCancel) { return(false); } } OnElementAdded(e); Generator.GenerateWhenElementAdded(this.Store, CandleModel.GetInstance(this.Store), element as ICustomizableElement); return(true); } catch (Exception ex) { IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>(); if (ide != null) { ide.ShowMessage(ex.Message); } return(false); } }
/// <summary> /// Ajout d'un élément /// </summary> /// <param name="e">The <see cref="DSLFactory.Candle.SystemModel.Strategies.StrategyElementElementAddedEventArgs"/> instance containing the event data.</param> /// <returns></returns> public virtual bool OnElementAdded(StrategyElementElementAddedEventArgs e) { foreach (StrategyBase strategy in GetStrategies(false)) { IStrategyAddElementInterceptor sa = strategy as IStrategyAddElementInterceptor; if (sa != null) { sa.OnElementAdded(this, e); if (e.UserCancel) { return(false); } if (e.CancelBubble) { break; } } } return(true); }
/// <summary> /// Runs the 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) { Entity entity = sender as Entity; if (entity != null) { // Si il y a une couche DAL, on crée le port correspondant DataAccessLayer dal = (DataAccessLayer) entity.DataLayer.Component.Layers.Find( delegate(SoftwareLayer layer) { return(layer is DataAccessLayer); }); if (dal != null) { DAOSelectorDlg dlg = new DAOSelectorDlg(dal, entity); e.UserCancel = dlg.ShowDialog() == DialogResult.Cancel; if (e.UserCancel) { return; } dlg.CreateDAO(); } } }
/// <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; }