public override bool Equals(object obj) { MetadataViewModel compareTo = obj as MetadataViewModel; if (compareTo != null) { if (MetadataValue == compareTo.MetadataValue && MetadataName == compareTo.MetadataName && MetadataTypeUid == compareTo.MetadataTypeUid && this.NodeUid == compareTo.NodeUid && this.RelationshipUid == compareTo.RelationshipUid && this.DescriptorTypeUid == compareTo.DescriptorTypeUid) { return(true); } else { return(false); } } else { return(false); } }
private void LoadData() { if (!HasChanges) { _metadata.Clear(); _changes.Clear(); if (NodeProxy != null && NodeProxy.Metadata != null) { List<MetadataViewModel> sortedList = new List<MetadataViewModel>(); foreach (MetadataContext context in NodeProxy.Metadata.Keys) { /* The 'Note' property has it's own editor panel intended for more text * The 'XPosition' and 'YPosition' are control via the map positioning * The 'Name' is the node text and editing is done via the node directly * The 'Created' and 'Modified' timestamps should not be able to be changed. * TODO: Decide if the CreatedBy and ModifiedBy properties should be editable. ***/ if (context.MetadataName != "Note" && context.MetadataName != "XPosition" && context.MetadataName != "YPosition" && context.MetadataName != "Name" && context.MetadataName != "Created" && context.MetadataName != "Modified" && context.MetadataName != "CollapseState" && context.MetadataName != "Visibility") { MetadataViewModel model = new MetadataViewModel(context, NodeProxy.Metadata[context]); if (!ContainsOriginal(context)) { _original.Add(context, model.Clone()); } _changes[model.OriginalMetadataName.ToLower()] = false; model.PropertyChanged += new PropertyChangedEventHandler(model_PropertyChanged); sortedList.Add(model); } } sortedList.Sort(new Comparison<MetadataViewModel>(CompareMetadata)); foreach (MetadataViewModel model in sortedList) { _metadata.Add(model); _metadataNames.Add(model.OriginalMetadataName); } } } }
private void ResetOriginals() { lock (_original) { _original.Clear(); foreach (MetadataContext context in NodeProxy.Metadata.Keys) { /* The 'Note' property has it's own editor panel intended for more text * The 'XPosition' and 'YPosition' are control via the map positioning * The 'Name' is the node text and editing is done via the node directly * The 'Created' and 'Modified' timestamps should not be able to be changed. * TODO: Decide if the CreatedBy and ModifiedBy properties should be editable. ***/ if (context.MetadataName != "Note" && context.MetadataName != "XPosition" && context.MetadataName != "YPosition" && context.MetadataName != "Name" && context.MetadataName != "Created" && context.MetadataName != "Modified" && context.MetadataName != "CollapseState" && context.MetadataName != "Visibility") { MetadataViewModel model = new MetadataViewModel(context, NodeProxy.Metadata[context]); if (!ContainsOriginal(context)) { _original.Add(context, model.Clone()); } } } } }
private void AddMetadataDialog_Closed(object sender, EventArgs e) { EditMetadataDialog dialog = sender as EditMetadataDialog; if (dialog != null && dialog.DialogResult.Value == true) { //only allow a key to go into the properties once if (!_changes.ContainsKey(dialog.MetadataName.ToLower())) { MetadataContext newContext = new MetadataContext(); newContext.MetadataName = dialog.MetadataName; newContext.NodeUid = NodeProxy.Id; SoapMetadata metadata = new SoapMetadata(); metadata.MetadataName = dialog.MetadataName; TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance<TypeManager>(); IMetadataTypeProxy[] metaDataTypes = typeManager.GetAllMetadataTypes(); foreach (IMetadataTypeProxy metadataType in metaDataTypes) { if (metadataType.Id == dialog.MetadataTypeUid) { SoapMetadataType soapMetadataType = new SoapMetadataType(); soapMetadataType.Id = metadataType.Id; soapMetadataType.Name = metadataType.Name; metadata.MetadataType = soapMetadataType; break; } } metadata.MetadataValue = dialog.Value; MetadataViewModel newData = new MetadataViewModel(newContext, metadata); _changes[newData.OriginalMetadataName.ToLower()] = true; _metadata.Add(newData); _metadataNames.Add(newData.MetadataName); newData.PropertyChanged += new PropertyChangedEventHandler(model_PropertyChanged); } else { MessageBox.Show("Metadata could not be added because the property name already existed", "Error Adding Metadata", MessageBoxButton.OK); } } }
private bool IsEqualToOriginal(MetadataViewModel metadata) { bool result = false; foreach (KeyValuePair<MetadataContext, MetadataViewModel> pair in _original) { MetadataContext context = pair.Key; MetadataViewModel model = pair.Value; if (context.NodeUid.Value == metadata.NodeUid && model.MetadataName == metadata.OriginalMetadataName) { if (context.DescriptorTypeUid.HasValue && context.DescriptorTypeUid.Value != metadata.DescriptorTypeUid) { continue; } if (context.RelationshipUid.HasValue && context.RelationshipUid.Value != metadata.RelationshipUid) { continue; } //the context is the same so compare the items if (model.Equals(metadata)) { return true; } else { return false; } } } return result; }
private void MarkChanged(MetadataViewModel model, DataGridRow changedRow, bool changed) { if (changed) { SaveButton.IsEnabled = true; changedRow.Foreground = new SolidColorBrush(Colors.Red); } else { if (!HasChanges) //checks if there are any other changes before resetting the Save button { SaveButton.IsEnabled = false; //if there are no other changes } changedRow.Foreground = new SolidColorBrush(Colors.Black); } }
private int CompareMetadata(MetadataViewModel metadata1, MetadataViewModel metadata2) { return metadata1.MetadataName.CompareTo(metadata2.MetadataName); }