Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0cd40eda3970598765f9549e4aae235133cee635 (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
/*******************************************************************************
 * Copyright (c) 2000, 2011 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.compare.structuremergeviewer;

import org.eclipse.compare.ITypedElement;
import org.eclipse.swt.graphics.Image;

/**
 * An abstract base implementation of the <code>IDiffElement</code> interface.
 * <p>
 * Subclasses may add behavior and state, and may override <code>getImage</code>
 * and <code>getType</code> to suit.
 * </p>
 */
public abstract class DiffElement implements IDiffElement {
	private int fKind;
	private IDiffContainer fParent;

	/**
	 * Creates a new <code>DiffElement</code> as a child of the given parent.
	 * If parent is not <code>null</code> the new element is added to the parent.
	 *
	 * @param parent the parent of this child; if not <code>null</code> this element is automatically added as a child
	 * @param kind the kind of change
	 */
	public DiffElement(IDiffContainer parent, int kind) {
		fParent= parent;
		fKind= kind;
		if (parent != null)
			parent.add(this);
	}

	/**
	 * The <code>DiffElement</code> implementation of this <code>ITypedInput</code>
	 * method returns <code>null</code>. Subclasses may re-implement to provide
	 * an image for this element.
	 * @return <code>null</code>.
	 */
	@Override
	public Image getImage() {
		return null;
	}

	/**
	 * The <code>DiffElement</code> implementation of this <code>ITypedElement</code>
	 * method returns <code>ITypedElement.UNKNOWN_TYPE</code>. Subclasses may
	 * re-implement to provide a type for this element.
	 * @return <code>ITypedElement.UNKNOWN_TYPE</code>.
	 */
	@Override
	public String getType() {
		return ITypedElement.UNKNOWN_TYPE;
	}

	/**
	 * Sets the kind of difference for this element.
	 *
	 * @param kind set the kind of difference this element represents
	 * @see Differencer
	 */
	public void setKind(int kind) {
		fKind= kind;
	}

	@Override
	public int getKind() {
		return fKind;
	}

	@Override
	public IDiffContainer getParent() {
		return fParent;
	}

	@Override
	public void setParent(IDiffContainer parent) {
		fParent= parent;
	}
}

Back to the top