Make quick diff aware of changes in the repository.
[egit/zawir.git] / org.spearce.egit.ui / src / org / spearce / egit / ui / internal / decorators / GitQuickDiffProvider.java
blob052552e4e8b584dbd90b45eb64af8312cdedb16f
1 /*******************************************************************************
2 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * See LICENSE for the full license text, also available.
8 *******************************************************************************/
9 package org.spearce.egit.ui.internal.decorators;
11 import java.io.IOException;
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.team.core.RepositoryProvider;
18 import org.eclipse.ui.IEditorInput;
19 import org.eclipse.ui.ide.ResourceUtil;
20 import org.eclipse.ui.texteditor.ITextEditor;
21 import org.eclipse.ui.texteditor.quickdiff.IQuickDiffReferenceProvider;
22 import org.spearce.egit.ui.Activator;
23 import org.spearce.egit.ui.UIText;
25 /**
26 * This class provides input for the Eclipse Quick Diff feature.
28 public class GitQuickDiffProvider implements IQuickDiffReferenceProvider {
30 private String id;
32 private GitDocument document;
34 private IResource resource;
36 public void dispose() {
37 Activator.trace("(GitQuickDiffProvider) dispose");
38 if (document != null)
39 document.dispose();
42 public String getId() {
43 return id;
46 public IDocument getReference(IProgressMonitor monitor)
47 throws CoreException {
48 Activator.trace("(GitQuickDiffProvider) file: " + resource);
49 RepositoryProvider provider = RepositoryProvider.getProvider(resource
50 .getProject());
51 if (provider != null) {
52 try {
53 document = GitDocument.create(resource);
54 } catch (CoreException e) {
55 Activator.error(UIText.QuickDiff_failedLoading, e);
56 } catch (IOException e) {
57 Activator.error(UIText.QuickDiff_failedLoading, e);
59 return document;
60 } else {
61 return null;
65 public boolean isEnabled() {
66 return true;
69 public void setActiveEditor(ITextEditor editor) {
70 IEditorInput editorInput = editor.getEditorInput();
71 resource = ResourceUtil.getResource(editorInput);
74 public void setId(String id) {
75 this.id = id;