/**
   * Sets the document associated to the viewer configuration.
   *
   * <p>Updates the line wrapper, if needed.
   *
   * @param aDocument Document associated to the source viewer
   */
  public void setDocument(final IDocument aDocument) {

    if (pAutoEditLineWrap != null && LineWrapUtil.get().isWrappingEnabled()) {
      pAutoEditLineWrap.registerListener(aDocument);
      pAutoEditLineWrap.wrapWholeDocument();
    }
  }
  /**
   * Post-save operations : re-wrapping if needed
   *
   * @param aSourceViewer The editor source viewer
   */
  public void postEditorPerformSave(final ISourceViewer aSourceViewer) {

    final IDocument document = aSourceViewer.getDocument();

    if (LineWrapUtil.get().isActiveMode(LineWrapMode.SOFT)) {
      pAutoEditLineWrap.registerListener(document);
      pAutoEditLineWrap.wrapWholeDocument();
    }
  }
  @Override
  public IAutoEditStrategy[] getAutoEditStrategies(
      final ISourceViewer aSourceViewer, final String aContentType) {

    if (pAutoEditIndent == null) {
      pAutoEditIndent = new DefaultIndentLineAutoEditStrategy();
    }

    if (pAutoEditLineWrap == null) {
      int maxLineLength = LineWrapUtil.get().getMaxLineLength();
      pAutoEditLineWrap =
          new HardLineWrapAutoEdit(RestPartitionScanner.PARTITIONING, maxLineLength);
    }

    List<IAutoEditStrategy> strategies = new ArrayList<IAutoEditStrategy>();
    strategies.add(pAutoEditIndent);

    // Only enable line wrapping in "default text"
    if (LineWrapUtil.get().isWrappingEnabled()
        && IDocument.DEFAULT_CONTENT_TYPE.equals(aContentType)) {
      strategies.add(pAutoEditLineWrap);
    }

    if (pPreferenceStore.getBoolean(IEditorPreferenceConstants.EDITOR_TABS_TO_SPACES)) {

      // Automatic tabs to space conversion
      if (pAutoEditTabsToSpace == null) {
        pAutoEditTabsToSpace = new TabsToSpacesConverter();
        pAutoEditTabsToSpace.setNumberOfSpacesPerTab(getTabWidth(aSourceViewer));
        pAutoEditTabsToSpace.setLineTracker(new DefaultLineTracker());
      }

      strategies.add(pAutoEditTabsToSpace);
    }

    return strategies.toArray(new IAutoEditStrategy[0]);
  }
  /**
   * On-save operations :
   *
   * <p>* Un-wrapping if needed
   *
   * <p>* Auto section markers normalization
   *
   * <p>* Auto formating when the editor saves the file
   *
   * @param aSourceViewer The editor source viewer
   */
  public void onEditorPerformSave(final ISourceViewer aSourceViewer) {

    final IDocument document = aSourceViewer.getDocument();

    if (pPreferenceStore.getBoolean(IEditorPreferenceConstants.EDITOR_SAVE_RESET_MARKERS)) {
      // Auto section blocks normalization

      RestContentOutlinePage outlinePage = null;

      if (pEditor != null) {
        outlinePage = pEditor.getOutlinePage();
      }

      if (outlinePage != null) {

        // Don't forget to refresh the tree !
        outlinePage.update();

        OutlineUtil.normalizeSectionsMarker(
            pEditor.getOutlinePage().getContentProvider().getRoot());
      }
    }

    // Formatting text _must_ be the last thing to do : it modifies the
    // document content, therefore it may induce unpredictable behavior for
    // next document readers
    if (pPreferenceStore.getBoolean(IEditorPreferenceConstants.EDITOR_SAVE_FORMAT)) {
      // Text format on save

      // Doc informations
      IRegion docRegion = new Region(0, document.getLength());

      // Store current pointer location
      Point currentLocation = aSourceViewer.getSelectedRange();

      // Format the document
      pDocFormatter.format(document, docRegion);

      // Reset point location
      aSourceViewer.setSelectedRange(currentLocation.x, currentLocation.y);
    }

    if (LineWrapUtil.get().isActiveMode(LineWrapMode.SOFT)) {
      // Soft wrap mode : remove all added end-of-line

      pAutoEditLineWrap.unregisterListener();
      pAutoEditLineWrap.removeWrapping();
    }
  }