use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.
the class ProjectContentTypes method usesContentTypePreferences.
static boolean usesContentTypePreferences(String projectName) {
try {
// be careful looking up for our node so not to create any nodes as side effect
Preferences node = PROJECT_SCOPE;
// for now, take the long way
if (!node.nodeExists(projectName))
return false;
node = node.node(projectName);
if (!node.nodeExists(Platform.PI_RUNTIME))
return false;
node = node.node(Platform.PI_RUNTIME);
if (!node.nodeExists(CONTENT_TYPE_PREF_NODE))
return false;
node = node.node(CONTENT_TYPE_PREF_NODE);
return node.getBoolean(PREF_LOCAL_CONTENT_TYPE_SETTINGS, false);
} catch (BackingStoreException e) {
// exception treated when retrieving the project preferences
}
return false;
}
use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.
the class CharsetManager method getCharsetFor.
/**
* Returns the charset explicitly set by the user for the given resource,
* or <code>null</code>. If no setting exists for the given resource and
* <code>recurse</code> is <code>true</code>, every parent up to the
* workspace root will be checked until a charset setting can be found.
*
* @param resourcePath the path for the resource
* @param recurse whether the parent should be queried
* @return the charset setting for the given resource
*/
public String getCharsetFor(IPath resourcePath, boolean recurse) {
Assert.isLegal(resourcePath.segmentCount() >= 1);
IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
Preferences encodingSettings = getPreferences(project, false);
if (encodingSettings == null)
// lookup by falling back to workspace's default setting
return recurse ? ResourcesPlugin.getEncoding() : null;
return internalGetCharsetFor(resourcePath, encodingSettings, recurse);
}
use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.
the class CharsetManager method getPreferences.
Preferences getPreferences(IProject project, boolean create) {
if (create)
// create all nodes down to the one we are interested in
return new ProjectScope(project).getNode(ResourcesPlugin.PI_RESOURCES).node(ENCODING_PREF_NODE);
// be careful looking up for our node so not to create any nodes as side effect
Preferences node = Platform.getPreferencesService().getRootNode().node(ProjectScope.SCOPE);
try {
// for now, take the long way
if (!node.nodeExists(project.getName()))
return null;
node = node.node(project.getName());
if (!node.nodeExists(ResourcesPlugin.PI_RESOURCES))
return null;
node = node.node(ResourcesPlugin.PI_RESOURCES);
if (!node.nodeExists(ENCODING_PREF_NODE))
return null;
return node.node(ENCODING_PREF_NODE);
} catch (BackingStoreException e) {
// nodeExists failed
String message = Messages.resources_readingEncoding;
Policy.log(new ResourceStatus(IResourceStatus.FAILED_GETTING_CHARSET, project.getFullPath(), message, e));
}
return null;
}
use of org.osgi.service.prefs.Preferences in project polymap4-core by Polymap4.
the class CharsetManager method setCharsetFor.
public void setCharsetFor(IPath resourcePath, String newCharset) throws CoreException {
// for the workspace root we just set a preference in the instance scope
if (resourcePath.segmentCount() == 0) {
org.eclipse.core.runtime.Preferences resourcesPreferences = ResourcesPlugin.getPlugin().getPluginPreferences();
if (newCharset != null)
resourcesPreferences.setValue(ResourcesPlugin.PREF_ENCODING, newCharset);
else
resourcesPreferences.setToDefault(ResourcesPlugin.PREF_ENCODING);
ResourcesPlugin.getPlugin().savePluginPreferences();
return;
}
// for all other cases, we set a property in the corresponding project
IProject project = workspace.getRoot().getProject(resourcePath.segment(0));
Preferences encodingSettings = getPreferences(project, true);
if (newCharset == null || newCharset.trim().length() == 0)
encodingSettings.remove(getKeyFor(resourcePath));
else
encodingSettings.put(getKeyFor(resourcePath), newCharset);
try {
// disable the listener so we don't react to changes made by ourselves
charsetListener.setDisabled(true);
// save changes
encodingSettings.flush();
} catch (BackingStoreException e) {
String message = Messages.resources_savingEncoding;
throw new ResourceException(IResourceStatus.FAILED_SETTING_CHARSET, project.getFullPath(), message, e);
} finally {
charsetListener.setDisabled(false);
}
}
use of org.osgi.service.prefs.Preferences in project eclipse-integration-commons by spring-projects.
the class CorePlugin method getUUID.
public static synchronized String getUUID() {
ServiceReference ref = getDefault().getBundle().getBundleContext().getServiceReference(IPreferencesService.class.getName());
IPreferencesService prefService = (IPreferencesService) getDefault().getBundle().getBundleContext().getService(ref);
try {
IEclipsePreferences prefs = (IEclipsePreferences) prefService.getRootNode().node(InstanceScope.SCOPE);
Preferences p = prefs.node(PLUGIN_ID);
if (StringUtils.isEmpty(p.get(UUID_PROPERTY_KEY, ""))) {
p.put(UUID_PROPERTY_KEY, UUID.randomUUID().toString());
}
return p.get(UUID_PROPERTY_KEY, "");
} finally {
if (prefService != null) {
getDefault().getBundle().getBundleContext().ungetService(ref);
}
}
}
Aggregations