private void performNewSearch(final IErlElement element) { final ErlangExternalFunctionCallRef ref = SearchUtil.getRefFromErlElement(element); final ErlSearchQuery query = new ErlSearchQuery( ref, IErlSearchConstants.REFERENCES, IErlSearchConstants.FUNCTION, getScope()); if (query.canRunInBackground()) { /* * This indirection with Object as parameter is needed to prevent * the loading of the Search plug-in: the VM verifies the method * call and hence loads the types used in the method signature, * eventually triggering the loading of a plug-in (in this case * ISearchQuery results in Search plug-in being loaded). */ NewSearchUI.runQueryInBackground(query); } else { final IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); /* * This indirection with Object as parameter is needed to prevent * the loading of the Search plug-in: the VM verifies the method * call and hence loads the types used in the method signature, * eventually triggering the loading of a plug-in (in this case it * would be ISearchQuery). */ final IStatus status = NewSearchUI.runQueryInForeground(progressService, query); if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) { ErrorDialog.openError( getShell(), "SearchMessages.Search_Error_search_title", "SearchMessages.Search_Error_search_message", status); } } }
@Override public void run() { ISearchQuery searchJob = null; ISelection selection = getSelection(); if (selection instanceof IStructuredSelection) { Object object = ((IStructuredSelection) selection).getFirstElement(); if (object instanceof ISourceReference) searchJob = createQuery((ISourceReference) object); } else if (selection instanceof ITextSelection) { ITextSelection selNode = (ITextSelection) selection; ICElement element = fEditor.getInputCElement(); while (element != null && !(element instanceof ITranslationUnit)) element = element.getParent(); if (element != null) { if (selNode.getLength() == 0) { IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()); IRegion reg = CWordFinder.findWord(document, selNode.getOffset()); selNode = new TextSelection(document, reg.getOffset(), reg.getLength()); } searchJob = createQuery(element, selNode); } } if (searchJob == null) { showStatusLineMessage(CSearchMessages.CSearchOperation_operationUnavailable_message); return; } clearStatusLine(); NewSearchUI.activateSearchResultView(); NewSearchUI.runQueryInBackground(searchJob); }
private void doSearch(ISelection sel) { IPackageFragment frag = getPackageFragment(sel); if (frag != null) { FindReferencesAction action = new FindReferencesAction(getPage().getEditorSite()); action.run(frag); } else if (sel instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) sel; PackageObject exportObject = (PackageObject) selection.getFirstElement(); NewSearchUI.runQueryInBackground(new BlankQuery(exportObject)); } }
@Override public boolean performAction() { try { source.saveState(DBeaverCore.getGlobalPreferenceStore()); NewSearchUI.runQueryInBackground(createQueryAdapter(source.createQuery())); } catch (Exception e) { UIUtils.showErrorDialog(getControl().getShell(), "Search", "Can't perform search", e); return false; } return true; }
@Override protected void doRun(ICElement[] elements) { if (elements.length == 0) { StatusLineHandler.showStatusLineMessage( fSite, CSearchMessages.CSearchOperation_operationUnavailable_message); return; } ISearchQuery searchJob = new CSearchUnresolvedIncludesQuery(elements); StatusLineHandler.clearStatusLine(fSite); NewSearchUI.activateSearchResultView(); NewSearchUI.runQueryInBackground(searchJob); }
/** * This helper method with Object as parameter is needed to prevent the loading of the Search * plug-in: the Interpreter verifies the method call and hence loads the types used in the method * signature, eventually triggering the loading of a plug-in (in this case ISearchQuery results in * Search plug-in being loaded). */ public static void runQueryInBackground(Object query) { NewSearchUI.runQueryInBackground((ISearchQuery) query); }
/** * 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); } }
public static void search(String scopeName, IType[] accessorClasses, IFile[] propertieFiles) { NLSSearchQuery query = new NLSSearchQuery( accessorClasses, propertieFiles, SearchEngine.createWorkspaceScope(), scopeName); NewSearchUI.runQueryInBackground(query); }