/** * Embeds an xText editor for the given resource into the given <code>parent</code>. * * @param parent the parent UI component * @param injector the injector configured for the editor and the grammar of <code>file</code> * @param resourceProvider the resource to be displayed * @param content the actual editable content in terms of prefix not to be shown [0], content to be displayed [1] * and postfix not to be shown[2] * @param requireWorkspaceResource whether the editor requires a workspace resource and shall complain at least in * the logs or whether it shall be silent * @return the embedded editor (or <b>null</b> if embedding failed) */ private static IEmbeddedEditor embedEditor(Composite parent, Injector injector, IEditedResourceProvider resourceProvider, String[] content, boolean requireWorkspaceResource) { // processIssuesBy EmbeddedEditorFactory factory = injector.getInstance(EmbeddedEditorFactory.class); EmbeddedEditor embeddedEditor = factory.newEditor(resourceProvider).showErrorAndWarningAnnotations() .withParent(parent); // solution by: http://stackoverflow.com/questions/15324481/xtext-dsl-embedded-editor-in-a-dialog EmbeddedEditorModelAccess partialEditorModelAccess = embeddedEditor.createPartialEditor(content[0], content[1], content[2], false); XtextSourceViewer viewer = embeddedEditor.getViewer(); StyledText text = viewer.getTextWidget(); try { Font font = text.getFont(); if (null != font) { // TODO preliminary, use editor configuration instead FontData[] fontData = font.getFontData(); if (null != fontData && fontData.length > 0) { text.setFont(new Font(font.getDevice(), "Consolas", fontData[0].getHeight(), fontData[0].getStyle())); } } } catch (SWTError e) { // no font, ignore EASyLoggerFactory.INSTANCE.getLogger(EmbeddingHelper.class, Activator.PLUGIN_ID).error(e.getMessage()); } return new EmbeddedXtextSourceEditor(embeddedEditor, viewer, partialEditorModelAccess, requireWorkspaceResource); }