Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2012 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
 package org.eclipse.xtext.ui.preferences;
import  org.eclipse.core.resources.IProject;
import  org.eclipse.core.resources.IWorkspaceRoot;
import  org.eclipse.core.resources.ResourcesPlugin;
import  org.eclipse.jface.preference.IPreferenceStore;

Sven Efftinge - Initial contribution and API
	private final static Logger log = Logger.getLogger(EclipsePreferencesProvider.class);
		final IProject project = getProject(context);
		final IPreferenceStore store = project != null ?
		final Map<StringStringpreferenceCache = Maps.newHashMap();
		return new IPreferenceValues() {
				try {
					String id = key.getId();
					String string = preferenceCache.get(id);
					if (string == null) {
						string = store.getString(id);
					return org.eclipse.jface.preference.IPreferenceStore.STRING_DEFAULT_DEFAULT.equals(string) ? key.getDefaultValue() : string;
catch (Exception e) {
					.error("Error getting preference for key '"+key.getId()+"'."e);
					return key.getDefaultValue();
	private IProject getProject(Resource resource) {
		URI uri = resource.getURI();
		if (uri.isPlatformResource()) {
			final IProject project = getWorkspaceRoot().getProject(uri.segment(1));
			if (project.isAccessible())
				return project;
		return null;
	private IWorkspaceRoot getWorkspaceRoot() {
		return ResourcesPlugin.getWorkspace().getRoot();
New to GrepCode? Check out our FAQ X