/// <summary>
        /// When the text in the editTextBox changes, fire off the query to populate the statement completion popup.
        /// </summary>
        private void DoStatementCompletion()
        {
            if (DisableCompletion)
            {
                return;
            }

            String searchText = TextBox.Text;

            if (searchText.Length == 0)
            {
                HideStatementCompletionForm();
                return;
            }
            if (_proteinMatcherLast != null)
            {
                //if (_proteinMatcherLast.Settings.SearchText == searchText)
                //{
                //    // Query is already executing for the text that the user typed: no work to do now.
                //    return;
                //}
                if (searchText.StartsWith(_proteinMatcherLast.Settings.SearchText))
                {
                    // If the new text is just longer than the previous text, see if we can just refine the results
                    // of the previous query.
                    var results    = _proteinMatcherLast.GetMatches();
                    var newResults = new List <ProteinMatch>();
                    if (results != null)
                    {
                        var oldSettings = _proteinMatcherLast.Settings;
                        var newSettings = new ProteinMatchSettings(oldSettings.ProteomeDbPath, oldSettings.Protease, MatchTypes, searchText);
                        newResults.AddRange(RefineMatches(results, newSettings));
                    }
                    if (newResults.Count == 0)
                    {
                        // Nothing from the previous query matches: hide the statement completion form.
                        HideStatementCompletionForm();
                        _proteinMatcherLast = null;
                    }
                    else
                    {
                        // Display the refined results: we'll still fire off another query to see if we get better results.
                        DisplayResultsNow(newResults, _proteinMatcherLast.MaxResults);
                    }
                }
            }

            if (_proteinMatcher != null)
            {
                _proteinMatcher.Cancel();
                _proteinMatcher = null;
            }
            var settings = CreateProteinMatchSettings(_documentUiContainer.DocumentUI, MatchTypes, searchText);

            if (settings != null)
            {
                _proteinMatcher = new ProteinMatchQuery(settings);
                _proteinMatcher.BeginExecute(DisplayResults);
            }
        }
Пример #2
0
        public static IList <ProteinMatch> RefineMatches(IEnumerable <ProteinMatch> matches, ProteinMatchSettings settings)
        {
            var newMatches = new List <ProteinMatch>();

            foreach (var match in matches)
            {
                var newMatch = new ProteinMatch(settings, match.Protein);
                if (!newMatch.MatchTypes.IsEmpty)
                {
                    newMatches.Add(newMatch);
                }
            }
            return(newMatches);
        }