public void run(IAction action) { boolean okay = false; if (fEditor instanceof ITextEditor) { ITextEditor textEditor = (ITextEditor) fEditor; IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); if (document != null) { ITextSelection textSelection = getTextSelection(textEditor); FindOccurrencesProcessor findOccurrenceProcessor = getProcessorForCurrentSelection(document, textSelection); if (findOccurrenceProcessor != null) { if (textEditor.getEditorInput() instanceof IFileEditorInput) { IFile file = ((IFileEditorInput) textEditor.getEditorInput()).getFile(); okay = findOccurrenceProcessor.findOccurrences(document, textSelection, file); } } } } if (okay) { // clear status message PlatformStatusLineUtil.clearStatusLine(); } else { String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0; // $NON-NLS-1$ if (fEditor instanceof StructuredTextEditor) { PlatformStatusLineUtil.displayTemporaryErrorMessage( ((StructuredTextEditor) fEditor).getTextViewer(), errorMessage); } else { PlatformStatusLineUtil.displayErrorMessage(errorMessage); PlatformStatusLineUtil.addOneTimeClearListener(); } } }
/** * Get the appropriate find occurrences processor * * @param document - assumes not null * @param textSelection * @return */ private FindOccurrencesProcessor getProcessorForCurrentSelection( IDocument document, ITextSelection textSelection) { // check if we have an action that's enabled on the current partition ITypedRegion tr = getPartition(document, textSelection); String partition = tr != null ? tr.getType() : ""; // $NON-NLS-1$ Iterator it = getProcessors().iterator(); FindOccurrencesProcessor processor = null; while (it.hasNext()) { processor = (FindOccurrencesProcessor) it.next(); // we just choose the first action that can handle the partition if (processor.enabledForParitition(partition)) return processor; } List extendedFindOccurrencesProcessors = ExtendedConfigurationBuilder.getInstance() .getConfigurations(FindOccurrencesProcessor.class.getName(), partition); for (int i = 0; i < extendedFindOccurrencesProcessors.size(); i++) { Object o = extendedFindOccurrencesProcessors.get(i); if (o instanceof FindOccurrencesProcessor) { /* * We just choose the first registered processor that explicitly says it can handle the * partition */ processor = (FindOccurrencesProcessor) o; if (processor.enabledForParitition(partition)) return processor; } } return null; }