Пример #1
0
        /// <summary>
        /// Update our reading to reflect the current selection
        /// </summary>
        protected override void OnORMSelectionContainerChanged()
        {
            if (CurrentORMSelectionContainer != null)
            {
                ICollection selectedObjects = base.GetSelectedComponents();
                FactType    theFact         = null;
                FactType    secondaryFact   = null;
                if (selectedObjects != null)
                {
                    foreach (object element in selectedObjects)
                    {
                        FactType testFact = ORMEditorUtility.ResolveContextFactType(element);
                        // Handle selection of multiple elements as long as
                        // they all resolve to the same fact
                        if (theFact == null)
                        {
                            theFact = testFact;
                            Role                 testImpliedRole;
                            RoleProxy            proxy;
                            ObjectifiedUnaryRole objectifiedUnaryRole;
                            if (null != (testImpliedRole = element as Role))
                            {
                                if (null != (proxy = testImpliedRole.Proxy))
                                {
                                    secondaryFact = proxy.FactType;
                                }
                                else if (null != (objectifiedUnaryRole = testImpliedRole.ObjectifiedUnaryRole))
                                {
                                    secondaryFact = objectifiedUnaryRole.FactType;
                                }
                            }
                        }
                        else if (testFact != theFact)
                        {
                            theFact = null;
                            break;
                        }
                        else
                        {
                            secondaryFact = null;
                        }
                    }
                }
                if (theFact != null && theFact.HasImplicitReadings)
                {
                    theFact       = null;
                    secondaryFact = null;
                }

                ActiveFactType activeFact = EditingFactType;

                FactType currentFact        = activeFact.FactType;
                FactType currentImpliedFact = activeFact.ImpliedFactType;

                if (theFact == null && currentFact != null)
                {
                    EditingFactType = ActiveFactType.Empty;
                }
                //selection could change between the shapes that are related to the fact
                else if (theFact != currentFact || secondaryFact != currentImpliedFact)
                {
                    ReadOnlyCollection <RoleBase> displayOrder = null;
                    IORMDesignerView designerView;
                    DiagramView      designer;
                    if (null != (designerView = CurrentORMSelectionContainer as IORMDesignerView) &&
                        null != (designer = designerView.CurrentDesigner))
                    {
                        SelectedShapesCollection shapes = designer.DiagramClientView.Selection;
                        if (shapes.Count == 1)
                        {
                            DiagramItem item = null;
                            foreach (DiagramItem iter in shapes)
                            {
                                item = iter;
                                break;
                            }
                            ShapeElement  shape     = item.Shape;
                            FactTypeShape factShape = shape as FactTypeShape;
                            while (factShape == null)
                            {
                                shape = shape.ParentShape;
                                if (shape == null)
                                {
                                    break;
                                }
                                factShape = shape as FactTypeShape;
                            }
                            if (factShape != null)
                            {
                                FactType        shapeFactType = factShape.AssociatedFactType;
                                Objectification objectification;
                                if (shapeFactType == theFact)
                                {
                                    displayOrder = new ReadOnlyCollection <RoleBase>(factShape.DisplayedRoleOrder);
                                }
                                else if (secondaryFact == null &&
                                         null != (objectification = shapeFactType.ImpliedByObjectification) &&
                                         objectification.NestedFactType == theFact)
                                {
                                    secondaryFact = shapeFactType;
                                }
                            }
                        }
                    }
                    EditingFactType = new ActiveFactType(theFact, secondaryFact, displayOrder);
                }
            }
            else
            {
                EditingFactType = ActiveFactType.Empty;
            }
        }
Пример #2
0
		/// <summary>
		/// Update our reading to reflect the current selection
		/// </summary>
		protected override void OnORMSelectionContainerChanged()
		{
			if (CurrentORMSelectionContainer != null)
			{
				ICollection selectedObjects = base.GetSelectedComponents();
				FactType theFact = null;
				FactType secondaryFact = null;
				if (selectedObjects != null)
				{
					foreach (object element in selectedObjects)
					{
						FactType testFact = ORMEditorUtility.ResolveContextFactType(element);
						// Handle selection of multiple elements as long as
						// they all resolve to the same fact
						if (theFact == null)
						{
							theFact = testFact;
							Role testImpliedRole;
							RoleProxy proxy;
							ObjectifiedUnaryRole objectifiedUnaryRole;
							if (null != (testImpliedRole = element as Role))
							{
								if (null != (proxy = testImpliedRole.Proxy))
								{
									secondaryFact = proxy.FactType;
								}
								else if (null != (objectifiedUnaryRole = testImpliedRole.ObjectifiedUnaryRole))
								{
									secondaryFact = objectifiedUnaryRole.FactType;
								}
							}
						}
						else if (testFact != theFact)
						{
							theFact = null;
							break;
						}
						else
						{
							secondaryFact = null;
						}
					}
				}
				if (theFact != null && theFact.HasImplicitReadings)
				{
					theFact = null;
					secondaryFact = null;
				}

				ActiveFactType activeFact = EditingFactType;

				FactType currentFact = activeFact.FactType;
				FactType currentImpliedFact = activeFact.ImpliedFactType;

				if (theFact == null && currentFact != null)
				{
					EditingFactType = ActiveFactType.Empty;
				}
				//selection could change between the shapes that are related to the fact
				else if (theFact != currentFact || secondaryFact != currentImpliedFact)
				{
					ReadOnlyCollection<RoleBase> displayOrder = null;
					IORMDesignerView designerView;
					DiagramView designer;
					if (null != (designerView = CurrentORMSelectionContainer as IORMDesignerView) &&
						null != (designer = designerView.CurrentDesigner))
					{
						SelectedShapesCollection shapes = designer.DiagramClientView.Selection;
						if (shapes.Count == 1)
						{
							DiagramItem item = null;
							foreach (DiagramItem iter in shapes)
							{
								item = iter;
								break;
							}
							ShapeElement shape = item.Shape;
							FactTypeShape factShape = shape as FactTypeShape;
							while (factShape == null)
							{
								shape = shape.ParentShape;
								if (shape == null)
								{
									break;
								}
								factShape = shape as FactTypeShape;
							}
							if (factShape != null)
							{
								FactType shapeFactType = factShape.AssociatedFactType;
								Objectification objectification;
								if (shapeFactType == theFact)
								{
									displayOrder = new ReadOnlyCollection<RoleBase>(factShape.DisplayedRoleOrder);
								}
								else if (secondaryFact == null &&
									null != (objectification = shapeFactType.ImpliedByObjectification) &&
									objectification.NestedFactType == theFact)
								{
									secondaryFact = shapeFactType;
								}
							}
						}
					}
					EditingFactType = new ActiveFactType(theFact, secondaryFact, displayOrder);
				}
			}
			else
			{
				EditingFactType = ActiveFactType.Empty;
			}
		}