コード例 #1
0
  /** @see IEditorActionDelegate#run */
  public void run(IAction action) {
    try {
      clearErrorMessage();

      if (editor instanceof JavaEditor) {
        try {
          IJavaElement[] editorElements = SelectionConverter.codeResolve((JavaEditor) editor);

          IJavaElement[] elements = internalSearch(editorElements, getProgressMonitor());
          if (elements != null) {
            if (elements.length == 1) {
              jumpToElement(elements[0]);
            } else if (elements.length > 1) {
              selectElementToJumpTo(elements);
            } else {
              showInfoMessage(getNoResultsMessage());
            }
          }
        } catch (JavaModelException e) {
          ImplementorsUI.log(e);
        }
      }
    } catch (RuntimeException e) {
      ImplementorsUI.log(e);
    }
  }
コード例 #2
0
  /**
   * Select the IJavaElement to jump to from a list of choices.
   *
   * @param implementors
   */
  private void selectElementToJumpTo(IJavaElement[] implementors) {
    ElementListSelectionDialog dialog =
        new ElementListSelectionDialog(
            ImplementorsUI.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell(),
            new AppearanceAwareLabelProvider(
                AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS
                    | JavaElementLabels.ALL_POST_QUALIFIED
                    | JavaElementLabels.APPEND_ROOT_PATH,
                AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS));

    dialog.setTitle(getSelectMethodTitle());
    dialog.setMessage(getSelectMethodMessage());
    dialog.setElements(implementors);
    dialog.setEmptySelectionMessage(getEmptySelectionMessage());
    dialog.setMultipleSelection(false);
    dialog.setBlockOnOpen(true);
    dialog.setDialogBoundsSettings(
        ImplementorsUI.getInstance().getDialogSettings(),
        ElementListSelectionDialog.DIALOG_PERSISTSIZE);
    if (dialog.open() == IDialogConstants.CANCEL_ID) return;

    Object[] selectedImplementors = dialog.getResult();
    if (selectedImplementors != null && selectedImplementors.length == 1) {
      IJavaElement element = (IJavaElement) selectedImplementors[0];
      jumpToElement(element);
    }
  }
コード例 #3
0
 private void jumpToElement(IJavaElement element) {
   if (element != null) {
     try {
       IEditorPart methodEditor = ImplementorsUtility.openInEditor(element, true);
       if (methodEditor != null) {
         JavaUI.revealInEditor(methodEditor, element);
       } else {
         showErrorMessage(
             ImplementorsMessages.getString(
                 "AbstractGotoActionDelegate.error_opening_editor")); //$NON-NLS-1$
       }
     } catch (JavaModelException e) {
       ImplementorsUI.log(e);
     } catch (PartInitException e) {
       ImplementorsUI.log(e);
     }
   }
 }