Beispiel #1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider sp, object value)
        {
            ModelElement model = context.Instance as ModelElement;

            if (model == null)
            {
                return(value);
            }

            _edSvc = (IWindowsFormsEditorService)sp.GetService(typeof(IWindowsFormsEditorService));
            if (_edSvc != null)
            {
                _comboBox = new ComboBox();
                _comboBox.DropDownStyle = ComboBoxStyle.Simple;

                int num1 = 0;
                SoftwareComponent component = CandleModel.GetInstance(model.Store).SoftwareComponent;
                string            item1     = PopulateListBoxItems(component.GetDefinedTypeNames(), out num1);
                _comboBox.Size         = new Size(num1 + 10, 120);
                _comboBox.KeyDown     += KeyDown;
                _comboBox.Leave       += ValueChanged;
                _comboBox.DoubleClick += ValueChanged;
                _comboBox.Click       += ValueChanged;
                _edSvc.DropDownControl(_comboBox);
                if (_comboBox.Text.Length == 0)
                {
                    return(value);
                }
                string item2 = _comboBox.Text;
                if ((item2 == null) || (item1 == item2))
                {
                    return(value);
                }

                if (!String.IsNullOrEmpty(item2))
                {
                    bool shouldCreateModel = false;
                    ClrTypeParser.Parse(item2, delegate(string typeName)
                    {
                        shouldCreateModel = true;
                        return(typeName);
                    });

                    // Si il y a des types à créer, il faut que la couche modèle existe
                    if (shouldCreateModel && component.DataLayer == null)
                    {
                        IIDEHelper ide = ServiceLocator.Instance.GetService <IIDEHelper>();
                        if (ide != null)
                        {
                            ide.ShowMessage(
                                String.Format("Can't create user type '{0}' because the models layer does not exist.",
                                              item2));
                        }
                    }
                    else
                    {
                        return(item2);
                    }
                }
            }
            return(value);
        }
Beispiel #2
0
        /// <summary>
        /// Génération du mapping des propriétés
        /// </summary>
        /// <param name="level"></param>
        /// <param name="root"></param>
        /// <param name="componentName"></param>
        private void GenerateMappingProperties(int level, Entity clazz, string componentName)
        {
            this.WriteLineWithIndent(level, "<!--  Properties    -->");

            foreach (DSLFactory.Candle.SystemModel.Property prop in clazz.Properties)
            {
                if (prop.IsPrimaryKey || prop.IsForeignKey)
                {
                    continue;
                }

                string   typeName = prop.Type;
                DataType refType  = _inheritanceTree.FindEntityByName(prop.Type);
                if (refType != null)
                {
                    typeName = refType.AssemblyQualifiedName;
                }
                else
                {
                    // C'est peut-être une énumération
                    refType = clazz.DataLayer.FindType(prop.Type) as Enumeration;
                    if (refType != null)
                    {
                        typeName = refType.FullName;
                    }
                }

                string columnName = prop.ColumnName;
                if (string.IsNullOrEmpty(columnName))
                {
                    columnName = StrategyManager.GetInstance(clazz.Store).NamingStrategy.CreateSQLColumnName(componentName, prop.Name);
                }

                // Propriété simple
                IList <string> types = ClrTypeParser.GetModelNamesFromClrType(prop.Type);
                if (types == null || types.Count == 0 || refType is Enumeration)
                {
                    this.WriteLineWithIndent(level, String.Format("<property name=\"{0}\" column=\"{1}\" type=\"{2}\"/>", prop.Name, columnName, typeName));
                }
                else
                {
                    // Component
                    this.WriteLineWithIndent(level, String.Format("<component name=\"{0}\" class=\"{1}\" >", prop.Name, typeName));

                    Entity entity = refType as Entity;
                    if (entity != null)
                    {
                        GenerateMappingProperties(level + 1, entity, columnName);

                        // Propriétés des classes de bases
                        while (entity.SuperClass != null)
                        {
                            entity = entity.SuperClass;
                            GenerateMappingProperties(level + 1, entity, columnName);
                        }
                    }
                    this.WriteLineWithIndent(level, "</component>");
                }
            }


            IList <Association> list = Association.GetLinksToTargets(clazz);

            foreach (Association association in list)
            {
                if (association.SourceMultiplicity == Multiplicity.OneMany || association.SourceMultiplicity == Multiplicity.ZeroMany)
                {
                    string lazy = NHibernateStrategy.AssociationLazyLoadingProperty.GetValue(association).ToString().ToLower();

                    this.WriteLine("");
                    this.WriteLineWithIndent(level, "<!-- Relation  0..* -->");
                    this.WriteLineWithIndent(level, "<bag ");
                    this.WriteLineWithIndent(level, String.Format("    name=\"{0}\" inverse=\"true\" lazy=\"{1}\" >", association.SourceRoleName, lazy));
                    this.WriteLineWithIndent(level, String.Format("    <key column=\"{0}\"/>", association.SourceRoleName));
                    this.WriteLineWithIndent(level, String.Format("    <one-to-many class=\"{0}\" />", association.Target.AssemblyQualifiedName));
                    this.WriteLineWithIndent(level, "</bag>");
                }
                else if (association.SourceMultiplicity != Multiplicity.NotApplicable)
                {
                    string insert    = NHibernateStrategy.AssociationInsertProperty.GetValue(association).ToString().ToLower();
                    string update    = NHibernateStrategy.AssociationUpdateProperty.GetValue(association).ToString().ToLower();
                    string outerJoin = NHibernateStrategy.AssociationOuterJoinProperty.GetValue(association).ToString().ToLower();
                    this.WriteLineWithIndent(level, String.Format("<many-to-one name=\"{0}\" class=\"{1}\" insert=\"{2}\" update=\"{3}\"  outer-join=\"{4}\">", association.SourceRoleName, association.Target.AssemblyQualifiedName, insert, update, outerJoin));
                    foreach (ForeignKey fk in association.ForeignKeys)
                    {
                        WriteColumn(level + 1, "<column name=\"{0}\"/>", fk.Column);
                    }
                    this.WriteLineWithIndent(level, "</many-to-one>");
                }
            }

            list = Association.GetLinksToSources(clazz);
            foreach (Association association in list)
            {
                if (association.TargetMultiplicity != Multiplicity.NotApplicable && !String.IsNullOrEmpty(association.TargetRoleName))
                {
                    string lazy = NHibernateStrategy.AssociationLazyLoadingProperty.GetValue(association).ToString().ToLower();

                    this.WriteLine("");
                    this.WriteLineWithIndent(level, "<!-- Relation  0..* -->");
                    this.WriteLineWithIndent(level, "<bag ");
                    this.WriteLineWithIndent(level, String.Format("    name=\"{0}\" inverse=\"true\" lazy=\"{1}\" >", association.TargetRoleName, lazy));
                    if (association.ForeignKeys.Count == 1)
                    {
                        WriteColumn(level + 1, "<key column=\"{0}\"/>", association.ForeignKeys[0].Column);
                    }
                    else
                    {
                        this.WriteLineWithIndent(level + 1, "<key>");
                        foreach (ForeignKey fk in association.ForeignKeys)
                        {
                            WriteColumn(level + 2, "<column name=\"{0}\"/>", fk.Column);
                        }
                        this.WriteLineWithIndent(level + 1, "</key>");
                    }
                    this.WriteLineWithIndent(level + 1, String.Format("<one-to-many class=\"{0}\" />", association.Source.AssemblyQualifiedName));
                    this.WriteLineWithIndent(level, "</bag>");
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Mise à jour des données du modèle avec les données saisies par l'utilisateur
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void Treeview_DataChanged(object sender, VirtualTreeGridDataChangedEventsArgs e)
        {
            ModelElement elem = e.Item.DataItem as ModelElement;

            if (_selectedObject == null || _selectedObject.Store == null || (elem != null && elem.IsDeleted))
            {
                return;
            }
            try
            {
                using (
                    Transaction transaction = _selectedObject.Store.TransactionManager.BeginTransaction("Update member")
                    )
                {
                    ITypeMember op = e.Item.DataItem;

                    // Suppression
                    if (e.IsDelete)
                    {
                        e.Item.Remove();
                    }
                    else
                    {
                        // Création
                        if (e.Item.IsNewValue)
                        {
                            op = _selectedObject.CreateModel(e.Item.Kind);
                        }
                        // Si rien n'a changé, on ne fait rien
                        else if (e.Item.IsCollection == op.IsCollection && e.Item.Name == op.Name &&
                                 e.Item.Type == op.Type && e.Item.Comment == op.Comment)
                        {
                            return;
                        }

                        // ---------------------------------------
                        // Mise à jour
                        // Nom
                        op.Name         = e.Item.Name;
                        op.Comment      = e.Item.Comment;
                        op.IsCollection = e.Item.IsCollection;
                        if (op is IArgument && !String.IsNullOrEmpty(e.Item.Direction))
                        {
                            ((IArgument)op).Direction =
                                (ArgumentDirection)Enum.Parse(typeof(ArgumentDirection), e.Item.Direction);
                        }

                        // Type
                        if (!String.IsNullOrEmpty(e.Item.Type))
                        {
                            try
                            {
                                op.Type         =
                                    e.Item.Type = ClrTypeParser.Parse(e.Item.Type, _component.CreateTypeIfNotExists);
                            }
                            catch
                            {
                                _treeview.CancelEdit();
                                e.Cancel = true;
                                return;
                            }
                        }
                        else
                        {
                            op.Type = e.Item.Type = _selectedObject.GetDefaultType(e.Item.Kind);
                        }

                        // Commit met à jour la liste des enfants du parent
                        e.Item.Commit(op);
                    }

                    transaction.Commit();

                    // Force le update dans le designer
                    ModelElement mel = ((TypeMember)e.Item.DataItem).Owner as ModelElement;
                    if (mel != null)
                    {
                        IList <PresentationElement> pels = PresentationViewsSubject.GetPresentation(mel);
                        if (pels.Count > 0)
                        {
                            ((ShapeElement)pels[0]).Invalidate();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Ne doit jamais arriver (bug quelque part le store de l'élément est quelquefois à null!!!!!)
                ILogger logger = ServiceLocator.Instance.GetService <ILogger>();
                if (logger != null)
                {
                    logger.WriteError("Details form", String.Format("DataGridView error on {0}", elem != null?elem.Id:Guid.Empty), ex);
                }
            }
        }