private void loadStyle(IncludeKind includeKind, String preferenceKey, ICProject project) {
   String value = PreferenceConstants.getPreference(preferenceKey, project, null);
   IncludeGroupStyle style = null;
   if (value != null) style = IncludeGroupStyle.fromXmlString(value, includeKind);
   if (style == null) style = new IncludeGroupStyle(includeKind);
   includeStyles.put(includeKind, style);
 }
 /**
  * Creates new content provider for dialog.
  *
  * @param viewer Tree viewer.
  */
 public CContentOutlinerProvider(TreeViewer viewer, IWorkbenchPartSite site) {
   super(true, true);
   treeViewer = viewer;
   final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
   setIncludesGrouping(store.getBoolean(PreferenceConstants.OUTLINE_GROUP_INCLUDES));
   setNamespacesGrouping(store.getBoolean(PreferenceConstants.OUTLINE_GROUP_NAMESPACES));
   setMemberGrouping(store.getBoolean(PreferenceConstants.OUTLINE_GROUP_MEMBERS));
   setMacroGrouping(store.getBoolean(PreferenceConstants.OUTLINE_GROUP_MACROS));
 }
 /** @see org.eclipse.jface.viewers.IContentProvider#dispose() */
 @Override
 public void dispose() {
   super.dispose();
   if (fListener != null) {
     CoreModel.getDefault().removeElementChangedListener(fListener);
     fListener = null;
   }
   if (fPropertyListener != null) {
     PreferenceConstants.getPreferenceStore().removePropertyChangeListener(fPropertyListener);
     fPropertyListener = null;
   }
 }
  /*
   * @see org.eclipse.cdt.internal.ui.BaseCElementContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
   */
  @Override
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    boolean isTU = newInput instanceof ITranslationUnit;

    if (isTU) {
      root = (ITranslationUnit) newInput;
      if (fListener == null) {
        fListener = new ElementChangedListener();
        CoreModel.getDefault().addElementChangedListener(fListener);
        fPropertyListener = new PropertyListener();
        PreferenceConstants.getPreferenceStore().addPropertyChangeListener(fPropertyListener);
      }
    } else {
      if (fListener != null) {
        CoreModel.getDefault().removeElementChangedListener(fListener);
        PreferenceConstants.getPreferenceStore().removePropertyChangeListener(fPropertyListener);
        fListener = null;
        fPropertyListener = null;
      }
      root = null;
    }
  }
 public HeaderSubstitutor(InclusionContext context) {
   fContext = context;
   fIncludeMaps = new IncludeMap[] {new IncludeMap(true), new IncludeMap(false)};
   IPreferencesService preferences = Platform.getPreferencesService();
   IScopeContext[] scopes = PreferenceConstants.getPreferenceScopes(context.getProject());
   String str =
       preferences.getString(
           CUIPlugin.PLUGIN_ID, PreferenceConstants.INCLUDES_HEADER_SUBSTITUTION, null, scopes);
   if (str != null) {
     List<HeaderSubstitutionMap> maps = HeaderSubstitutionMap.deserializeMaps(str);
     for (HeaderSubstitutionMap map : maps) {
       if (!map.isCppOnly() || fContext.isCXXLanguage()) {
         fIncludeMaps[0].addAllMappings(map.getUnconditionalSubstitutionMap());
         fIncludeMaps[1].addAllMappings(map.getOptionalSubstitutionMap());
       }
     }
   }
 }
 public AbstractPreferencePage() {
   super();
   setPreferenceStore(PreferenceConstants.getPreferenceStore());
   fOverlayStore = new OverlayPreferenceStore(getPreferenceStore(), createOverlayStoreKeys());
 }
  public IncludePreferences(ICProject project) {
    includeStyles = new HashMap<IncludeKind, IncludeGroupStyle>();
    loadStyle(IncludeKind.RELATED, PreferenceConstants.INCLUDE_STYLE_RELATED, project);
    loadStyle(IncludeKind.PARTNER, PreferenceConstants.INCLUDE_STYLE_PARTNER, project);
    loadStyle(IncludeKind.IN_SAME_FOLDER, PreferenceConstants.INCLUDE_STYLE_SAME_FOLDER, project);
    loadStyle(IncludeKind.IN_SUBFOLDER, PreferenceConstants.INCLUDE_STYLE_SUBFOLDER, project);
    loadStyle(IncludeKind.SYSTEM, PreferenceConstants.INCLUDE_STYLE_SYSTEM, project);
    loadStyle(
        IncludeKind.SYSTEM_WITH_EXTENSION,
        PreferenceConstants.INCLUDE_STYLE_SYSTEM_WITH_EXTENSION,
        project);
    loadStyle(
        IncludeKind.SYSTEM_WITHOUT_EXTENSION,
        PreferenceConstants.INCLUDE_STYLE_SYSTEM_WITHOUT_EXTENSION,
        project);
    loadStyle(IncludeKind.OTHER, PreferenceConstants.INCLUDE_STYLE_OTHER, project);
    loadStyle(IncludeKind.IN_SAME_PROJECT, PreferenceConstants.INCLUDE_STYLE_SAME_PROJECT, project);
    loadStyle(
        IncludeKind.IN_OTHER_PROJECT, PreferenceConstants.INCLUDE_STYLE_OTHER_PROJECT, project);
    loadStyle(IncludeKind.EXTERNAL, PreferenceConstants.INCLUDE_STYLE_EXTERNAL, project);
    // Unclassified includes are always kept together.
    includeStyles.get(IncludeKind.OTHER).setKeepTogether(true);
    // Normalize order property of the styles to make sure that the numbers are sequential.
    List<IncludeGroupStyle> styles = new ArrayList<IncludeGroupStyle>(includeStyles.values());
    Collections.sort(styles);
    for (int i = 0; i < styles.size(); i++) {
      styles.get(i).setOrder(i);
    }
    // TODO(sprigogin): Load styles for headers matching patterns.

    forwardDeclareCompositeTypes =
        PreferenceConstants.getPreference(
            PreferenceConstants.FORWARD_DECLARE_COMPOSITE_TYPES, project, true);
    forwardDeclareEnums =
        PreferenceConstants.getPreference(
            PreferenceConstants.FORWARD_DECLARE_ENUMS, project, false);
    forwardDeclareFunctions =
        PreferenceConstants.getPreference(
            PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, project, false);
    forwardDeclareExternalVariables =
        PreferenceConstants.getPreference(
            PreferenceConstants.FORWARD_DECLARE_EXTERNAL_VARIABLES, project, false);
    forwardDeclareTemplates =
        PreferenceConstants.getPreference(
            PreferenceConstants.FORWARD_DECLARE_TEMPLATES, project, false);
    forwardDeclareNamespaceElements =
        PreferenceConstants.getPreference(
            PreferenceConstants.FORWARD_DECLARE_NAMESPACE_ELEMENTS, project, true);

    // Although templates may be forward declared, it is done so rarely that we assume that it
    // never happens.
    // TODO(sprigogin): Create a preference for this.
    assumeTemplatesMayBeForwardDeclared = false;

    String value =
        PreferenceConstants.getPreference(
            PreferenceConstants.INCLUDES_PARTNER_FILE_SUFFIXES,
            project,
            DEFAULT_PARTNER_FILE_SUFFIXES);
    partnerFileSuffixes = value.split(","); // $NON-NLS-1$

    heuristicHeaderSubstitution =
        PreferenceConstants.getPreference(
            PreferenceConstants.INCLUDES_HEURISTIC_HEADER_SUBSTITUTION, project, true);

    allowReordering =
        PreferenceConstants.getPreference(
            PreferenceConstants.INCLUDES_ALLOW_REORDERING, project, true);

    // TODO(sprigogin): Create a preference for this.
    allowIndirectInclusion = false;

    allowPartnerIndirectInclusion =
        PreferenceConstants.getPreference(
            PreferenceConstants.INCLUDES_ALLOW_PARTNER_INDIRECT_INCLUSION, project, true);

    // Unused include handling preferences
    value =
        PreferenceConstants.getPreference(
            PreferenceConstants.INCLUDES_UNUSED_STATEMENTS_DISPOSITION, project, null);
    UnusedStatementDisposition disposition = null;
    if (value != null) disposition = UnusedStatementDisposition.valueOf(value);
    if (disposition == null) disposition = UnusedStatementDisposition.COMMENT_OUT;
    unusedStatementsDisposition = disposition;
  }