/** * Displays the given error message in the status line. * * @param message the message to display */ protected void showErrorMessage(String message) { if (fPart instanceof IViewPart) { IViewSite viewSite = ((IViewPart) fPart).getViewSite(); IStatusLineManager manager = viewSite.getActionBars().getStatusLineManager(); manager.setErrorMessage(message); Display.getCurrent().beep(); } }
/** * Here, all the editors available will be gotten and searched (if possible). * * <p>Note that editors that are not in the workspace may not be searched (it should be possible * to do, but one may have to reimplement large portions of the search for that to work). */ public static void findInOpenDocuments( final String searchText, final boolean caseSensitive, final boolean wholeWord, final boolean isRegEx, IStatusLineManager statusLineManager) { IWorkbenchWindow window = EditorUtils.getActiveWorkbenchWindow(); if (window == null) { if (statusLineManager != null) statusLineManager.setErrorMessage("Active workbench window is null."); return; } IWorkbenchPage activePage = window.getActivePage(); if (activePage == null) { if (statusLineManager != null) statusLineManager.setErrorMessage("Active page is null."); return; } IEditorReference editorsArray[] = activePage.getEditorReferences(); final List<IFile> files = new ArrayList<IFile>(); for (int i = 0; i < editorsArray.length; i++) { IEditorPart realEditor = editorsArray[i].getEditor(true); if (realEditor != null) { if (realEditor instanceof MultiPageEditorPart) { try { Method getPageCount = MultiPageEditorPart.class.getDeclaredMethod("getPageCount"); getPageCount.setAccessible(true); Method getEditor = MultiPageEditorPart.class.getDeclaredMethod("getEditor", int.class); getEditor.setAccessible(true); Integer pageCount = (Integer) getPageCount.invoke(realEditor); for (int j = 0; j < pageCount; j++) { IEditorPart part = (IEditorPart) getEditor.invoke(realEditor, j); if (part != null) { IEditorInput input = part.getEditorInput(); if (input != null) { IFile file = (IFile) input.getAdapter(IFile.class); if (file != null) { files.add(file); } } } } } catch (Throwable e1) { // Log it but keep going on. Log.log(e1); } } else { IEditorInput input = realEditor.getEditorInput(); if (input != null) { IFile file = (IFile) input.getAdapter(IFile.class); if (file != null) { files.add(file); } else { // it has input, but it's not adaptable to an IFile! if (statusLineManager != null) statusLineManager.setMessage( "Warning: Editors not in the workspace cannot be searched."); // but we keep on going... } } } } } if (files.size() == 0) { if (statusLineManager != null) statusLineManager.setMessage( "No file was found to perform the search (editors not in the workspace cannot be searched)."); return; } try { ISearchQuery query = TextSearchQueryProvider.getPreferred() .createQuery( new TextSearchInput() { public boolean isRegExSearch() { return isRegEx; } public boolean isCaseSensitiveSearch() { return caseSensitive; } public String getSearchText() { return searchText; } public FileTextSearchScope getScope() { return FileTextSearchScope.newSearchScope( files.toArray(new IResource[files.size()]), new String[] {"*"}, true); } }); NewSearchUI.runQueryInBackground(query); } catch (CoreException e1) { Log.log(e1); } }
/* * @see EditorActionBarContributor#setActiveEditor(IEditorPart) */ @Override public void setActiveEditor(IEditorPart part) { super.setActiveEditor(part); ITextEditor textEditor = null; if (part instanceof ITextEditor) textEditor = (ITextEditor) part; fTogglePresentation.setEditor(textEditor); fToggleMarkOccurrencesAction.setEditor(textEditor); fGotoMatchingBracket.setAction( getAction(textEditor, GotoMatchingBracketAction.GOTO_MATCHING_BRACKET)); fShowOutline.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_OUTLINE)); fOpenHierarchy.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_HIERARCHY)); fOpenStructure.setAction(getAction(textEditor, IJavaEditorActionDefinitionIds.OPEN_STRUCTURE)); fStructureSelectEnclosingAction.setAction( getAction(textEditor, StructureSelectionAction.ENCLOSING)); fStructureSelectNextAction.setAction(getAction(textEditor, StructureSelectionAction.NEXT)); fStructureSelectPreviousAction.setAction( getAction(textEditor, StructureSelectionAction.PREVIOUS)); fStructureSelectHistoryAction.setAction( getAction(textEditor, StructureSelectionAction.HISTORY)); fGotoNextMemberAction.setAction( getAction(textEditor, GoToNextPreviousMemberAction.NEXT_MEMBER)); fGotoPreviousMemberAction.setAction( getAction(textEditor, GoToNextPreviousMemberAction.PREVIOUS_MEMBER)); fRemoveOccurrenceAnnotationsAction.setAction( getAction(textEditor, "RemoveOccurrenceAnnotations")); // $NON-NLS-1$ fRetargetShowInformationAction.setAction( getAction(textEditor, ITextEditorActionConstants.SHOW_INFORMATION)); if (part instanceof JavaEditor) { JavaEditor javaEditor = (JavaEditor) part; javaEditor.getActionGroup().fillActionBars(getActionBars()); FoldingActionGroup foldingActions = javaEditor.getFoldingActionGroup(); if (foldingActions != null) foldingActions.updateActionBars(); } IActionBars actionBars = getActionBars(); IStatusLineManager manager = actionBars.getStatusLineManager(); manager.setMessage(null); manager.setErrorMessage(null); /** The global actions to be connected with editor actions */ IAction action = getAction(textEditor, ITextEditorActionConstants.NEXT); actionBars.setGlobalActionHandler(ITextEditorActionDefinitionIds.GOTO_NEXT_ANNOTATION, action); actionBars.setGlobalActionHandler(ITextEditorActionConstants.NEXT, action); action = getAction(textEditor, ITextEditorActionConstants.PREVIOUS); actionBars.setGlobalActionHandler( ITextEditorActionDefinitionIds.GOTO_PREVIOUS_ANNOTATION, action); actionBars.setGlobalActionHandler(ITextEditorActionConstants.PREVIOUS, action); action = getAction(textEditor, IJavaEditorActionConstants.COPY_QUALIFIED_NAME); actionBars.setGlobalActionHandler(CopyQualifiedNameAction.ACTION_HANDLER_ID, action); actionBars.setGlobalActionHandler( IJavaEditorActionDefinitionIds.SHOW_IN_BREADCRUMB, getAction(textEditor, IJavaEditorActionDefinitionIds.SHOW_IN_BREADCRUMB)); actionBars.setGlobalActionHandler( "org.eclipse.jdt.internal.ui.actions.OpenHyperlink", getAction(textEditor, ITextEditorActionConstants.OPEN_HYPERLINK)); // $NON-NLS-1$ }