blob: 37a2651457cc7abed4591e00af2f981880ad0b92 (
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
113
114
115
116
117
118
|
/*******************************************************************************
* Copyright (c) 2000, 2011 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.compare;
import java.io.BufferedInputStream;
import java.io.InputStream;
import org.eclipse.core.resources.IEncodedStorage;
import org.eclipse.core.resources.IFileState;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.swt.graphics.Image;
/**
* A combination <code>IFileState</code> and <code>ITypedElement</code> that can be used as
* an input to a compare viewer or other places where an <code>IStreamContentAccessor</code>
* is needed.
* <p>
* <p>
* Clients may instantiate this class; it is not intended to be subclassed.
* </p>
* @noextend This class is not intended to be subclassed by clients.
*/
public class HistoryItem implements IEncodedStreamContentAccessor, ITypedElement, IModificationDate, IResourceProvider {
private ITypedElement fBase;
private IFileState fFileState;
/**
* Creates a <code>HistoryItem</code> object which combines the given <code>IFileState</code>
* and <code>ITypedElement</code> into an object
* which is suitable as input for a compare viewer or <code>ReplaceWithEditionDialog</code>.
*
* @param base the implementation of the <code>ITypedElement</code> interface delegates to this base <code>ITypedElement</code>
* @param fileState the <code>IFileState</code> from which the streamable contents and the modification time is derived from
*/
public HistoryItem(ITypedElement base, IFileState fileState) {
fBase= base;
fFileState= fileState;
}
/* (non-Javadoc)
* see ITypedElement.getName
*/
@Override
public String getName() {
return fBase.getName();
}
/* (non-Javadoc)
* see ITypedElement.getImage
*/
@Override
public Image getImage() {
return fBase.getImage();
}
/* (non-Javadoc)
* see ITypedElement.getType
*/
@Override
public String getType() {
return fBase.getType();
}
/* (non-Javadoc)
* see IModificationDate.getModificationDate
*/
@Override
public long getModificationDate() {
return fFileState.getModificationTime();
}
/* (non-Javadoc)
* see IStreamContentAccessor.getContents
*/
@Override
public InputStream getContents() throws CoreException {
return new BufferedInputStream(fFileState.getContents());
}
/* (non-Javadoc)
* @see org.eclipse.compare.IEncodedStreamContentAccessor#getCharset()
*/
@Override
public String getCharset() throws CoreException {
String charset= fFileState.getCharset();
if (charset == null) {
IResource resource= getResource();
if (resource instanceof IEncodedStorage)
charset= ((IEncodedStorage)resource).getCharset();
}
return charset;
}
/* (non-Javadoc)
* @see org.eclipse.compare.internal.IResourceProvider#getResource()
*/
@Override
public IResource getResource() {
IPath fullPath= fFileState.getFullPath();
return ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath);
}
}
|