/// <summary>
        /// Search.
        /// </summary>
        /// <param name="args">Search data.</param>
        protected virtual void Search(SearchEventArgs args)
        {
            if (args.SelectedSearchCriteria == null || args.SelectedSearchSource == null)
                return;

            // search
            List<ModelElement> selectableElements = this.ViewModelStore.TopMostStore.GetDomainModelServices().SearchProcessor.GetSearchableElements(this.Store, this.SelectedSearchSource.Source);

            if (args.SelectedSearchSource.Source == SearchSourceEnum.Custom && args.SelectedSearchSourceElements != null &&
                args.SelectedSearchCriteria.Criteria != SearchCriteriaEnum.Custom)
            {
                selectableElements = args.SelectedSearchSourceElements;
            }
            else
                if (args.SelectedSearchCriteria.Criteria == SearchCriteriaEnum.Custom ||
                    args.SelectedSearchSource.Source == SearchSourceEnum.Custom)
                    return;

            this.SearchResultViewModel.SearchOptionsSummary = this.CreateOptionsSummary(args);
            
            if( args.SelectedSearchSource.Source != SearchSourceEnum.Custom )
                selectableElements = this.ViewModelStore.TopMostStore.GetDomainModelServices().SearchProcessor.GetSearchableElements(this.Store, args.SelectedSearchSource.Source);

            // search sources
            SearchResultViewModel.SearchResults.Clear();

            if (!args.DoFindInResult)
            {
                foreach (ModelElement modelElement in selectableElements)
                {
                    List<SearchResult> searchResults = this.ViewModelStore.TopMostStore.GetDomainModelServices().SearchProcessor.Search(modelElement, args.SelectedSearchCriteria.Criteria,
                        args.SearchText, new SearchOptions(args.DoMatchCase, args.DoMatchWholeWord));

                    if (searchResults != null)
                    {
                        foreach (SearchResult searchResult in searchResults)
                            if (searchResult.IsSuccessFull && searchResult.Source != null)
                            {
                                SearchResultViewModel.SearchResults.Add(new SearchResultItemViewModel(this.ViewModelStore, searchResult));
                            }
                    }
                }
            }
            else
            {
                List<ModelElement> temp = new List<ModelElement>();
                foreach (ModelElement modelElement in selectableElements)
                {
                    List<SearchResult> searchResults = this.ViewModelStore.TopMostStore.GetDomainModelServices().SearchProcessor.Search(modelElement, args.SelectedSearchCriteria.Criteria,
                        args.SearchText, new SearchOptions(args.DoMatchCase, args.DoMatchWholeWord));
                    if (searchResults != null)
                        foreach (SearchResult searchResult in searchResults)
                            if (searchResult.IsSuccessFull && searchResult.Source != null)
                                if (!temp.Contains(searchResult.Source))
                                    temp.Add(searchResult.Source);
                }
                foreach (ModelElement modelElement in temp)
                {
                    List<SearchResult> searchResults = this.ViewModelStore.TopMostStore.GetDomainModelServices().SearchProcessor.Search(modelElement, args.SelectedSearchCriteriaInResult.Criteria,
                        args.SearchTextInResult, new SearchOptions(args.DoMatchCase, args.DoMatchWholeWord));

                    if (searchResults != null)
                    {
                        foreach (SearchResult searchResult in searchResults)
                            if (searchResult.IsSuccessFull && searchResult.Source != null)
                            {
                                SearchResultViewModel.SearchResults.Add(new SearchResultItemViewModel(this.ViewModelStore, searchResult));
                            }
                    }
                }
            }

            // sort result
            SearchResultViewModel.Sort(SearchResultViewModel.SortOrder, SearchResultViewModel.IsSortedAscending);

            // set summary
            this.SearchResultViewModel.SearchResultSummary =

                PDEResources.Resources.SearchViewModel_ResultsFound + ": " + SearchResultViewModel.SearchResults.Count + "     " +
                PDEResources.Resources.SearchViewModel_TotalElementsSearched + ": " + selectableElements.Count;

            if (!this.SearchResultViewModel.IsDockingPaneVisible)
            {
                // show docking pane
                this.EventManager.GetEvent<ShowViewModelRequestEvent>().Publish(new ShowViewModelRequestEventArgs(this.SearchResultViewModel));
            }
            else
            {
                // bring to front
                this.EventManager.GetEvent<BringToFrontViewModelRequestEvent>().Publish(new BringToFrontViewModelRequestEventArgs(this.SearchResultViewModel));
            }
        }
        /// <summary>
        /// Search command executed.
        /// </summary>
        protected virtual void SearchCommand_Executed()
        {
            SearchEventArgs args = new SearchEventArgs(this.SearchText, this.SelectedSearchSource, this.SelectedSearchCriteria);
            args.DoFindInResult = this.DoFindInResult;
            args.DoMatchCase = this.DoMatchCase;
            args.DoMatchWholeWord = this.DoMatchWholeWord;
            args.SearchTextInResult = this.SearchTextInResult;
            args.SelectedSearchCriteriaInResult = this.SelectedSearchCriteriaInResult;

            this.Search(args);
        }
        /// <summary>
        /// Creates an options summary as a string.
        /// </summary>
        /// <returns>Options summary as string.</returns>
        protected virtual string CreateOptionsSummary(SearchEventArgs args)
        {            
            if (!this.DoFindInResult)
                return string.Format(PDEResources.Resources.SearchViewModel_OptionsSummary, args.SearchText,
                    args.SelectedSearchSource.DisplayName, args.SelectedSearchCriteria.DisplayName);
            else
                return string.Format(PDEResources.Resources.SearchViewModel_OptionsSummaryAdv, args.SearchText,
                    args.SelectedSearchSource.DisplayName, args.SelectedSearchCriteria.DisplayName,
                    args.SearchTextInResult, args.SelectedSearchCriteriaInResult.DisplayName);

            /*
            string summary = "Find all '" + args.SearchText + "', Source: " + args.SelectedSearchSource.DisplayName + ", ";
            summary += "Criteria: " + args.SelectedSearchCriteria.DisplayName;

            if (args.DoFindInResult)
            {
                summary += " and in results find '" + args.SearchTextInResult + "', " + "Criteria: " + args.SelectedSearchCriteria.DisplayName;
            }

            return summary;
            */
        }
 /// <summary>
 /// Reactns on a SearchEvent beeing received.
 /// </summary>
 /// <param name="args">Event data.</param>
 private void ReactOnSearchRequest(SearchEventArgs args)
 {
     Search(args);
 }
        /// <summary>
        /// SearchCommand executed.
        /// </summary>
        private void SearchCommand_Executed()
        {
            if (this.CurrentEditorViewModels == null)
                return;

            if (this.CurrentEditorViewModels.Count == 0)
                return;

            List<ModelElement> elements = new List<ModelElement>();
            foreach(PropertyGridEditorViewModel vm in this.CurrentEditorViewModels)
                if (vm.Elements != null)
                {
                    foreach(object obj in vm.Elements)
                        if (obj is ModelElement)
                        {
                            ModelElement modelElement = obj as ModelElement;
                            if (!elements.Contains(modelElement))
                                elements.Add(modelElement);
                        }
                }

            SearchEventArgs args = new SearchEventArgs(this.SearchText, elements, new Search.SearchCriteria(SearchCriteriaEnum.Properties, "Properties"));
            this.EventManager.GetEvent<SearchEvent>().Publish(args);
        }