Custom Preferences Page [message #1512566] |
Mon, 15 December 2014 21:33 |
Cioran Naroic Messages: 18 Registered: December 2013 |
Junior Member |
|
|
Hi folks,
I created a new page for my DSL in the UI module (inspired from org.eclipse.xtext.ui.refactoring.ui.RefactoringPreferencePage):
class MelangePreferences
{
public static final String EMF_COMPLIANT_INTERFACES = "emfCompliantInterfaces"
public static final String GENERATE_EMF_ARTIFACTS = "generateEmfArtifacts"
public static class Initializer implements IPreferenceStoreInitializer {
override initialize(IPreferenceStoreAccess store) {
store.writablePreferenceStore.setDefault(EMF_COMPLIANT_INTERFACES, true)
store.writablePreferenceStore.setDefault(GENERATE_EMF_ARTIFACTS, false)
}
}
@Inject
IPreferenceStoreAccess store
def boolean isEmfCompliantInterfaces() {
return store.preferenceStore.getBoolean(EMF_COMPLIANT_INTERFACES)
}
def boolean isGenerateEmfArtifacts() {
return store.preferenceStore.getBoolean(GENERATE_EMF_ARTIFACTS)
}
def void setEmfCompliantInterfaces(boolean value) {
store.writablePreferenceStore.setValue(EMF_COMPLIANT_INTERFACES, value)
}
def void setGenerateEmfArtifacts(boolean value) {
store.writablePreferenceStore.setValue(GENERATE_EMF_ARTIFACTS, value)
}
}
class MelangePreferencePage extends LanguageRootPreferencePage
{
override init(IWorkbench workbench) {
setPreferenceStore(MelangeActivator.instance.preferenceStore)
}
override createFieldEditors() {
addField(...)
addField(...)
}
}
Once binded in the plugin.xml, I can see the new page with my options.
However, I face two problems now:
- Default values are not set. The store seems to work properly (values are kept after restarting workspace), but they are not set to their default value. I guess my MelangePreferences.Initializer needs to be binded or referenced from somewhere, but I didn't find where.
- How do I programmatically access the preferences values? It's working fine in the UI project, but these options need to be used in my compiler (JvmModelInferrer), i.e. in the "not-UI" Xtext project containing the grammar. I cannot get an @Inject IPreferenceStoreAccess here, nor access the constants that define my preferences identifiers. I guess putting the UI project as a dependency to the Grammar project is not the solution.
Thanks,
Cioran
|
|
|
Re: Custom Preferences Page [message #1512930 is a reply to message #1512566] |
Tue, 16 December 2014 04:51 |
|
you can add any bindings to ui module
public void configureIPreferenceStoreInitializer(com.google.inject.Binder binder) {
binder.bind(IPreferenceStoreInitializer.class).annotatedWith(Names.named("WhatEver")).to(YourPreferencesInitializer.class);
super .....
}
have a look at how org.eclipse.xtext.preferences.IPreferenceValues is used throughout xtexts/xtends code
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.02485 seconds