コード例 #1
0
  /**
   * Update all formatter settings with the settings of the specified profile.
   *
   * @param profile The profile to write to the preference store
   */
  private void writeToPreferenceStore(Profile profile, IScopeContext context) {
    final Map<String, String> profileOptions = profile.getSettings();

    for (int i = 0; i < fKeySets.length; i++) {
      updatePreferences(
          context.getNode(fKeySets[i].getNodeName()), fKeySets[i].getKeys(), profileOptions);
    }

    final IEclipsePreferences uiPrefs = context.getNode(JavaUI.ID_PLUGIN);
    if (uiPrefs.getInt(fProfileVersionKey, 0) != fProfileVersioner.getCurrentVersion()) {
      uiPrefs.putInt(fProfileVersionKey, fProfileVersioner.getCurrentVersion());
    }

    if (context.getName() == InstanceScope.SCOPE) {
      uiPrefs.put(fProfileKey, profile.getID());
    } else if (context.getName() == ProjectScope.SCOPE && !profile.isSharedProfile()) {
      uiPrefs.put(fProfileKey, profile.getID());
    }
  }
コード例 #2
0
  /**
   * Only to read project specific settings to find out to what profile it matches.
   *
   * @param context The project context
   */
  private Map<String, String> readFromPreferenceStore(
      IScopeContext context, Profile workspaceProfile) {
    final Map<String, String> profileOptions = new HashMap<String, String>();
    IEclipsePreferences uiPrefs = context.getNode(JavaUI.ID_PLUGIN);

    int version = uiPrefs.getInt(fProfileVersionKey, fProfileVersioner.getFirstVersion());
    if (version != fProfileVersioner.getCurrentVersion()) {
      Map<String, String> allOptions = new HashMap<String, String>();
      for (int i = 0; i < fKeySets.length; i++) {
        addAll(context.getNode(fKeySets[i].getNodeName()), allOptions);
      }
      CustomProfile profile =
          new CustomProfile(
              "tmp", allOptions, version, fProfileVersioner.getProfileKind()); // $NON-NLS-1$
      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<String> keyIter = keySet.getKeys().iterator(); keyIter.hasNext(); ) {
        final String key = keyIter.next();
        String 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;
  }