0

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!

4

1 回答 1

0

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.

于 2013-11-19T16:46:23.497 回答