Frage

I want to use Xtext's editor to edit a String attribute of an EObject instead of editing a text file. How can I achieve this? I found this thread but it only mentions the workaround of creating a temp file. There must be a more elegant solution. I thought of creating a custom EditorInput but I'm not sure where to start. Thanks in advance for any pointers!

War es hilfreich?

Lösung

Since 2.2, the supported solution is using IEditedResourceProvider with an EmbeddedEditorFactory (since editing an attribute belongs to an embedded editor anyway). Sample code in Xtend (the attribute is updated whenever the editor changes):

val injector = MyDslActivator.instance.getInjector(MyDslActivator.COM_EXAMPLE_MY_DSL)
val resourceSet = injector.getInstance(IResourceSetProvider).get(null)
val fileExtension = injector.getInstance(Key.get(String, Names.named(Constants.FILE_EXTENSIONS)))
val resourceProvider = [|
    resourceSet.createResource(createURI('''temp.«fileExtension»''')) as XtextResource
]
injector.getInstance(EmbeddedEditorFactory).newEditor(resourceProvider).withParent(parent) => [
    createPartialEditor("", editedAttribute ?: "", "", false)
    document.addModelListener[_ | editedAttribute = document.get]
]

Based on: EditTemplateDialog source, StackOverflow, Eclipse Forum.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top