use of org.eclipse.ui.texteditor.AbstractTextEditor in project dbeaver by dbeaver.
the class UIUtils method enableHostEditorKeyBindings.
/**
* Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host editor is extender of
* AbstractTextEditor Uses reflection because setActionActivation is private method
* TODO: find better way to disable key bindings or prioritize event handling to widgets
*
* @param partSite workbench part site
* @param enable enable or disable
*/
@Deprecated
public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
IWorkbenchPart part = partSite.getPart();
if (part instanceof AbstractTextEditor) {
AbstractTextEditor hostEditor = (AbstractTextEditor) part;
if (hostEditor instanceof BaseTextEditor) {
StyledText textWidget = ((BaseTextEditor) hostEditor).getTextViewer().getTextWidget();
if (textWidget == null || textWidget.isDisposed()) {
return;
}
}
try {
Method activatorMethod = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
activatorMethod.setAccessible(true);
activatorMethod.invoke(hostEditor, enable);
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
log.warn("Can't disable text editor action activations", e);
}
// hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
}
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project titan.EclipsePlug-ins by eclipse.
the class OpenSourceAction method openEditor.
/**
* Opens the editor for the given source file
*
* This method is intended to use only by {@link org.eclipse.titan.log.viewer.actions.OpenSourceViewMenuAction}
*
* @param targetFile The source file
* @param lineNumber The line number to select
* @param logView The view which initiated this action (used only to report errors on the status line)
* @param forceEditorOpening
*/
public static void openEditor(final IFile targetFile, final int lineNumber, final IViewPart logView, final boolean forceEditorOpening) {
// search for the editor to open the file
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(targetFile.getName());
if (desc == null) {
desc = PlatformUI.getWorkbench().getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
if (desc == null) {
logView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The editor could not be found");
return;
}
}
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
IWorkbenchPage activePage = window.getActivePage();
if (activePage == null) {
return;
}
try {
FileEditorInput editorInput = new FileEditorInput(targetFile);
IEditorPart editorPart = activePage.findEditor(editorInput);
if (editorPart == null) {
if (!forceEditorOpening) {
return;
}
editorPart = activePage.openEditor(editorInput, desc.getId());
}
if (!(editorPart instanceof AbstractTextEditor)) {
logView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("Could not jump to the target position");
return;
}
AbstractTextEditor textEditor = (AbstractTextEditor) editorPart;
IDocument targetDocument = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
if (targetDocument == null) {
logView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The target document does not exist");
return;
}
if (lineNumber >= targetDocument.getNumberOfLines()) {
logView.getViewSite().getActionBars().getStatusLineManager().setErrorMessage("The position is after the last line in the source code.");
return;
}
// Line numbers are indexed from zero in the editors
IRegion lineRegion = targetDocument.getLineInformation(lineNumber - 1);
activePage.bringToTop(textEditor);
textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength());
} catch (PartInitException e) {
ErrorReporter.logExceptionStackTrace(e);
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project titan.EclipsePlug-ins by eclipse.
the class LocationHighlighter method jumpToLocation.
/**
* Jump to the provided location and highlight it.
*/
public static void jumpToLocation(final Location location) {
final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
if (desc == null) {
return;
}
try {
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IEditorPart editorPart = page.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
if (editorPart != null && editorPart instanceof AbstractTextEditor) {
((AbstractTextEditor) editorPart).setHighlightRange(location.getOffset(), 0, true);
}
} catch (final PartInitException e) {
ErrorReporter.logExceptionStackTrace("Error while opening the editor", e);
}
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method selectAndRevealDeclaration.
/**
* Opens an editor for the provided declaration, and in this editor the
* location of the declaration is revealed and selected.
*
* @param declaration
* the declaration to reveal
*/
private void selectAndRevealDeclaration(final Location location) {
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
if (desc == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TTCN3EDITORNOTFOUND);
return;
}
try {
IWorkbenchPage page = targetEditor.getSite().getPage();
IEditorPart editorPart = page.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
if (editorPart != null && (editorPart instanceof AbstractTextEditor)) {
((AbstractTextEditor) editorPart).selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
}
} catch (PartInitException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project titan.EclipsePlug-ins by eclipse.
the class OpenDeclaration method selectAndRevealDeclaration.
/**
* Opens an editor for the provided declaration, and in this editor the
* location of the declaration is revealed and selected.
*
* @param declaration
* the declaration to reveal
*/
private void selectAndRevealDeclaration(final Location location) {
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
if (desc == null) {
targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(TTCNPPEDITORNOTFOUND);
return;
}
try {
IWorkbenchPage page = targetEditor.getSite().getPage();
IEditorPart editorPart = page.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
if (editorPart != null && (editorPart instanceof AbstractTextEditor)) {
((AbstractTextEditor) editorPart).selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
}
} catch (PartInitException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
Aggregations