Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.Key == Key.F1)
            {
                // do not respond to F1 Help
                e.Handled = true;
                return;
            }

            if (e.Key == Key.Insert)
            {
                var selected = GetSelectedExplorerEFElement();
                var context  = new EfiTransactionContext();
                if (selected is ExplorerComplexTypes)
                {
                    var cpc = new CommandProcessorContext(
                        Context, EfiTransactionOriginator.ExplorerWindowOriginatorId,
                        Design.Resources.Tx_AddComplexType, null, context);
                    var complexType = CreateComplexTypeCommand.CreateComplexTypeWithDefaultName(cpc);
                    Debug.Assert(complexType != null, "Creating ComplexType failed");
                    NavigateToElementAndPutInRenameMode(complexType);
                    return;
                }

                var explorerComplexType = selected as ExplorerComplexType;
                if (explorerComplexType != null)
                {
                    var complexType = explorerComplexType.ModelItem as ComplexType;
                    if (complexType != null)
                    {
                        var cpc = new CommandProcessorContext(
                            Context,
                            EfiTransactionOriginator.ExplorerWindowOriginatorId,
                            Design.Resources.Tx_CreateScalarProperty, null, context);
                        var property = CreateComplexTypePropertyCommand.CreateDefaultProperty(
                            cpc, complexType,
                            ModelConstants.DefaultPropertyType);
                        Debug.Assert(property != null, "Creating Property failed");
                        NavigateToElementAndPutInRenameMode(property);
                    }
                    else
                    {
                        Debug.Fail("complexType shouldn't be null");
                    }
                    return;
                }

                // Event handler if the user presses 'Insert' button from the keyboard in the EnumTypes node.
                var explorerEnumTypes = selected as ExplorerEnumTypes;
                if (explorerEnumTypes != null)
                {
                    var entityModel = explorerEnumTypes.Parent.ModelItem as ConceptualEntityModel;
                    if (EdmFeatureManager.GetEnumTypeFeatureState(entityModel.Artifact).IsEnabled())
                    {
                        var cpc = new CommandProcessorContext(
                            Context,
                            EfiTransactionOriginator.ExplorerWindowOriginatorId,
                            Design.Resources.Tx_CreateScalarProperty, null, context);
                        var enumType = CreateEnumTypeCommand.CreateEnumTypeWithDefaultName(cpc);
                        Debug.Assert(enumType != null, "Creating Enum failed");
                        NavigateToElementAndPutInRenameMode(enumType);
                    }
                    return;
                }

                // Event handler if the user presses 'Insert' button from the keyboard in the diagrams node.
                var explorerDiagram = selected as ExplorerDiagrams;
                if (explorerDiagram != null)
                {
                    var diagrams = explorerDiagram.ModelItem as Diagrams;
                    if (diagrams != null)
                    {
                        var cpc = new CommandProcessorContext(
                            Context,
                            EfiTransactionOriginator.ExplorerWindowOriginatorId,
                            Design.Resources.Tx_CreateDiagram, null, context);
                        var diagram = CreateDiagramCommand.CreateDiagramWithDefaultName(cpc);
                        Debug.Assert(diagram != null, "The selected ExplorerEFElementItem is not type of diagram.");
                        NavigateToElementAndPutInRenameMode(diagram);
                        // Automatically open the diagram that we selected in the previous line.
                        var selectedExplorerEFElement = GetSelectedExplorerEFElement();
                        if (selectedExplorerEFElement is ExplorerDiagram)
                        {
                            ExecuteActivate();
                        }
                        else
                        {
                            Debug.Fail("The selected ExplorerEFElementItem is not type of diagram.");
                        }
                    }
                    else
                    {
                        Debug.Fail("diagram folder shouldn't be null");
                    }
                    return;
                }
            }

            base.OnKeyDown(e);
        }