private void ComboBoxLostFocus(object sender, RoutedEventArgs e) { var comboBox = (ComboBox)sender; //if (comboBox.SelectedItem == null) //{ // return; //} var newItem = comboBox.Text; if (string.IsNullOrEmpty(newItem)) { return; } NotifyingMetadataItem mdItem = comboBox.DataContext as NotifyingMetadataItem; if (mdItem == null) { return; } if (mdItem.Name != newItem) { mdItem.Name = newItem; // triggers ItemsSource binding refresh } #if DEBUG if (!comboBox.Items.Contains(newItem)) { Debugger.Break(); } #endif }
private void DeleteButton_OnClick(object sender, RoutedEventArgs e) { Button button = sender as Button; NotifyingMetadataItem metadata = button.DataContext as NotifyingMetadataItem; m_ViewModel.RemoveMetadata(metadata); }
//return true if valid //Expected: NotifyingMetadataItem and list of ValidationItems public override object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values[0] == null || values[1] == null) { return(true); } if (!(values[0] is NotifyingMetadataItem) || !(values[1] is IEnumerable <ValidationItem>)) { return(true); } NotifyingMetadataItem metadataItem = (NotifyingMetadataItem)values[0]; IEnumerable <ValidationItem> validationItems = (IEnumerable <ValidationItem>)values[1]; foreach (ValidationItem item in validationItems) { if (item is AbstractMetadataValidationErrorWithTarget) { if ((item as AbstractMetadataValidationErrorWithTarget).Target == metadataItem.UrakawaMetadata) { return(false); } } } return(true); }
public void RemoveMetadata(NotifyingMetadataItem metadata) { Presentation presentation = m_UrakawaSession.DocumentProject.Presentations.Get(0); MetadataRemoveCommand cmd = presentation.CommandFactory.CreateMetadataRemoveCommand (metadata.UrakawaMetadata); presentation.UndoRedoManager.Execute(cmd); }
public override object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values[0] == null || values[1] == null) { return(""); } if (!(values[0] is NotifyingMetadataItem) || !(values[1] is IEnumerable <ValidationItem>)) { return(""); } NotifyingMetadataItem item = values[0] as NotifyingMetadataItem; IEnumerable <ValidationItem> errors = values[1] as IEnumerable <ValidationItem>; string error = DescriptiveErrorTextConverter.GetErrorText(item, errors); if (string.IsNullOrEmpty(error)) { error = Tobi_Plugin_MetadataPane_Lang.NoErrors; } else { error = string.Format(Tobi_Plugin_MetadataPane_Lang.ErrorItem, error); } string primaryId = ""; if (item.IsPrimaryIdentifier) { primaryId = Tobi_Plugin_MetadataPane_Lang.IsPrimaryIdentifier; } string canEditDelete = Tobi_Plugin_MetadataPane_Lang.Delete_Tooltip2; if (item.CanEditOrDelete) { canEditDelete = Tobi_Plugin_MetadataPane_Lang.Delete_Tooltip; } string synonyms = ""; if (item.Definition.Synonyms != null && item.Definition.Synonyms.Count > 0) { synonyms = string.Format(Tobi_Plugin_MetadataPane_Lang.Synonyms, string.Join(",", item.Definition.Synonyms.ToArray())); } //name = content. errors. primary id. can delete. definition. synonyms. occurrence. string retval = string.Format(Tobi_Plugin_MetadataPane_Lang.CompleteSummary, item.Name, item.Content, error, primaryId, canEditDelete, item.Definition.Description, synonyms, MetadataUtilities.OccurrenceToString(item.Definition)); return(retval); }
//when a new metadata object assumes the role of primary identifier, //set IsPrimaryIdentifier to false on all other metadata objects private void notifyOfPrimaryIdentifierChange(NotifyingMetadataItem item) { if (item.IsPrimaryIdentifier) { foreach (NotifyingMetadataItem m in m_Metadatas) { if (m != item && m.IsPrimaryIdentifier) { m.IsPrimaryIdentifier = false; } } } }
private void AddButton_OnClick(object sender, RoutedEventArgs e) { m_ViewModel.AddEmptyMetadata(); ObservableCollection <NotifyingMetadataItem> metadataItems = m_ViewModel.MetadataCollection.Metadatas; if (metadataItems.Count > 0) { NotifyingMetadataItem metadata = metadataItems[metadataItems.Count - 1]; SetSelectedListItem(metadata); } }
//add a metadata item and bring focus to it private void AddMissingItem(string name) { m_ViewModel.AddEmptyMetadata(); ObservableCollection <NotifyingMetadataItem> metadataItems = m_ViewModel.MetadataCollection.Metadatas; if (metadataItems.Count > 0) { NotifyingMetadataItem selection = metadataItems[metadataItems.Count - 1]; selection.Name = name; SetSelectedListItem(selection); } }
public bool IsCandidateForPrimaryIdentifier(NotifyingMetadataItem item) { if (item == null) { return(false); } if (item.Definition == null) { return(false); } return(item.Definition.Name.Equals(SupportedMetadata_Z39862005.DC_Identifier, StringComparison.Ordinal)); //OrdinalIgnoreCase }
// all new item additions end up here private void addItem(Metadata metadata) { MetadataDefinition definition = SupportedMetadata_Z39862005.DefinitionSet.GetMetadataDefinition(metadata.NameContentAttribute.Name, true); //filter out read-only items because they will be filled in by Tobi at export time if (!definition.IsReadOnly) { NotifyingMetadataItem newItem = new NotifyingMetadataItem(metadata, this, definition); newItem.BindPropertyChangedToAction(() => newItem.IsPrimaryIdentifier, () => notifyOfPrimaryIdentifierChange(newItem)); m_Metadatas.Add(newItem); newItem.UrakawaMetadata.Changed += new EventHandler <DataModelChangedEventArgs>(UrakawaMetadata_Changed); NotifyChanged(new EventArgs()); } }
public static string GetErrorText(NotifyingMetadataItem metadata, IEnumerable <ValidationItem> errors) { //find the error for this metadata object ValidationItem error = errors.Where(v => (v is AbstractMetadataValidationErrorWithTarget) && (v as AbstractMetadataValidationErrorWithTarget).Target == metadata.UrakawaMetadata).FirstOrDefault(); if (error == null) { return(""); } return(error.Message); }
//Expected: NotifyingMetadataItem and list of ValidationItems public override object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values[0] == null || values[1] == null) { return(""); } if (!(values[0] is NotifyingMetadataItem) || !(values[1] is IEnumerable <ValidationItem>)) { return(""); } NotifyingMetadataItem metadata = (NotifyingMetadataItem)values[0]; IEnumerable <ValidationItem> errors = (IEnumerable <ValidationItem>)values[1]; return(GetErrorText(metadata, errors)); }
//this works for adding new items, but not for adding missing items or highlighting existing ones. why? private void SetSelectedListItem(NotifyingMetadataItem selection) { if (selection != null) { CollectionViewSource cvs = (CollectionViewSource)FindResource("MetadatasCVS"); if (cvs != null) { cvs.View.MoveCurrentTo(selection); } //MetadataList.SelectedItem = selection; MetadataList.ScrollIntoView(selection); FocusHelper.Focus(FocusableItem); } }
//analyzes the whole collection and decides if the given item can be edited or deleted public bool CanEditOrDelete(NotifyingMetadataItem item) { if (!item.IsRequired) { return(true); } if (item.Definition == null) { return(true); } int count = Metadatas.Count(meta => meta.Definition == item.Definition); if (count > 1) { return(true); } return(false); }
//return Visible if the item is a candidate for being the primary identifier //else return Hidden //value parameters: the metadata object, and the MetadataCollection public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(System.Windows.Visibility.Collapsed); } if (!(value is NotifyingMetadataItem)) { return(Visibility.Collapsed); } NotifyingMetadataItem item = (NotifyingMetadataItem)value; MetadataCollection metadatas = item.ParentCollection; if (item.IsPrimaryIdentifier || metadatas.IsCandidateForPrimaryIdentifier(item)) { return(Visibility.Visible); } return(Visibility.Collapsed); }
private void SetSelectedListItem(Metadata metadata) { ObservableCollection <NotifyingMetadataItem> metadatas = ((MetadataPaneViewModel)DataContext).MetadataCollection.Metadatas; IEnumerator <NotifyingMetadataItem> enumerator = metadatas.GetEnumerator(); NotifyingMetadataItem selection = null; while (enumerator.MoveNext()) { if (enumerator.Current.UrakawaMetadata == metadata) { selection = enumerator.Current; break; } } if (selection != null) { SetSelectedListItem(selection); } }