Search in sources :

Example 1 with ComponentDescriptor

use of org.eclipse.n4js.utils.ComponentDescriptor in project n4js by eclipse.

the class AbstractN4JSPreferenceStoreAccessor method populateCompilerConfiguration.

/**
 * @param outputName
 *            the output name that identifies the output configuration but in our case also the registered compiler.
 * @param compilerDescriptor
 *            the compiler descriptor holding the values either stored last time this details page was used or the
 *            default values for the compiler
 */
public void populateCompilerConfiguration(String outputName, T compilerDescriptor) {
    // defaults
    preferenceInitializer.initialize(scopedAccessor);
    boolean initialLoad = false;
    ComponentDescriptor currentlyStoredCompilerDescriptor = compilerDescriptor.getCurrentlyStoredComponentDescriptor();
    if (currentlyStoredCompilerDescriptor == null) {
        // default configuration
        currentlyStoredCompilerDescriptor = compilerDescriptor;
        initialLoad = true;
    }
    Map<String, String> originalSettings = currentlyStoredCompilerDescriptor.fillMap(outputName);
    IPreferenceStore preferenceStore = getPreferenceStore();
    // populate
    // use a copy here has we don't want to change the default values provided by the registered compilers
    @SuppressWarnings("unchecked") T newCompilerDescriptor = (T) compilerDescriptor.copy();
    for (IComponentProperties<T> prop : getComponentPropertiesValues()) {
        if (prop.getType() == Boolean.class) {
            prop.setValueInCompilerDescriptor(newCompilerDescriptor, outputName, preferenceStore.getBoolean(prop.getKey(outputName)));
        } else {
            prop.setValueInCompilerDescriptor(newCompilerDescriptor, outputName, preferenceStore.getString(prop.getKey(outputName)));
        }
    }
    Map<String, String> currentSettings = newCompilerDescriptor.fillMap(outputName);
    Map<String, ValueDifference<String>> changes = getPreferenceChanges(originalSettings, currentSettings);
    if (!initialLoad) {
        compilerDescriptor.setChanges(changes);
    }
    compilerDescriptor.setCurrentlyStoredComponentDescriptor(newCompilerDescriptor);
}
Also used : ComponentDescriptor(org.eclipse.n4js.utils.ComponentDescriptor) ValueDifference(com.google.common.collect.MapDifference.ValueDifference) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

ValueDifference (com.google.common.collect.MapDifference.ValueDifference)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 ComponentDescriptor (org.eclipse.n4js.utils.ComponentDescriptor)1