Esempio n. 1
0
        private void InitializeRelationControl(LexRelation relation)
        {
            //TODO: refactor this (sortHelper, pairStringLexEntryIdList, _keyIdMap, GetKeyIdPairFromLexEntry)
            //      to use ApproximateFinder. Eventually refactor the automcompletetextbox to just take one

            IWritingSystemDefinition writingSystem   = GetWritingSystemFromField();
            ResultSet <LexEntry>     recordTokenList =
                _lexEntryRepository.GetAllEntriesSortedByLexicalFormOrAlternative(writingSystem);

            _resultSet = recordTokenList;

            AutoCompleteWithCreationBox <RecordToken <LexEntry>, string> picker =
                CreatePicker <RecordToken <LexEntry> >(relation);

            picker.GetKeyValueFromValue = GetRecordTokenFromTargetId;
            picker.GetValueFromKeyValue = GetTargetIdFromRecordToken;

            picker.Box.ItemDisplayStringAdaptor = new PairStringLexEntryIdDisplayProvider();
            picker.Box.FormToObjectFinder       = FindRecordTokenFromForm;
            picker.Box.ItemFilterer             = FindClosestAndNextClosestAndPrefixedPairStringLexEntryForms;

            picker.Box.Items = recordTokenList;
            if (!String.IsNullOrEmpty(relation.TargetId))
            {
                picker.Box.SelectedItem = GetRecordTokenFromLexEntry(_lexEntryRepository.GetLexEntryWithMatchingId(relation.TargetId));
            }

            picker.CreateNewClicked += OnCreateNewPairStringLexEntryId;
            _control = picker;
        }
        private AutoCompleteWithCreationBox <KV, ValueT> MakePicker()
        {
            AutoCompleteWithCreationBox <KV, ValueT> picker =
                new AutoCompleteWithCreationBox <KV, ValueT>(_visibility, _serviceProvider);

            picker.Box.FormToObjectFinder = _choiceSystemAdaptor.GetValueFromFormNonGeneric;

            picker.Box.WritingSystem            = _writingSystems[0];
            picker.GetKeyValueFromValue         = _choiceSystemAdaptor.GetKeyValueFromValue;
            picker.GetValueFromKeyValue         = _choiceSystemAdaptor.GetValueFromKeyValue;
            picker.Box.ItemDisplayStringAdaptor = _choiceSystemAdaptor;
            picker.Box.Mode         = EntryMode.List;
            picker.Box.Items        = _sourceChoices;
            picker.Box.MinimumSize  = new Size(30, 10);
            picker.Box.ItemFilterer = _choiceSystemAdaptor.GetItemsToOffer;
            picker.Box.PopupWidth   = _popupWidth;

            picker.Box.UserLostFocus += OnChildLostFocus;

            if (CreateNewTargetItem != null)
            {
                picker.CreateNewClicked += OnCreateNewClicked;
            }
            return(picker);
        }
        public void Setup()
        {
            _ws = WritingSystemDefinition.Parse("qaa-x-qaa");
            _ws.DefaultFontName = "Arial";
            _ws.DefaultFontSize = (float)55.9;
            //            _createNewClickedFired=false;
            //            _valueChangedFired = false;
            _sourceChoices = new OptionsList();
            _choiceKeys    = new List <string>();
            AddSourceChoice("one", "1", "Notice, this is not the number two.");
            //nb: key 'two' in there
            AddSourceChoice("two", "2", "A description of two which includes the word duo.");
            AddSourceChoice("three",
                            "3",
                            "A description of this which includes the word trio and is not two.");

            _displayAdaptor = new OptionDisplayAdaptor(_sourceChoices, _ws.Id);
            _control        =
                new AutoCompleteWithCreationBox <Option, string>(
                    CommonEnumerations.VisibilitySetting.Visible, null);
            _control.Name             = "autobox";
            _control.Box.Items        = _sourceChoices.Options;
            _control.Box.ItemFilterer = _displayAdaptor.GetItemsToOffer;

            //leave for individual tests _control.CreateNewClicked += new EventHandler<CreateNewArgs>(_control_CreateNewClicked);
            _control.Box.ItemDisplayStringAdaptor = _displayAdaptor;
            _control.Box.WritingSystem            = _ws;
            _control.GetKeyValueFromValue         = _displayAdaptor.GetOptionFromKey;
            _control.GetValueFromKeyValue         = _displayAdaptor.GetKeyFromOption;
            _control.ValueChanged += _control_ValueChanged;

            _dataBeingEditted = new OptionRef();
        }
Esempio n. 4
0
        public void TriggerFindApproximate_Single()
        {
            AddRelation(_source, _singleSynonymRelationField.FieldName, _target.Id);

            Control c = RelationController.CreateWidget(_source,
                                                        _singleSynonymRelationType,
                                                        _singleSynonymRelationField,
                                                        _lexEntryRepository,
                                                        delegate { });
            Form form = new Form();

            form.Controls.Add(c);
            AutoCompleteWithCreationBox <RecordToken <LexEntry>, string> picker =
                (AutoCompleteWithCreationBox <RecordToken <LexEntry>, string>)c;

            ((WeSayAutoCompleteTextBox)(picker.Box)).Paste("text");
        }
        private void AddControls()
        {
            if (DesignMode)
            {
                return;
            }
            SuspendLayout();
            if (Parent != null)
            {
                BackColor = Parent.BackColor;
            }

            Controls.Clear();
            foreach (KEY_CONTAINER item in _chosenItems)
            {
                AutoCompleteWithCreationBox <KV, ValueT> picker = MakePicker();
                picker.Box.Tag          = item;
                picker.Box.SelectedItem = _choiceSystemAdaptor.GetKeyValueFromKey_Container(item);
                if (picker.Box.SelectedItem == null)                 //couldn't find a match for the key
                {
                    picker.Box.Text = item.Key;
                    // the box will recognize the problem and display a red background
                }

                //the binding itself doesn't need to be "owned" by us... it controls its own lifetime
                new SimpleBinding <ValueT>(item, picker);

                Controls.Add(picker);
            }
            OnBackColorChanged(this, null);
            //set the appropriate background for the pickers if we're readonly

            //add a blank to type in
            if (_visibility != CommonEnumerations.VisibilitySetting.ReadOnly)
            {
                AddEmptyPicker();
            }
            ResumeLayout(false);
            PerformLayout();
        }
        private void emptyPicker_ValueChanged(object sender, EventArgs e)
        {
            AutoCompleteWithCreationBox <KV, ValueT> picker =
                (AutoCompleteWithCreationBox <KV, ValueT>)sender;
            KV kv = (KV)picker.Box.SelectedItem;

            if (kv != null)
            {
                picker.ValueChanged -= emptyPicker_ValueChanged;
                _emptyPicker         = null;
                _ignoreListChanged   = true;
                KEY_CONTAINER newGuy = (KEY_CONTAINER)_chosenItems.AddNew();
                _choiceSystemAdaptor.UpdateKeyContainerFromKeyValue(kv, newGuy);
                _ignoreListChanged = false;
                picker.Box.Tag     = newGuy;

                //the binding itself doesn't need to be "owned" by us... it controls its own lifetime
                new SimpleBinding <ValueT>(newGuy, picker);

                AddEmptyPicker();
            }
        }
Esempio n. 7
0
        public void ChangeBoundRelation_Single_ToNonExistantCreate_CreatesRelation()
        {
            LexRelation relation = AddRelation(_source, _singleSynonymRelationField.FieldName, _target.Id);

            Control c = RelationController.CreateWidget(_source,
                                                        _singleSynonymRelationType,
                                                        _singleSynonymRelationField,
                                                        _lexEntryRepository,
                                                        delegate { });

            c.Text = "new";

            AutoCompleteWithCreationBox <RecordToken <LexEntry>, string> picker =
                (AutoCompleteWithCreationBox <RecordToken <LexEntry>, string>)c;

            picker.CreateNewObjectFromText();

            LexEntry newEntry = _lexEntryRepository.GetLexEntryWithMatchingId(relation.Key);

            Assert.IsNotNull(newEntry);
            Assert.AreEqual("new", newEntry.LexicalForm[WritingSystemsIdsForTests.OtherIdForTest]);
        }
Esempio n. 8
0
        private AutoCompleteWithCreationBox <T, string> CreatePicker <T>(LexRelation relation)
            where T : class
        {
            var picker = new AutoCompleteWithCreationBox <T, string> (
                CommonEnumerations.VisibilitySetting.Visible,
                WeSayWordsProject.Project.ServiceLocator
                );

            picker.Box.Tag = relation;
            //                    switch (type.TargetType)
            //                    {
            //                        case LexRelationType.TargetTypes.Entry:
            //                            //picker.Box.Items = Project.WeSayWordsProject.Project
            //                            break;
            //                        case LexRelationType.TargetTypes.Sense:
            //                            break;
            //                        default:
            //                            break;
            //                    }
            picker.Box.WritingSystem = GetWritingSystemFromField();
            picker.Box.PopupWidth    = 200;

            //review:
            picker.Box.MinimumSize = new Size(40, 10);
            if (picker.Box.SelectedItem == null && !string.IsNullOrEmpty(relation.Key))
            {
                picker.Box.Text = relation.Key;
                // picker.Box.ShowRedSquiggle = true;
            }

            _binding = new SimpleBinding <string>(relation, picker);
            //for underlinging the relation in the preview pane
            _binding.CurrentItemChanged += _focusDelegate;

            return(picker);
        }
        public void Setup()
        {
            _ws = new WritingSystem("xx", new Font("Arial", (float) 55.9));
            //            _createNewClickedFired=false;
            //            _valueChangedFired = false;
            _sourceChoices = new OptionsList();
            _choiceKeys = new List<string>();
            AddSourceChoice("one", "1", "Notice, this is not the number two.");
            //nb: key 'two' in there
            AddSourceChoice("two", "2", "A description of two which includes the word duo.");
            AddSourceChoice("three",
                            "3",
                            "A description of this which includes the word trio and is not two.");

            _displayAdaptor = new OptionDisplayAdaptor(_sourceChoices, _ws.Id);
            _control =
                    new AutoCompleteWithCreationBox<Option, string>(
                            CommonEnumerations.VisibilitySetting.Visible);
            _control.Name = "autobox";
            _control.Box.Items = _sourceChoices.Options;
            _control.Box.ItemFilterer = _displayAdaptor.GetItemsToOffer;

            //leave for individual tests _control.CreateNewClicked += new EventHandler<CreateNewArgs>(_control_CreateNewClicked);
            _control.Box.ItemDisplayStringAdaptor = _displayAdaptor;
            _control.Box.WritingSystem = _ws;
            _control.GetKeyValueFromValue = _displayAdaptor.GetOptionFromKey;
            _control.GetValueFromKeyValue = _displayAdaptor.GetKeyFromOption;
            _control.ValueChanged += _control_ValueChanged;

            _dataBeingEditted = new OptionRef();
        }
Esempio n. 10
0
 private void AddEmptyPicker()
 {
     _emptyPicker = MakePicker();
     _emptyPicker.ValueChanged += emptyPicker_ValueChanged;
     Controls.Add(_emptyPicker);
 }