Community
Participate
Working Groups
I'm working on a new bundle which allows to easily embedd Xtext editors as expression editors in the BPEL designer (expression editors were reintroduced in bug 391913). As soon as I have a patch I'll push it to gerrit (together with some examples).
Created attachment 224376 [details] two expression editors (for the greeting example and fowler dsl example)
Created attachment 224377 [details] error markers
Created attachment 224378 [details] code completion
I pushed a patch set to Gerrit https://git.eclipse.org/r/#/c/9077 I'll detail what I've done. I created an abstract subclass of AbstractExpressionAssignCategory (see bug 391913), called AbstractXtextExpressionAssignCategory; this class implements createStyledText by creating an Xtext EmbeddedEditor, and returning its StyledText widget which will then be embedded in the bpel design as an expression editor: public abstract class AbstractXtextExpressionAssignCategory extends AbstractExpressionAssignCategory implements IAssignCategory { /** * @param styledTextComposite * the Composite for the StyledText * @return the created and configured StyledText based on an * {@link EmbeddedEditor} */ protected StyledText createStyledText(Composite styledTextComposite) { Composite editor = getWidgetFactory().createComposite(this.fEditorArea, SWT.BORDER); editor.setLayout(new GridLayout()); GridData layoutData = new GridData(GridData.FILL_BOTH); editor.setLayoutData(layoutData); EmbeddedEditor embeddedEditor = getInjector().getInstance( XtextEmbeddedEditorProvider.class).getXtextEmbeddedEditor( editor); final ISourceViewer viewer = embeddedEditor.getViewer(); StyledText textWidget = viewer.getTextWidget(); // textWidget.setLayoutData(new GridData(GridData.FILL_BOTH)); return textWidget; } /** * This must redefined so to return the {@link Injector} for your own Xtext * DSL. * * You can get the injector from the Activator generated by Xtext for your * DSL in the ui plugin, for instance * * <pre> * org.xtext.example.mydsl.ui.internal.MyDslActivator.getInstance().getInjector( * MyDslActivator.ORG_XTEXT_EXAMPLE_MYDSL_MYDSL); * </pre> * * @return */ public abstract Injector getInjector(); /** * A string to identify your DSL. * * @see org.eclipse.bpel.ui.properties.AbstractExpressionAssignCategory#getExpressionLanguage() */ public abstract String getExpressionLanguage(); } This class relies on XtextEmbeddedEditorProvider which internally implements a IEditedResourceProvider (required by Xtext EmbeddedEditorFactory) which basically creates a synthetic resource that will be used by the EmbeddedEditor. The AbstractXtextExpressionAssignCategory only needs an Injector to start, and this can be easily retrieved using the Activator automatically created by Xtext for your DSL in the ui plugin (it also needs a name to identify the expression language). For instance, the programmer who wants to embed an editor for his DSL, say MyDsl, only needs to provide a subclass, like the following (it also contains some derived methods to fill labels and descriptions in the bpel designer property view): public class FowlerDslXtextExpressionAssignCategory extends AbstractXtextExpressionAssignCategory { public String getName() { return "Xtext FowlerDsl Editor"; } public Injector getInjector() { return StatemachineActivator .getInstance() .getInjector( StatemachineActivator.ORG_ECLIPSE_XTEXT_EXAMPLE_FOWLERDSL_STATEMACHINE); } public String getExpressionLanguage() { return "fowler"; } protected String getStyledTextLabelString() { return "Edit the statemachine expression"; } } And of course declare an extension point <extension point="org.eclipse.bpel.ui.assignCategoryAdditions"> <assignSection class="org.eclipse.bpel.ui.xtext.examples.FowlerDslXtextExpressionAssignCategory" name="Xtext Fowler DSL"> </assignSection> </extension> In the patch set there's also a project, org.eclipse.bpel.ui.xtext.examples, which defines the embedded editors for some classical Xtext examples: the greeting example, the fowler dsl example, and the arithmetics examples (the corresponding Xtext DSL projects are also in the patch set). To try the examples one can use the "Xtext Embedded Editors Examples.launch" in the project org.eclipse.bpel.ui.xtext.examples (which also sets the vm argument for PermGen, required by Xtext). In the screenshots you can see - two expression editors (for the greeting example and fowler dsl example) - error markers - code completion