protected internal CurrentModelSelection GetCurrentSelectedPersistentType() { CurrentModelSelection result = new CurrentModelSelection(); result.DocData = Owner.GetModelingDocData(); result.DiagramDocView = Owner.GetDiagramDocView(); result.CurrentSelection = Owner.CurrentSelection; result.IsPersistentTypeSelected = Owner.CurrentSelection.OfType <PersistentShape>().Count() == 1; result.IsCompartmentSelected = Owner.CurrentSelection.OfType <Compartment>().Count() == 1; if (result.IsPersistentTypeSelected || result.IsCompartmentSelected) { if (result.IsPersistentTypeSelected) { result.CurrentPersistentType = Owner.CurrentSelection.OfType <PersistentShape>().Select(shape => shape.ModelElement).OfType <PersistentType>().Single(); } else { Compartment compartment = Owner.CurrentSelection.OfType <Compartment>().Single(); result.CompartmentName = compartment.Name; result.CurrentPersistentType = (PersistentType)compartment.ParentShape.ModelElement; } } return(result); }
public override void QueryStatus(MenuCommand menuCommand) { CurrentModelSelection modelSelection = GetCurrentSelectedPersistentType(); bool enabled = modelSelection.GetFromSelection <EntityDiagram>(false).Any(); menuCommand.Enabled = enabled; menuCommand.Visible = enabled; }
public override void QueryStatus(MenuCommand menuCommand) { CurrentModelSelection modelSelection = GetCurrentSelectedPersistentType(); bool enabled = modelSelection.GetFromSelection <Interface>().Where(item => item.TypeKind == PersistentTypeKind.Interface).Count() == 1; menuCommand.Enabled = enabled; menuCommand.Visible = enabled; }
protected override void InternalQueryStatus(MenuCommand menuCommand, CurrentModelSelection currentSelection, bool compartmentNavigationProperties, bool compartmentIndexes) { var currentPersistentType = currentSelection.CurrentPersistentType; menuCommand.Visible = (currentSelection.IsCompartmentSelected && !compartmentNavigationProperties && !compartmentIndexes) || (currentSelection.IsPersistentTypeSelected && currentPersistentType.TypeKind != PersistentTypeKind.Structure); }
public override void QueryStatus(MenuCommand menuCommand) { CurrentModelSelection modelSelection = GetCurrentSelectedPersistentType(); bool selectedEntityDiagram = modelSelection.GetFromSelection <EntityDiagram>(false).Any(); menuCommand.Visible = selectedEntityDiagram || (modelSelection.IsPersistentTypeSelected && modelSelection.CurrentPersistentType.TypeKind.In(PersistentTypeKind.Entity, PersistentTypeKind.Interface, PersistentTypeKind.Structure)); }
protected override void InternalQueryStatus(MenuCommand menuCommand, CurrentModelSelection currentSelection, bool compartmentNavigationProperties, bool compartmentIndexes) { // menuCommand.Visible = !compartmentNavigationProperties && !compartmentIndexes; // if (menuCommand.Visible && currentSelection.IsPersistentTypeSelected) // { // menuCommand.Visible = // !currentSelection.CurrentPersistentType.TypeKind.In(PersistentTypeKind.ExternalType, // PersistentTypeKind.TypedEntitySet); // } var currentPersistentType = currentSelection.CurrentPersistentType; menuCommand.Visible = (currentSelection.IsCompartmentSelected && !compartmentNavigationProperties && !compartmentIndexes) || (currentSelection.IsPersistentTypeSelected && currentPersistentType.TypeKind.In(PersistentTypeKind.ExternalType, PersistentTypeKind.TypedEntitySet)); }
public override void QueryStatus(MenuCommand menuCommand) { CurrentModelSelection currentSelection = GetCurrentSelectedPersistentType(); bool compartmentNavigationProperties = currentSelection.IsCompartmentSelected && Util.StringEqual(currentSelection.CompartmentName, COMPARTMENT_NAME_NAVIGATION_PROPERTIES, true); bool compartmentIndexes = currentSelection.IsCompartmentSelected && Util.StringEqual(currentSelection.CompartmentName, COMPARTMENT_NAME_INDEXES, true); menuCommand.Visible = currentSelection.IsPersistentTypeSelected && !currentSelection.CurrentPersistentType.TypeKind.In(PersistentTypeKind.ExternalType, PersistentTypeKind.TypedEntitySet); var selectedShapesCollection = currentSelection.DiagramDocView.CurrentDesigner.Selection; if (!menuCommand.Visible) { InternalQueryStatus(menuCommand, currentSelection, compartmentNavigationProperties, compartmentIndexes); } }
public override void ExecCommand(MenuCommand menuCommand) { CurrentModelSelection modelSelection = GetCurrentSelectedPersistentType(); EntityDiagram entityDiagram = modelSelection.GetFromSelection <EntityDiagram>(false).Single(); EntityModel entityModel = entityDiagram.Store.ElementDirectory.FindElements <EntityModel>().Single(); IEnumerable <Tuple <string, EntityKind> > existingTypeNames = entityDiagram.Store.ElementDirectory.FindElements <PersistentType>() .Where(item => item.TypeKind.In(PersistentTypeKind.Entity, PersistentTypeKind.Interface, PersistentTypeKind.Structure)) .Select(item => new Tuple <string, EntityKind>(item.Name, ConvertTypeKind(item.TypeKind))); Func <string, EntityKind, PersistentType> findTypeFunc = (typeName, typeKind) => entityDiagram.Store.ElementDirectory .FindElements <PersistentType>() .Where(item => item.Name == typeName && ConvertTypeKind(item.TypeKind) == typeKind) .SingleOrDefault(); FormAddPersistentType.ResultData resultData; if (FormAddPersistentType.DialogShow(existingTypeNames, out resultData)) { modelSelection.MakeActionWithinTransaction(string.Format("Add new {0} with name '{1}'", resultData.TypeKind, resultData.TypeName), delegate { PersistentType newEntity = null; switch (resultData.TypeKind) { case EntityKind.Entity: { newEntity = new Entity(entityModel.Partition); if (resultData.BaseTypeInfo.Item1.HasValue) { Entity entity = (Entity)newEntity; entity.BaseType = findTypeFunc(resultData.BaseTypeInfo.Item2, resultData.BaseTypeInfo.Item1.Value) as EntityBase; } break; } case EntityKind.Structure: { newEntity = new Structure(entityModel.Partition); if (resultData.BaseTypeInfo.Item1.HasValue) { Structure structure = (Structure)newEntity; structure.BaseType = findTypeFunc(resultData.BaseTypeInfo.Item2, resultData.BaseTypeInfo.Item1.Value) as EntityBase; } break; } case EntityKind.Interface: { newEntity = new Interface(entityModel.Partition); if (resultData.BaseTypeInfo.Item1.HasValue) { Interface @interface = (Interface)newEntity; Interface baseInterface = findTypeFunc(resultData.BaseTypeInfo.Item2, resultData.BaseTypeInfo.Item1.Value) as Interface; @interface.InheritedInterfaces.Add(baseInterface); } break; } } newEntity.Name = resultData.TypeName; entityModel.PersistentTypes.Add(newEntity); // create key property if (resultData.KeyPropertyInfo.Item1) { var newProperty = new ScalarProperty(newEntity.Partition); newProperty.Name = resultData.KeyPropertyInfo.Item2; newProperty.KeyAttribute.Enabled = true; Guid typeId = SystemPrimitiveTypesConverter.GetTypeId(resultData.KeyPropertyInfo.Item3); newProperty.Type = (DomainType)entityModel.GetDomainType(typeId); newEntity.Properties.Add(newProperty); } Owner.SelectModelElement((ModelElement)newEntity); }); } }
public override void ExecCommand(MenuCommand menuCommand) { CurrentModelSelection currentSelection = GetCurrentSelectedPersistentType(); IInterface sourceInterface = currentSelection.CurrentPersistentType as IInterface; FormImplementInterface.ImplementData resultData; var helperDic = new Dictionary <IInterface, FormImplementInterface.InterfaceTreeItem>(); var sourceInterfaceItem = new FormImplementInterface.InterfaceTreeItem(sourceInterface.Name, sourceInterface); helperDic.Add(sourceInterface, sourceInterfaceItem); var currentInterfaceItem = sourceInterfaceItem; int currentLevel = 0; var inheritanceTree = InheritanceTreeCache.Get(sourceInterface); //sourceInterface.GetInheritanceTree(); if (!inheritanceTree.TreeRebuilded) { inheritanceTree.RebuildTree(false); } inheritanceTree.IterateTree(false, delegate(InheritanceTreeIterator iterator) { if (iterator.Level != currentLevel) { currentLevel = iterator.Level; currentInterfaceItem = helperDic[iterator.Parent.Interface]; } var childItem = new FormImplementInterface.InterfaceTreeItem(iterator.Current.Interface.Name, iterator.Current.Interface); childItem.Parent = currentInterfaceItem; currentInterfaceItem.Childs.Add(childItem); if (!helperDic.ContainsKey(iterator.Current.Interface)) { helperDic.Add(iterator.Current.Interface, childItem); } }); if (FormImplementInterface.DialogShow("Implement interface into new Entity or Structure", "Type name", sourceInterfaceItem, out resultData)) { PersistentTypeKind typeKind = resultData.EntityKind == EntityKind.Entity ? PersistentTypeKind.Entity : PersistentTypeKind.Structure; var rootItem = resultData.Root; IInterface rootInterface = (IInterface)rootItem.Data; (sourceInterface as PersistentType).Store.MakeActionWithinTransaction( string.Format( "Implementing root interface '{0}' (with in/direct inheritances) to new '{1}' named '{2}'", rootInterface.Name, typeKind, resultData.Name), delegate { IEntityBase newEntity = rootInterface.ImplementToNewType(typeKind, resultData.Name, ImplementTypeOptions.Default); if (newEntity != null) { foreach (var interfaceToImplementItem in resultData.Selection.Where(item => item.Parent == null)) { IInterface interfaceToImplement = (IInterface)interfaceToImplementItem.Data; if (interfaceToImplement != rootInterface) { interfaceToImplement.ImplementToType(newEntity, ImplementTypeOptions.Default); } } Owner.SelectModelElement((ModelElement)newEntity); } }); } }
public override void ExecCommand(MenuCommand menuCommand) { CurrentModelSelection modelSelection = GetCurrentSelectedPersistentType(); EntityDiagram entityDiagram = modelSelection.GetFromSelection <EntityDiagram>(false).SingleOrDefault(); PersistentType persistentType = modelSelection.IsPersistentTypeSelected ? modelSelection.CurrentPersistentType : null; Store store = persistentType != null ? persistentType.Store : entityDiagram.Store; IEnumerable <PersistentTypeItem> existingTypeNames = store.ElementDirectory.FindElements <PersistentType>() .Where(item => item.TypeKind.In(PersistentTypeKind.Entity, PersistentTypeKind.Interface, PersistentTypeKind.Structure)) .Select(item => new PersistentTypeItem(item.Name, ModelUtil.ConvertTo(item.TypeKind), item.AllProperties.Select(prop => prop.Name).ToArray())); PersistentTypeItem persistentTypeEnd1 = persistentType == null ? null : new PersistentTypeItem( persistentType.Name, ModelUtil.ConvertTo(persistentType.TypeKind), persistentType.AllProperties.Select(prop => prop.Name). ToArray()); Func <PersistentTypeItem, PersistentType> findTypeFunc = (typeItemd) => store.ElementDirectory .FindElements <PersistentType>() .Where(item => item.Name == typeItemd.Name && ModelUtil.ConvertTo(item.TypeKind) == typeItemd.Kind) .SingleOrDefault(); IEnumerable <string> existingAssociations = store.ElementDirectory.FindElements <PersistentTypeHasAssociations>().Select(assoc => assoc.Name).ToArray(); if (existingTypeNames.Count() < 2) { MessageBox.Show("There must be at least 2 persistent types to make association.", "Add Association...", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //FormAddAssociation.ResultData resultData; //if (FormAddAssociation.DialogShow(existingTypeNames, existingAssociations, persistentTypeEnd1, out resultData)) FormAddAssociation.ResultData resultData; if (FormAddAssociation.DialogShow(existingTypeNames, existingAssociations, persistentTypeEnd1, out resultData)) { modelSelection.MakeActionWithinTransaction(string.Format("Add new association '{0}'", resultData.AssociationName), delegate { PersistentType sourcePersistentType = findTypeFunc(resultData.PersistentItem1.TypeItem); PersistentType targetPersistentType = findTypeFunc(resultData.PersistentItem2.TypeItem); IAssociationInfo sourceInfo = new AssociationInfo { Multiplicity = resultData.PersistentItem2.Multiplicity, OnOwnerRemove = AssociationOnRemoveAction.Default, OnTargetRemove = AssociationOnRemoveAction.Default, UseAssociationAttribute = resultData.PersistentItem2.UseAssociationAttribute }; sourceInfo.PairTo.SetAsCustom(resultData.PersistentItem1.PropertyName); IAssociationInfo targetInfo = new AssociationInfo { Multiplicity = resultData.PersistentItem1.Multiplicity, OnOwnerRemove = AssociationOnRemoveAction.Default, OnTargetRemove = AssociationOnRemoveAction.Default, UseAssociationAttribute = resultData.PersistentItem1.UseAssociationAttribute }; targetInfo.PairTo.SetAsCustom(resultData.PersistentItem2.PropertyName); if (resultData.SimpleMode && sourcePersistentType == targetPersistentType) { targetInfo = sourceInfo; targetPersistentType = sourcePersistentType; } var persistentTypesAssociation = AssociationConnectorBuilder.CreatePersistentTypesAssociation(sourcePersistentType, targetPersistentType, sourceInfo, targetInfo, resultData.AssociationName, true, !resultData.SimpleMode); Owner.SelectModelElement((ModelElement)persistentTypesAssociation); }); } }
protected abstract void InternalQueryStatus(MenuCommand menuCommand, CurrentModelSelection currentSelection, bool compartmentNavigationProperties, bool compartmentIndexes);