Search in sources :

Example 21 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project xtext-xtend by eclipse.

the class AbstractProfileManager method readFromPreferenceStore.

/**
 * Only to read project specific settings to find out to what profile it matches.
 *
 * @param context
 *            The project context
 */
private Map readFromPreferenceStore(IScopeContext context, Profile workspaceProfile) {
    final Map profileOptions = new HashMap();
    IEclipsePreferences uiPrefs = context.getNode(getNodeId());
    int version = uiPrefs.getInt(fProfileVersionKey, fProfileVersioner.getFirstVersion());
    if (version != fProfileVersioner.getCurrentVersion()) {
        Map allOptions = new HashMap();
        for (int i = 0; i < fKeySets.length; i++) {
            addAll(context.getNode(fKeySets[i].getNodeName()), allOptions);
        }
        // $NON-NLS-1$
        CustomProfile profile = new CustomProfile("tmp", allOptions, version, fProfileVersioner.getProfileKind());
        fProfileVersioner.update(profile);
        return profile.getSettings();
    }
    boolean hasValues = false;
    for (int i = 0; i < fKeySets.length; i++) {
        KeySet keySet = fKeySets[i];
        IEclipsePreferences preferences = context.getNode(keySet.getNodeName());
        for (final Iterator keyIter = keySet.getKeys().iterator(); keyIter.hasNext(); ) {
            final String key = (String) keyIter.next();
            Object val = preferences.get(key, null);
            if (val != null) {
                hasValues = true;
            } else {
                val = workspaceProfile.getSettings().get(key);
            }
            profileOptions.put(key, val);
        }
    }
    if (!hasValues) {
        return null;
    }
    setLatestCompliance(profileOptions);
    return profileOptions;
}
Also used : HashMap(java.util.HashMap) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 22 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project xtext-xtend by eclipse.

the class AbstractProfileManager method updateProfilesWithName.

@Override
protected void updateProfilesWithName(String oldName, Profile newProfile, boolean applySettings) {
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (int i = 0; i < projects.length; i++) {
        IScopeContext projectScope = fPreferencesAccess.getProjectScope(projects[i]);
        IEclipsePreferences node = projectScope.getNode(getNodeId());
        String profileId = node.get(fProfileKey, null);
        if (oldName.equals(profileId)) {
            if (newProfile == null) {
                node.remove(fProfileKey);
            } else {
                if (applySettings) {
                    writeToPreferenceStore(newProfile, projectScope);
                } else {
                    node.put(fProfileKey, newProfile.getID());
                }
            }
        }
    }
    IScopeContext instanceScope = fPreferencesAccess.getInstanceScope();
    final IEclipsePreferences uiPrefs = instanceScope.getNode(getNodeId());
    if (newProfile != null && oldName.equals(uiPrefs.get(fProfileKey, null))) {
        writeToPreferenceStore(newProfile, instanceScope);
    }
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IProject(org.eclipse.core.resources.IProject)

Example 23 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project xtext-xtend by eclipse.

the class AbstractProfileManager method clearAllSettings.

@Override
public void clearAllSettings(IScopeContext context) {
    for (int i = 0; i < fKeySets.length; i++) {
        updatePreferences(context.getNode(fKeySets[i].getNodeName()), fKeySets[i].getKeys(), Collections.EMPTY_MAP);
    }
    final IEclipsePreferences uiPrefs = context.getNode(getNodeId());
    uiPrefs.remove(fProfileKey);
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 24 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project xtext-xtend by eclipse.

the class XtendProjectConfigurator method writePreferences.

private void writePreferences(OutputConfiguration configuration, IProject project) {
    ProjectScope projectPreferences = new ProjectScope(project);
    IEclipsePreferences languagePreferences = projectPreferences.getNode("org.eclipse.xtend.core.Xtend");
    languagePreferences.putBoolean(OptionsConfigurationBlock.isProjectSpecificPropertyKey(BuilderConfigurationBlock.PROPERTY_PREFIX), true);
    languagePreferences.putBoolean(getKey(configuration, INSTALL_DSL_AS_PRIMARY_SOURCE), configuration.isInstallDslAsPrimarySource());
    languagePreferences.putBoolean(getKey(configuration, HIDE_LOCAL_SYNTHETIC_VARIABLES), configuration.isHideSyntheticLocalVariables());
    languagePreferences.putBoolean(getKey(configuration, USE_OUTPUT_PER_SOURCE_FOLDER), true);
    for (SourceMapping sourceMapping : configuration.getSourceMappings()) {
        languagePreferences.put(getOutputForSourceFolderKey(configuration, sourceMapping.getSourceFolder()), Strings.nullToEmpty(sourceMapping.getOutputDirectory()));
    }
    try {
        languagePreferences.flush();
    } catch (BackingStoreException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) SourceMapping(org.eclipse.xtext.generator.OutputConfiguration.SourceMapping)

Example 25 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project linuxtools by eclipse.

the class MetadataPageTest method isPreferencesCorrect.

/**
 * Get the current project preference for the category tag and check if the values
 * stored are the same as the values passed in.
 *
 * @param category The preference category to check.
 * @param value The value to check.
 * @return True if the value is same as what is stored, false otherwise.
 */
private boolean isPreferencesCorrect(String category, String value) {
    IEclipsePreferences pref = project.getEclipsePreferences();
    IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
    String actual = pref.get(category, prefStore.getDefaultString(category));
    return actual.equals(value);
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)79 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Test (org.junit.Test)11 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)9 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 ProjectScope (org.eclipse.core.resources.ProjectScope)6 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)6 After (org.junit.After)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2