Replace System.out with proper tracing
[egit/spearce.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / decorators / GitQuickDiffProvider.java
blob8b3f8cd1c91146d87a62173c93bedcfd752085b8
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 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *******************************************************************************/
10 package org.eclipse.egit.ui.internal.decorators;
12 import java.io.IOException;
13 import java.util.Map;
14 import java.util.WeakHashMap;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.egit.core.internal.trace.GitTraceLocation;
20 import org.eclipse.egit.ui.Activator;
21 import org.eclipse.egit.ui.UIText;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.team.core.RepositoryProvider;
24 import org.eclipse.ui.IEditorInput;
25 import org.eclipse.ui.ide.ResourceUtil;
26 import org.eclipse.ui.texteditor.ITextEditor;
27 import org.eclipse.ui.texteditor.quickdiff.IQuickDiffReferenceProvider;
28 import org.eclipse.jgit.lib.Repository;
30 /**
31 * This class provides input for the Eclipse Quick Diff feature.
33 public class GitQuickDiffProvider implements IQuickDiffReferenceProvider {
35 private String id;
37 private GitDocument document;
39 private IResource resource;
41 static Map<Repository,String> baseline = new WeakHashMap<Repository,String>();
43 /**
44 * Create the GitQuickDiffProvider instance
46 public GitQuickDiffProvider() {
47 // TODO is this the right location?
48 if (GitTraceLocation.UI.isActive())
49 GitTraceLocation.getTrace().traceEntry(GitTraceLocation.UI.getLocation());
50 // Empty
53 public void dispose() {
54 // TODO is this the right location?
55 if (GitTraceLocation.UI.isActive())
56 GitTraceLocation.getTrace().traceEntry(GitTraceLocation.UI.getLocation());
57 if (document != null)
58 document.dispose();
61 public String getId() {
62 return id;
65 public IDocument getReference(IProgressMonitor monitor)
66 throws CoreException {
67 // TODO is this the right location?
68 if (GitTraceLocation.UI.isActive())
69 GitTraceLocation.getTrace().trace(
70 GitTraceLocation.UI.getLocation(),
71 "(GitQuickDiffProvider) file: " + resource); //$NON-NLS-1$
72 if (resource == null)
73 return null;
74 RepositoryProvider provider = RepositoryProvider.getProvider(resource
75 .getProject());
76 if (provider != null) {
77 try {
78 document = GitDocument.create(resource);
79 } catch (IOException e) {
80 Activator.error(UIText.QuickDiff_failedLoading, e);
82 return document;
83 } else {
84 return null;
88 public boolean isEnabled() {
89 return true;
92 public void setActiveEditor(ITextEditor editor) {
93 // TODO is this the right location?
94 if (GitTraceLocation.UI.isActive())
95 GitTraceLocation.getTrace().traceEntry(
96 GitTraceLocation.UI.getLocation(), editor.getTitle());
97 IEditorInput editorInput = editor.getEditorInput();
98 resource = ResourceUtil.getResource(editorInput);
101 public void setId(String id) {
102 this.id = id;
106 * Set a new baseline for quickdiff
108 * @param repository
109 * @param baseline any commit reference, ref, symref or sha-1
110 * @throws IOException
112 public static void setBaselineReference(final Repository repository, final String baseline) throws IOException {
113 GitQuickDiffProvider.baseline.put(repository, baseline);
114 GitDocument.refreshRelevant(repository);