3

I'm writing an Eclipse plugin with a wizard (org.eclipse.jface.wizard.Wizard) which creates a new file with a basic code template. To simplify the "piecing together" of the file contents, I plan to stuff everything into one long string, inject it into the file, and then call my custom Formatter (inherits org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter) to clean up all the indentation and so on.

Question is, how do I go about calling the formatter programmatically? In the wizard I call IDE.openEditor() and get back a handle to an IEditorPart. What can I do from here?

John J. Camilleri
  • 4,171
  • 5
  • 31
  • 41

1 Answers1

6

Well, I have found my answer:

IEditorPart editor = IDE.openEditor(page, file, true);
XtextEditor xed = (XtextEditor)editor;
((SourceViewer)xed.getInternalSourceViewer()).doOperation(ISourceViewer.FORMAT);

Maybe that will help someone else looking for something similar!

John J. Camilleri
  • 4,171
  • 5
  • 31
  • 41