protected override void InvokeInternal(CommandProcessorContext cpc) { var nExistingTypeShapeCount = _entity.GetAntiDependenciesOfType <EntityTypeShape>().Count(ets => ets.Diagram.Id == _diagram.Id.Value); Debug.Assert( nExistingTypeShapeCount == 0, "There is already Entity Type Shape for entity :" + _entity.Name + " in the diagram " + _diagram.Name); if (nExistingTypeShapeCount == 0) { var shape = new EntityTypeShape(_diagram, null); _diagram.AddEntityTypeShape(shape); shape.EntityType.SetRefName(_entity); shape.Width.Value = DEFAULTWIDTH; // The DSL will set the correct locations for the shapes at a later point, but we need to provide initial values for X and Y in the meantime // so that we can construct the shape. We're using random numbers here to ensure that if the DSL fails for some reason, new shapes do not // stack directly on top of each other. shape.PointX.Value = _rand.NextDouble() * 12.0; shape.PointY.Value = _rand.NextDouble() * 32.0; if (_fillColor != EntityDesignerDiagramConstant.EntityTypeShapeDefaultFillColor) { shape.FillColor.Value = _fillColor; } XmlModelHelper.NormalizeAndResolve(shape); _created = shape; } }
protected override void InvokeInternal(CommandProcessorContext cpc) { var nExistingTypeShapeCount = _entity.GetAntiDependenciesOfType<EntityTypeShape>().Count(ets => ets.Diagram.Id == _diagram.Id.Value); Debug.Assert( nExistingTypeShapeCount == 0, "There is already Entity Type Shape for entity :" + _entity.Name + " in the diagram " + _diagram.Name); if (nExistingTypeShapeCount == 0) { var shape = new EntityTypeShape(_diagram, null); _diagram.AddEntityTypeShape(shape); shape.EntityType.SetRefName(_entity); shape.Width.Value = DEFAULTWIDTH; // The DSL will set the correct locations for the shapes at a later point, but we need to provide initial values for X and Y in the meantime // so that we can construct the shape. We're using random numbers here to ensure that if the DSL fails for some reason, new shapes do not // stack directly on top of each other. shape.PointX.Value = _rand.NextDouble() * 12.0; shape.PointY.Value = _rand.NextDouble() * 32.0; if (_fillColor != EntityDesignerDiagramConstant.EntityTypeShapeDefaultFillColor) { shape.FillColor.Value = _fillColor; } XmlModelHelper.NormalizeAndResolve(shape); _created = shape; } }
private ExplorerEntityTypeShape AddEntityTypeShape(EntityTypeShape entityTypeShape) { var explorerEntityTypeShape = ModelToExplorerModelXRef.GetNew(_context, entityTypeShape, this, typeof(ExplorerEntityTypeShape)) as ExplorerEntityTypeShape; _explorerEntityTypeShapes.Insert(explorerEntityTypeShape); return(explorerEntityTypeShape); }
internal CreateEntityTypeShapeCommand(Diagram diagram, EntityType entity, Color fillColor) { CommandValidation.ValidateConceptualEntityType(entity); Debug.Assert(diagram != null, "diagram is null"); _diagram = diagram; _entity = entity; _created = null; _fillColor = fillColor; }
internal override void Invoke(CommandProcessorContext cpc) { var viewModel = EntityTypeShape.GetRootViewModel(); Debug.Assert(viewModel != null, "Unable to find root view model from entity type shape: " + EntityTypeShape.AccessibleName); if (viewModel != null) { var modelEntityShape = viewModel.ModelXRef.GetExisting(EntityTypeShape) as Model.Designer.EntityTypeShape; if (modelEntityShape != null) { DeleteEFElementCommand.DeleteInTransaction(cpc, modelEntityShape); viewModel.ModelXRef.Remove(modelEntityShape, EntityTypeShape); } } }
internal override void Initialize(EFObject obj, EditingContext editingContext, bool runningInVS) { _entityTypeShape = obj as EntityTypeShape; Debug.Assert(_entityTypeShape != null, "EFObject is null or is not a type of EntityTypeShape."); if (_entityTypeShape != null) { var entityType = _entityTypeShape.EntityType.Target; Debug.Assert(entityType != null, "EntityTypeShape does not contain instance of an entity type."); if (entityType != null) { base.Initialize(entityType, editingContext, runningInVS); } } }
internal EntityTypeClipboardFormat(EntityTypeShape entityTypeShape) : this(entityTypeShape.EntityType.Target) { _entityTypeShapeFillColor = entityTypeShape.FillColor.Value; }
/// <summary> /// Deletes the passed in EntityTypeShape and the associated connectors. /// </summary> /// <param name="entityType"></param> internal DeleteEntityTypeShapeCommand(EntityTypeShape entityTypeShape) : base(entityTypeShape) { }
public ExplorerEntityTypeShape(EditingContext context, EntityTypeShape entityTypeShape, ExplorerEFElement parent) : base(context, entityTypeShape, parent) { // do nothing. }
internal void AddNewInheritance(EntityTypeShape entityShape) { if ((Partition.GetLocks() & Locks.Add) == Locks.Add) { return; } // If user selected an EntityTypeShape, use corresponding EntityType // else default to first EntityType in the model ViewModelEntityType baseEntity = null; ConceptualEntityType modelEntity = null; if (entityShape != null) { baseEntity = entityShape.ModelElement as ViewModelEntityType; modelEntity = ModelElement.ModelXRef.GetExisting(baseEntity) as ConceptualEntityType; Debug.Assert(modelEntity != null); } var model = ModelElement.ModelXRef.GetExisting(ModelElement) as ConceptualEntityModel; Debug.Assert(model != null); var cets = new List<ConceptualEntityType>(model.EntityTypes().Cast<ConceptualEntityType>()); using (var dialog = new NewInheritanceDialog(modelEntity, cets)) { if (dialog.ShowDialog() == DialogResult.OK) { using (var t = Store.TransactionManager.BeginTransaction(EntityDesignerResources.Tx_AddInheritance)) { t.Context.Add(EfiTransactionOriginator.TransactionOriginatorDiagramId, DiagramId); ViewModelChangeContext.GetNewOrExistingContext(t).ViewModelChanges.Add(new Inheritance_AddFromDialog(dialog)); t.Commit(); } } } }
/// <summary> /// Adds an entity type shape to the diagram /// </summary> /// <param name="entityType">Model entity type to add to the diagram.</param> /// <returns>An EntityTypeShape object</returns> public EntityTypeShape AddEntityTypeShape(ModelEntityType entityType) { if (entityType == null) { throw new ArgumentNullException("entityType"); } EntityTypeShape ets = EntityTypeShapes.FirstOrDefault(es => es.EntityType == entityType); if (ets == null) { ets = new EntityTypeShape(ParentFile, this, entityType); ets.Removed += new EventHandler(ets_Removed); _entityTypeShapes.Add(ets.EntityTypeName, ets); } return ets; }
internal EntityTypeShapeDelete(EntityTypeShape entityShape) : base(entityShape) { }
/// <summary> /// Expand the passed in entity type shape. /// </summary> /// <param name="entityTypeShape"></param> internal void ExpandEntityTypeShape(EntityTypeShape entityTypeShape) { SetEntityShapesExpanded(new[] { entityTypeShape }, true); }
/// <summary> /// Collapse the passed in entity type shape. /// </summary> /// <param name="entityTypeShape">Entity type shape to be collapsed.</param> internal void CollapseEntityTypeShape(EntityTypeShape entityTypeShape) { SetEntityShapesExpanded(new[] { entityTypeShape }, false); }
public void AddNewFunctionImport(EntityTypeShape entityShape) { if ((Partition.GetLocks() & Locks.Add) == Locks.Add) { return; } ViewModelEntityType baseEntity = null; Model.Entity.EntityType modelEntity = null; if (entityShape != null) { baseEntity = entityShape.TypedModelElement; Debug.Assert(baseEntity != null); modelEntity = ModelElement.ModelXRef.GetExisting(baseEntity) as Model.Entity.EntityType; Debug.Assert(modelEntity != null); } // get the necessary conceptual model elements var cModel = ModelElement.ModelXRef.GetExisting(ModelElement) as ConceptualEntityModel; Debug.Assert(cModel != null, "Could not find a conceptual entity model associated with this artifact"); ConceptualEntityContainer cContainer = null; if (cModel != null) { cContainer = cModel.FirstEntityContainer as ConceptualEntityContainer; Debug.Assert(cContainer != null, "There is no conceptual entity container in the conceptual entity model"); } // get the necessary storage model elements and mapping model elements var artifactService = ModelElement.EditingContext.GetEFArtifactService(); Debug.Assert( artifactService != null && artifactService.Artifact != null, "There is no artifact service/artifact associated with this editing context"); StorageEntityModel sModel = null; EntityContainerMapping ecMapping = null; if (artifactService != null && artifactService.Artifact != null) { sModel = artifactService.Artifact.StorageModel(); Debug.Assert(sModel != null, "Could not find a storage entity model associated with this artifact"); var mModel = artifactService.Artifact.MappingModel(); Debug.Assert(mModel != null, "Could not find a mapping model associated with this artifact"); if (mModel != null) { ecMapping = mModel.FirstEntityContainerMapping; Debug.Assert( ecMapping != null, "There must be an entity container mapping in the mapping model to create the function import mapping"); } } if (cModel != null && sModel != null && cContainer != null && ecMapping != null) { var schemaVersion = artifactService.Artifact.SchemaVersion; if (null == schemaVersion) { Debug.Assert( false, typeof(EntityDesignerDiagram).Name + " could not determine Version for path " + artifactService.Artifact.Uri.LocalPath); return; } EntityDesignViewModelHelper.CreateFunctionImport( ModelElement.EditingContext, artifactService.Artifact, null, sModel, cModel, cContainer, modelEntity, EfiTransactionOriginator.EntityDesignerOriginatorId); } }
protected EntityTypeShapeModelChange(EntityTypeShape entityTypeShape) { _entityTypeShape = entityTypeShape; }
internal void AutoPositionShape(EntityTypeShape entityTypeShape) { //determine initial nextX/nextY position and if we're going to start adding horizontally or vertically... if (_nextShapeX == null || _nextShapeY == null) { decimal diagramWidth = DiagramWidth; decimal diagramHeight = DiagramHeight; if (diagramHeight > diagramWidth) { _addVertical = true; _nextShapeX = diagramWidth + .75M; _nextShapeY = .75M; _maxY = diagramHeight; } else { _addVertical = false; _nextShapeX = .75M; _nextShapeY = diagramHeight + .75M; _maxX = diagramWidth; } } //set position and size for the current element entityTypeShape.Top = _nextShapeY.Value; entityTypeShape.Left = _nextShapeX.Value; entityTypeShape.Width = 1.5M; entityTypeShape.Height = 2M; //increase nextx/nexty depending on if we're adding horizontally or vertically if (_addVertical) { _nextShapeY = _nextShapeY.Value + 2.5M; if (_nextShapeY > _maxY) { _nextShapeY = null; } } else { _nextShapeX = _nextShapeX.Value + 2M; if (_nextShapeX > _maxX) { _nextShapeX = null; } } }
private ExplorerEntityTypeShape AddEntityTypeShape(EntityTypeShape entityTypeShape) { var explorerEntityTypeShape = ModelToExplorerModelXRef.GetNew(_context, entityTypeShape, this, typeof(ExplorerEntityTypeShape)) as ExplorerEntityTypeShape; _explorerEntityTypeShapes.Insert(explorerEntityTypeShape); return explorerEntityTypeShape; }
internal void AddNewAssociation(EntityTypeShape entityShape) { if ((Partition.GetLocks() & Locks.Add) == Locks.Add) { return; } // If user selected an EntityTypeShape, use corresponding EntityType // else default to first EntityType in the model ViewModelEntityType end1 = null; if (entityShape != null) { end1 = entityShape.ModelElement as ViewModelEntityType; } if (end1 == null) { end1 = ModelElement.EntityTypes[0]; } // Pick something for the second end (defaulting to the next EntityType in the model) ViewModelEntityType end2 = null; var index = ModelElement.EntityTypes.IndexOf(end1) + 1; if (ModelElement.EntityTypes.Count <= index) { index = 0; } end2 = ModelElement.EntityTypes[index]; var modelEnd1Entity = ModelElement.ModelXRef.GetExisting(end1) as Model.Entity.EntityType; var modelEnd2Entity = ModelElement.ModelXRef.GetExisting(end2) as Model.Entity.EntityType; Debug.Assert(modelEnd1Entity != null && modelEnd2Entity != null); var model = modelEnd1Entity.Parent as ConceptualEntityModel; Debug.Assert(model != null); using (var dialog = new NewAssociationDialog(model.EntityTypes(), modelEnd1Entity, modelEnd2Entity)) { if (dialog.ShowDialog() == DialogResult.OK) { try { Store.RuleManager.DisableRule(typeof(Association_AddRule)); using (var t = Store.TransactionManager.BeginTransaction(EntityDesignerResources.Tx_AddAssociation)) { t.Context.Add(EfiTransactionOriginator.TransactionOriginatorDiagramId, DiagramId); ViewModelChangeContext.GetNewOrExistingContext(t).ViewModelChanges.Add(new Association_AddFromDialog(dialog)); t.Commit(); } } finally { Store.RuleManager.EnableRule(typeof(Association_AddRule)); } } } }