private static Control MakeOptionCollectionWidget(PalasoDataObject target, Field field) { OptionsList availableOptions = WeSayWordsProject.Project.GetOptionsList(field, false); OptionRefCollection refsOfChoices = target.GetOrCreateProperty <OptionRefCollection>(field.FieldName); IList <IWritingSystemDefinition> writingSystems = BasilProject.Project.WritingSystemsFromIds(field.WritingSystemIds); IChoiceSystemAdaptor <Option, string, OptionRef> displayAdaptor; if (field.FieldName == LexSense.WellKnownProperties.SemanticDomainDdp4) { displayAdaptor = new DdpOptionDisplayAdaptor(availableOptions, field.WritingSystemIds[0]); } else { displayAdaptor = new OptionDisplayAdaptor(availableOptions, field.WritingSystemIds[0]); } ReferenceCollectionEditor <Option, string, OptionRef> control = new ReferenceCollectionEditor <Option, string, OptionRef>(refsOfChoices.Members, availableOptions. Options, writingSystems, field.Visibility, displayAdaptor, WeSayWordsProject.Project.ServiceLocator); control.AlternateEmptinessHelper = refsOfChoices; return(control); }
private static LexRelation AddRelation(PalasoDataObject source, string fieldName, string targetId) { LexRelationCollection relationColection = source.GetOrCreateProperty <LexRelationCollection>(fieldName); LexRelation relation = new LexRelation(fieldName, targetId, source); relationColection.Relations.Add(relation); return(relation); }
protected Control MakeCheckBoxWidget(PalasoDataObject target, Field field) { FlagState boxState = target.GetOrCreateProperty <FlagState>(field.FieldName); CheckBoxControl control = new CheckBoxControl(boxState.Value, field.DisplayName, field.FieldName); SimpleBinding <bool> binding = new SimpleBinding <bool>(boxState, control); binding.CurrentItemChanged += _detailList.OnBinding_ChangeOfWhichItemIsInFocus; return(control); }
protected Control MakeOptionWidget(PalasoDataObject target, Field field) { OptionRef optionRefTarget = target.GetOrCreateProperty <OptionRef>(field.FieldName); OptionsList list = WeSayWordsProject.Project.GetOptionsList(field, false); IWritingSystemDefinition preferredWritingSystem = _viewTemplate.GetDefaultWritingSystemForField(field.FieldName); SingleOptionControl control = new SingleOptionControl(optionRefTarget, list, field.FieldName, preferredWritingSystem, WeSayWordsProject.Project.ServiceLocator); SimpleBinding <string> binding = new SimpleBinding <string>(optionRefTarget, control); binding.CurrentItemChanged += _detailList.OnBinding_ChangeOfWhichItemIsInFocus; return(control); }
protected override Control MakePictureWidget(PalasoDataObject target, Field field, DetailList detailList) { PictureRef pictureRef = target.GetOrCreateProperty <PictureRef>(field.FieldName); PictureControl control = _serviceProvider.GetService(typeof(PictureControl)) as PictureControl; control.SearchTermProvider = new SenseSearchTermProvider(target as LexSense); if (!String.IsNullOrEmpty(pictureRef.Value)) { control.Value = pictureRef.Value; } SimpleBinding <string> binding = new SimpleBinding <string>(pictureRef, control); binding.CurrentItemChanged += detailList.OnBinding_ChangeOfWhichItemIsInFocus; return(control); }
private void MakeControl() { //relations come to us in collections, even when they are atomic // this will get a collection if we already have some for this field, or else // it will make one. If unused, it will be cleaned up at the right time by the PalasoDataObject parent. var targetRelationCollection = _relationParent.GetOrCreateProperty <LexRelationCollection>(_field.FieldName); switch (_relationType.Multiplicity) { case LexRelationType.Multiplicities.One: LexRelation relation; if (targetRelationCollection.Relations.Count > 0) { relation = targetRelationCollection.Relations[0]; relation.Parent = _relationParent; } else { //we have to make one so we can show the control. It will be cleaned up, if not used, by the PalasoDataObject target relation = new LexRelation(_field.FieldName, string.Empty, _relationParent); targetRelationCollection.Relations.Add(relation); } InitializeRelationControl(relation); break; // case LexRelationType.Multiplicities.Many: // _control = new ReferenceCollectionEditor<LexRelation> // (targetRelationCollection.Relations, // _field.WritingSystemIds); // break; default: break; } }
private int AddOneCustomField(PalasoDataObject target, Field customField, int insertAtRow, int rowCount) { IReportEmptiness data = target.GetProperty <IReportEmptiness>(customField.FieldName); if (!customField.GetDoShow(data, ShowNormallyHiddenFields)) { return(rowCount); } Control box; switch (customField.DataTypeName) { case "Picture": box = MakePictureWidget(target, customField, _detailList); if (box == null) { return(rowCount); // other code does the user notification } break; case "Flag": box = MakeCheckBoxWidget(target, customField); break; case "Option": box = MakeOptionWidget(target, customField); break; case "OptionCollection": box = MakeOptionCollectionWidget(target, customField); break; case "MultiText": box = MakeBoundControl( target.GetOrCreateProperty <MultiText>(customField.FieldName), customField); break; default: LexRelationType lexRelType = GetRelationType(customField.DataTypeName); if (lexRelType != null) { box = MakeRelationWidget(target, lexRelType, customField); } else { throw new ApplicationException( string.Format("WeSay doesn't understand how to layout a {0}", customField.DataTypeName)); } break; } string label = StringCatalog.Get(customField.DisplayName); //for checkboxes, the label is part of the control if (customField.DataTypeName == "Flag") { label = string.Empty; } Control c = DetailList.AddWidgetRow(StringCatalog.Get(label), false, box, insertAtRow, false); DetailList.GetRow(c); ++rowCount; return(rowCount); }