Java Code Examples for org.eclipse.search.ui.text.Match#getElement()

The following examples show how to use org.eclipse.search.ui.text.Match#getElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OccurrencesSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public boolean isShownInEditor(Match match, IEditorPart editor) {
	Object element= match.getElement();
	IJavaElement je= ((JavaElementLine) element).getJavaElement();
	IEditorInput editorInput= editor.getEditorInput();
	if (editorInput instanceof IFileEditorInput) {
		try {
			return ((IFileEditorInput)editorInput).getFile().equals(je.getCorrespondingResource());
		} catch (JavaModelException e) {
			return false;
		}
	} else if (editorInput instanceof IClassFileEditorInput) {
		return ((IClassFileEditorInput)editorInput).getClassFile().equals(je);
	}

	return false;
}
 
Example 2
Source File: JavaSearchResultPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
	IEditorPart editor= fEditorOpener.openMatch(match);

	if (editor != null && activate)
		editor.getEditorSite().getPage().activate(editor);
	Object element= match.getElement();
	if (editor instanceof ITextEditor) {
		ITextEditor textEditor= (ITextEditor) editor;
		textEditor.selectAndReveal(offset, length);
	} else if (editor != null) {
		if (element instanceof IFile) {
			IFile file= (IFile) element;
			showWithMarker(editor, file, offset, length);
		}
	} else if (getInput() instanceof JavaSearchResult) {
		JavaSearchResult result= (JavaSearchResult) getInput();
		IMatchPresentation participant= result.getSearchParticpant(element);
		if (participant != null)
			participant.showMatch(match, offset, length, activate);
	}
}
 
Example 3
Source File: UIParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void showMatch(Match match, int currentOffset, int currentLength, boolean activate) {
	Object o = match.getElement();
	if (o instanceof IReferenceDescription) {
		IReferenceDescription descr = (IReferenceDescription) o;
		if (activate) {
			uriEditorOpener.open(descr.getSourceEObjectUri(), descr.getEReference(), descr.getIndexInList(),
					true);
		}
	}
}
 
Example 4
Source File: TypeScriptSearchResultPage.java    From typescript.java with MIT License 5 votes vote down vote up
protected void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
	IFile file= (IFile) match.getElement();
	IWorkbenchPage page= getSite().getPage();
	if (offset >= 0 && length != 0) {
		openAndSelect(page, file, offset, length, activate);
	} else {
		open(page, file, activate);
	}
}
 
Example 5
Source File: NLSSearchEditorOpener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Object getElementToOpen(Match match) {
	Object element= match.getElement();
	if (element instanceof IJavaElement) {
		return element;
	} else if (element instanceof FileEntry) {
		FileEntry fileEntry= (FileEntry) element;
		return fileEntry.getPropertiesFile();
	} else if (element instanceof CompilationUnitEntry) {
		return ((CompilationUnitEntry)element).getCompilationUnit();
	}
	// this should not happen
	return null;
}
 
Example 6
Source File: JavaSearchQuery.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void reportMatch(Match match) {
	IMatchPresentation participant= fParticipant.getUIParticipant();
	if (participant == null || match.getElement() instanceof IJavaElement || match.getElement() instanceof IResource) {
		fSearchResult.addMatch(match);
	} else {
		fSearchResult.addMatch(match, participant);
	}
}
 
Example 7
Source File: AbstractJavaSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isShownInEditor(Match match, IEditorPart editor) {
	Object element= match.getElement();
	if (element instanceof IJavaElement) {
		element= ((IJavaElement) element).getOpenable(); // class file or compilation unit
		return element != null && element.equals(editor.getEditorInput().getAdapter(IJavaElement.class));
	} else if (element instanceof IFile) {
		return element.equals(editor.getEditorInput().getAdapter(IFile.class));
	}
	return false;
}
 
Example 8
Source File: JavaSearchResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
boolean addMatch(Match match, IMatchPresentation participant) {
	Object element= match.getElement();
	if (fElementsToParticipants.get(element) != null) {
		// TODO must access the participant id / label to properly report the error.
		JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), 0, "A second search participant was found for an element", null)); //$NON-NLS-1$
		return false;
	}
	fElementsToParticipants.put(element, participant);
	addMatch(match);
	return true;
}
 
Example 9
Source File: AbstractSearchIndexResultPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
    IFile file = (IFile) match.getElement();
    IWorkbenchPage page = getSite().getPage();
    if (offset >= 0 && length != 0) {
        openAndSelect(page, file, offset, length, activate);
    } else {
        open(page, file, activate);
    }
}
 
Example 10
Source File: FileSearchPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
    IFile file = (IFile) match.getElement();
    IWorkbenchPage page = getSite().getPage();
    if (offset >= 0 && length != 0) {
        fEditorOpener.openAndSelect(page, file, offset, length, activate);
    } else {
        fEditorOpener.open(page, file, activate);
    }
}
 
Example 11
Source File: ModulaSearchResult.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public boolean isShownInEditor(Match match, IEditorPart editor) {
    Object element = match.getElement();
    if (element instanceof IFile)
        return isMatchContained(editor, (IFile) element);
    return false;
}
 
Example 12
Source File: JavaSearchEditorOpener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected Object getElementToOpen(Match match) {
	return match.getElement();
}