private static ModelItem FindActivityModelItem(ModelTreeManager modelTreeManager, Activity errorTarget) { // Search the lowest Activity ModelItem lowestModelItem = null; List <Activity> parentChain = GetParentChain(errorTarget); Fx.Assert(parentChain != null, "Cannot find parent chain for " + errorTarget.DisplayName); foreach (Activity parent in parentChain) { lowestModelItem = modelTreeManager.GetModelItem(parent); if (lowestModelItem != null) { break; } } ModelItem foundItem = null; // Find in nearest parent first. if (lowestModelItem != null) { // The foundItem could be null because lowestModelItem is not errorTarget's parent any more. // This happens if background validation hasn't finished updating errorTarget's parent. foundItem = ModelTreeManager.FindFirst(lowestModelItem, (modelItem) => (modelItem.GetCurrentValue() == errorTarget)); } // Not found, search from root. if (foundItem == null) { foundItem = FindActivityModelItemFromRoot(modelTreeManager, errorTarget); } return(foundItem); }
// Find model item and properly create it if necessary. internal static ModelItem FindModelItem(ModelTreeManager modelTreeManager, object sourceDetail) { if (sourceDetail == null) { return(null); } Fx.Assert(modelTreeManager != null, "modelTreeManager != null"); Activity element = sourceDetail as Activity; object errorTarget = sourceDetail; // if source detail is not an Activity, we just expand the model tree to search it. if (element == null) { return(ModelTreeManager.FindFirst(modelTreeManager.Root, (modelItem) => (modelItem.GetCurrentValue() == errorTarget))); } else { return(FindActivityModelItem(modelTreeManager, element)); } }
private static ModelItem FindActivityModelItemFromRoot(ModelTreeManager modelTreeManager, Activity errorTarget) { ModelItem root = modelTreeManager.Root; Fx.Assert(root != null && errorTarget != null, "root != null && errorTarget != null"); ModelProperty property = root.Properties["Properties"]; ModelItem propertiesModelItem = property == null ? null : property.Value; ModelItem foundItem = null; if (propertiesModelItem != null) { // So,search "Properties" first to delay expanding "Implementation" and other properties. foundItem = ModelTreeManager.FindFirst(propertiesModelItem, (modelItem) => (modelItem.GetCurrentValue() == errorTarget)); } // If activity is not in Properties, expand others except Properties. foundItem = foundItem ?? ModelTreeManager.FindFirst( root, (modelItem) => (modelItem.GetCurrentValue() == errorTarget), (modelItem) => { return(modelItem != propertiesModelItem); }); return(foundItem); }