blob: 12e5be628ff1bf870330ef6553d5916fea31110a (
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
|
/*******************************************************************************
* Copyright (c) 2000, 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.examples.localhistory;
import java.util.*;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.variants.IResourceVariantComparator;
import org.eclipse.team.examples.filesystem.FileSystemPlugin;
public class LocalHistorySubscriber extends Subscriber {
private long timestamp;
private static final long LAST_FILESTATE = 0L;
private LocalHistoryVariantComparator comparator;
public LocalHistorySubscriber() {
this(LAST_FILESTATE);
}
public LocalHistorySubscriber(long timestamp) {
this.timestamp = timestamp;
this.comparator = new LocalHistoryVariantComparator();
}
public String getName() {
return "Local History Subscriber"; //$NON-NLS-1$
}
public boolean isSupervised(IResource resource) throws TeamException {
// all resources in the workspace can potentially have resource history
return true;
}
public IResource[] members(IResource resource) throws TeamException {
try {
if(resource.getType() == IResource.FILE) {
return new IResource[0];
}
IContainer container = (IContainer)resource;
List existingChildren = new ArrayList(Arrays.asList(container.members()));
existingChildren.addAll(Arrays.asList(container.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, new NullProgressMonitor())));
return (IResource[]) existingChildren.toArray(new IResource[existingChildren.size()]);
} catch (CoreException e) {
FileSystemPlugin.getPlugin().getLog().log(e.getStatus());
return new IResource[0];
}
}
public IResource[] roots() {
return ResourcesPlugin.getWorkspace().getRoot().getProjects();
}
public SyncInfo getSyncInfo(IResource resource) throws TeamException {
try {
if(resource.getType() == IResource.FILE) {
IFile file = (IFile)resource;
IFileState[] states = file.getHistory(new NullProgressMonitor());
if(states.length > 0) {
// last state only
SyncInfo info = new SyncInfo(file,null, new LocalHistoryVariant(states[0]), comparator);
info.init();
return info;
}
}
} catch (CoreException e) {
FileSystemPlugin.getPlugin().getLog().log(e.getStatus());
}
return new SyncInfo(resource, null, null, comparator) {
protected int calculateKind() throws TeamException {
return IN_SYNC;
}
};
}
public IResourceVariantComparator getResourceComparator() {
return comparator;
}
public void refresh(IResource[] resources, int depth, IProgressMonitor monitor) throws TeamException {
}
}
|