KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > databinding > observable > tree > TreeDiffNode


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 package org.eclipse.core.internal.databinding.observable.tree;
13
14 /**
15  * @since 1.1
16  *
17  */

18 public abstract class TreeDiffNode {
19
20     /**
21      *
22      */

23     public final static int NO_CHANGE = 0x00;
24
25     /**
26      *
27      */

28     public final static int ADDED = 0x01;
29
30     /**
31      *
32      */

33     public final static int REMOVED = 0x02;
34
35     /**
36      *
37      */

38     public final static int REPLACED = 0x03;
39
40     /**
41      *
42      */

43     public static final TreeDiffNode[] NO_CHILDREN = new TreeDiffNode[0];
44
45     /**
46      *
47      */

48     public static final int INDEX_UNKNOWN = -1;
49
50     /**
51      * @return the change type
52      */

53     public abstract int getChangeType();
54
55     /**
56      * @return the element that was removed, or the replaced element
57      */

58     public abstract Object JavaDoc getOldElement();
59
60     /**
61      * @return the element that was not changed, added, or the replacement
62      * element
63      */

64     public abstract Object JavaDoc getNewElement();
65
66     /**
67      * @return the index at which the element was added, removed, or replaced
68      */

69     public abstract int getIndex();
70
71     /**
72      * Returns the child tree diff objects that describe changes to children. If
73      * the change type is REMOVED, there will be no children.
74      *
75      * @return the nodes representing changes to children
76      */

77     public abstract TreeDiffNode[] getChildren();
78
79     protected void doAccept(TreeDiffVisitor visitor, TreePath parentPath) {
80         TreePath currentPath = parentPath.createChildPath(getNewElement());
81         boolean recurse = visitor.visit(this, currentPath);
82         if (recurse) {
83             TreeDiffNode[] children = getChildren();
84             for (int i = 0; i < children.length; i++) {
85                 TreeDiffNode child = children[i];
86                 child.doAccept(visitor, currentPath);
87             }
88         }
89     }
90
91 }
92
Popular Tags