use of org.eclipse.ui.texteditor.AbstractTextEditor in project webtools.sourceediting by eclipse.
the class ContentAssistTestUtilities method getProposals.
/**
* <p>
* Returns the content assist proposals when invoked at the offset provided.
* </p>
*
* @param fileNum
* @param lineNum
* @param lineRelativeCharOffset
* @param numOfPages
*/
private static ICompletionProposal[][] getProposals(TestProjectSetup testProject, String filePath, int lineNum, int lineRelativeCharOffset, int numOfPages) throws Exception {
IFile file = testProject.getFile(filePath);
AbstractTextEditor editor = testProject.getEditor(file);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int offset = doc.getLineOffset(lineNum) + lineRelativeCharOffset;
ICompletionProposal[][] pages = getProposals(editor, offset, numOfPages);
return pages;
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project webtools.sourceediting by eclipse.
the class TestProjectSetup method getEditor.
/**
* <p>
* Given a <code>file</code> get an editor for it. If an editor has already been retrieved for
* the given <code>file</code> then return the same already open editor.
* </p>
*
* <p>
* When opening the editor it will also standardized the line endings to <code>\n</code>
* </p>
*
* @param file
* open and return an editor for this
* @return <code>StructuredTextEditor</code> opened from the given <code>file</code>
*/
public AbstractTextEditor getEditor(IFile file) {
AbstractTextEditor editor = (AbstractTextEditor) fFileToEditorMap.get(file);
if (editor == null) {
try {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = workbenchWindow.getActivePage();
IEditorPart editorPart = null;
if (file.getFileExtension().equals("js")) {
editorPart = IDE.openEditor(page, file, true, true);
} else if (file.getFileExtension().equals("html")) {
editorPart = IDE.openEditor(page, file, "org.eclipse.wst.html.core.htmlsource.source", true);
}
if (editorPart instanceof AbstractTextEditor) {
editor = (AbstractTextEditor) editorPart;
} else {
Assert.fail("Unable to open structured text editor");
}
if (editor != null) {
standardizeLineEndings(editor);
fFileToEditorMap.put(file, editor);
} else {
Assert.fail("Could not open editor for " + file);
}
} catch (Exception e) {
Assert.fail("Could not open editor for " + file + " exception: " + e.getMessage());
}
}
return editor;
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project webtools.sourceediting by eclipse.
the class TestProjectSetup method tearDown.
/**
* <p>
* This is run once after all of the tests have been run
* </p>
*
* @see junit.extensions.TestSetup#tearDown()
*/
public void tearDown() throws Exception {
// close out the editors
Iterator iter = fFileToEditorMap.values().iterator();
while (iter.hasNext()) {
AbstractTextEditor editor = (AbstractTextEditor) iter.next();
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);
}
this.fFileToEditorMap.clear();
// delete the project
if (this.fDeleteOnTearDown) {
this.fProject.delete(true, new NullProgressMonitor());
}
// restore properties
if (fPreviousWTPAutoTestNonInteractivePropValue != null) {
System.setProperty(WTP_AUTOTEST_NONINTERACTIVE, fPreviousWTPAutoTestNonInteractivePropValue);
}
}
use of org.eclipse.ui.texteditor.AbstractTextEditor in project dbeaver by serge-rider.
the class TextEditorUtils 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;
Control widget = hostEditor.getAdapter(Control.class);
if (widget == null || widget.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 dbeaver by dbeaver.
the class TextEditorUtils 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;
Control widget = hostEditor.getAdapter(Control.class);
if (widget == null || widget.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);
}
}
Aggregations