diff org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.d @ 95:6208d4f6a277

Added trees for databinding.beans and observable
author Frank Benoit <benoit@tionex.de>
date Tue, 21 Apr 2009 10:55:51 +0200
parents
children b74ac5dfcc06
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/tree/TreeDiffNode.d	Tue Apr 21 10:55:51 2009 +0200
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2007 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.core.internal.databinding.observable.tree;
+
+/**
+ * @since 1.1
+ * 
+ */
+public abstract class TreeDiffNode {
+
+    /**
+     * 
+     */
+    public final static int NO_CHANGE = 0x00;
+
+    /**
+     * 
+     */
+    public final static int ADDED = 0x01;
+
+    /**
+     * 
+     */
+    public final static int REMOVED = 0x02;
+
+    /**
+     * 
+     */
+    public final static int REPLACED = 0x03;
+
+    /**
+     * 
+     */
+    public static final TreeDiffNode[] NO_CHILDREN = new TreeDiffNode[0];
+
+    /**
+     * 
+     */
+    public static final int INDEX_UNKNOWN = -1;
+
+    /**
+     * @return the change type
+     */
+    public abstract int getChangeType();
+
+    /**
+     * @return the element that was removed, or the replaced element
+     */
+    public abstract Object getOldElement();
+
+    /**
+     * @return the element that was not changed, added, or the replacement
+     *         element
+     */
+    public abstract Object getNewElement();
+
+    /**
+     * @return the index at which the element was added, removed, or replaced
+     */
+    public abstract int getIndex();
+
+    /**
+     * Returns the child tree diff objects that describe changes to children. If
+     * the change type is REMOVED, there will be no children.
+     * 
+     * @return the nodes representing changes to children
+     */
+    public abstract TreeDiffNode[] getChildren();
+
+    protected void doAccept(TreeDiffVisitor visitor, TreePath parentPath) {
+        TreePath currentPath = parentPath.createChildPath(getNewElement());
+        bool recurse = visitor.visit(this, currentPath);
+        if (recurse) {
+            TreeDiffNode[] children = getChildren();
+            for (int i = 0; i < children.length; i++) {
+                TreeDiffNode child = children[i];
+                child.doAccept(visitor, currentPath);
+            }
+        }
+    }
+
+}