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
;
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
;
31 * This class provides input for the Eclipse Quick Diff feature.
33 public class GitQuickDiffProvider
implements IQuickDiffReferenceProvider
{
37 private GitDocument document
;
39 private IResource resource
;
41 static Map
<Repository
,String
> baseline
= new WeakHashMap
<Repository
,String
>();
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());
53 public void dispose() {
54 // TODO is this the right location?
55 if (GitTraceLocation
.UI
.isActive())
56 GitTraceLocation
.getTrace().traceEntry(GitTraceLocation
.UI
.getLocation());
61 public String
getId() {
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$
74 RepositoryProvider provider
= RepositoryProvider
.getProvider(resource
76 if (provider
!= null) {
78 document
= GitDocument
.create(resource
);
79 } catch (IOException e
) {
80 Activator
.error(UIText
.QuickDiff_failedLoading
, e
);
88 public boolean isEnabled() {
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
) {
106 * Set a new baseline for quickdiff
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
);