예제 #1
0
        /// <summary>
        /// Update our reading to reflect the current selection
        /// </summary>
        protected override void OnORMSelectionContainerChanged()
        {
            if (myEditor == null)
            {
                return;
            }
            ICollection selectedObjects;

            if (CurrentORMSelectionContainer != null && (null != (selectedObjects = base.GetSelectedComponents())) && selectedObjects.Count == 1)
            {
                foreach (object selectedObject in selectedObjects)
                {
                    ObjectType testObjectType;
                    FactType   testFactType;
                    if (null != (testObjectType = EditorUtility.ResolveContextInstance(selectedObject, false) as ObjectType))
                    {
                        if (testObjectType.IsValueType)
                        {
                            SelectedValueType = testObjectType;
                        }
                        else
                        {
                            SelectedEntityType = testObjectType;
                        }
                    }
                    else if (null != (testFactType = ORMEditorUtility.ResolveContextFactType(selectedObject) as FactType))
                    {
                        // For a role selection on non-link fact type with an implied population,
                        // show the proxy object type instead of the readonly proxied fact type view.
                        // This allows us to directly edit the implied population, including repair
                        // of population mandatory errors that display on the role of a fact type
                        // with an implied population.
                        FactTypeInstanceImplication implication;
                        if (selectedObject is Role &&
                            (implication = new FactTypeInstanceImplication(testFactType)).IsImplied &&
                            implication.ImpliedProxyRole == null &&
                            implication.IdentifyingSupertype != null)
                        {
                            SelectedEntityType = implication.ImpliedByEntityType;
                        }
                        else
                        {
                            SelectedFactType = testFactType;
                        }
                    }
                    else
                    {
                        NullSelection();
                    }
                }
            }
            else
            {
                NullSelection();
            }
        }
예제 #2
0
        /// <summary>
        /// Attempts to fix a PopulationMandatoryError
        /// </summary>
        /// <param name="error">Error to be corrected</param>
        /// <param name="autoCorrectRole">The <see cref="Role"/> to correct the error for.</param>
        /// <param name="autoCorrectFactType">If the <paramref name="autoCorrectRole"/> is not specified, select
        /// a unique constrained role from this <see cref="FactType"/></param>
        /// <returns><see langword="true"/> if the error was automatically corrected.</returns>
        public bool AutoCorrectMandatoryError(PopulationMandatoryError error, Role autoCorrectRole, FactType autoCorrectFactType)
        {
            bool retVal = false;
            ObjectTypeInstance             objectInstance  = error.ObjectTypeInstance;
            LinkedElementCollection <Role> constraintRoles = error.MandatoryConstraint.RoleCollection;

            // If the constraint has multiple roles, then we need to pick
            // a role to activate. This is trivial for a simple mandatory
            // constraint, or if a role in the constraint is selected. However,
            // if we have only a FactType selection, then there may be multiple
            // potential roles in the constraint for ring situations.
            if (constraintRoles.Count == 1)
            {
                autoCorrectRole     = constraintRoles[0];
                autoCorrectFactType = autoCorrectRole.FactType;
            }
            else
            {
                // We're only interested in one selected item, this code
                // path should not be running with multiple items selected.
                if (autoCorrectRole == null)
                {
                    if (autoCorrectFactType != null)
                    {
                        foreach (Role testRole in constraintRoles)
                        {
                            if (testRole.FactType == autoCorrectFactType)
                            {
                                if (autoCorrectRole == null)
                                {
                                    autoCorrectRole = testRole;
                                }
                                else
                                {
                                    // Ambiguous selection, there is nothing further we can do
                                    autoCorrectRole = null;
                                    break;
                                }
                            }
                        }
                    }
                }
                else if (autoCorrectFactType == null)
                {
                    autoCorrectFactType = autoCorrectRole.FactType;
                }
            }
            if (autoCorrectFactType != null)
            {
                // Verify the selection, which needs to be set before this method is called
                SubtypeFact subtypeFact;
                bool        correctSelection;
                if (CurrentFrameVisibility != FrameVisibility.Visible)
                {
                    // If the window is not active then it does not have a selection
                    this.ShowNoActivate();
                }
                if (null != (subtypeFact = autoCorrectFactType as SubtypeFact) &&
                    subtypeFact.ProvidesPreferredIdentifier)
                {
                    ObjectType subtype = subtypeFact.Subtype;
                    ObjectType selectedEntityType;
                    FactType   objectifiedFactType;
                    correctSelection = (null != (selectedEntityType = SelectedEntityType) && selectedEntityType == subtype) ||
                                       (null != (objectifiedFactType = subtype.NestedFactType) && objectifiedFactType == SelectedFactType);
                }
                else if (!(correctSelection = SelectedFactType == autoCorrectFactType))
                {
                    FactTypeInstanceImplication implication = new FactTypeInstanceImplication(autoCorrectFactType);
                    correctSelection = implication.IsImplied && implication.ImpliedProxyRole == null && implication.IdentifyingSupertype != null && implication.ImpliedByEntityType == SelectedEntityType;
                }
                if (correctSelection)
                {
                    this.Show();
                    if (autoCorrectRole != null)
                    {
                        retVal = myEditor.AutoCorrectMandatoryError(error, autoCorrectRole);
                    }
                }
            }
            return(retVal);
        }
		/// <summary>
		/// Attempts to fix a PopulationMandatoryError
		/// </summary>
		/// <param name="error">Error to be corrected</param>
		/// <param name="autoCorrectRole">The <see cref="Role"/> to correct the error for.</param>
		/// <param name="autoCorrectFactType">If the <paramref name="autoCorrectRole"/> is not specified, select
		/// a unique constrained role from this <see cref="FactType"/></param>
		/// <returns><see langword="true"/> if the error was automatically corrected.</returns>
		public bool AutoCorrectMandatoryError(PopulationMandatoryError error, Role autoCorrectRole, FactType autoCorrectFactType)
		{
			bool retVal = false;
			ObjectTypeInstance objectInstance = error.ObjectTypeInstance;
			LinkedElementCollection<Role> constraintRoles = error.MandatoryConstraint.RoleCollection;

			// If the constraint has multiple roles, then we need to pick
			// a role to activate. This is trivial for a simple mandatory
			// constraint, or if a role in the constraint is selected. However,
			// if we have only a FactType selection, then there may be multiple
			// potential roles in the constraint for ring situations.
			if (constraintRoles.Count == 1)
			{
				autoCorrectRole = constraintRoles[0];
				autoCorrectFactType = autoCorrectRole.FactType;
			}
			else
			{
				// We're only interested in one selected item, this code
				// path should not be running with multiple items selected.
				if (autoCorrectRole == null)
				{
					if (autoCorrectFactType != null)
					{
						foreach (Role testRole in constraintRoles)
						{
							if (testRole.FactType == autoCorrectFactType)
							{
								if (autoCorrectRole == null)
								{
									autoCorrectRole = testRole;
								}
								else
								{
									// Ambiguous selection, there is nothing further we can do
									autoCorrectRole = null;
									break;
								}
							}
						}
					}
				}
				else if (autoCorrectFactType == null)
				{
					autoCorrectFactType = autoCorrectRole.FactType;
				}
			}
			if (autoCorrectFactType != null)
			{
				// Verify the selection, which needs to be set before this method is called
				SubtypeFact subtypeFact;
				bool correctSelection;
				if (CurrentFrameVisibility != FrameVisibility.Visible)
				{
					// If the window is not active then it does not have a selection
					this.ShowNoActivate();
				}
				if (null != (subtypeFact = autoCorrectFactType as SubtypeFact) &&
					subtypeFact.ProvidesPreferredIdentifier)
				{
					ObjectType subtype = subtypeFact.Subtype;
					ObjectType selectedEntityType;
					FactType objectifiedFactType;
					correctSelection = (null != (selectedEntityType = SelectedEntityType) && selectedEntityType == subtype) ||
						(null != (objectifiedFactType = subtype.NestedFactType) && objectifiedFactType == SelectedFactType);
				}
				else if (!(correctSelection = SelectedFactType == autoCorrectFactType))
				{
					FactTypeInstanceImplication implication = new FactTypeInstanceImplication(autoCorrectFactType);
					correctSelection = implication.IsImplied && implication.ImpliedProxyRole == null && implication.IdentifyingSupertype != null && implication.ImpliedByEntityType == SelectedEntityType;
				}
				if (correctSelection)
				{
					this.Show();
					if (autoCorrectRole != null)
					{
						retVal = myEditor.AutoCorrectMandatoryError(error, autoCorrectRole);
					}
				}
			}
			return retVal;
		}
		/// <summary>
		/// Update our reading to reflect the current selection
		/// </summary>
		protected override void OnORMSelectionContainerChanged()
		{
			if (myEditor == null)
			{
				return;
			}
			ICollection selectedObjects;
			if (CurrentORMSelectionContainer != null && (null != (selectedObjects = base.GetSelectedComponents())) && selectedObjects.Count == 1)
			{
				foreach (object selectedObject in selectedObjects)
				{
					ObjectType testObjectType;
					FactType testFactType;
					if (null != (testObjectType = EditorUtility.ResolveContextInstance(selectedObject, false) as ObjectType))
					{
						if (testObjectType.IsValueType)
						{
							SelectedValueType = testObjectType;
						}
						else
						{
							SelectedEntityType = testObjectType;
						}
					}
					else if (null != (testFactType = ORMEditorUtility.ResolveContextFactType(selectedObject) as FactType))
					{
						// For a role selection on non-link fact type with an implied population,
						// show the proxy object type instead of the readonly proxied fact type view.
						// This allows us to directly edit the implied population, including repair
						// of population mandatory errors that display on the role of a fact type
						// with an implied population.
						FactTypeInstanceImplication implication;
						if (selectedObject is Role &&
							(implication = new FactTypeInstanceImplication(testFactType)).IsImplied &&
							implication.ImpliedProxyRole == null &&
							implication.IdentifyingSupertype != null)
						{
							SelectedEntityType = implication.ImpliedByEntityType;
						}
						else
						{
							SelectedFactType = testFactType;
						}
					}
					else
					{
						NullSelection();
					}
				}
			}
			else
			{
				NullSelection();
			}
		}