示例#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);
        }
示例#2
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);
                }
            }
        }