///--------------------------------------------------------------------------------
        /// <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);
            EntityReferencesViewModel items             = DataContext as EntityReferencesViewModel;
            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 EntityReferenceDialogControl();
                EntityReference newItem = new EntityReference();
                newItem.PropertyID = Guid.NewGuid();
                newItem.Solution   = items.Solution;
                newItem.Entity     = items.Entity;
                //newItem.ReferenceEntity = diagramEntityView.DiagramEntity.Entity;
                EntityReferenceViewModel newItemView = new EntityReferenceViewModel(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.AddEntityReference(newItemView);
                }
                dialog.Close();
                dialog    = null;
                e.Handled = true;
                return;
            }
        }
Ejemplo n.º 2
0
        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;
                }
            }
        }
Ejemplo n.º 3
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method handles dropping items onto the treeview.</summary>
        ///
        /// <param name="data">The data as a viewmodel.</param>
        ///--------------------------------------------------------------------------------
        protected void Paste(IWorkspaceViewModel data)
        {
            SolutionViewModel             solution;
            ProjectViewModel              assembly;
            DatabaseSourceViewModel       databaseSource;
            AuditPropertyViewModel        auditProperty;
            FeatureViewModel              feature;
            EntityViewModel               entity;
            CollectionViewModel           collectionProperty;
            PropertyReferenceViewModel    derivedProperty;
            PropertyViewModel             property;
            EntityReferenceViewModel      referenceProperty;
            MethodViewModel               method;
            ParameterViewModel            parameter;
            IndexViewModel                index;
            IndexPropertyViewModel        indexProperty;
            RelationshipViewModel         relationship;
            RelationshipPropertyViewModel relationshipProperty;

            if (data is ProjectViewModel)
            {
                // process assembly drop
                assembly = data as ProjectViewModel;
                solution = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(assembly);
                }
                else if (solution.ProjectsFolder.Projects.Find("Name", assembly.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (assembly != DataContext as ProjectViewModel)
                    {
                        HandleDuplicateDrop(assembly);
                    }
                }
                else
                {
                    // do the drop
                    ProjectViewModel view = solution.ProjectsFolder.PasteProject(assembly, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is DatabaseSourceViewModel)
            {
                // process databaseSource drop
                databaseSource = data as DatabaseSourceViewModel;
                solution       = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(databaseSource);
                }
                else if (solution.SpecificationSourcesFolder.DatabaseSources.Find("Name", databaseSource.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (databaseSource != DataContext as DatabaseSourceViewModel)
                    {
                        HandleDuplicateDrop(databaseSource);
                    }
                }
                else
                {
                    // do the drop
                    DatabaseSourceViewModel view = solution.SpecificationSourcesFolder.PasteDatabaseSource(databaseSource, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is AuditPropertyViewModel)
            {
                // process auditProperty drop
                auditProperty = data as AuditPropertyViewModel;
                solution      = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(auditProperty);
                }
                else if (solution.AuditPropertiesFolder.AuditProperties.Find("Name", auditProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (auditProperty != DataContext as AuditPropertyViewModel)
                    {
                        HandleDuplicateDrop(auditProperty);
                    }
                }
                else
                {
                    // do the drop
                    AuditPropertyViewModel view = solution.AuditPropertiesFolder.PasteAuditProperty(auditProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is FeatureViewModel)
            {
                // process feature drop
                feature  = data as FeatureViewModel;
                solution = DataContext as SolutionViewModel;
                if (solution == null)
                {
                    // get parent solution
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                }
                if (solution == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(feature);
                }
                else if (solution.FeaturesFolder.Features.Find("Name", feature.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (feature != DataContext as FeatureViewModel)
                    {
                        HandleDuplicateDrop(feature);
                    }
                }
                else
                {
                    // do the drop
                    Mouse.OverrideCursor = Cursors.Wait;
                    FeatureViewModel view = solution.FeaturesFolder.PasteFeature(feature, true);
                    view.ShowInTreeView();
                    solution.Refresh(true);
                    Mouse.OverrideCursor = null;
                }
            }
            else if (data is EntityViewModel)
            {
                // process entity drop
                entity  = data as EntityViewModel;
                feature = DataContext as FeatureViewModel;
                if (feature == null)
                {
                    // get parent feature
                    feature = ViewModelHelper.FindParentView <FeatureViewModel>(this);
                }
                if (feature == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(entity);
                }
                else if (feature.Entities.Find("Name", entity.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (entity != DataContext as EntityViewModel)
                    {
                        HandleDuplicateDrop(entity);
                    }
                }
                else
                {
                    // do the drop
                    Mouse.OverrideCursor = Cursors.Wait;
                    EntityViewModel view = feature.PasteEntity(entity, true);
                    view.ShowInTreeView();
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                    if (solution != null)
                    {
                        solution.Refresh(true);
                    }
                    Mouse.OverrideCursor = null;
                }
            }
            else if (data is CollectionViewModel)
            {
                // process collectionProperty drop
                collectionProperty = data as CollectionViewModel;
                entity             = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(collectionProperty);
                }
                else if (entity.CollectionsFolder.Collections.Find("Name", collectionProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (collectionProperty != DataContext as CollectionViewModel)
                    {
                        HandleDuplicateDrop(collectionProperty);
                    }
                }
                else
                {
                    // do the drop
                    CollectionViewModel view = entity.CollectionsFolder.PasteCollection(collectionProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is PropertyReferenceViewModel)
            {
                // process derivedProperty drop
                derivedProperty = data as PropertyReferenceViewModel;
                entity          = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(derivedProperty);
                }
                else if (entity.PropertyReferencesFolder.PropertyReferences.Find("Name", derivedProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (derivedProperty != DataContext as PropertyReferenceViewModel)
                    {
                        HandleDuplicateDrop(derivedProperty);
                    }
                }
                else
                {
                    // do the drop
                    PropertyReferenceViewModel view = entity.PropertyReferencesFolder.PastePropertyReference(derivedProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is PropertyViewModel)
            {
                // process property drop
                property = data as PropertyViewModel;
                entity   = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(property);
                }
                else if (entity.PropertiesFolder.Properties.Find("Name", property.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (property != DataContext as PropertyViewModel)
                    {
                        HandleDuplicateDrop(property);
                    }
                }
                else
                {
                    // do the drop
                    PropertyViewModel view = entity.PropertiesFolder.PasteProperty(property, true);
                    solution = ViewModelHelper.FindParentView <SolutionViewModel>(this);
                    if (solution != null)
                    {
                        solution.Refresh(true);
                    }
                    view.ShowInTreeView();
                }
            }
            else if (data is EntityReferenceViewModel)
            {
                // process referenceProperty drop
                referenceProperty = data as EntityReferenceViewModel;
                entity            = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(referenceProperty);
                }
                else if (entity.EntityReferencesFolder.EntityReferences.Find("Name", referenceProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (referenceProperty != DataContext as EntityReferenceViewModel)
                    {
                        HandleDuplicateDrop(referenceProperty);
                    }
                }
                else
                {
                    // do the drop
                    EntityReferenceViewModel view = entity.EntityReferencesFolder.PasteEntityReference(referenceProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is MethodViewModel)
            {
                // process method drop
                method = data as MethodViewModel;
                entity = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(method);
                }
                else if (entity.MethodsFolder.Methods.Find("Name", method.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (method != DataContext as MethodViewModel)
                    {
                        HandleDuplicateDrop(method);
                    }
                }
                else
                {
                    // do the drop
                    MethodViewModel view = entity.MethodsFolder.PasteMethod(method, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is ParameterViewModel)
            {
                // process parameter drop
                parameter = data as ParameterViewModel;
                method    = DataContext as MethodViewModel;
                if (method == null)
                {
                    // get parent method
                    method = ViewModelHelper.FindParentView <MethodViewModel>(this);
                }
                if (method == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(parameter);
                }
                else if (method.Parameters.Find("Name", parameter.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (parameter != DataContext as ParameterViewModel)
                    {
                        HandleDuplicateDrop(parameter);
                    }
                }
                else
                {
                    // do the drop
                    ParameterViewModel view = method.PasteParameter(parameter, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is IndexViewModel)
            {
                // process index drop
                index  = data as IndexViewModel;
                entity = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(index);
                }
                else if (entity.IndexesFolder.Indexes.Find("Name", index.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (index != DataContext as IndexViewModel)
                    {
                        HandleDuplicateDrop(index);
                    }
                }
                else
                {
                    // do the drop
                    IndexViewModel view = entity.IndexesFolder.PasteIndex(index, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is IndexPropertyViewModel)
            {
                // process index drop
                indexProperty = data as IndexPropertyViewModel;
                index         = DataContext as IndexViewModel;
                if (index == null)
                {
                    // get parent index
                    index = ViewModelHelper.FindParentView <IndexViewModel>(this);
                }
                if (index == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(indexProperty);
                }
                else if (index.IndexProperties.Find("Name", indexProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (indexProperty != DataContext as IndexPropertyViewModel)
                    {
                        HandleDuplicateDrop(indexProperty);
                    }
                }
                else
                {
                    // do the drop
                    IndexPropertyViewModel view = index.PasteIndexProperty(indexProperty, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is RelationshipViewModel)
            {
                // process relationship drop
                relationship = data as RelationshipViewModel;
                entity       = DataContext as EntityViewModel;
                if (entity == null)
                {
                    // get parent entity
                    entity = ViewModelHelper.FindParentView <EntityViewModel>(this);
                }
                if (entity == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(relationship);
                }
                else if (entity.RelationshipsFolder.Relationships.Find("Name", relationship.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (relationship != DataContext as RelationshipViewModel)
                    {
                        HandleDuplicateDrop(relationship);
                    }
                }
                else
                {
                    // do the drop
                    RelationshipViewModel view = entity.RelationshipsFolder.PasteRelationship(relationship, true);
                    view.ShowInTreeView();
                }
            }
            else if (data is RelationshipPropertyViewModel)
            {
                // process relationshipProperty drop
                relationshipProperty = data as RelationshipPropertyViewModel;
                relationship         = DataContext as RelationshipViewModel;
                if (relationship == null)
                {
                    // get parent relationship
                    relationship = ViewModelHelper.FindParentView <RelationshipViewModel>(this);
                }
                if (relationship == null)
                {
                    // invalid drop location
                    HandleInvalidDrop(relationshipProperty);
                }
                else if (relationship.RelationshipProperties.Find("Name", relationshipProperty.Name) != null)
                {
                    // duplicate item found, cannot drop
                    if (relationshipProperty != DataContext as RelationshipPropertyViewModel)
                    {
                        HandleDuplicateDrop(relationshipProperty);
                    }
                }
                else
                {
                    // do the drop
                    RelationshipPropertyViewModel view = relationship.PasteRelationshipProperty(relationshipProperty, true);
                    view.ShowInTreeView();
                }
            }
        }