Ejemplo n.º 1
0
 private boolean performNewSearch() throws CoreException {
   final SearchPatternData data = getPatternData();
   final int includeMask = getIncludeMask();
   // Setup search scope
   ErlSearchScope scope = EMPTY_SCOPE;
   String scopeDescription = null;
   final boolean searchSources = (includeMask & SearchUtil.SEARCH_IN_SOURCES) != 0;
   final boolean searchExternals = (includeMask & SearchUtil.SEARCH_IN_EXTERNALS) != 0;
   final boolean searchOtp = (includeMask & SearchUtil.SEARCH_IN_OTP_LIBRARIES) != 0;
   final int selectedScope = getContainer().getSelectedScope();
   switch (selectedScope) {
     case ISearchPageContainer.WORKSPACE_SCOPE:
       if (searchSources) {
         scope = SearchCoreUtil.getWorkspaceScope(searchExternals, searchOtp);
       }
       scopeDescription = SearchUtil.getWorkspaceScopeDescription();
       break;
     case ISearchPageContainer.SELECTED_PROJECTS_SCOPE:
       final String[] projectNames = getContainer().getSelectedProjectNames();
       if (searchSources) {
         scope =
             SearchCoreUtil.getProjectsScope(
                 SearchCoreUtil.getProjects(projectNames), searchExternals, searchOtp);
       }
       scopeDescription =
           SearchUtil.getProjectScopeDescription(SearchCoreUtil.getProjects(projectNames));
       break;
     case ISearchPageContainer.SELECTION_SCOPE:
       if (searchSources) {
         scope =
             SearchUtil.getSelectionScope(
                 getContainer().getSelection(), searchExternals, searchOtp);
       }
       scopeDescription = SearchUtil.getSelectionScopeDescription(getContainer().getSelection());
       break;
     case ISearchPageContainer.WORKING_SET_SCOPE:
       {
         final IWorkingSet[] workingSets = getContainer().getSelectedWorkingSets();
         // should not happen - just to be sure
         if (workingSets == null || workingSets.length < 1) {
           return false;
         }
         scopeDescription = SearchUtil.getWorkingSetsScopeDescription(workingSets);
         if (searchSources) {
           scope = SearchUtil.getWorkingSetsScope(workingSets, searchExternals, searchOtp);
         }
         SearchUtil.updateLRUWorkingSets(workingSets);
       }
   }
   final ErlangSearchPattern searchPattern =
       SearchUtil.getSearchPattern(
           null, data.getSearchFor(), data.getPattern(), data.getLimitTo());
   SearchUtil.runQuery(searchPattern, scope, scopeDescription, getShell());
   return true;
 }
 public Object execute(final ExecutionEvent event) throws ExecutionException {
   Object selection = HandlerUtil.getVariable(event, ISources.ACTIVE_CURRENT_SELECTION_NAME);
   Shell shell = (Shell) HandlerUtil.getVariable(event, ISources.ACTIVE_SHELL_NAME);
   if (selection instanceof IStructuredSelection) {
     Object firstElement = ((IStructuredSelection) selection).getFirstElement();
     if (firstElement instanceof IErlElement) {
       IErlElement element = (IErlElement) firstElement;
       final ErlangSearchPattern pattern =
           SearchUtil.getSearchPatternFromErlElementAndLimitTo(
               element, ErlangSearchPattern.REFERENCES);
       SearchUtil.runQuery(
           pattern,
           SearchUtil.getWorkspaceScope(),
           SearchUtil.getWorkspaceScopeDescription(),
           shell);
     }
   }
   return null;
 }