Example #1
0
        private void OnMenuShowShape(object sender, EventArgs e)
        {
            NodeShape firstShape = CurrentSelection.OfType <NodeShape>().FirstOrDefault();

            if (firstShape != null)
            {
                using (Transaction tx = firstShape.Store.TransactionManager.BeginTransaction("HideShapes"))
                {
                    LinkedElementCollection <ShapeElement> childShapes = CurrentDocView.CurrentDiagram.NavigationRoot.NestedChildShapes;

                    foreach (ClassShape shape in childShapes.OfType <ClassShape>().Where(s => !s.IsVisible))
                    {
                        shape.Visible = true;
                    }

                    foreach (EnumShape shape in childShapes.OfType <EnumShape>().Where(s => !s.IsVisible))
                    {
                        shape.Visible = true;
                    }

                    foreach (ShapeElement shape in childShapes.Where(s => !s.IsVisible))
                    {
                        shape.Show();
                    }

                    tx.Commit();
                }
            }
        }
Example #2
0
 private void OnStatusHideShape(object sender, EventArgs e)
 {
     if (sender is MenuCommand command)
     {
         command.Visible = command.Enabled = CurrentSelection.OfType <ClassShape>().Any() || CurrentSelection.OfType <EnumShape>().Any();
     }
 }
Example #3
0
        private void OnMenuHideShape(object sender, EventArgs e)
        {
            Store store = CurrentSelection.OfType <NodeShape>().FirstOrDefault()?.Store;

            if (store != null)
            {
                using (Transaction tx = store.TransactionManager.BeginTransaction("HideShapes"))
                {
                    foreach (ClassShape shape in CurrentSelection.OfType <ClassShape>())
                    {
                        shape.Visible = false;
                    }

                    foreach (EnumShape shape in CurrentSelection.OfType <EnumShape>())
                    {
                        shape.Visible = false;
                    }

                    foreach (CommentBoxShape shape in CurrentSelection.OfType <CommentBoxShape>())
                    {
                        shape.Visible = false;
                    }

                    tx.Commit();
                }
            }
        }
Example #4
0
        private void OnMenuAddProperties(object sender, EventArgs e)
        {
            NodeShape shapeElement = CurrentSelection.OfType <ClassShape>().FirstOrDefault();

            if (shapeElement?.ModelElement is ModelClass element)
            {
                AddCodeForm codeForm = new AddCodeForm(element);
                if (codeForm.ShowDialog() == DialogResult.OK)
                {
                    using (Transaction tx = element.Store.TransactionManager.BeginTransaction("AddProperties"))
                    {
                        element.Attributes.Clear();
                        IEnumerable <ModelAttribute> modelAttributes =
                            codeForm.Lines
                            .Select(s => ModelAttribute.Parse(element.ModelRoot, s))
                            .Where(attr => attr != null)
                            .Select(parseResult => new ModelAttribute(element.Store,
                                                                      new PropertyAssignment(ModelAttribute.NameDomainPropertyId, parseResult.Name),
                                                                      new PropertyAssignment(ModelAttribute.TypeDomainPropertyId, parseResult.Type ?? "String"),
                                                                      new PropertyAssignment(ModelAttribute.RequiredDomainPropertyId, parseResult.Required ?? true),
                                                                      new PropertyAssignment(ModelAttribute.MaxLengthDomainPropertyId, parseResult.MaxLength ?? 0),
                                                                      new PropertyAssignment(ModelAttribute.InitialValueDomainPropertyId, parseResult.InitialValue),
                                                                      new PropertyAssignment(ModelAttribute.IsIdentityDomainPropertyId, parseResult.IsIdentity),
                                                                      new PropertyAssignment(ModelAttribute.SetterVisibilityDomainPropertyId, parseResult.SetterVisibility ?? SetterAccessModifier.Public)
                                                                      ));
                        element.Attributes.AddRange(modelAttributes);
                        tx.Commit();
                    }
                }
            }
        }
Example #5
0
 private void OnMenuMergeAssociations(object sender, EventArgs e)
 {
     UnidirectionalAssociation[] selected = CurrentSelection.OfType <UnidirectionalConnector>()
                                            .Select(connector => connector.ModelElement)
                                            .Cast <UnidirectionalAssociation>()
                                            .ToArray();
     ((EFModelDocData)CurrentDocData).Merge(selected);
 }
Example #6
0
 private void OnStatusAddValues(object sender, EventArgs e)
 {
     if (sender is MenuCommand command)
     {
         command.Visible = CurrentSelection.OfType <EnumShape>().Any() && !CurrentSelection.OfType <ClassShape>().Any();
         command.Enabled = CurrentSelection.OfType <EnumShape>().Count() == 1;
     }
 }
Example #7
0
 private void OnStatusAddProperties(object sender, EventArgs e)
 {
     if (sender is MenuCommand command)
     {
         command.Visible = true;
         command.Enabled = CurrentSelection.OfType <ClassShape>().Count() == 1;
     }
 }
Example #8
0
        private void OnMenuSplitAssociation(object sender, EventArgs e)
        {
            BidirectionalAssociation selected = CurrentSelection.OfType <BidirectionalConnector>()
                                                .Select(connector => connector.ModelElement)
                                                .Cast <BidirectionalAssociation>()
                                                .Single();

            ((EFModelDocData)CurrentDocData).Split(selected);
        }
Example #9
0
        private void OnStatusRemoveShape(object sender, EventArgs e)
        {
            if (sender is MenuCommand command)
            {
                command.Visible = true;

                // don't check for CommentBoxShape - they can't be removed from the diagram, only deleted
                command.Enabled = CurrentSelection.OfType <ClassShape>().Any() ||
                                  CurrentSelection.OfType <EnumShape>().Any();
            }
        }
Example #10
0
        /// <summary>Virtual method to process the menu Delete operation</summary>
        protected override void ProcessOnMenuDeleteCommand()
        {
            foreach (EnumShape enumShape in CurrentSelection.OfType <EnumShape>())
            {
                if (enumShape.ModelElement is ModelEnum modelEnum &&
                    ModelEnum.IsUsed(modelEnum) &&
                    BooleanQuestionDisplay.Show($"{modelEnum.FullName} is used as an entity property. Deleting the enumeration will remove those properties. Are you sure?") != true)
                {
                    return;
                }
            }

            base.ProcessOnMenuDeleteCommand();
        }
Example #11
0
        private void OnMenuExpandSelected(object sender, EventArgs e)
        {
            using (Transaction tx = CurrentSelection.OfType <NodeShape>().First().Store.TransactionManager.BeginTransaction("Expand Selected"))
            {
                foreach (ClassShape classShape in CurrentSelection.OfType <ClassShape>())
                {
                    classShape.ExpandShape();
                }

                foreach (EnumShape enumShape in CurrentSelection.OfType <EnumShape>())
                {
                    enumShape.ExpandShape();
                }

                tx.Commit();
            }
        }
Example #12
0
        private void OnStatusSplitAssociation(object sender, EventArgs e)
        {
            if (sender is MenuCommand command)
            {
                Store     store     = CurrentDocData.Store;
                ModelRoot modelRoot = store.ModelRoot();
                command.Visible = true;

                BidirectionalAssociation[] selected = CurrentSelection.OfType <BidirectionalConnector>()
                                                      .Select(connector => connector.ModelElement)
                                                      .Cast <BidirectionalAssociation>()
                                                      .ToArray();

                command.Enabled = modelRoot != null &&
                                  CurrentDocData is EFModelDocData &&
                                  selected.Length == 1;
            }
        }
Example #13
0
        private void OnStatusMergeAssociations(object sender, EventArgs e)
        {
            if (sender is MenuCommand command)
            {
                Store     store     = CurrentDocData.Store;
                ModelRoot modelRoot = store.ModelRoot();
                command.Visible = true;

                UnidirectionalAssociation[] selected = CurrentSelection.OfType <UnidirectionalConnector>()
                                                       .Select(connector => connector.ModelElement)
                                                       .Cast <UnidirectionalAssociation>()
                                                       .ToArray();

                command.Enabled = modelRoot != null &&
                                  CurrentDocData is EFModelDocData &&
                                  selected.Length == 2 &&
                                  selected[0].Source == selected[1].Target &&
                                  selected[0].Target == selected[1].Source;
            }
        }
Example #14
0
        private void OnMenuRemoveShape(object sender, EventArgs e)
        {
            Store store = CurrentSelection.OfType <NodeShape>().FirstOrDefault()?.Store;

            if (store != null)
            {
                using (Transaction tx = store.TransactionManager.BeginTransaction("HideShapes"))
                {
                    // note that we're deleting the shape, not the represented model element
                    foreach (ClassShape shape in CurrentSelection.OfType <ClassShape>())
                    {
                        shape.Delete();
                    }

                    foreach (EnumShape shape in CurrentSelection.OfType <EnumShape>())
                    {
                        shape.Delete();
                    }

                    // don't check for CommentBoxShape - they can't be removed from the diagram, only deleted
                    tx.Commit();
                }
            }
        }
Example #15
0
        private void OnMenuAddValues(object sender, EventArgs e)
        {
            NodeShape shapeElement = CurrentSelection.OfType <EnumShape>().FirstOrDefault();

            if (shapeElement?.ModelElement is ModelEnum element)
            {
                AddCodeForm codeForm = new AddCodeForm(element);

                if (codeForm.ShowDialog() == DialogResult.OK)
                {
                    using (Transaction tx = element.Store.TransactionManager.BeginTransaction("AddValues"))
                    {
                        element.Values.Clear();

                        foreach (string codeFormLine in codeForm.Lines)
                        {
                            try
                            {
                                string[] parts = codeFormLine.Replace(",", string.Empty)
                                                 .Replace(";", string.Empty)
                                                 .Split('=')
                                                 .Select(x => x.Trim())
                                                 .ToArray();

                                string message = null;

                                if (parts.Length > 0)
                                {
                                    if (!CodeGenerator.IsValidLanguageIndependentIdentifier(parts[0]))
                                    {
                                        message = $"Could not add '{parts[0]}' to {element.Name}: '{parts[0]}' is not a valid .NET identifier";
                                    }
                                    else if (element.Values.Any(x => x.Name == parts[0]))
                                    {
                                        message = $"Could not add {parts[0]} to {element.Name}: {parts[0]} already in use";
                                    }
                                    else
                                    {
                                        switch (parts.Length)
                                        {
                                        case 1:

                                            element.Values.Add(new ModelEnumValue(element.Store,
                                                                                  new PropertyAssignment(ModelEnumValue.NameDomainPropertyId, parts[0])));

                                            break;

                                        case 2:

                                            element.Values.Add(new ModelEnumValue(element.Store,
                                                                                  new PropertyAssignment(ModelEnumValue.NameDomainPropertyId, parts[0]),
                                                                                  new PropertyAssignment(ModelEnumValue.ValueDomainPropertyId, parts[1])));

                                            break;

                                        default:
                                            message = $"Could not add '{codeFormLine}' to {element.Name}: The string was not in the proper format.";

                                            break;
                                        }
                                    }

                                    if (message != null)
                                    {
                                        Messages.AddWarning(message);
                                    }
                                }
                            }
                            catch (Exception exception)
                            {
                                Messages.AddWarning($"Could not parse '{codeFormLine}'. {exception.Message}. The line will be discarded.");
                            }
                        }

                        tx.Commit();
                    }
                }
            }
        }
Example #16
0
        private void OnMenuAddProperties(object sender, EventArgs e)
        {
            NodeShape shapeElement = CurrentSelection.OfType <ClassShape>().FirstOrDefault();

            if (shapeElement?.ModelElement is ModelClass element)
            {
                AddCodeForm codeForm = new AddCodeForm(element);

                if (codeForm.ShowDialog() == DialogResult.OK)
                {
                    using (Transaction tx = element.Store.TransactionManager.BeginTransaction("AddProperties"))
                    {
                        element.Attributes.Clear();

                        foreach (string codeFormLine in codeForm.Lines)
                        {
                            try
                            {
                                ParseResult parseResult = ModelAttribute.Parse(element.ModelRoot, codeFormLine);

                                if (parseResult == null)
                                {
                                    Messages.AddWarning($"Could not parse '{codeFormLine}'. The line will be discarded.");

                                    continue;
                                }

                                string message = null;

                                if (string.IsNullOrEmpty(parseResult.Name) || !CodeGenerator.IsValidLanguageIndependentIdentifier(parseResult.Name))
                                {
                                    message = $"Could not add '{parseResult.Name}' to {element.Name}: '{parseResult.Name}' is not a valid .NET identifier";
                                }
                                else if (element.AllAttributes.Any(x => x.Name == parseResult.Name))
                                {
                                    message = $"Could not add {parseResult.Name} to {element.Name}: {parseResult.Name} already in use";
                                }
                                else if (element.AllNavigationProperties().Any(p => p.PropertyName == parseResult.Name))
                                {
                                    message = $"Could not add {parseResult.Name} to {element.Name}: {parseResult.Name} already in use";
                                }

                                if (message != null)
                                {
                                    Messages.AddWarning(message);

                                    continue;
                                }

                                ModelAttribute modelAttribute = new ModelAttribute(element.Store,
                                                                                   new PropertyAssignment(ModelAttribute.NameDomainPropertyId, parseResult.Name),
                                                                                   new PropertyAssignment(ModelAttribute.TypeDomainPropertyId, parseResult.Type ?? "String"),
                                                                                   new PropertyAssignment(ModelAttribute.RequiredDomainPropertyId, parseResult.Required ?? true),
                                                                                   new PropertyAssignment(ModelAttribute.MaxLengthDomainPropertyId, parseResult.MaxLength ?? -1),
                                                                                   new PropertyAssignment(ModelAttribute.MinLengthDomainPropertyId, parseResult.MinLength ?? 0),
                                                                                   new PropertyAssignment(ModelAttribute.InitialValueDomainPropertyId, parseResult.InitialValue),
                                                                                   new PropertyAssignment(ModelAttribute.IsIdentityDomainPropertyId, parseResult.IsIdentity),
                                                                                   new PropertyAssignment(ModelAttribute.SetterVisibilityDomainPropertyId, parseResult.SetterVisibility ?? SetterAccessModifier.Public));

                                element.Attributes.Add(modelAttribute);
                            }
                            catch (Exception exception)
                            {
                                Messages.AddWarning($"Could not parse '{codeFormLine}'. {exception.Message}. The line will be discarded.");
                            }
                        }

                        tx.Commit();
                    }
                }
            }
        }