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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*******************************************************************************
* Copyright (c) 2009, 2017 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.synchronize.patch;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.internal.core.patch.*;
import org.eclipse.compare.internal.patch.*;
import org.eclipse.compare.structuremergeviewer.*;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Platform;
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
// TODO: extend PatchDiffNode, update navigatorContent triggerPoints when done
public class PatchWorkspace extends DiffNode implements IAdaptable {
private WorkspacePatcher patcher;
public PatchWorkspace(WorkspacePatcher patcher) {
super(null, Differencer.NO_CHANGE);
this.patcher = patcher;
}
public WorkspacePatcher getPatcher() {
return patcher;
}
public IResource getResource() {
return ResourcesPlugin.getWorkspace().getRoot();
}
@Override
public String getName() {
return "Patch Root Workspace"; //$NON-NLS-1$
}
@Override
public IDiffContainer getParent() {
return null;
}
@Override
public IDiffElement[] getChildren() {
/*
* Create a complete tree of patch model objects - elements of the
* patch, but return only top-level ones: PatchProjectDiffNode(s) for a
* workspace patch or FileDiffResult(s) otherwise. See
* org.eclipse.compare.internal
* .patch.PatchCompareEditorInput.buildTree()
*/
IDiffElement[] children;
if (getPatcher().isWorkspacePatch()) {
children = processProjects(getPatcher().getDiffProjects());
} else {
children = processDiffs(getPatcher().getDiffs());
}
return children;
}
// see org.eclipse.compare.internal.patch.PatchCompareEditorInput.processDiffs(FilePatch2[])
private IDiffElement[] processDiffs(FilePatch2[] diffs) {
List result = new ArrayList();
for (int i = 0; i < diffs.length; i++) {
result.addAll(processDiff(diffs[i], this));
}
return (IDiffElement[]) result.toArray(new IDiffElement[result.size()]);
}
// see org.eclipse.compare.internal.patch.PatchCompareEditorInput.processProjects(DiffProject[])
private IDiffElement[] processProjects(DiffProject[] diffProjects) {
List result = new ArrayList();
for (int i = 0; i < diffProjects.length; i++) {
PatchProjectDiffNode projectNode = new PatchProjectDiffNode(this, diffProjects[i], getPatcher().getConfiguration());
result.add(projectNode);
FilePatch2[] diffs = diffProjects[i].getFileDiffs();
for (int j = 0; j < diffs.length; j++) {
FilePatch2 fileDiff = diffs[j];
processDiff(fileDiff, projectNode);
}
}
return (IDiffElement[]) result.toArray(new IDiffElement[result.size()]);
}
// see org.eclipse.compare.internal.patch.PatchCompareEditorInput.processDiff(FilePatch2, DiffNode)
private List/*<IDiffElement>*/ processDiff(FilePatch2 diff, DiffNode parent) {
List result = new ArrayList();
FileDiffResult diffResult = getPatcher().getDiffResult(diff);
PatchFileDiffNode node = new PatchFileDiffNode(diffResult, parent, PatchFileDiffNode.getKind(diffResult), PatchFileDiffNode.getAncestorElement(diffResult), getLeftElement(diffResult), PatchFileDiffNode.getRightElement(diffResult));
result.add(node);
HunkResult[] hunkResults = diffResult.getHunkResults();
for (int i = 0; i < hunkResults.length; i++) {
HunkResult hunkResult = hunkResults[i];
new HunkDiffNode(hunkResult, node, Differencer.CHANGE, HunkDiffNode.getAncestorElement(hunkResult, false), getLeftElement(hunkResult), HunkDiffNode.getRightElement(hunkResult, false));
// result.add(hunkDiffNode);
}
return result;
}
private static ITypedElement getLeftElement(final FileDiffResult result) {
return new LocalResourceTypedElement(((WorkspaceFileDiffResult)result).getTargetFile()) {
@Override
public String getName() {
// as in org.eclipse.compare.internal.patch.PatchFileTypedElement
return result.getTargetPath().toString();
}
};
}
private static ITypedElement getLeftElement(final HunkResult result) {
return new LocalResourceTypedElement(((WorkspaceFileDiffResult)result.getDiffResult()).getTargetFile()) {
@Override
public String getName() {
// as in org.eclipse.compare.internal.patch.HunkTypedElement
return result.getHunk().getLabel();
}
};
}
// cannot extend PlatformObject (already extends DiffNode) so implement
// IAdaptable
@Override
public <T> T getAdapter(Class<T> adapter) {
return Platform.getAdapterManager().getAdapter(this, adapter);
}
}
|