public void UnGroup(GroupViewModel groupVM) { GroupViewModel targetVM = groupVM; List <WidgetViewModBase> WidgetChildren = targetVM.WidgetChildren; foreach (WidgetViewModBase item in WidgetChildren) { item.ParentID = Guid.Empty; } IGroups ChildGroups = targetVM.GroupChildren; //======================================================render the group //Create the external Groups List <WidgetViewModBase> GroupVMs = new List <WidgetViewModBase>(); foreach (IGroup it in ChildGroups) { WidgetViewModBase vmItem = WidgetFactory.CreateGroup(it); if (vmItem == null) { return; } vmItem.IsGroup = true; GroupVMs.Add(vmItem); } //Remove the parent group targetVM.IsSelected = false; _selectionService.RemoveWidget(targetVM); Items.Remove(targetVM); //Initialize the new Group //if (GroupVMs.Count <= 0) // return; foreach (WidgetViewModBase wdg in Items) { foreach (GroupViewModel group in GroupVMs) { if (true == group.IsChild(wdg.widgetGID, false)) { wdg.ParentID = group.widgetGID; wdg.IsGroup = false; wdg.IsSelected = false; group.AddChild(wdg); } } } //UI Render the Groups foreach (GroupViewModel group in GroupVMs) { group.Status = GroupStatus.Selected; Items.Add(group); group.Refresh(); } //=========================================== //Select new childreb foreach (WidgetViewModBase item in WidgetChildren) { if (item.ParentID == Guid.Empty) { item.IsSelected = true; item.IsGroup = false; } } //Last _model.UnGroup(groupVM.WidgetID); _ListEventAggregator.GetEvent <GroupChangedEvent>().Publish(false); }
private List <WidgetViewModBase> CreateVMObjects(IObjectContainer container) { List <WidgetViewModBase> all = new List <WidgetViewModBase>(); //common widget foreach (IWidget newItem in container.WidgetList) { if (newItem != null && newItem.ParentGroup == null) { WidgetViewModBase vmItem = WidgetFactory.CreateWidget(newItem); vmItem.ParentPageVM = this; all.Add(vmItem); } } //common master foreach (IMaster newItem in container.MasterList) { if (newItem != null && newItem.ParentGroup == null) { WidgetViewModBase vmItem = WidgetFactory.CreateWidget(newItem); vmItem.ParentPageVM = this; all.Add(vmItem); } } //master and it's all children foreach (IGroup newGroup in container.GroupList) { GroupViewModel vmGroup = null; if (newGroup != null && newGroup.ParentGroup == null) { vmGroup = WidgetFactory.CreateGroup(newGroup) as GroupViewModel; vmGroup.IsGroup = true; vmGroup.Status = GroupStatus.Selected; } List <IRegion> children = new List <IRegion>(); GetWidgetChildren(newGroup, children); if (children.Count < 1 || vmGroup == null) { continue; } all.Add(vmGroup); foreach (IRegion item in children) { WidgetViewModBase vmChild = WidgetFactory.CreateWidget(item); if (vmChild == null) { continue; } vmChild.IsGroup = false; vmChild.ParentID = newGroup.Guid; vmChild.IsSelected = false; vmGroup.AddChild(vmChild); all.Add(vmChild); } } return(all); }