public void AddRelatedItemsTest() { var shapeColor = Color.Cyan; ChangeEntityTypesFillColorTest( "AddRelatedItems", shapeColor, (artifact, commandProcessorContext) => { var diagram = CreateDiagramCommand.CreateDiagramWithDefaultName(commandProcessorContext); var docData = GetDocData(commandProcessorContext.EditingContext); docData.OpenDiagram(diagram.Id.Value); CreateEntityTypeShapeCommand.CreateEntityTypeShapeAndConnectorsInDiagram( commandProcessorContext, diagram, (ConceptualEntityType)artifact.ConceptualModel.EntityTypes().Single(et => et.LocalName.Value == "author"), shapeColor, false); var entityDesignerDiagram = docData.GetEntityDesignerDiagram(diagram.Id.Value); var author = entityDesignerDiagram.GetShape("author"); Assert.IsNotNull(author, "Could not get DSL entity type shape instance of 'author'."); entityDesignerDiagram.SelectDiagramItems(new[] { author }); Dte.ExecuteCommand("OtherContextMenus.MicrosoftDataEntityDesignContext.IncludeRelated"); var titleauthor = entityDesignerDiagram.GetShape("titleauthor"); Assert.IsNotNull(titleauthor, "Could not get DSL entity type shape instance of 'titleauthor'."); Assert.AreEqual(shapeColor, author.FillColor); Assert.AreEqual(shapeColor, titleauthor.FillColor); }); }
private void DisplayNewDiagram() { // Find a unique name for the new Diagram int N = 0; string newName; bool found; do { ++N; newName = string.Format("Diagram {0}", N); // Search name in list of diagrams found = false; foreach (Diagram d in project.Repository.GetDiagrams()) { if (d.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)) { found = true; break; } } } while (found); Diagram diagram = new Diagram(newName); CreateDiagramCommand cmd = new CreateDiagramCommand(diagram); project.ExecuteCommand(cmd); UpdateDiagramCombo(); diagramComboBox.Text = newName; }
internal static void StaticInvoke(CommandProcessorContext cpc, EntityDesignerDiagram diagram) { var viewModel = diagram.ModelElement; Debug.Assert(viewModel != null, "Why Diagram's Model Element is null?"); if (viewModel != null) { var artifact = cpc.Artifact; Debug.Assert(artifact != null && artifact.DesignerInfo() != null && artifact.DesignerInfo().Diagrams != null); if (artifact != null && artifact.DesignerInfo() != null && artifact.DesignerInfo().Diagrams != null) { var modelDiagram = CreateDiagramCommand.CreateDiagramWithDefaultName(cpc); Debug.Assert(modelDiagram != null); using (var t = diagram.Store.TransactionManager.BeginTransaction("Set Diagram Id", false)) { diagram.DiagramId = modelDiagram.Id.Value; t.Commit(); } viewModel.ModelXRef.Add(modelDiagram, diagram, viewModel.EditingContext); } } }
/// <ToBeCompleted></ToBeCompleted> public Diagram CreateDiagram(string name) { if (name == null) throw new ArgumentNullException("name"); AssertProjectIsOpen(); // Create new diagram Diagram diagram = new Diagram(name); diagram.Width = 1000; diagram.Height = 1000; ICommand cmd = new CreateDiagramCommand(diagram); project.ExecuteCommand(cmd); return diagram; }
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); }
public void CopyAndPasteInMultipleDiagramsTest() { var shapeColor = Color.Brown; ChangeEntityTypesFillColorTest( "CopyAndPasteMulti", shapeColor, (artifact, commandProcessorContext) => { var docData = GetDocData(commandProcessorContext.EditingContext); var entityDesignerDiagram = docData.GetEntityDesignerDiagram(); Assert.IsNotNull(entityDesignerDiagram, "Could not get an instance of EntityDesignerDiagram from editingcontext."); var author = entityDesignerDiagram.GetShape("author"); Assert.IsNotNull(author, "Could not get DSL entity type shape instance of 'author'."); var titleAuthor = entityDesignerDiagram.GetShape("titleauthor"); Assert.IsNotNull(titleAuthor, "Could not get DSL entity type shape instance of 'titleauthor'."); entityDesignerDiagram.SelectDiagramItems(new[] { author, titleAuthor }); DesignerUtilities.Copy(Dte); var diagram = CreateDiagramCommand.CreateDiagramWithDefaultName(commandProcessorContext); docData.OpenDiagram(diagram.Id.Value); DesignerUtilities.Paste(Dte); // Get the newly created diagram. entityDesignerDiagram = docData.GetEntityDesignerDiagram(diagram.Id.Value); author = entityDesignerDiagram.GetShape("author"); Assert.IsNotNull(author, "Entity: 'author' should exists in diagram:" + diagram.Name); titleAuthor = entityDesignerDiagram.GetShape("titleauthor"); Assert.IsNotNull(titleAuthor, "Entity: 'titleauthor' should exists in diagram:" + diagram.Name); var associationConnector = entityDesignerDiagram.NestedChildShapes.OfType <EntityDesignerView.AssociationConnector>().FirstOrDefault(); Assert.IsNotNull( associationConnector, "There should have been association connector created between entities 'author' and 'titleauthor'."); var entityDesignerViewModel = entityDesignerDiagram.ModelElement; Assert.IsNotNull(entityDesignerViewModel, "Diagram's ModelElement is not a type of EntityDesignerViewModel"); var association = (Association)entityDesignerViewModel.ModelXRef.GetExisting(associationConnector.ModelElement); Assert.IsNotNull( association, "Could not find association for associationConnector" + associationConnector.AccessibleName + " from Model Xref."); var entityTypesInAssociation = association.AssociationEnds().Select(ae => ae.Type.Target).Distinct().ToList(); Assert.AreEqual(2, entityTypesInAssociation.Count); Assert.IsFalse( entityTypesInAssociation.Any(et => et.LocalName.Value != "author" && et.LocalName.Value != "titleauthor"), "The association between author and title-author is not created in diagram: " + diagram.Name); Assert.AreEqual(shapeColor, author.FillColor); Assert.AreEqual(shapeColor, titleAuthor.FillColor); }); }
private void DisplayNewDiagram() { // Find a unique name for the new Diagram int N = 0; string newName; bool found; do { ++N; newName = string.Format("Diagram {0}", N); // Search name in list of diagrams found = false; foreach (Diagram d in project.Repository.GetDiagrams()) if (d.Name.Equals(newName, StringComparison.InvariantCultureIgnoreCase)) { found = true; break; } } while (found); Diagram diagram = new Diagram(newName); CreateDiagramCommand cmd = new CreateDiagramCommand(diagram); project.ExecuteCommand(cmd); UpdateDiagramCombo(); diagramComboBox.Text = newName; }