Java Code Examples for org.eclipse.ui.texteditor.ITextEditor#setFocus()

The following examples show how to use org.eclipse.ui.texteditor.ITextEditor#setFocus() . 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: TestHTML.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFormat() throws Exception {
	final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("testHTMLFile" + System.currentTimeMillis());
	project.create(null);
	project.open(null);
	final IFile file = project.getFile("blah.html");
	file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null);
	ITextEditor editor = (ITextEditor) IDE
			.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
	editor.setFocus();
	editor.getSelectionProvider().setSelection(new TextSelection(0, 0));
	IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
	AtomicReference<Exception> ex = new AtomicReference<>();
	new DisplayHelper() {
		@Override protected boolean condition() {
			try {
				handlerService.executeCommand("org.eclipse.lsp4e.format", null);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
	}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
	if (ex.get() != null) {
		throw ex.get();
	}
	new DisplayHelper() {
		@Override protected boolean condition() {
			return editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1;
		}
	}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000);
}
 
Example 2
Source File: WithMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
public boolean beginSession(ITextEditor editor, IWorkbenchPage page, ExecutionEvent event) {
	boolean ok = false;
	this.editor = editor;
	this.page = page;
	// TODO: Hack?  When the command view was double clicked, then M-x executing
	// the editor doesn't really have focus, so force it.
	try {
		inBegin = true;
		editor.setFocus();
	} finally {
		inBegin = false;
	}
	minibufferStringImpl = new MinibufferImpl(getDocument(),lowercase);
	if (initializeBuffer(editor,page)) {
		ok = install();
		if (ok) {
			if (handlesCtrl() || handlesAlt()){
				setKeyFilter(false);
			}
			if (initStatusMsg()) {
				// clear any normal/error message
				doSetResultMessage(EMPTY_STR, true);
				doSetResultMessage(EMPTY_STR, false);
			}
			// initialize our status message
			updateStatusLine(EMPTY_STR);
		} else {
			endSession();
		}
	}
	return ok;
}