コード例 #1
0
        // <summary>
        //     Show the dialog to edit an existing enum type.
        // </summary>
        public static void EditEnumType(
            EditingContext editingContext, string originatingId, EnumTypeViewModel enumTypeViewModel, EventHandler onDialogActivated = null)
        {
            if (editingContext == null)
            {
                throw new ArgumentNullException("editingContext");
            }
            if (enumTypeViewModel == null)
            {
                throw new ArgumentNullException("enumTypeViewModel");
            }

            Debug.Assert(
                !enumTypeViewModel.IsNew,
                typeof(EntityDesignViewModelHelper).Name + ".EditEnumType: Expected existing enum type is passed in");

            if (enumTypeViewModel.IsNew == false)
            {
                var result = ShowEnumTypeDialog(enumTypeViewModel, onDialogActivated);

                var enumType = enumTypeViewModel.EnumType;
                if (result == true)
                {
                    var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_UpdateEnumType);

                    cp.EnqueueCommand(
                        new SetEnumTypeFacetCommand(
                            enumType
                            , enumTypeViewModel.Name, enumTypeViewModel.SelectedUnderlyingType
                            , enumTypeViewModel.IsReferenceExternalType ? enumTypeViewModel.ExternalTypeName : String.Empty
                            , enumTypeViewModel.IsFlag));

                    // We delete and create enum type members.
                    // TODO: we might want to do intelligent edit for large number of enum type member.
                    foreach (var enumTypeMember in enumType.Members())
                    {
                        cp.EnqueueCommand(enumTypeMember.GetDeleteCommand());
                    }

                    foreach (var enumTypeMemberViewModel in enumTypeViewModel.Members)
                    {
                        if (String.IsNullOrWhiteSpace(enumTypeMemberViewModel.Name) == false)
                        {
                            cp.EnqueueCommand(
                                new CreateEnumTypeMemberCommand(enumType, enumTypeMemberViewModel.Name, enumTypeMemberViewModel.Value));
                        }
                    }

                    cp.Invoke();
                }
            }
        }
コード例 #2
0
 public EnumTypeDialog(EnumTypeViewModel vm)
 {
     _enumTypeViewModel = vm;
     this.DataContext   = _enumTypeViewModel;
     InitializeComponent();
     if (vm.IsNew)
     {
         this.Title = EntityDesignerResources.EnumDialog_NewEnumWindowTitle;
     }
     else
     {
         this.Title = EntityDesignerResources.EnumDialog_EditEnumWindowTitle;
     }
     this.HasHelpButton = false;
 }
コード例 #3
0
        // <summary>
        //     Show the dialog to create a new enum type.
        // </summary>
        public static EnumType AddNewEnumType(
            string selectedUnderlyingType, EditingContext editingContext, string originatingId, EventHandler onDialogActivated = null)
        {
            if (editingContext == null)
            {
                throw new ArgumentNullException("editingContext");
            }

            var artifactService      = editingContext.GetEFArtifactService();
            var entityDesignArtifact = artifactService.Artifact as EntityDesignArtifact;

            Debug.Assert(
                entityDesignArtifact != null,
                typeof(EntityDesignViewModelHelper).Name
                + ".AddEnumType: Unable to find Entity Design Artifact from the passed in editing context.");

            if (entityDesignArtifact != null)
            {
                var vm = new EnumTypeViewModel(entityDesignArtifact, selectedUnderlyingType);

                var result = ShowEnumTypeDialog(vm, onDialogActivated);

                if (result == true &&
                    vm.IsValid)
                {
                    var cp = new CommandProcessor(editingContext, originatingId, Resources.Tx_CreateEnumType);
                    var createEnumTypeCommand = new CreateEnumTypeCommand(
                        vm.Name, vm.SelectedUnderlyingType
                        , (vm.IsReferenceExternalType ? vm.ExternalTypeName : String.Empty), vm.IsFlag, false);

                    cp.EnqueueCommand(createEnumTypeCommand);

                    foreach (var member in vm.Members)
                    {
                        if (String.IsNullOrWhiteSpace(member.Name) == false)
                        {
                            cp.EnqueueCommand(new CreateEnumTypeMemberCommand(createEnumTypeCommand, member.Name, member.Value));
                        }
                    }
                    cp.Invoke();
                    return(createEnumTypeCommand.EnumType);
                }
            }
            return(null);
        }
コード例 #4
0
        protected override void OnClosing(CancelEventArgs e)
        {
            // When ok button is clicked:
            // - First we need to ensure all the changes in data-grid are committed.
            // - If the view model is not in valid state,  block the dialog from closing.
            if (_isOkButtonClicked)
            {
                CommitDialogControlsManually();

                EnumTypeViewModel vm = this.DataContext as EnumTypeViewModel;
                Debug.Assert(vm != null, "Dialog DataContext is not type of EnumTypeViewModel");
                if (vm != null && vm.IsValid == false)
                {
                    e.Cancel           = true;
                    _isOkButtonClicked = false;
                    return;
                }
            }
            base.OnClosing(e);
        }
コード例 #5
0
        private static bool?ShowEnumTypeDialog(EnumTypeViewModel enumTypeViewModel, EventHandler onDialogActivated)
        {
            bool?result;

            try
            {
                var dialog = new EnumTypeDialog(enumTypeViewModel);
                if (onDialogActivated != null)
                {
                    EnumTypeDialog.DialogActivatedTestEvent += onDialogActivated;
                }
                result = dialog.ShowModal();
            }
            finally
            {
                if (onDialogActivated != null)
                {
                    EnumTypeDialog.DialogActivatedTestEvent -= onDialogActivated;
                }
            }

            return(result);
        }