///-------------------------------------------------------------------------------- /// <summary>This method handles the execution of the new command.</summary> /// /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> ///-------------------------------------------------------------------------------- private void NewExecuted(object sender, ExecutedRoutedEventArgs e) { Point currentPosition = MouseUtilities.GetMousePosition(this); CollectionsViewModel items = DataContext as CollectionsViewModel; EntityDiagramControl diagram = VisualItemHelper.VisualUpwardSearch <EntityDiagramControl>(this) as EntityDiagramControl; DiagramEntityViewModel diagramEntityView = diagram.DataContext as DiagramEntityViewModel; if (items != null && diagramEntityView != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new CollectionDialogControl(); Collection newItem = new Collection(); newItem.PropertyID = Guid.NewGuid(); newItem.Solution = items.Solution; newItem.Entity = items.Entity; //newItem.ReferenceEntity = diagramEntityView.DiagramEntity.Entity; CollectionViewModel newItemView = new CollectionViewModel(newItem, items.Solution); newItemView.IsFreeDialog = true; dialog.DataContext = newItemView; dialog.Title = newItemView.Title; newItemView.RequestClose += new EventHandler(Item_RequestClose); #region protected #endregion protected dialog.ShowDialog(); if (newItemView.IsOK == true) { items.AddCollection(newItemView); } dialog.Close(); dialog = null; e.Handled = true; return; } }
protected override void OnDrop(DragEventArgs e) { base.OnDrop(e); Point currentPosition = MouseUtilities.GetMousePosition(this); DiagramViewModel diagramView = ParentCanvas.DataContext as DiagramViewModel; DiagramEntityViewModel diagramEntityView = DataContext as DiagramEntityViewModel; if (diagramView != null && diagramEntityView != null) { // try drop as diagram relationship DiagramRelationshipViewModel dragRelationship = e.Data.GetData(typeof(DiagramRelationshipViewModel)) as DiagramRelationshipViewModel; if (dragRelationship != null) { dragRelationship.SinkDiagramEntityViewModel = diagramEntityView; dragRelationship.Diagram = diagramView; dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 650 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new RelationshipDialogControl(); Relationship newRelationship = new Relationship(); newRelationship.RelationshipID = Guid.NewGuid(); newRelationship.Solution = dragRelationship.Solution; newRelationship.ReferencedEntity = dragRelationship.SinkDiagramEntityViewModel.DiagramEntity.Entity; newRelationship.Entity = dragRelationship.SourceDiagramEntityViewModel.DiagramEntity.Entity; RelationshipViewModel newRelationshipView = new RelationshipViewModel(newRelationship, dragRelationship.Solution); dialog.DataContext = newRelationshipView; dialog.Title = newRelationshipView.Title; newRelationshipView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newRelationshipView.IsOK == true) { dragRelationship.RelationshipViewModel = newRelationshipView; diagramView.CreateRelationship(dragRelationship); } dialog.Close(); dialog = null; e.Handled = true; return; } // try drop as collection CollectionsViewModel dragCollections = e.Data.GetData(typeof(CollectionsViewModel)) as CollectionsViewModel; if (dragCollections != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new CollectionDialogControl(); Collection newProperty = new Collection(); newProperty.PropertyID = Guid.NewGuid(); newProperty.Solution = dragCollections.Solution; newProperty.Entity = dragCollections.Entity; newProperty.ReferencedEntity = diagramEntityView.DiagramEntity.Entity; CollectionViewModel newPropertyView = new CollectionViewModel(newProperty, dragCollections.Solution); dialog.DataContext = newPropertyView; dialog.Title = newPropertyView.Title; newPropertyView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newPropertyView.IsOK == true) { dragCollections.AddCollection(newPropertyView); } dialog.Close(); dialog = null; e.Handled = true; return; } // try drop as property reference PropertyReferencesViewModel dragPropertyReferences = e.Data.GetData(typeof(PropertyReferencesViewModel)) as PropertyReferencesViewModel; if (dragPropertyReferences != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new PropertyReferenceDialogControl(); PropertyReference newProperty = new PropertyReference(); newProperty.PropertyID = Guid.NewGuid(); newProperty.Solution = dragPropertyReferences.Solution; newProperty.Entity = dragPropertyReferences.Entity; PropertyReferenceViewModel newPropertyView = new PropertyReferenceViewModel(newProperty, dragPropertyReferences.Solution); newPropertyView.ReferencedEntityID = diagramEntityView.EntityViewModel.EntityID; newPropertyView.RefreshProperties(); dialog.DataContext = newPropertyView; dialog.Title = newPropertyView.Title; newPropertyView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newPropertyView.IsOK == true) { dragPropertyReferences.AddPropertyReference(newPropertyView); } dialog.Close(); dialog = null; e.Handled = true; return; } // try drop as entity reference EntityReferencesViewModel dragEntityReferences = e.Data.GetData(typeof(EntityReferencesViewModel)) as EntityReferencesViewModel; if (dragEntityReferences != null) { dialog = new Window(); dialog.Height = 450 * UserSettingsHelper.Instance.ControlSize; dialog.Width = 400 * UserSettingsHelper.Instance.ControlSize; dialog.Left = Math.Max(currentPosition.X, 20); dialog.Top = Math.Max(currentPosition.Y, 20); dialog.Content = new EntityReferenceDialogControl(); EntityReference newProperty = new EntityReference(); newProperty.PropertyID = Guid.NewGuid(); newProperty.Solution = dragEntityReferences.Solution; newProperty.Entity = dragEntityReferences.Entity; newProperty.ReferencedEntity = diagramEntityView.DiagramEntity.Entity; EntityReferenceViewModel newPropertyView = new EntityReferenceViewModel(newProperty, dragEntityReferences.Solution); dialog.DataContext = newPropertyView; dialog.Title = newPropertyView.Title; newPropertyView.RequestClose += new EventHandler(Item_RequestClose); dialog.ShowDialog(); if (newPropertyView.IsOK == true) { dragEntityReferences.AddEntityReference(newPropertyView); } dialog.Close(); dialog = null; e.Handled = true; return; } } }