use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project eclipse.platform.runtime by eclipse.
the class ContentTypeMatcher method getMatchingRegexpAssociated.
public Collection<? extends ContentType> getMatchingRegexpAssociated(ContentTypeCatalog catalog, String fileName, final int typeMask) {
if ((typeMask & IContentType.FILE_PATTERN_SPEC) == 0) {
// $NON-NLS-1$
throw new IllegalArgumentException("This method only applies for FILE_REGEXP_SPEC.");
}
final IEclipsePreferences root = context.getNode(ContentTypeManager.CONTENT_TYPE_PREF_NODE);
final Set<ContentType> result = new HashSet<>(3);
try {
root.accept(node -> {
if (node == root)
return true;
String[] fileSpecs = ContentTypeSettings.getFileSpecs(node, typeMask);
for (String fileSpecification : fileSpecs) if (Pattern.matches(catalog.toRegexp(fileSpecification), fileName)) {
ContentType associated = catalog.getContentType(node.name());
if (associated != null)
result.add(associated);
break;
}
return false;
});
} catch (BackingStoreException bse) {
ContentType.log(ContentMessages.content_errorLoadingSettings, bse);
}
return result == null ? Collections.EMPTY_SET : result;
}
use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project eclipse.platform.runtime by eclipse.
the class ContentTypeMatcher method getDirectlyAssociated.
/**
* Enumerates all content types whose settings satisfy the given file spec type mask.
*/
public Collection<ContentType> getDirectlyAssociated(final ContentTypeCatalog catalog, final String fileSpec, final int typeMask) {
if ((typeMask & (IContentType.FILE_EXTENSION_SPEC | IContentType.FILE_NAME_SPEC)) == 0) {
// $NON-NLS-1$
throw new IllegalArgumentException("This method only apply to name or extension based associations");
}
// TODO: make sure we include built-in associations as well
final IEclipsePreferences root = context.getNode(ContentTypeManager.CONTENT_TYPE_PREF_NODE);
final Set<ContentType> result = new HashSet<>(3);
try {
root.accept(node -> {
if (node == root)
return true;
String[] fileSpecs = ContentTypeSettings.getFileSpecs(node, typeMask);
for (String fileSpecification : fileSpecs) if (fileSpecification.equalsIgnoreCase(fileSpec)) {
ContentType associated = catalog.getContentType(node.name());
if (associated != null)
result.add(associated);
break;
}
return false;
});
} catch (BackingStoreException bse) {
ContentType.log(ContentMessages.content_errorLoadingSettings, bse);
}
return result == null ? Collections.EMPTY_SET : result;
}
use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project eclipse.platform.runtime by eclipse.
the class PreferenceForwarderTest method testListenerOnRemove.
/* Comment this test out until we are able to use session tests
* with it. - ddw
* public void testPluginPrefs() {
IPluginRegistry registry = InternalPlatform.getPluginRegistry();
IPluginDescriptor resPlugin = registry.getPluginDescriptor("org.eclipse.core.resources");
Preferences perfs = null;
try {
perfs = resPlugin.getPlugin().getPluginPreferences();
} catch (CoreException ce) {
fail("0.1 core exception from getPlugin");
}
boolean oneBoolean = perfs.getBoolean("OneBoolean");
double oneDouble = perfs.getDouble("OneDouble");
float oneFloat = perfs.getFloat("OneFloat");
int oneInt = perfs.getInt("OneInt");
long oneLong = perfs.getLong("OneLong");
String oneString = perfs.getString("OneString");
assertTrue("1.0 boolean", oneBoolean);
assertTrue("2.0 double", oneDouble == 4);
assertTrue("3.0 float", oneFloat == 4.3f);
assertTrue("4.0 int", oneInt == 5);
assertTrue("5.0 long", oneLong == 6);
assertTrue("6.0 string", oneString.equals("A string from the plugin root directory"));
int a = 4;
int b = 3;
}
*/
/*
* Regression test for bug 178815.
*/
public void testListenerOnRemove() {
// create a new log listener that will fail if anything is written
ILogListener logListener = new ILogListener() {
@Override
public void logging(IStatus status, String plugin) {
CoreException ex = new CoreException(status);
fail("0.99", ex);
}
};
// set a preference value to get everything initialized
String id = getUniqueString();
Preferences ps = new PreferenceForwarder(id);
ps.setValue("key", "value");
// add a property change listener which will cause one to be
// added at the preference node level
IPropertyChangeListener listener = new Preferences.IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
}
};
ps.addPropertyChangeListener(listener);
ps.setValue("key2", "value2");
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(id);
// add our log listener and remove the node. nothing should be logged.
RuntimeLog.addLogListener(logListener);
try {
node.removeNode();
} catch (BackingStoreException e) {
fail("4.99", e);
} catch (IllegalStateException e) {
fail("5.00", e);
} finally {
RuntimeLog.removeLogListener(logListener);
}
}
use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project webtools.servertools by eclipse.
the class ServerPreferenceModifyListener method preApply.
/* (non-Javadoc)
* @see org.eclipse.core.runtime.preferences.PreferenceModifyListener#preApply(org.eclipse.core.runtime.preferences.IEclipsePreferences)
*/
public IEclipsePreferences preApply(IEclipsePreferences node) {
Preferences instance = node.node(InstanceScope.SCOPE);
Preferences runtimes = instance.node(ServerPlugin.PLUGIN_ID);
if (runtimes != null)
// $NON-NLS-1$
removeLockedServerRuntimePreference(runtimes);
return super.preApply(node);
}
use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project mdw-designer by CenturyLinkCloud.
the class WorkspaceConfigurator method setFormatter.
protected void setFormatter() {
IScopeContext instanceScope = InstanceScope.INSTANCE;
IEclipsePreferences uiPrefs = instanceScope.getNode(JavaUI.ID_PLUGIN);
if (getWorkspaceConfig().getCodeFormatter().equals(WorkspaceConfig.CODE_FORMATTERS[0]))
uiPrefs.put("formatter_profile", "_CenturyLinkIT");
else
uiPrefs.put("formatter_profile", "_MDWCodeFormatter");
try {
uiPrefs.flush();
uiPrefs.sync();
IProfileVersioner profileVersioner = new ProfileVersioner();
ProfileStore profileStore = new FormatterProfileStore(profileVersioner);
List<ProfileManager.Profile> profiles = profileStore.readProfiles(instanceScope);
if (profiles == null)
profiles = profileStore.readProfiles(DefaultScope.INSTANCE);
if (profiles == null)
profiles = new ArrayList<>();
WorkingCopyManager workingCopyManager = new WorkingCopyManager();
PreferencesAccess access = PreferencesAccess.getWorkingCopyPreferences(workingCopyManager);
ProfileManager profileManager = new FormatterProfileManager(profiles, instanceScope, access, profileVersioner);
profileManager.commitChanges(instanceScope);
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Set Code Formatter");
}
}
Aggregations