@Override
 public String getLabel() {
   String label =
       DartElementLabels.getTextLabel(
           fElement, DartElementLabels.ALL_DEFAULT | DartElementLabels.ALL_FULLY_QUALIFIED);
   return Messages.format(DartUIMessages.JavaUIHelp_link_label, label);
 }
 private String getSearchPatternDescription() {
   if (patternData.hasElement()) {
     DartElement element = ((ElementQuerySpecification) patternData).getElement();
     return DartElementLabels.getElementLabel(
         element,
         DartElementLabels.ALL_DEFAULT
             | DartElementLabels.ALL_FULLY_QUALIFIED
             | DartElementLabels.USE_RESOLVED);
   } else if (patternData.hasNode()) {
     // TODO(messick): Make this better, if needed.
     DartNode node = ((NodeQuerySpecification) patternData).getNode();
     if (node instanceof DartIdentifier) {
       return ((DartIdentifier) node).getName();
     } else {
       return node.getObjectIdentifier();
     }
   }
   return BasicElementLabels.getFilePattern(
       ((PatternQuerySpecification) patternData).getPattern());
 }
  public DartDocHelpContext(IContext context, Object[] elements) throws DartModelException {
    Assert.isNotNull(elements);
    if (context instanceof IContext2) {
      fTitle = ((IContext2) context).getTitle();
    }

    List<IHelpResource> helpResources = new ArrayList<IHelpResource>();

    String javadocSummary = null;
    for (int i = 0; i < elements.length; i++) {
      if (elements[i] instanceof DartElement) {
        DartElement element = (DartElement) elements[i];
        // if element isn't on the build path skip it
        if (!ActionUtil.isOnBuildPath(element)) {
          continue;
        }

        // Create Javadoc summary
        if (BUG_85719_FIXED) {
          if (javadocSummary == null) {
            javadocSummary = retrieveText(element);
            if (javadocSummary != null) {
              String elementLabel =
                  DartElementLabels.getTextLabel(element, DartElementLabels.ALL_DEFAULT);

              // FIXME: needs to be NLSed once the code becomes active
              javadocSummary =
                  "<b>DartDoc for "
                      + elementLabel
                      + ":</b><br>"
                      + javadocSummary; //$NON-NLS-1$//$NON-NLS-2$
            }
          } else {
            javadocSummary = ""; // no Javadoc summary for multiple selection //$NON-NLS-1$
          }
        }

        URL url = DartUI.getDartDocLocation(element, true);
        if (url == null || doesNotExist(url)) {
          DartX.todo();
          //          IPackageFragmentRoot root = DartModelUtil.getPackageFragmentRoot(element);
          //          if (root != null) {
          //            url = DartUI.getJSdocBaseLocation(element);
          //            if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
          //              element = element.getDartProject();
          //            } else {
          //              element = root;
          //            }
          //            url = DartUI.getJSdocLocation(element, false);
          //          }
        }
        if (url != null) {
          IHelpResource javaResource = new JavaUIHelpResource(element, getURLString(url));
          helpResources.add(javaResource);
        }
      }
    }

    // Add static help topics
    if (context != null) {
      IHelpResource[] resources = context.getRelatedTopics();
      if (resources != null) {
        for (int j = 0; j < resources.length; j++) {
          helpResources.add(resources[j]);
        }
      }
    }

    fHelpResources = helpResources.toArray(new IHelpResource[helpResources.size()]);

    if (context != null) {
      fText = context.getText();
    }

    if (BUG_85719_FIXED) {
      if (javadocSummary != null && javadocSummary.length() > 0) {
        if (fText != null) {
          fText = context.getText() + "<br><br>" + javadocSummary; // $NON-NLS-1$
        } else {
          fText = javadocSummary;
        }
      }
    }

    if (fText == null) {
      fText = ""; // $NON-NLS-1$
    }
  }
  @Override
  public IStatus run(IProgressMonitor monitor) {
    final DartSearchResult textResult = (DartSearchResult) getSearchResult();
    textResult.removeAll();
    SearchEngine engine = SearchEngineFactory.createSearchEngine();

    //  try {
    //  int totalTicks= 1000;
    // TODO (pquitslund): add search participant support
    //  IProject[] projects=
    // JavaSearchScopeFactory.getInstance().getProjects(fPatternData.getScope());
    //  final SearchParticipantRecord[] participantDescriptors=
    // SearchParticipantsExtensionPoint.getInstance().getSearchParticipants(projects);
    //  final int[] ticks= new int[participantDescriptors.length];
    //  for (int i= 0; i < participantDescriptors.length; i++) {
    //    final int iPrime= i;
    //    ISafeRunnable runnable= new ISafeRunnable() {
    //      public void handleException(Throwable exception) {
    //        ticks[iPrime]= 0;
    //        String message= SearchMessages.JavaSearchQuery_error_participant_estimate;
    //        DartToolsPlugin.log(new Status(IStatus.ERROR, DartToolsPlugin.getPluginId(), 0,
    // message, exception));
    //      }
    //
    //      public void run() throws Exception {
    //        ticks[iPrime]=
    // participantDescriptors[iPrime].getParticipant().estimateTicks(fPatternData);
    //      }
    //    };
    //
    //    SafeRunner.run(runnable);
    //    totalTicks+= ticks[i];
    //  }

    SearchResultCollector collector = new SearchResultCollector(textResult);
    SearchScope scope = patternData.getScope();

    if (patternData.hasElement()) {
      DartElement element = ((ElementQuerySpecification) patternData).getElement();
      if (!element.exists()) {
        String patternString =
            DartElementLabels.getElementLabel(element, DartElementLabels.ALL_DEFAULT);
        return new Status(
            IStatus.ERROR,
            DartToolsPlugin.getPluginId(),
            0,
            Messages.format(
                SearchMessages.DartSearchQuery_error_element_does_not_exist, patternString),
            null);
      }

      try {
        if (patternData.isReferencesSearch()) {
          searchForReferences(engine, element, scope, null, collector, monitor);
        }
        if (patternData.isDeclarationsSearch()) {
          searchForDeclarations(engine, element, scope, null, collector, monitor);
        }
        if (patternData.isOverridesSearch()) {
          searchForOverrides(engine, element, scope, null, collector, monitor);
        }
      } catch (SearchException e) {
        DartToolsPlugin.log(e);
        // TODO: do we need to update the UI as well? Or schedule another search?
      } catch (CoreException ex) {
        DartToolsPlugin.log(ex);
      }

    } else if (patternData.hasNode()) {

      DartNode node = ((NodeQuerySpecification) patternData).getNode();
      if (node instanceof DartIdentifier) {
        DartIdentifier id = (DartIdentifier) node;

        try {
          if (patternData.isReferencesSearch()) {
            searchForReferences(engine, id, scope, null, collector, monitor);
          }
          if (patternData.isDeclarationsSearch()) {
            searchForDeclarations(engine, id, scope, null, collector, monitor);
          }
        } catch (SearchException e) {
          DartToolsPlugin.log(e);
        } catch (CoreException ex) {
          DartToolsPlugin.log(ex);
        }
      }
    }

    //      engine.search(pattern, new SearchParticipant[] {
    // SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector,
    // mainSearchPM);
    // TODO (pquitslund): add search participant support
    //      for (int i= 0; i < participantDescriptors.length; i++) {
    //        final ISearchRequestor requestor= new
    // SearchRequestor(participantDescriptors[i].getParticipant(), textResult);
    //        final IProgressMonitor participantPM= new SubProgressMonitor(monitor, ticks[i]);
    //
    //        final int iPrime= i;
    //        ISafeRunnable runnable= new ISafeRunnable() {
    //          public void handleException(Throwable exception) {
    //            participantDescriptors[iPrime].getDescriptor().disable();
    //            String message= SearchMessages.JavaSearchQuery_error_participant_search;
    //            DartToolsPlugin.log(new Status(IStatus.ERROR, DartToolsPlugin.getPluginId(), 0,
    // message, exception));
    //          }
    //
    //          public void run() throws Exception {
    //
    //            final IQueryParticipant participant=
    // participantDescriptors[iPrime].getParticipant();
    //            final PerformanceStats stats= PerformanceStats.getStats(PERF_SEARCH_PARTICIPANT,
    // participant);
    //            stats.startRun();
    //
    //            participant.search(requestor, fPatternData, participantPM);
    //
    //            stats.endRun();
    //          }
    //        };

    //        SafeRunner.run(runnable);
    //      }

    //    } catch (CoreException e) {
    //      return e.getStatus();
    //    }

    String message =
        Messages.format(
            SearchMessages.DartSearchQuery_status_ok_message,
            String.valueOf(textResult.getMatchCount()));
    return new Status(IStatus.OK, DartToolsPlugin.getPluginId(), 0, message, null);
  }