78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2006, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 *******************************************************************************/
|
|
11
|
|
12 module org.eclipse.core.internal.databinding.observable.tree.TreeDiffNode;
|
81
|
13 import org.eclipse.core.internal.databinding.observable.tree.TreeDiffVisitor;
|
|
14 import org.eclipse.core.internal.databinding.observable.tree.TreePath;
|
78
|
15
|
|
16 import java.lang.all;
|
|
17
|
|
18 /**
|
|
19 * @since 1.1
|
|
20 *
|
|
21 */
|
|
22 public abstract class TreeDiffNode {
|
|
23
|
|
24 /**
|
|
25 *
|
|
26 */
|
|
27 public final static int NO_CHANGE = 0x00;
|
|
28
|
|
29 /**
|
|
30 *
|
|
31 */
|
|
32 public final static int ADDED = 0x01;
|
|
33
|
|
34 /**
|
|
35 *
|
|
36 */
|
|
37 public final static int REMOVED = 0x02;
|
|
38
|
|
39 /**
|
|
40 *
|
|
41 */
|
|
42 public final static int REPLACED = 0x03;
|
|
43
|
|
44 /**
|
|
45 *
|
|
46 */
|
|
47 public static final TreeDiffNode[] NO_CHILDREN = new TreeDiffNode[0];
|
|
48
|
|
49 /**
|
|
50 *
|
|
51 */
|
|
52 public static final int INDEX_UNKNOWN = -1;
|
|
53
|
|
54 /**
|
|
55 * @return the change type
|
|
56 */
|
|
57 public abstract int getChangeType();
|
|
58
|
|
59 /**
|
|
60 * @return the element that was removed, or the replaced element
|
|
61 */
|
|
62 public abstract Object getOldElement();
|
|
63
|
|
64 /**
|
|
65 * @return the element that was not changed, added, or the replacement
|
|
66 * element
|
|
67 */
|
|
68 public abstract Object getNewElement();
|
|
69
|
|
70 /**
|
|
71 * @return the index at which the element was added, removed, or replaced
|
|
72 */
|
|
73 public abstract int getIndex();
|
|
74
|
|
75 /**
|
|
76 * Returns the child tree diff objects that describe changes to children. If
|
|
77 * the change type is REMOVED, there will be no children.
|
|
78 *
|
|
79 * @return the nodes representing changes to children
|
|
80 */
|
|
81 public abstract TreeDiffNode[] getChildren();
|
|
82
|
|
83 protected void doAccept(TreeDiffVisitor visitor, TreePath parentPath) {
|
|
84 TreePath currentPath = parentPath.createChildPath(getNewElement());
|
|
85 bool recurse = visitor.visit(this, currentPath);
|
|
86 if (recurse) {
|
|
87 TreeDiffNode[] children = getChildren();
|
|
88 for (int i = 0; i < children.length; i++) {
|
|
89 TreeDiffNode child = children[i];
|
|
90 child.doAccept(visitor, currentPath);
|
|
91 }
|
|
92 }
|
|
93 }
|
|
94
|
|
95 }
|