Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Custom Preferences Page(Access the preferences store and default values)
Custom Preferences Page [message #1512566] Mon, 15 December 2014 21:33 Go to next message
Cioran Naroic is currently offline Cioran NaroicFriend
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:


  1. 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.
  2. 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 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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
Previous Topic:Expression and Remembering Parentheses
Next Topic:Syntax highlighting does not update editor from preference page
Goto Forum:
  


Current Time: Thu Apr 25 12:45:50 GMT 2024

Powered by FUDForum. Page generated in 0.02485 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top