コード例 #1
0
        /// <summary>
        /// Checks to see if the Model Element contains errors
        /// </summary>
        /// <param name="modelElement">Any <see cref="ModelElement"/>. Errors may be reported if the element implements <see cref="IModelErrorOwner"/></param>
        /// <param name="useFilter">The filter for the error being displayed. See <see cref="ModelErrorUses"/> for more information.</param>
        /// <param name="displayFilter">The <see cref="ModelErrorDisplayFilter"/> filter to determine if errors should be displayed or not.</param>
        /// <returns>Returns <see langword="true"/> if the errors are present for the provided filters</returns>
        public static bool HasErrors(ModelElement modelElement, ModelErrorUses useFilter, ModelErrorDisplayFilter displayFilter)
        {
            bool             hasError   = false;
            IModelErrorOwner errorOwner = modelElement as IModelErrorOwner;

            if (errorOwner != null)
            {
                foreach (ModelErrorUsage usage in errorOwner.GetErrorCollection(useFilter))
                {
                    if (ModelError.IsDisplayed(usage.Error, displayFilter))
                    {
                        hasError = true;
                        break;
                    }
                }
            }
            return(hasError);
        }
コード例 #2
0
        /// <summary>
        /// Attempt to activate an activatable error.
        /// </summary>
        /// <param name="e">DiagramPointEventArgs. Indicates the element to activate.</param>
        /// <returns>true if an error was activated</returns>
        public static bool AttemptErrorActivation(DiagramPointEventArgs e)
        {
            bool retVal = false;

            if (!e.Handled)
            {
                DiagramClientView clientView = e.DiagramClientView;
                MouseAction       action     = clientView.ActiveMouseAction;
                if ((action == null || !(action is ConnectAction || action is ToolboxAction)) &&
                    clientView.Selection.Count == 1)
                {
                    DiagramItem           diagramItem = e.DiagramHitTestInfo.HitDiagramItem;
                    IModelErrorActivation activator   = diagramItem.Shape as IModelErrorActivation;
                    if (activator != null)
                    {
                        IModelErrorOwner errorOwner = null;
                        foreach (ModelElement mel in diagramItem.RepresentedElements)
                        {
                            errorOwner = EditorUtility.ResolveContextInstance(mel, false) as IModelErrorOwner;
                            break;
                        }
                        if (errorOwner != null)
                        {
                            ModelErrorDisplayFilter displayFilter = null;
                            ORMDiagram diagram;
                            ORMModel   model;
                            if (null != (diagram = diagramItem.Diagram as ORMDiagram) &&
                                null != (model = diagram.ModelElement as ORMModel))
                            {
                                displayFilter = model.ModelErrorDisplayFilter;
                            }
                            MouseAction startingMouseAction = clientView.ActiveMouseAction;
                            foreach (ModelError error in errorOwner.GetErrorCollection(ModelErrorUses.DisplayPrimary))
                            {
                                if (ModelError.IsDisplayed(error, displayFilter))
                                {
                                    if (activator.ActivateModelError(error))
                                    {
                                        // UNDONE: MSBUG Report Microsoft bug DiagramClientView.OnDoubleClick is checking
                                        // for an active mouse action after the double click and clearing it if it is set.
                                        // This may be appropriate if the mouse action was set before the subfield double
                                        // click and did not change during the callback, but is definitely not appropriate
                                        // if the double click activated the mouse action.
                                        // Note that this bug makes it impossible to override OnDoubleClick and OnSubFieldDoubleClick
                                        // because e.Handled cannot be reliably checked, so there is no way to call base.OnDoubleClick
                                        // of base.OnSubFieldDoubleClick from a more derived class without attempting error activation
                                        // twice. If this is fixed, then any OnDoubleClick/OnSubFieldDoubleClick implementation
                                        // that simply defers to this method then calls the base can be eliminated in favor
                                        // of the same methods here.
                                        if (clientView.ActiveMouseAction == startingMouseAction)
                                        {
                                            e.Handled = true;
                                        }
                                        retVal = true;
                                        break;
                                    }
                                    else
                                    {
                                        if (!retVal)
                                        {
                                            IORMToolTaskItem     task;
                                            IORMToolServices     services;
                                            IORMToolTaskProvider provider;
                                            if (null != (task = error.TaskData as IORMToolTaskItem) &&
                                                null != (services = error.Store as IORMToolServices) &&
                                                null != (provider = services.TaskProvider))
                                            {
                                                if (provider.NavigateTo(task))
                                                {
                                                    retVal = true;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(retVal);
        }