Java Code Examples for org.eclipse.jdt.internal.ui.javaeditor.EditorUtility#revealInEditor()

The following examples show how to use org.eclipse.jdt.internal.ui.javaeditor.EditorUtility#revealInEditor() . 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: AddJavaDocStubAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	IMember[] members= getSelectedMembers(selection);
	if (members == null || members.length == 0) {
		return;
	}

	try {
		ICompilationUnit cu= members[0].getCompilationUnit();
		if (!ActionUtil.isEditable(getShell(), cu)) {
			return;
		}

		// open the editor, forces the creation of a working copy
		IEditorPart editor= JavaUI.openInEditor(cu);

		if (ElementValidator.check(members, getShell(), getDialogTitle(), false))
			run(members);
		JavaModelUtil.reconcile(cu);
		EditorUtility.revealInEditor(editor, members[0]);

	} catch (CoreException e) {
		ExceptionHandler.handle(e, getShell(), getDialogTitle(), ActionMessages.AddJavaDocStubsAction_error_actionFailed);
	}
}
 
Example 2
Source File: PropertyKeyHyperlink.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void open(KeyReference keyReference) {
	if (keyReference == null)
		return;

	try {
		IEditorPart part= keyReference.element != null ? EditorUtility.openInEditor(keyReference.element, true) : EditorUtility.openInEditor(keyReference.resource, true);
		if (part != null)
			EditorUtility.revealInEditor(part, keyReference.offset, keyReference.length);
	} catch (PartInitException x) {

		String message= null;

		IWorkbenchAdapter wbAdapter= (IWorkbenchAdapter)((IAdaptable)keyReference).getAdapter(IWorkbenchAdapter.class);
		if (wbAdapter != null)
			message= Messages.format(PropertiesFileEditorMessages.OpenAction_error_messageArgs,
					new String[] { wbAdapter.getLabel(keyReference), x.getLocalizedMessage() } );

		if (message == null)
			message= Messages.format(PropertiesFileEditorMessages.OpenAction_error_message, x.getLocalizedMessage());

		MessageDialog.openError(fShell,
			PropertiesFileEditorMessages.OpenAction_error_messageProblems,
			message);
	}
}
 
Example 3
Source File: TypeHierarchyViewPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void revealElementInEditor(Object elem, StructuredViewer originViewer) {
	// only allow revealing when the type hierarchy is the active page
	// no revealing after selection events due to model changes

	if (getSite().getPage().getActivePart() != this) {
		return;
	}

	if (fSelectionProviderMediator.getViewerInFocus() != originViewer) {
		return;
	}

	IEditorPart editorPart= EditorUtility.isOpenInEditor(elem);
	if (editorPart != null && (elem instanceof IJavaElement)) {
		getSite().getPage().removePartListener(fPartListener);
		getSite().getPage().bringToTop(editorPart);
		EditorUtility.revealInEditor(editorPart, (IJavaElement) elem);
		getSite().getPage().addPartListener(fPartListener);
	}
}
 
Example 4
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Links to editor (if option enabled)
 * @param selection the selection
 */
private void linkToEditor(ISelection selection) {
	Object obj= SelectionUtil.getSingleElement(selection);
	if (obj != null) {
		IEditorPart part= EditorUtility.isOpenInEditor(obj);
		if (part != null) {
			IWorkbenchPage page= getSite().getPage();
			page.bringToTop(part);
			if (obj instanceof IJavaElement)
				EditorUtility.revealInEditor(part, (IJavaElement)obj);
		}
	}
}
 
Example 5
Source File: JavaSearchEditorOpener.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IEditorPart openElement(Object element) throws PartInitException {
	IWorkbenchPage wbPage= JavaPlugin.getActivePage();
	IEditorPart editor;
	if (NewSearchUI.reuseEditor())
		editor= showWithReuse(element, wbPage);
	else
		editor= showWithoutReuse(element);

	if (element instanceof IJavaElement)
		EditorUtility.revealInEditor(editor, (IJavaElement) element);

	return editor;
}
 
Example 6
Source File: AbstractInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void gotoSelectedElement() {
	Object selectedElement= getSelectedElement();
	if (selectedElement != null) {
		try {
			dispose();
			IEditorPart part= EditorUtility.openInEditor(selectedElement, true);
			if (part != null && selectedElement instanceof IJavaElement)
				EditorUtility.revealInEditor(part, (IJavaElement) selectedElement);
		} catch (CoreException ex) {
			JavaPlugin.log(ex);
		}
	}
}
 
Example 7
Source File: JavaFileLinkHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) {
	if (selection == null || selection.isEmpty())
		return;
	Object element= selection.getFirstElement();
	IEditorPart part= EditorUtility.isOpenInEditor(element);
	if (part != null) {
		page.bringToTop(part);
		if (element instanceof IJavaElement)
			EditorUtility.revealInEditor(part, (IJavaElement) element);
	}

}
 
Example 8
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Links to editor (if option enabled)
 * @param selection the selection
 */
private void linkToEditor(ISelection selection) {
	Object obj= SelectionUtil.getSingleElement(selection);
	if (obj != null) {
		IEditorPart part= EditorUtility.isOpenInEditor(obj);
		if (part != null) {
			IWorkbenchPage page= getSite().getPage();
			page.bringToTop(part);
			if (obj instanceof IJavaElement)
				EditorUtility.revealInEditor(part, (IJavaElement) obj);
		}
	}
}
 
Example 9
Source File: JavaUI.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Opens an editor on the given Java element in the active page. Valid elements are all Java elements that are {@link ISourceReference}.
	 * For elements inside a compilation unit or class file, the parent is opened in the editor is opened.
	 * If there already is an open Java editor for the given element, it is returned.
 *
 * @param element the input element; either a compilation unit
 *   (<code>ICompilationUnit</code>) or a class file (<code>IClassFile</code>) or source references inside.
 * @param activate if set, the editor will be activated.
 * @param reveal if set, the element will be revealed.
 * @return returns the editor part of the opened editor or <code>null</code> if the element is not a {@link ISourceReference} or the
 * file was opened in an external editor.
 * @exception PartInitException if the editor could not be initialized or no workbench page is active
 * @exception JavaModelException if this element does not exist or if an exception occurs while accessing its underlying resource
 * @since 3.3
 */
public static IEditorPart openInEditor(IJavaElement element, boolean activate, boolean reveal) throws JavaModelException, PartInitException {
	if (!(element instanceof ISourceReference)) {
		return null;
	}
	IEditorPart part= EditorUtility.openInEditor(element, activate);
	if (reveal && part != null) {
		EditorUtility.revealInEditor(part, element);
	}
	return part;
}
 
Example 10
Source File: JavaUI.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Reveals the given java element  in the given editor. If the element is not an instance
 * of <code>ISourceReference</code> this method result in a NOP. If it is a source
 * reference no checking is done if the editor displays a compilation unit or class file that
 * contains the source reference element. The editor simply reveals the source range
 * denoted by the given element.
 *
 * @param part the editor displaying a compilation unit or class file
 * @param element the element to be revealed
 *
 * @since 2.0
 */
public static void revealInEditor(IEditorPart part, IJavaElement element) {
	EditorUtility.revealInEditor(part, element);
}