/// <summary>
        /// Manage events associated with the schema customization state.
        /// The primary function of schema customization is to reassociate
        /// schema customizations when a schema is deleted and recreated.
        /// Therefore, the data is maintained outside the transacted store
        /// and must be updated with events to remain consistent across
        /// undo and redo operations.
        /// </summary>
        /// <param name="eventManager">The <see cref="ModelingEventManager"/> to attach
        /// to. The assumption is that this is called for state change events on document
        /// loaded.</param>
        /// <param name="store">The <see cref="Store"/> used to retrieve type information.</param>
        /// <param name="action">The action to take (add or remove the handler)</param>
        public static void ManageModelingEventHandlers(ModelingEventManager eventManager, Store store, EventHandlerAction action)
        {
            DomainDataDirectory dataDir = store.DomainDataDirectory;

            eventManager.AddOrRemoveHandler(dataDir.FindDomainClass(Column.DomainClassId), new EventHandler <ElementPropertyChangedEventArgs>(ColumnPropertyChanged), action);
            eventManager.AddOrRemoveHandler(dataDir.FindDomainClass(Table.DomainClassId), new EventHandler <ElementPropertyChangedEventArgs>(TablePropertyChanged), action);
            eventManager.AddOrRemoveHandler(dataDir.FindDomainClass(Schema.DomainClassId), new EventHandler <ElementPropertyChangedEventArgs>(SchemaPropertyChanged), action);
            eventManager.AddOrRemoveHandler(dataDir.FindDomainRole(TableContainsColumn.ColumnDomainRoleId), new EventHandler <RolePlayerOrderChangedEventArgs>(ColumnOrderChanged), action);
        }
Esempio n. 2
0
        /// <summary>
        /// Manages <see cref="EventHandler{TEventArgs}"/>s in the <see cref="Store"/> for <see cref="ExternalConstraintShape"/>s.
        /// </summary>
        /// <param name="store">The <see cref="Store"/> for which the <see cref="EventHandler{TEventArgs}"/>s should be managed.</param>
        /// <param name="eventManager">The <see cref="ModelingEventManager"/> used to manage the <see cref="EventHandler{TEventArgs}"/>s.</param>
        /// <param name="action">The <see cref="EventHandlerAction"/> that should be taken for the <see cref="EventHandler{TEventArgs}"/>s.</param>
        public static new void ManageEventHandlers(Store store, ModelingEventManager eventManager, EventHandlerAction action)
        {
            DomainDataDirectory dataDirectory = store.DomainDataDirectory;

            eventManager.AddOrRemoveHandler(dataDirectory.FindDomainRole(SetComparisonConstraintHasRoleSequence.RoleSequenceDomainRoleId), new EventHandler <RolePlayerOrderChangedEventArgs>(RolePlayerOrderChangedEvent), action);

            eventManager.AddOrRemoveHandler(dataDirectory.FindDomainProperty(SetComparisonConstraint.ModalityDomainPropertyId), new EventHandler <ElementPropertyChangedEventArgs>(SetComparisonConstraintChangedEvent), action);
            eventManager.AddOrRemoveHandler(dataDirectory.FindDomainProperty(SetConstraint.ModalityDomainPropertyId), new EventHandler <ElementPropertyChangedEventArgs>(SetConstraintChangedEvent), action);

            DomainClassInfo classInfo = dataDirectory.FindDomainRelationship(EntityTypeHasPreferredIdentifier.DomainClassId);

            eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementAddedEventArgs>(PreferredIdentifierAddedEvent), action);
            eventManager.AddOrRemoveHandler(classInfo, new EventHandler <ElementDeletedEventArgs>(PreferredIdentifierRemovedEvent), action);
            eventManager.AddOrRemoveHandler(classInfo, new EventHandler <RolePlayerChangedEventArgs>(PreferredIdentifierRolePlayerChangedEvent), action);
        }
Esempio n. 3
0
        /// <summary>
        /// Manages <see cref="EventHandler{TEventArgs}"/>s in the <see cref="Store"/> for <see cref="TableShape"/>s.
        /// </summary>
        /// <param name="store">The <see cref="Store"/> for which the <see cref="EventHandler{TEventArgs}"/>s should be managed.</param>
        /// <param name="eventManager">The <see cref="ModelingEventManager"/> used to manage the <see cref="EventHandler{TEventArgs}"/>s.</param>
        /// <param name="action">The <see cref="EventHandlerAction"/> that should be taken for the <see cref="EventHandler{TEventArgs}"/>s.</param>
        public static void ManageEventHandlers(Store store, ModelingEventManager eventManager, EventHandlerAction action)
        {
            DomainDataDirectory dataDirectory = store.DomainDataDirectory;
            DomainPropertyInfo  propertyInfo  = dataDirectory.FindDomainProperty(TableShape.UpdateCounterDomainPropertyId);

            eventManager.AddOrRemoveHandler(propertyInfo, new EventHandler <ElementPropertyChangedEventArgs>(UpdateShapeEvent), action);

            if (action == EventHandlerAction.Add)
            {
                // We don't want this rule on. This forces a full repopulation of the compartment,
                // which makes it impossible to determine the old index of a selected item. If this is
                // on, then the ColumnRenamedEvent does not work for the initial transaction.
                store.RuleManager.DisableRule(typeof(CompartmentItemChangeRule));
            }
#if CUSTOMSORT
            propertyInfo = dataDirectory.FindDomainProperty(Column.NameDomainPropertyId);
            eventManager.AddOrRemoveHandler(propertyInfo, new EventHandler <ElementPropertyChangedEventArgs>(ColumnRenamedEvent), action);
#else // CUSTOMSORT
            eventManager.AddOrRemoveHandler(dataDirectory.FindDomainRole(TableContainsColumn.ColumnDomainRoleId), new EventHandler <RolePlayerOrderChangedEventArgs>(ColumnOrderChanged), action);
#endif // CUSTOMSORT
        }
Esempio n. 4
0
        private static void InvalidateIndirectErrorOwnerDisplay(ModelElement element, DomainDataDirectory domainDataDirectory, Predicate <ModelElement> filter)
        {
            IHasIndirectModelErrorOwner indirectOwner = element as IHasIndirectModelErrorOwner;

            if (indirectOwner != null)
            {
                Guid[] metaRoles = indirectOwner.GetIndirectModelErrorOwnerLinkRoles();
                int    roleCount;
                if (metaRoles != null &&
                    0 != (roleCount = metaRoles.Length))
                {
                    if (domainDataDirectory == null)
                    {
                        domainDataDirectory = element.Store.DomainDataDirectory;
                    }
                    for (int i = 0; i < roleCount; ++i)
                    {
                        Debug.Assert(metaRoles[i] != Guid.Empty);
                        DomainRoleInfo metaRole = domainDataDirectory.FindDomainRole(metaRoles[i]);
                        if (metaRole != null)
                        {
                            LinkedElementCollection <ModelElement> counterparts = metaRole.GetLinkedElements(element);
                            int counterpartCount = counterparts.Count;
                            for (int j = 0; j < counterpartCount; ++j)
                            {
                                ModelElement counterpart = counterparts[j];
                                if (filter != null && filter(counterpart))
                                {
                                    continue;
                                }
                                if (counterpart is IModelErrorOwner)
                                {
                                    InvalidateErrorOwnerDisplay(counterpart);
                                }
                                InvalidateIndirectErrorOwnerDisplay(
                                    counterpart,
                                    domainDataDirectory,
                                    delegate(ModelElement testElement)
                                {
                                    return(testElement == element ||
                                           (filter != null && filter(testElement)));
                                });
                            }
                        }
                    }
                }
            }
            ElementLink elementLink;
            IElementLinkRoleHasIndirectModelErrorOwner indirectLinkRoleOwner;

            if (null != (indirectLinkRoleOwner = element as IElementLinkRoleHasIndirectModelErrorOwner) &&
                null != (elementLink = element as ElementLink))
            {
                Guid[] metaRoles = indirectLinkRoleOwner.GetIndirectModelErrorOwnerElementLinkRoles();
                int    roleCount;
                if (metaRoles != null &&
                    0 != (roleCount = metaRoles.Length))
                {
                    if (domainDataDirectory == null)
                    {
                        domainDataDirectory = element.Store.DomainDataDirectory;
                    }
                    for (int i = 0; i < roleCount; ++i)
                    {
                        Debug.Assert(metaRoles[i] != Guid.Empty);
                        DomainRoleInfo metaRole = domainDataDirectory.FindDomainRole(metaRoles[i]);
                        if (metaRole != null)
                        {
                            ModelElement rolePlayer = metaRole.GetRolePlayer(elementLink);
                            if (filter != null && filter(rolePlayer))
                            {
                                continue;
                            }
                            if (rolePlayer is IModelErrorOwner)
                            {
                                InvalidateErrorOwnerDisplay(rolePlayer);
                            }
                            InvalidateIndirectErrorOwnerDisplay(
                                rolePlayer,
                                domainDataDirectory,
                                delegate(ModelElement testElement)
                            {
                                return(testElement == element ||
                                       (filter != null && filter(testElement)));
                            });
                        }
                    }
                }
            }
        }
 private void EnsureDomainAttributesInitialized(DomainDataDirectory domainDataDirectory)
 {
     if (!myCustomPropertyAttributesInitialized)
     {
         lock (LockObject)
         {
             if (!myCustomPropertyAttributesInitialized)
             {
                 ConstraintDisplayPositionDomainPropertyAttributes = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(FactTypeShape.ConstraintDisplayPositionDomainPropertyId));
                 DisplayOrientationDomainPropertyAttributes        = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayOrientationDomainPropertyId));
                 DisplayRelatedTypesDomainPropertyAttributes       = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayRelatedTypesDomainPropertyId));
                 DisplayRoleNamesDomainPropertyAttributes          = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayRoleNamesDomainPropertyId));
                 DisplayAsObjectTypeDomainPropertyAttributes       = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayAsObjectTypeDomainPropertyId));
                 ExpandRefModeDomainPropertyAttributes             = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(FactTypeShape.ExpandRefModeDomainPropertyId));
                 NameDomainPropertyAttributes          = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(ORMNamedElement.NameDomainPropertyId));
                 IsIndependentDomainPropertyAttributes = GetDomainPropertyAttributes(domainDataDirectory.FindDomainProperty(ObjectType.IsIndependentDomainPropertyId));
                 NestedFactTypeDomainRoleAttributes    = AddExpandableElementTypeConverterAttribute(GetRolePlayerPropertyAttributes(domainDataDirectory.FindDomainRole(Objectification.NestedFactTypeDomainRoleId)));
                 NestingTypeDomainRoleAttributes       = AddExpandableElementTypeConverterAttribute(GetRolePlayerPropertyAttributes(domainDataDirectory.FindDomainRole(Objectification.NestingTypeDomainRoleId)));
                 myCustomPropertyAttributesInitialized = true;
             }
         }
     }
 }
        /// <summary>
        /// Show selected properties from the <see cref="FactType.NestingType"/> and the
        /// <see cref="Objectification.NestedFactType"/> for an objectified <see cref="FactType"/>,
        /// as well as expandable nodes for each of the underlying instances.
        /// </summary>
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            FactType factType = ModelElement;

            if (FactTypeShape.ShouldDrawObjectification(factType))
            {
                FactTypeShape       factTypeShape              = PresentationElement;
                Objectification     objectification            = factType.Objectification;
                ObjectType          nestingType                = objectification.NestingType;
                bool                nestingTypeHasRelatedTypes = nestingType.IsSubtypeOrSupertype;
                DomainDataDirectory domainDataDirectory        = factType.Store.DomainDataDirectory;
                EnsureDomainAttributesInitialized(domainDataDirectory);

                PropertyDescriptorCollection retVal;
                if (factTypeShape.DisplayAsObjectType)
                {
                    retVal = new PropertyDescriptorCollection(null);
                    Type componentType = typeof(FactTypeShape);
                    foreach (PropertyDescriptor nestingTypeDescriptor in TypeDescriptor.GetProperties(nestingType))
                    {
                        if (nestingTypeDescriptor.Name == "NestedFactType")
                        {
                            continue;
                        }
                        retVal.Add(EditorUtility.RedirectPropertyDescriptor(nestingType, nestingTypeDescriptor, componentType));
                    }
                    retVal.Add(CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayAsObjectTypeDomainPropertyId), DisplayAsObjectTypeDomainPropertyAttributes));
                    retVal.Add(CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.ExpandRefModeDomainPropertyId), ExpandRefModeDomainPropertyAttributes));
                    retVal.Add(new ObjectifyingEntityTypePropertyDescriptor(factType, domainDataDirectory.FindDomainRole(Objectification.NestingTypeDomainRoleId), NestedFactTypeDomainRoleAttributes));
                    retVal.Add(new ObjectifiedFactTypePropertyDescriptor(nestingType, domainDataDirectory.FindDomainRole(Objectification.NestedFactTypeDomainRoleId), NestingTypeDomainRoleAttributes));
                    if (nestingTypeHasRelatedTypes)
                    {
                        retVal.Add(CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayRelatedTypesDomainPropertyId), DisplayRelatedTypesDomainPropertyAttributes));
                    }
                }
                else
                {
                    PropertyDescriptor[] descriptors = new PropertyDescriptor[nestingTypeHasRelatedTypes ? 9 : 8];
                    descriptors[0] = CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.ConstraintDisplayPositionDomainPropertyId), ConstraintDisplayPositionDomainPropertyAttributes);
                    descriptors[1] = CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayOrientationDomainPropertyId), DisplayOrientationDomainPropertyAttributes);
                    descriptors[2] = CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayRoleNamesDomainPropertyId), DisplayRoleNamesDomainPropertyAttributes);
                    descriptors[3] = CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayAsObjectTypeDomainPropertyId), DisplayAsObjectTypeDomainPropertyAttributes);
                    descriptors[4] = CreatePropertyDescriptor(nestingType, domainDataDirectory.FindDomainProperty(ORMNamedElement.NameDomainPropertyId), NameDomainPropertyAttributes);
                    descriptors[5] = CreatePropertyDescriptor(nestingType, domainDataDirectory.FindDomainProperty(ObjectType.IsIndependentDomainPropertyId), IsIndependentDomainPropertyAttributes);
                    descriptors[6] = new ObjectifyingEntityTypePropertyDescriptor(factType, domainDataDirectory.FindDomainRole(Objectification.NestingTypeDomainRoleId), NestedFactTypeDomainRoleAttributes);
                    descriptors[7] = new ObjectifiedFactTypePropertyDescriptor(nestingType, domainDataDirectory.FindDomainRole(Objectification.NestedFactTypeDomainRoleId), NestingTypeDomainRoleAttributes);
                    if (nestingTypeHasRelatedTypes)
                    {
                        descriptors[8] = CreatePropertyDescriptor(factTypeShape, domainDataDirectory.FindDomainProperty(FactTypeShape.DisplayRelatedTypesDomainPropertyId), DisplayRelatedTypesDomainPropertyAttributes);
                    }
                    retVal = new PropertyDescriptorCollection(descriptors);
                }

                // This mockup of important properties means that extension providers cannot add properties
                // here by adding to the objecttype or facttype. Use an extension on the Objectification type
                // itself to add extension properties.
                ((IFrameworkServices)factType.Store).PropertyProviderService.GetProvidedProperties(objectification, retVal);
                return(retVal);
            }
            return(base.GetProperties(attributes));
        }
Esempio n. 7
0
        private static void WalkAssociatedElementsHelper(ModelElement element, AssociatedErrorElementCallback callback, Predicate <ModelElement> filter)
        {
            if (element is IModelErrorOwner)
            {
                callback(element);
            }
            IHasIndirectModelErrorOwner indirectOwner;
            DomainDataDirectory         domainDataDirectory = null;

            if (null != (indirectOwner = element as IHasIndirectModelErrorOwner))
            {
                Guid[] indirectRoles;
                int    indirectRoleCount;
                if (null != (indirectRoles = indirectOwner.GetIndirectModelErrorOwnerLinkRoles()) &&
                    0 != (indirectRoleCount = indirectRoles.Length))
                {
                    domainDataDirectory = element.Store.DomainDataDirectory;
                    for (int i = 0; i < indirectRoleCount; ++i)
                    {
                        foreach (ModelElement linkedElement in domainDataDirectory.FindDomainRole(indirectRoles[i]).GetLinkedElements(element))
                        {
                            if (filter != null && filter(linkedElement))
                            {
                                continue;
                            }
                            WalkAssociatedElementsHelper(
                                linkedElement,
                                callback,
                                delegate(ModelElement testElement)
                            {
                                return(testElement == element ||
                                       (filter != null && filter(testElement)));
                            });
                        }
                    }
                }
            }
            ElementLink elementLink;
            IElementLinkRoleHasIndirectModelErrorOwner indirectLinkRoleOwner;

            if (null != (indirectLinkRoleOwner = element as IElementLinkRoleHasIndirectModelErrorOwner) &&
                null != (elementLink = element as ElementLink))
            {
                Guid[] metaRoles = indirectLinkRoleOwner.GetIndirectModelErrorOwnerElementLinkRoles();
                int    roleCount;
                if (metaRoles != null &&
                    0 != (roleCount = metaRoles.Length))
                {
                    if (domainDataDirectory == null)
                    {
                        domainDataDirectory = element.Store.DomainDataDirectory;
                    }
                    for (int i = 0; i < roleCount; ++i)
                    {
                        DomainRoleInfo metaRole = domainDataDirectory.FindDomainRole(metaRoles[i]);
                        if (metaRole != null)
                        {
                            ModelElement rolePlayer = metaRole.GetRolePlayer(elementLink);
                            if (filter != null && filter(rolePlayer))
                            {
                                continue;
                            }
                            WalkAssociatedElementsHelper(
                                rolePlayer,
                                callback,
                                delegate(ModelElement testElement)
                            {
                                return(testElement == element ||
                                       (filter != null && filter(testElement)));
                            });
                        }
                    }
                }
            }
        }
Esempio n. 8
0
		private static void InvalidateIndirectErrorOwnerDisplay(ModelElement element, DomainDataDirectory domainDataDirectory, Predicate<ModelElement> filter)
		{
			IHasIndirectModelErrorOwner indirectOwner = element as IHasIndirectModelErrorOwner;
			if (indirectOwner != null)
			{
				Guid[] metaRoles = indirectOwner.GetIndirectModelErrorOwnerLinkRoles();
				int roleCount;
				if (metaRoles != null &&
					0 != (roleCount = metaRoles.Length))
				{
					if (domainDataDirectory == null)
					{
						domainDataDirectory = element.Store.DomainDataDirectory;
					}
					for (int i = 0; i < roleCount; ++i)
					{
						Debug.Assert(metaRoles[i] != Guid.Empty);
						DomainRoleInfo metaRole = domainDataDirectory.FindDomainRole(metaRoles[i]);
						if (metaRole != null)
						{
							LinkedElementCollection<ModelElement> counterparts = metaRole.GetLinkedElements(element);
							int counterpartCount = counterparts.Count;
							for (int j = 0; j < counterpartCount; ++j)
							{
								ModelElement counterpart = counterparts[j];
								if (filter != null && filter(counterpart))
								{
									continue;
								}
								if (counterpart is IModelErrorOwner)
								{
									InvalidateErrorOwnerDisplay(counterpart);
								}
								InvalidateIndirectErrorOwnerDisplay(
									counterpart,
									domainDataDirectory,
									delegate(ModelElement testElement)
									{
										return testElement == element ||
											(filter != null && filter(testElement));
									});
							}
						}
					}
				}
			}
			ElementLink elementLink;
			IElementLinkRoleHasIndirectModelErrorOwner indirectLinkRoleOwner;
			if (null != (indirectLinkRoleOwner = element as IElementLinkRoleHasIndirectModelErrorOwner) &&
				null != (elementLink = element as ElementLink))
			{
				Guid[] metaRoles = indirectLinkRoleOwner.GetIndirectModelErrorOwnerElementLinkRoles();
				int roleCount;
				if (metaRoles != null &&
					0 != (roleCount = metaRoles.Length))
				{
					if (domainDataDirectory == null)
					{
						domainDataDirectory = element.Store.DomainDataDirectory;
					}
					for (int i = 0; i < roleCount; ++i)
					{
						Debug.Assert(metaRoles[i] != Guid.Empty);
						DomainRoleInfo metaRole = domainDataDirectory.FindDomainRole(metaRoles[i]);
						if (metaRole != null)
						{
							ModelElement rolePlayer = metaRole.GetRolePlayer(elementLink);
							if (filter != null && filter(rolePlayer))
							{
								continue;
							}
							if (rolePlayer is IModelErrorOwner)
							{
								InvalidateErrorOwnerDisplay(rolePlayer);
							}
							InvalidateIndirectErrorOwnerDisplay(
								rolePlayer,
								domainDataDirectory,
								delegate(ModelElement testElement)
								{
									return testElement == element ||
										(filter != null && filter(testElement));
								});
						}
					}
				}
			}
		}