blob: 91bb79480e435401c726a5a773b9d7039163b432 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.jsdt.astview;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.jsdt.core.IJavaScriptElement;
import org.eclipse.wst.jsdt.core.ITypeRoot;
import org.eclipse.wst.jsdt.ui.JavaScriptUI;
/**
*
*/
public class EditorUtility {
private EditorUtility() {
super();
}
public static IEditorPart getActiveEditor() {
IWorkbenchWindow window= ASTViewPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page= window.getActivePage();
if (page != null) {
return page.getActiveEditor();
}
}
return null;
}
public static ITypeRoot getJavaInput(IEditorPart part) {
IEditorInput editorInput= part.getEditorInput();
if (editorInput != null) {
IJavaScriptElement input= JavaScriptUI.getEditorInputJavaElement(editorInput);
if (input instanceof ITypeRoot) {
return (ITypeRoot) input;
}
}
return null;
}
public static void selectInEditor(ITextEditor editor, int offset, int length) {
IEditorPart active = getActiveEditor();
if (active != editor) {
editor.getSite().getPage().activate(editor);
}
editor.selectAndReveal(offset, length);
}
}