private void DisplayTree_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { var position = e.GetPosition(this.DisplayTree); var hitItem = this.DisplayTree.InputHitTest(position) as DependencyObject; if (hitItem != null && hitItem != this.DisplayTree) { var item = FindAncestor <TreeViewItem>(hitItem); // we might have been clicked without having a treeview item selected if (item == null) { return; } var structure = item.Header as ModelSystemDisplayStructure; this.SelectedModule = structure.Structure; if (structure.Structure != null) { if (structure.Structure.IsCollection) { ((UMSIContextMenu)this.ContextMenu).SetData( this.RootModule, ModelSystemStructure.GetParent(this.RootModule, structure.Structure), structure.Structure); } else { ((UMSIContextMenu)this.ContextMenu).SetData( ModelSystemStructure.CheckForRootModule(this.RootModule, structure.Structure, ModelSystemStructure.GetRootRequirement(structure.Structure.Type)), ModelSystemStructure.GetParent(this.RootModule, structure.Structure), structure.Structure); } } } }
private bool IsAssignable(IModelSystemStructure rootStructure, IModelSystemStructure parentStructure, IModelSystemStructure selectedElement) { // This will update what module we are using for the root as per the Re-rootable extension for XTMF try { var parent = parentStructure == null ? typeof(IModelSystemTemplate) : parentStructure.Type; if (this.CopyBuffer.IsCollection) { // Make sure that we are doing collection to collection and that they are of the right types if (!selectedElement.IsCollection || !selectedElement.ParentFieldType.IsAssignableFrom(this.CopyBuffer.ParentFieldType)) { return(false); } // now make sure that every new element is alright with the parent and root var parentType = selectedElement.ParentFieldType; var arguements = parentType.IsArray ? parentType.GetElementType() : parentType.GetGenericArguments()[0]; foreach (var member in this.CopyBuffer.Children) { var t = member.Type; if (arguements.IsAssignableFrom(t) && (parent == null || ModelSystemStructure.CheckForParent(parent, t)) && ModelSystemStructure.CheckForRootModule(rootStructure, selectedElement, t) != null) { return(true); } } } else { var t = this.CopyBuffer.Type; rootStructure = ModelSystemStructure.CheckForRootModule(rootStructure, selectedElement, t); if (selectedElement.IsCollection) { var parentType = selectedElement.ParentFieldType; var arguements = parentType.IsArray ? parentType.GetElementType() : parentType.GetGenericArguments()[0]; if (arguements.IsAssignableFrom(t) && (ModelSystemStructure.CheckForParent(parent, t)) && ModelSystemStructure.CheckForRootModule(rootStructure, selectedElement, t) != null) { return(true); } } else { if (selectedElement.ParentFieldType.IsAssignableFrom(t) && (parent == null || ModelSystemStructure.CheckForParent(parent, t)) && ModelSystemStructure.CheckForRootModule(rootStructure, selectedElement, t) != null) { return(true); } } } } catch { return(false); } return(false); }
private IModelSystemStructure GetRoot(IModelSystemStructure rootFor) { return(ModelSystemStructure.CheckForRootModule(this.Root, rootFor, ModelSystemStructure.GetRootRequirement(rootFor.Type))); }