Search in sources :

Example 1 with FindOccurrencesProcessor

use of org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor in project webtools.sourceediting by eclipse.

the class HTMLFindOccurrencesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    boolean okay = false;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        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 {
        // $NON-NLS-1$
        String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
        if (textEditor instanceof StructuredTextEditor) {
            PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) textEditor).getTextViewer(), errorMessage);
        } else {
            PlatformStatusLineUtil.displayErrorMessage(errorMessage);
            PlatformStatusLineUtil.addOneTimeClearListener();
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FindOccurrencesProcessor(org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor) HTMLFindOccurrencesProcessor(org.eclipse.wst.html.ui.internal.search.HTMLFindOccurrencesProcessor) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 2 with FindOccurrencesProcessor

use of org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor in project webtools.sourceediting by eclipse.

the class HTMLFindOccurrencesHandler method getProcessorForCurrentSelection.

/**
 * 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);
    // $NON-NLS-1$
    String partition = tr != null ? tr.getType() : "";
    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;
}
Also used : Iterator(java.util.Iterator) FindOccurrencesProcessor(org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor) HTMLFindOccurrencesProcessor(org.eclipse.wst.html.ui.internal.search.HTMLFindOccurrencesProcessor) ITypedRegion(org.eclipse.jface.text.ITypedRegion) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with FindOccurrencesProcessor

use of org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor in project webtools.sourceediting by eclipse.

the class FindOccurrencesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editorPart instanceof ITextEditor)
        textEditor = (ITextEditor) editorPart;
    else {
        Object o = editorPart.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    boolean okay = false;
    if (textEditor != null) {
        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 {
        // $NON-NLS-1$
        String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
        if (textEditor instanceof StructuredTextEditor) {
            PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) textEditor).getTextViewer(), errorMessage);
        } else {
            PlatformStatusLineUtil.displayErrorMessage(errorMessage);
            PlatformStatusLineUtil.addOneTimeClearListener();
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FindOccurrencesProcessor(org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 4 with FindOccurrencesProcessor

use of org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor in project webtools.sourceediting by eclipse.

the class XMLFindOccurencesHandler method getProcessorForCurrentSelection.

/**
 * Get the appropriate find occurrences processor
 *
 * @param document -
 *            assumes not null
 * @param textSelection
 * @return FindOccurrencesProcessor
 */
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);
    // $NON-NLS-1$
    String partition = tr != null ? tr.getType() : "";
    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;
}
Also used : Iterator(java.util.Iterator) XMLFindOccurrencesProcessor(org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesProcessor) FindOccurrencesProcessor(org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor) ITypedRegion(org.eclipse.jface.text.ITypedRegion) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with FindOccurrencesProcessor

use of org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor in project webtools.sourceediting by eclipse.

the class XMLFindOccurencesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    boolean okay = false;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        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 {
        // $NON-NLS-1$
        String errorMessage = SSEUIMessages.FindOccurrencesActionProvider_0;
        if (textEditor instanceof StructuredTextEditor) {
            PlatformStatusLineUtil.displayTemporaryErrorMessage(((StructuredTextEditor) textEditor).getTextViewer(), errorMessage);
        } else {
            PlatformStatusLineUtil.displayErrorMessage(errorMessage);
            PlatformStatusLineUtil.addOneTimeClearListener();
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) IFileEditorInput(org.eclipse.ui.IFileEditorInput) XMLFindOccurrencesProcessor(org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesProcessor) FindOccurrencesProcessor(org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor) IEditorPart(org.eclipse.ui.IEditorPart) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

FindOccurrencesProcessor (org.eclipse.wst.sse.ui.internal.search.FindOccurrencesProcessor)6 Iterator (java.util.Iterator)3 List (java.util.List)3 IFile (org.eclipse.core.resources.IFile)3 IDocument (org.eclipse.jface.text.IDocument)3 ITextSelection (org.eclipse.jface.text.ITextSelection)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 IEditorPart (org.eclipse.ui.IEditorPart)3 IFileEditorInput (org.eclipse.ui.IFileEditorInput)3 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)3 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)3 ArrayList (java.util.ArrayList)2 HTMLFindOccurrencesProcessor (org.eclipse.wst.html.ui.internal.search.HTMLFindOccurrencesProcessor)2 XMLFindOccurrencesProcessor (org.eclipse.wst.xml.ui.internal.search.XMLFindOccurrencesProcessor)2