public static ExecutedRoutedEventHandler AddAssociationExecuted(UIElement parent, Func <CSDLView> getCSDLView, Func <DesignerView> getDesignerView, UIEntityType defaultEntityType1, Action <UIAssociation> specialActionToDoWhenNewItemAdded) { return((object sender, ExecutedRoutedEventArgs e) => { var csdlView = getCSDLView(); var designerView = getDesignerView(); var addAssociationWindow = new AddAssociationWindow { Owner = VisualTreeHelperUtil.GetControlAscendant <Window>(parent), DataContext = csdlView, NavigationProperty1EntityType = defaultEntityType1 }; switch (addAssociationWindow.ShowDialog()) { case true: var uiAssociation = csdlView.AddAssociation(addAssociationWindow.AssociationName, addAssociationWindow.NavigationProperty1Name, addAssociationWindow.NavigationProperty1EntityType, addAssociationWindow.NavigationProperty1Cardinality.Value, addAssociationWindow.NavigationProperty2Name, addAssociationWindow.NavigationProperty2EntityType, addAssociationWindow.NavigationProperty2Cardinality.Value); SizeChangedEventHandler actionToDoWhenNewItemAdded = null; bool drawAssociation = false; DesignerCanvas designerCanvas = parent as DesignerCanvas; if (designerCanvas == null) { designerCanvas = VisualTreeHelperUtil.GetControlAscendant <DesignerCanvas>(parent); } var navigationProperty1EntityTypeDesigner = designerCanvas.GetTypeDesigner(uiAssociation.NavigationProperty1.ParentType); var navigationProperty2EntityTypeDesigner = designerCanvas.GetTypeDesigner(uiAssociation.NavigationProperty2.ParentType); actionToDoWhenNewItemAdded = (object o, SizeChangedEventArgs scea) => { if (designerView.ContainsEntityType(uiAssociation.NavigationProperty1.ParentType) && designerView.ContainsEntityType(uiAssociation.NavigationProperty2.ParentType)) { if (drawAssociation) { navigationProperty1EntityTypeDesigner.DrawAssociation(navigationProperty2EntityTypeDesigner, uiAssociation.NavigationProperty1.BusinessInstance as NavigationProperty); } else { drawAssociation = true; } } if (specialActionToDoWhenNewItemAdded != null) { specialActionToDoWhenNewItemAdded(uiAssociation); } ((ListView)o).SizeChanged -= actionToDoWhenNewItemAdded; }; navigationProperty1EntityTypeDesigner.propertiesListView.SizeChanged += actionToDoWhenNewItemAdded; if (navigationProperty2EntityTypeDesigner != null) { navigationProperty2EntityTypeDesigner.propertiesListView.SizeChanged += actionToDoWhenNewItemAdded; } break; } }); }
public static DesignerCanvas GetDesignerCanvas(EDMDesignerViewContent container, EDMView edmView, DesignerView designerView) { DesignerCanvas designerCanvas = null; //if (designerView == null) //{ // EntityTypeDesigner.Init = true; // designerView = new DesignerView(); // designerView.ArrangeTypeDesigners = true; // designerView.Name = edmView.Name; // designerView.Zoom = 100; // if (edmView.CSDL.CSDL != null) // { // foreach (UIEntityType entityType in edmView.CSDL.EntityTypes) // { // designerView.AddTypeDesigner(new EntityTypeDesigner(entityType) { IsExpanded = true }); // } // } // EntityTypeDesigner.Init = false; //} if (designerView != null && _designerCanvas.ContainsKey(designerView)) { designerCanvas = _designerCanvas[designerView]; var parent = designerCanvas.Parent as DesignerCanvasPreview; if (parent != null) { parent.Content = null; } else { ((ContentControl)designerCanvas.Parent).Content = null; } } else { designerCanvas = new DesignerCanvas(container) { EDMView = edmView, DesignerView = designerView, Background = Brushes.White }; _designerCanvas.Add(designerView, designerCanvas); } return(designerCanvas); }
public override void Load(OpenedFile file, Stream stream) { Debug.Assert(file == this.PrimaryFile); EDMDesignerChangeWatcher.Init = true; // Load EDMX from stream XElement edmxElement = null; Action<XElement> readMoreAction = edmxElt => edmxElement = edmxElt; _edmView = new EDMView(stream, readMoreAction); // If EDMX is empty run EDM Wizard if (_edmView.EDM.IsEmpty) { edmxElement = null; EDMWizardWindow wizard = RunWizard(file, ProjectService.CurrentProject.RootNamespace); if (wizard.DialogResult == true) _edmView = new EDMView(wizard.EDMXDocument, readMoreAction); else return; } // Load or generate DesignerView and EntityTypeDesigners EntityTypeDesigner.Init = true; XElement designerViewsElement = null; if (edmxElement == null || (designerViewsElement = EDMXIO.ReadSection(edmxElement, EDMXIO.EDMXSection.DesignerViews)) == null) { designerViewsElement = DesignerIO.GenerateNewDesignerViewsFromCSDLView(_edmView); } if (edmxElement != null && designerViewsElement != null) DesignerIO.Read(_edmView, designerViewsElement, entityType => new EntityTypeDesigner(entityType), complexType => new ComplexTypeDesigner(complexType)); EntityTypeDesigner.Init = false; // Call DoEvents, otherwise drawing associations can fail VisualHelper.DoEvents(); // Gets the designer canvas _designerCanvas = DesignerCanvas.GetDesignerCanvas(this, _edmView, _edmView.DesignerViews.FirstOrDefault()); _scrollViewer.Content = _designerCanvas; // Register CSDL of EDMX in CSDL DatabaseTreeView CSDLDatabaseTreeViewAdditionalNode.Instance.CSDLViews.Add(_edmView.CSDL); EDMDesignerChangeWatcher.Init = false; }
public override void Load(OpenedFile file, Stream stream) { Debug.Assert(file == this.PrimaryFile); EDMDesignerChangeWatcher.Init = true; // Load EDMX from stream XElement edmxElement = null; Action<XElement> readMoreAction = edmxElt => edmxElement = edmxElt; _edmView = new EDMView(stream, readMoreAction); // If EDMX is empty run EDM Wizard if (_edmView.EDM.IsEmpty) { edmxElement = null; string ns = String.Empty; if (ProjectService.CurrentProject == null) { ns = ICSharpCode.Core.MessageService.ShowInputBox("EDMDesigner","Enter NameSpace","DefaultNamespace"); } else { ns = ProjectService.CurrentProject.RootNamespace; } EDMWizardWindow wizard = RunWizard(file, ns); if (wizard.DialogResult == true) _edmView = new EDMView(wizard.EDMXDocument, readMoreAction); else throw new WizardCancelledException(); } // Load or generate DesignerView and EntityTypeDesigners EntityTypeDesigner.Init = true; XElement designerViewsElement = null; if (edmxElement == null || (designerViewsElement = EDMXIO.ReadSection(edmxElement, EDMXIO.EDMXSection.DesignerViews)) == null) { designerViewsElement = DesignerIO.GenerateNewDesignerViewsFromCSDLView(_edmView); } if (edmxElement != null && designerViewsElement != null) DesignerIO.Read(_edmView, designerViewsElement, entityType => new EntityTypeDesigner(entityType), complexType => new ComplexTypeDesigner(complexType)); EntityTypeDesigner.Init = false; // Gets the designer canvas _designerCanvas = DesignerCanvas.GetDesignerCanvas(this, _edmView, _edmView.DesignerViews.FirstOrDefault()); _scrollViewer.Content = _designerCanvas; // Register CSDL of EDMX in CSDL DatabaseTreeView CSDLViews.Add(_edmView.CSDL); EDMDesignerChangeWatcher.Init = false; }
public static DesignerCanvas GetDesignerCanvas(EDMDesignerViewContent container, EDMView edmView, DesignerView designerView) { DesignerCanvas designerCanvas = null; //if (designerView == null) //{ // EntityTypeDesigner.Init = true; // designerView = new DesignerView(); // designerView.ArrangeTypeDesigners = true; // designerView.Name = edmView.Name; // designerView.Zoom = 100; // if (edmView.CSDL.CSDL != null) // { // foreach (UIEntityType entityType in edmView.CSDL.EntityTypes) // { // designerView.AddTypeDesigner(new EntityTypeDesigner(entityType) { IsExpanded = true }); // } // } // EntityTypeDesigner.Init = false; //} if (designerView != null && _designerCanvas.ContainsKey(designerView)) { designerCanvas = _designerCanvas[designerView]; var parent = designerCanvas.Parent as DesignerCanvasPreview; if (parent != null) parent.Content = null; else ((ContentControl)designerCanvas.Parent).Content = null; } else { designerCanvas = new DesignerCanvas(container) { EDMView = edmView, DesignerView = designerView, Background = Brushes.White }; _designerCanvas.Add(designerView, designerCanvas); } return designerCanvas; }