I used Martia Kayarik pointers to answer this question. I have work with the following code, which, however, uses the internal string identifier from TextEditor. However, here everything goes.
getAdapter() in the view should be implemented as follows ( viewer is an instance of TextViewer )
public Object getAdapter(Class adapter) { if (IFindReplaceTarget.class.equals(adapter)) { if (viewer != null) { return viewer.getFindReplaceTarget(); } } return super.getAdapter(adapter); }
In the createPartControl() your view, add this code:
FindReplaceAction findAction= new FindReplaceAction(ResourceBundle.getBundle("org.eclipse.ui.texteditor.ConstructedTextEditorMessages"), null, this); IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class); IHandler handler= new AbstractHandler() { public Object execute(ExecutionEvent event) throws ExecutionException { if (viewer != null && viewer.getDocument() != null) findAction.run(); return null; } }; handlerService.activateHandler("org.eclipse.ui.edit.findReplace", handler);
XML is not required.
source share