Beispiel #1
0
        private void UpdateSettingsFromGui()
        {
            if (!EscherAttributeContentValidator.IsValidCsdlEntityTypeName(entityNameTextBox.Text))
            {
                baseTypeComboBox.Enabled = false;
                entitySetTextBox.Enabled = false;
                groupBox2.Enabled        = false;
            }
            else
            {
                groupBox2.Enabled        = true;
                baseTypeComboBox.Enabled = true;

                if (BaseEntityType == null)
                {
                    entitySetTextBox.Enabled = true;
                    groupBox2.Enabled        = true;
                    var proposedEntitySetName = ModelHelper.ConstructProposedEntitySetName(_model.Artifact, EntityName);
                    entitySetTextBox.Text       = ModelHelper.GetUniqueName(typeof(EntitySet), _model.FirstEntityContainer, proposedEntitySetName);
                    keyPropertyCheckBox.Checked = true;
                }
                else
                {
                    keyPropertyCheckBox.Checked = false;
                    entitySetTextBox.Enabled    = false;
                    entitySetTextBox.Text       = BaseEntityType.EntitySet.LocalName.Value;
                    groupBox2.Enabled           = false;
                }
            }
        }
Beispiel #2
0
 private void ValidateName(ValidationContext context)
 {
     if (!EscherAttributeContentValidator.IsValidCsdlEntityTypeName(Name))
     {
         var message = String.Format(CultureInfo.CurrentCulture, Resources.Error_EntityNameInvalid, Name);
         context.LogError(message, Resources.ErrorCode_EntityNameInvalid, this);
     }
 }
Beispiel #3
0
        /// <summary>
        ///     Do the following when an EntityType changes:
        ///     - Update roles in related Associations
        /// </summary>
        /// <param name="e"></param>
        public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
        {
            base.ElementPropertyChanged(e);

            // if the element is deleted or about to be deleted, this rule will get fired.
            // Just return immediately here because we don't care if the entity-type's property has changed.
            if (e.ModelElement.IsDeleted ||
                e.ModelElement.IsDeleting)
            {
                return;
            }

            var changedEntity = e.ModelElement as EntityType;

            Debug.Assert(changedEntity != null);
            Debug.Assert(changedEntity.EntityDesignerViewModel != null);

            if (changedEntity != null &&
                changedEntity.EntityDesignerViewModel != null)
            {
                var viewModel = changedEntity.EntityDesignerViewModel;
                var tx        = ModelUtils.GetCurrentTx(e.ModelElement.Store);
                Debug.Assert(tx != null);
                // don't do the auto update stuff if we are in the middle of deserialization
                if (tx != null &&
                    !tx.IsSerializing)
                {
                    // are they changing the name?
                    if (e.DomainProperty.Id == NameableItem.NameDomainPropertyId)
                    {
                        // if we are creating this Entity, there is no 'change' to do
                        if (viewModel.ModelXRef.GetExisting(changedEntity) == null)
                        {
                            return;
                        }

                        if (!EscherAttributeContentValidator.IsValidCsdlEntityTypeName(changedEntity.Name))
                        {
                            throw new InvalidOperationException(
                                      String.Format(CultureInfo.CurrentCulture, Resources.Error_EntityNameInvalid, changedEntity.Name));
                        }

                        if (ModelUtils.IsUniqueName(changedEntity, changedEntity.Name, viewModel.EditingContext) == false)
                        {
                            throw new InvalidOperationException(
                                      String.Format(CultureInfo.CurrentCulture, Resources.Error_EntityNameDuplicate, changedEntity.Name));
                        }

                        ViewModelChangeContext.GetNewOrExistingContext(tx).ViewModelChanges.Add(new EntityTypeChange(changedEntity));
                    }
                }
            }
        }
Beispiel #4
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (_needsValidation)
            {
                _needsValidation = false;

                if (!EscherAttributeContentValidator.IsValidCsdlEntityTypeName(entityNameTextBox.Text))
                {
                    VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_InvalidEntityNameMsg);
                    e.Cancel = true;
                    entityNameTextBox.Focus();
                }
                else
                {
                    string msg;
                    if (!ModelHelper.IsUniqueName(typeof(EntityType), _model, entityNameTextBox.Text, false, out msg))
                    {
                        VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_EnsureUniqueNameMsg);
                        e.Cancel = true;
                        entityNameTextBox.Focus();
                        return;
                    }

                    if (entitySetTextBox.Enabled)
                    {
                        if (!EscherAttributeContentValidator.IsValidCsdlEntitySetName(EntitySetName))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_InvalidEntitySetMsg);
                            e.Cancel = true;
                            entitySetTextBox.Focus();
                            return;
                        }

                        if (!ModelHelper.IsUniqueName(typeof(EntitySet), _model.FirstEntityContainer, EntitySetName, false, out msg))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_EnsureUniqueSetNameMsg);
                            e.Cancel = true;
                            entitySetTextBox.Focus();
                            return;
                        }
                    }

                    if (propertyNameTextBox.Enabled)
                    {
                        if (!EscherAttributeContentValidator.IsValidCsdlPropertyName(propertyNameTextBox.Text))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.NewEntityDialog_InvalidKeyPropertyNameMsg);
                            e.Cancel = true;
                            propertyNameTextBox.Focus();
                            return;
                        }
                        else if (propertyNameTextBox.Text.Equals(EntityName, StringComparison.Ordinal))
                        {
                            VsUtils.ShowErrorDialog(DialogsResource.SameEntityAndPropertyNameMsg);
                            e.Cancel = true;
                            propertyNameTextBox.Focus();
                            return;
                        }
                    }
                }
            }
        }