public override void EditObject(LookupType type, int objectID) { SiteExplorerNodeViewModel viewModel = null; switch (type) { case LookupType.Material: viewModel = ViewModelFromObjectID(SiteExplorerNodeType.Material, objectID); break; case LookupType.Region: viewModel = ViewModelFromObjectID(SiteExplorerNodeType.Region, objectID); break; case LookupType.Site: viewModel = ViewModelFromObjectID(SiteExplorerNodeType.Site, objectID); break; case LookupType.SiteVisit: viewModel = ViewModelFromObjectID(SiteExplorerNodeType.SiteVisit, objectID); break; case LookupType.Trap: viewModel = ViewModelFromObjectID(SiteExplorerNodeType.Trap, objectID); break; } if (viewModel != null) { _explorer.EditNode(viewModel); } }
private ObservableCollection <HierarchicalViewModelBase> BuildExplorerModel(List <SiteExplorerNode> list, bool isFindModel) { list.Sort((item1, item2) => { int compare = item1.ElemType.CompareTo(item2.ElemType); if (compare == 0) { return(item1.Name.CompareTo(item2.Name)); } return(compare); }); var regionsModel = new ObservableCollection <HierarchicalViewModelBase>(list.ConvertAll((model) => { var viewModel = new SiteExplorerNodeViewModel(model, isFindModel); if (model.NumChildren > 0) { viewModel.Children.Add(new ViewModelPlaceholder("Loading...")); viewModel.LazyLoadChildren += new HierarchicalViewModelAction(viewModel_LazyLoadChildren); } return(viewModel); })); return(regionsModel); }
private void EditNode(SiteExplorerNodeViewModel node, Func <bool, DatabaseCommandControl> editorFactory, PermissionCategory permCategory) { if (node.ElemID < 0) { ErrorMessage.Show("You must first apply the changes before editing the details of this item!"); return; } else { var readOnly = !User.HasPermission(permCategory, PERMISSION_MASK.UPDATE); var editor = editorFactory(readOnly); string caption = ""; var readOnlyStr = readOnly ? "(Read Only)" : ""; if (node.IsTemplate) { caption = string.Format("{0} Template [{1}] {2}", node.NodeType.ToString(), node.ElemID, readOnlyStr); } else { caption = string.Format("{0} Detail {1} [{2}] {3}", node.NodeType.ToString(), node.Name, node.ElemID, readOnlyStr); } PluginManager.Instance.AddNonDockableContent(Owner, editor, caption, SizeToContent.Manual); } }
public DatabaseCommand GetRenameActionForNode(SiteExplorerNodeViewModel selected) { if (selected != null) { switch (selected.NodeType) { case SiteExplorerNodeType.Region: return(new RenameRegionCommand(selected.Model)); case SiteExplorerNodeType.SiteGroup: return(new RenameSiteGroupCommand(selected.Model)); case SiteExplorerNodeType.Site: return(new RenameSiteCommand(selected.Model)); case SiteExplorerNodeType.SiteVisit: return(new RenameSiteVisitCommand(selected.Model)); case SiteExplorerNodeType.Trap: return(new RenameTrapCommand(selected.Model)); case SiteExplorerNodeType.Material: return(new RenameMaterialCommand(selected.Model)); } } return(null); }
public void EditNode(SiteExplorerNodeViewModel node) { switch (node.NodeType) { case SiteExplorerNodeType.Site: EditSite(node); break; case SiteExplorerNodeType.Region: EditRegion(node); break; case SiteExplorerNodeType.SiteGroup: break; case SiteExplorerNodeType.SiteVisit: EditSiteVisit(node); break; case SiteExplorerNodeType.Material: EditMaterial(node); break; case SiteExplorerNodeType.Trap: EditTrap(node); break; } }
public MergeSiteOptions(Window owner, User user, SiteExplorerNodeViewModel source, SiteExplorerNodeViewModel dest) { this.Owner = owner; this.User = user; InitializeComponent(); this.SourceNode = source; this.DestNode = dest; lblCaption.Content = string.Format("Are you sure you want to merge '{0}' with '{1}'?", source.Name, dest.Name); }
private static MenuItem CreateFavoriteMenuItems(MaterialExplorer explorer, SiteExplorerNodeViewModel node) { MenuItemBuilder builder = new MenuItemBuilder(); MenuItem add = builder.New("Add to favorites").MenuItem; add.Items.Add(builder.New("User specific").Handler(() => { explorer.Favorites.AddToFavorites(node, false); }).MenuItem); add.Items.Add(builder.New("Global").Handler(() => { explorer.Favorites.AddToFavorites(node, true); }).MenuItem); return(add); }
internal void EditMaterial(SiteExplorerNodeViewModel material) { EditNode(material, (readOnly) => { var form = new MaterialDetails(User, material.ElemID, readOnly); form.ChangesCommitted += new PendingChangesCommittedHandler((s) => { Refresh(); }); return(form); }, PermissionCategory.SPARC_MATERIAL); }
internal void EditSiteVisit(SiteExplorerNodeViewModel sitevisit) { EditNode(sitevisit, (readOnly) => { var form = new SiteVisitDetails(User, sitevisit.ElemID, readOnly); form.ChangesCommitted += new PendingChangesCommittedHandler((s) => { Refresh(); }); return(form); }, PermissionCategory.SPARC_SITEVISIT); }
internal void RefreshNode(SiteExplorerNodeViewModel parent) { var surrogateModel = new ObservableCollection <HierarchicalViewModelBase>(); surrogateModel.Add(parent); var expanded = GetExpandedParentages(surrogateModel); parent.IsChildrenLoaded = false; parent.IsExpanded = false; ExpandParentages(surrogateModel, expanded); }
private void MergeSites(SiteExplorerNodeViewModel oldNode, SiteExplorerNodeViewModel newNode) { var frm = new MergeSiteOptions(this.FindParentWindow(), User, oldNode, newNode); if (frm.ShowDialog().GetValueOrDefault(false)) { newNode.IsChanged = true; foreach (SiteExplorerNodeViewModel other in frm.SelectedNodes) { other.IsDeleted = true; RegisterPendingChange(new MergeSiteCommand(other.Model, newNode.Model), this); } } }
private void MoveNode(SiteExplorerNodeViewModel source, SiteExplorerNodeViewModel dest) { DatabaseCommand moveAction = null; if (source.Parent == dest) { ErrorMessage.Show("'{0}' is already a child of '{1}'.", source.Name, dest.Name); return; } switch (source.NodeType) { case SiteExplorerNodeType.Site: moveAction = new MoveSiteCommand(source.Model, dest.Model); break; case SiteExplorerNodeType.SiteGroup: moveAction = new MoveSiteGroupCommand(source.Model, dest.Model); break; case SiteExplorerNodeType.Region: moveAction = new MoveRegionCommand(source.Model, dest.Model); break; case SiteExplorerNodeType.SiteVisit: moveAction = new MoveSiteVisitCommand(source.Model, dest.Model); break; case SiteExplorerNodeType.Material: moveAction = new MoveMaterialCommand(source.Model, dest.Model); break; case SiteExplorerNodeType.Trap: moveAction = new MoveTrapCommand(source.Model, dest.Model); break; } if (moveAction != null) { if (source.Parent != null) { source.Parent.Children.Remove(source); } dest.IsChanged = true; dest.IsExpanded = true; dest.Children.Add(source); RegisterPendingChange(moveAction, this); } }
public MaterialForTrapReport(User user, SiteExplorerNodeViewModel trap) : base(user) { this.Trap = trap; RegisterViewer(new TabularDataViewerSource()); DefineColumn("BiotaFullName", "Taxa"); DefineColumn("FullRegion", "Region"); DefineColumn("Local", "Locality"); DefineColumn("FormattedLatLong", "Lat/Long"); DefineColumn("Collectors"); DefineColumn("Dates"); DefineColumn("AccessionNo"); }
protected int FindIDOfParentType(SiteExplorerNodeViewModel node, SiteExplorerNodeType nodeType, int defaultId = -1) { HierarchicalViewModelBase p = node; while (p != null && (p as SiteExplorerNodeViewModel).NodeType != nodeType) { p = p.Parent; } if (p != null) { return((p as SiteExplorerNodeViewModel).ElemID); } return(defaultId); }
private static MenuItem CreateReportMenuItems(SiteExplorerNodeViewModel node, MaterialExplorer explorer) { var builder = new MenuItemBuilder(); MenuItem reports = builder.New("Reports").MenuItem; var list = explorer.Owner.GetReportsForNode(node); foreach (IBioLinkReport report in list) { IBioLinkReport reportToExecute = report; reports.Items.Add(builder.New(report.Name).Handler(() => { PluginManager.Instance.RunReport(explorer.Owner, reportToExecute); }).MenuItem); } return(reports); }
private void AskMoveMergeNode(SiteExplorerNodeViewModel source, SiteExplorerNodeViewModel dest) { // Regions and site groups can either be merged or moved. Need to ask... var frm = new DragDropOptions(this.FindParentWindow()); if (frm.ShowDialog().GetValueOrDefault(false)) { if (frm.DragDropOption == DragDropOption.Merge) { MergeNodes(source, dest); } else { MoveNode(source, dest); } } }
public List <IBioLinkReport> GetReportsForNode(SiteExplorerNodeViewModel node) { List <IBioLinkReport> list = new List <IBioLinkReport>(); switch (node.NodeType) { case SiteExplorerNodeType.Trap: list.Add(new MaterialForTrapReport(User, node)); break; case SiteExplorerNodeType.Site: case SiteExplorerNodeType.Region: list.Add(new TaxaForSiteReport(User, node.Model)); break; } return(list); }
internal void EditRDE(SiteExplorerNodeViewModel node) { RapidDataEntry control = null; if (node != null && (node.NodeType == SiteExplorerNodeType.Site || node.NodeType == SiteExplorerNodeType.SiteVisit || node.NodeType == SiteExplorerNodeType.Material)) { control = new RapidDataEntry(this, User, node.ElemID, node.NodeType, node); } else { control = new RapidDataEntry(this, User, -1, SiteExplorerNodeType.Site, null); } control.ChangesCommitted += new PendingChangesCommittedHandler((s) => { Refresh(); }); PluginManager.Instance.AddNonDockableContent(Owner, control, "RDE", SizeToContent.Manual); }
public void ShowInContents(SiteExplorerNodeViewModel node) { if (node == null) { return; } var parentage = new MaterialService(User).GetSiteExplorerNodeParentage(node.ElemID, node.NodeType); var childlist = RegionsModel; tabMaterial.InvokeIfRequired(() => { tabMaterial.SelectedIndex = 0; // ensure contents tab is showing }); tvwMaterial.InvokeIfRequired(() => { tvwMaterial.Focus(); }); tvwMaterial.InvokeIfRequired(() => { HierarchicalViewModelBase child = null; foreach (SiteExplorerNode element in parentage) { child = childlist.FirstOrDefault((vm) => (vm.ObjectID.HasValue ? vm.ObjectID.Value : 0) == element.ElemID); if (child == null) { break; } if (child.Parent != null && !child.Parent.IsExpanded) { child.Parent.IsExpanded = true; } child.IsExpanded = true; childlist = child.Children; } if (child != null) { tvwMaterial.BringModelToView(child, regionsNode); child.IsSelected = true; } }); }
internal void DeleteNode(SiteExplorerNodeViewModel node, Func <DatabaseCommand> actionFactory, PermissionCategory permCategory) { if (!node.IsDeleted) { if (!User.HasPermission(permCategory, PERMISSION_MASK.DELETE)) { ErrorMessage.Show("You do not have permission to delete this item!"); return; } node.Traverse((child) => { child.IsDeleted = true; }); if (actionFactory != null) { RegisterPendingChange(actionFactory(), this); } } }
public SiteCompare(Window owner, User user, SiteExplorerNodeViewModel dest, List <SiteExplorerNodeViewModel> otherSites) { this.Owner = owner; this.User = user; InitializeComponent(); Destination = dest; _compareModel = new ObservableCollection <SiteExplorerNodeViewModel>(otherSites.ConvertAll((vm) => { vm.IsSelected = true; return(vm); })); txtMergeInto.Text = dest.Name; lstRemove.ItemsSource = _compareModel; grpDiff.DataContextChanged += new DependencyPropertyChangedEventHandler(grpDiff_DataContextChanged); if (_compareModel.Count > 0) { lstRemove.SelectedItem = _compareModel[0]; } }
public DatabaseCommand AddNewItem(HierarchicalViewModelBase selectedItem) { var parent = selectedItem as SiteExplorerNodeViewModel; Debug.Assert(parent != null); var model = new SiteExplorerNode(); model.ElemID = -1; model.ElemType = "Region"; model.Name = "<New Region>"; model.ParentID = parent.ElemID; model.RegionID = parent.RegionID; var viewModel = new SiteExplorerNodeViewModel(model); parent.Children.Add(viewModel); viewModel.IsSelected = true; viewModel.IsRenaming = true; return(new InsertRegionCommand(viewModel.Model, viewModel)); }
private void MergeNodes(SiteExplorerNodeViewModel oldNode, SiteExplorerNodeViewModel newNode) { DatabaseCommand mergeAction = null; switch (oldNode.NodeType) { case SiteExplorerNodeType.SiteGroup: mergeAction = new MergeSiteGroupCommand(oldNode.Model, newNode.Model); break; case SiteExplorerNodeType.SiteVisit: mergeAction = new MergeSiteVisitCommand(oldNode.Model, newNode.Model); break; case SiteExplorerNodeType.Material: mergeAction = new MergeMaterialCommand(oldNode.Model, newNode.Model); break; case SiteExplorerNodeType.Trap: mergeAction = new MergeTrapCommand(oldNode.Model, newNode.Model); break; case SiteExplorerNodeType.Region: mergeAction = new MergeRegionCommand(oldNode.Model, newNode.Model); break; } if (mergeAction != null) { if (this.Question(string.Format("Are you sure you want to merge '{0}' with '{1}'?", oldNode.DisplayLabel, newNode.DisplayLabel), "Merge " + oldNode.NodeType)) { oldNode.IsDeleted = true; newNode.IsChanged = true; RegisterPendingChange(mergeAction, this); } } }
internal SiteExplorerNodeViewModel AddNewNode(HierarchicalViewModelBase parent, SiteExplorerNodeType nodeType, Func <SiteExplorerNodeViewModel, DatabaseCommand> commandFactoryFunction) { if (parent != null) { parent.IsExpanded = true; } var model = new SiteExplorerNode(); model.Name = string.Format("<New {0}>", nodeType.ToString()); if (parent is SiteExplorerNodeViewModel) { model.ParentID = (parent as SiteExplorerNodeViewModel).ElemID; } model.ElemType = nodeType.ToString(); model.ElemID = -1; model.RegionID = -1; var viewModel = new SiteExplorerNodeViewModel(model); if (parent != null) { viewModel.Parent = parent; parent.Children.Add(viewModel); } viewModel.IsSelected = true; viewModel.IsRenaming = true; if (commandFactoryFunction != null) { RegisterPendingChange(commandFactoryFunction(viewModel), this); } return(viewModel); }
internal void AddMaterial(SiteExplorerNodeViewModel parent, int templateId = 0) { AddNewNode(parent, SiteExplorerNodeType.Material, (viewModel) => { return(new InsertMaterialCommand(viewModel.Model, viewModel, templateId)); }); }
internal void AddTrap(SiteExplorerNodeViewModel parent) { AddNewNode(parent, SiteExplorerNodeType.Trap, (viewModel) => { return(new InsertTrapCommand(viewModel.Model, viewModel)); }); }
internal void AddSiteVisit(SiteExplorerNodeViewModel parent, int templateId = 0) { AddNewNode(parent, SiteExplorerNodeType.SiteVisit, (viewModel) => { return(new InsertSiteVisitCommand(viewModel.Model, viewModel, templateId)); }); }
internal SiteExplorerNodeViewModel AddSite(SiteExplorerNodeViewModel parent, int templateId = 0) { return(AddNewNode(parent, SiteExplorerNodeType.Site, (viewModel) => { return new InsertSiteCommand(viewModel.Model, viewModel, templateId); })); }
internal SiteExplorerNodeViewModel AddSiteGroup(SiteExplorerNodeViewModel parent) { return(AddNewNode(parent, SiteExplorerNodeType.SiteGroup, (viewModel) => { return new InsertSiteGroupCommand(viewModel.Model, viewModel); })); }
private string MakeDropMapKey(SiteExplorerNodeViewModel source, SiteExplorerNodeViewModel dest) { return(MakeDropMapKey(source.NodeType, dest.NodeType)); }