blob: 6bbc6d0480eae55f41269de2eac3b68557517256 (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.internal.ui.mapping;
import java.io.InputStream;
import org.eclipse.compare.*;
import org.eclipse.core.resources.IEncodedStorage;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.team.core.history.IFileRevision;
/**
* A typed element for file revisions
*/
public class FileStateTypedElement extends BufferedContent implements ITypedElement, IEditableContent, IEncodedStreamContentAccessor {
IFileRevision state;
private IStorage bufferedContents;
public FileStateTypedElement(IFileRevision state) {
this.state = state;
}
/* (non-Javadoc)
* @see org.eclipse.compare.BufferedContent#createStream()
*/
protected InputStream createStream() throws CoreException {
if(bufferedContents == null) {
cacheContents(new NullProgressMonitor());
}
if (bufferedContents != null) {
return bufferedContents.getContents();
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.compare.ITypedElement#getName()
*/
public String getName() {
return state.getName();
}
/* (non-Javadoc)
* @see org.eclipse.compare.ITypedElement#getImage()
*/
public Image getImage() {
return CompareUI.getImage(getType());
}
/* (non-Javadoc)
* @see org.eclipse.compare.ITypedElement#getType()
*/
public String getType() {
String name = getName();
if (name != null) {
int index = name.lastIndexOf('.');
if (index == -1)
return ""; //$NON-NLS-1$
if (index == (name.length() - 1))
return ""; //$NON-NLS-1$
return name.substring(index + 1);
}
return ITypedElement.FOLDER_TYPE;
}
/* (non-Javadoc)
* @see org.eclipse.compare.IEditableContent#isEditable()
*/
public boolean isEditable() {
return false;
}
/* (non-Javadoc)
* @see org.eclipse.compare.IEditableContent#replace(org.eclipse.compare.ITypedElement, org.eclipse.compare.ITypedElement)
*/
public ITypedElement replace(ITypedElement dest, ITypedElement src) {
return null;
}
/* (non-Javadoc)
* @see org.eclipse.compare.IEncodedStreamContentAccessor#getCharset()
*/
public String getCharset() throws CoreException {
if(bufferedContents == null) {
cacheContents(new NullProgressMonitor());
}
if (bufferedContents instanceof IEncodedStorage) {
return ((IEncodedStorage)bufferedContents).getCharset();
}
return null;
}
/**
* Cache the contents for the remote resource in a local buffer
* @param monitor
*/
public void cacheContents(IProgressMonitor monitor) throws CoreException {
bufferedContents = state.getStorage(monitor);
}
}
|