Skip to main content
summaryrefslogtreecommitdiffstats
blob: f81a6e272a2882e3f015a4430db921c0726302ea (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
119
120
/*******************************************************************************
 * Copyright (c) 2003 - 2005 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.bugzilla.compare;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
import org.eclipse.compare.structuremergeviewer.Differencer;
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylar.bugzilla.core.BugReport;


/**
 * A two-way or three-way compare for <code>BugReport</code> objects.
 */
public class BugzillaCompareInput extends CompareEditorInput {

	private boolean threeWay= false;
	private Object root;
	private IStructureComparator ancestor = null;
	private IStructureComparator left = null;
	private IStructureComparator right = null;
	
	/**
	 * Constructor.
	 * 
	 * @param configuration
	 *            The compare configuration used in this compare input.
	 * @see CompareConfiguration
	 */
	public BugzillaCompareInput(CompareConfiguration configuration) {
		super(configuration);
	}

	@Override
	protected Object prepareInput(IProgressMonitor monitor) {
		if (left == null || right == null) {
			return null;
		}
		Differencer d= new Differencer();
		root= d.findDifferences(threeWay, monitor, null, ancestor, left, right);
		return root;
	}

	/**
	 * @return The original object that's to be compared (appears on the top of
	 *         the compare view).
	 */
	public IStructureComparator getAncestor() {
		return ancestor;
	}
	
	/**
	 * Sets the original object that's to be compared (appears on the top of the
	 * compare view).
	 * 
	 * @param newAncestor
	 *            The new original object.
	 */
	public void setAncestor(BugReport newAncestor) {
		threeWay = (newAncestor != null);
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
		ancestor = structureCreator.getStructure(newAncestor);
	}
	
	/**
	 * @return The local object that's to be compared (appears on the left side
	 *         of the compare view).
	 */
	public IStructureComparator getLeft() {
		return left;
	}
	
	/**
	 * Sets the local object that's to be compared (appears on the left side of
	 * the compare view).
	 * 
	 * @param newLeft
	 *            The new local object.
	 */
	public void setLeft(BugReport newLeft) {
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
		left = structureCreator.getStructure(newLeft);
	}
	
	/**
	 * @return The online object that's to be compared (appears on the right
	 *         side of the compare view).
	 */
	public IStructureComparator getRight() {
		return right;
	}
	
	/**
	 * Sets the online object that's to be compared (appears on the right side
	 * of the compare view).
	 * 
	 * @param newRight
	 *            The new online object.
	 */
	public void setRight(BugReport newRight) {
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
		right = structureCreator.getStructure(newRight);
	}
	
	/**
	 * @return <code>true</code> if a three-way comparison is to be done.
	 */
	public boolean isThreeWay() {
		return threeWay;
	}
}

Back to the top