コード例 #1
0
        private void OnMenuAddComplexTypeProperty(object sender, EventArgs e)
        {
            var cmd = sender as MenuCommand;

            if (cmd != null)
            {
                if (CurrentExplorerInfo != null &&
                    CurrentExplorerInfo._explorerFrame != null)
                {
                    var explorerComplexType = CurrentExplorerInfo._explorerFrame.GetSelectedExplorerEFElement() as ExplorerComplexType;
                    if (explorerComplexType != null)
                    {
                        if (cmd.Properties.Contains(PackageConstants.guidEscherCmdSet))
                        {
                            var context = new EfiTransactionContext();
                            var cpc     = new CommandProcessorContext(
                                EditingContext, EfiTransactionOriginator.ExplorerWindowOriginatorId, Resources.Tx_CreateScalarProperty, null,
                                context);
                            Property createdProperty = null;
                            var      type            = cmd.Properties[PackageConstants.guidEscherCmdSet] as string;
                            if (type != null)
                            {
                                createdProperty = CreateComplexTypePropertyCommand.CreateDefaultProperty(
                                    cpc, explorerComplexType.ModelItem as ComplexType, type);
                            }
                            else
                            {
                                var complexType = cmd.Properties[PackageConstants.guidEscherCmdSet] as ComplexType;
                                Debug.Assert(complexType != null, "Unexpected property type");
                                if (complexType != null)
                                {
                                    createdProperty = CreateComplexTypePropertyCommand.CreateDefaultProperty(
                                        cpc, explorerComplexType.ModelItem as ComplexType, complexType);
                                }
                            }
                            if (createdProperty != null)
                            {
                                var info = CurrentExplorerInfo;
                                if (info != null &&
                                    info._explorerFrame != null)
                                {
                                    var frame = info._explorerFrame as EntityDesignExplorerFrame;
                                    Debug.Assert(frame != null, "Could not get Explorer frame");
                                    if (frame != null)
                                    {
                                        frame.NavigateToElementAndPutInRenameMode(createdProperty);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #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);
        }