Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 35a90310fcede7b7de16f95e5af51ccf1df0e925 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (c) 2012, 2013 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.releng.version.ui.quickfixes;

import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.filebuffers.LocationKind;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.text.IDocument;

/**
 * @author Eike Stepper
 */
public abstract class AbstractDocumentResolution extends AbstractResolution
{
  public AbstractDocumentResolution(IMarker marker, String label, String imageKey)
  {
    super(marker, label, imageKey);
  }

  @Override
  protected final void apply(IMarker marker) throws Exception
  {
    IPath fullPath = ((IFile)marker.getResource()).getFullPath();
    ITextFileBufferManager.DEFAULT.connect(fullPath, LocationKind.IFILE, new NullProgressMonitor());

    try
    {
      ITextFileBuffer buffer = ITextFileBufferManager.DEFAULT.getTextFileBuffer(fullPath, LocationKind.IFILE);
      boolean wasDirty = buffer.isDirty();

      IDocument document = buffer.getDocument();
      if (apply(marker, document))
      {
        if (!wasDirty && !buffer.isShared())
        {
          buffer.commit(new NullProgressMonitor(), true);
        }
      }
    }
    finally
    {
      ITextFileBufferManager.DEFAULT.disconnect(fullPath, LocationKind.IFILE, new NullProgressMonitor());
    }
  }

  protected abstract boolean apply(IMarker marker, IDocument document) throws Exception;
}

Back to the top