/* $File: $
* Copyright 2000-2002 SoundBite Corporation. All Rights Reserved.
*/
package com.perforce.jdev;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
import javax.swing.tree.TreeNode;
import oracle.ide.explorer.ChildFilter;
import oracle.ide.explorer.TNode;
import oracle.ide.explorer.TreeExplorer;
import oracle.ide.model.Element;
import java.util.List;
/**
* Describe class <code>P4TNode</code> here.
*
* @author <a href="mailto:PKrause@PKRAUSE"></a>
* @version 1.0
*/
public class P4TNode implements TNode {
/** Description of the Field */
private P4Node dataElement;
/** Description of the Field */
private List childNodes;
/** Description of the Field */
private P4TNode[] ancestorPath;
/** Description of the Field */
private TreeExplorer ownerComponent;
/** Description of the Field */
private Comparator childComparator;
/** Description of the Field */
private ChildFilter childFilter;
/**
*Constructor for the P4TNode object
*
* @param element Description of Parameter
* @param owner Description of Parameter
*/
public P4TNode(P4Node element, TreeExplorer owner)
{
dataElement = element;
ancestorPath = new P4TNode[0];
ownerComponent = owner;
}
/**
*Constructor for the P4TNode object
*
* @param element Description of Parameter
* @param ancestors Description of Parameter
*/
public P4TNode(P4Node element, P4TNode[] ancestors)
{
dataElement = element;
ancestorPath = ancestors;
ownerComponent = ancestors[0].getOwner();
childComparator = ancestors[0].getComparator();
childFilter = ancestors[0].getChildFilter();
}
/**
* Sets the value of the child filter property
*
* @param cf The new child filter value
*/
public void setChildFilter(ChildFilter cf)
{
childFilter = cf;
}
/**
* Sets the value of the comparator property
*
* @param comp The new comparator value
*/
public void setComparator(Comparator comp)
{
childComparator = comp;
}
/**
* Sets the value of the bit property
*
* @param bit The new bit value
*/
public void setBit(int bit)
{
dataElement.getAttributes().set(bit);
}
/**
* Gets the value of the owner property
*
* @return The Owner value
*/
public TreeExplorer getOwner()
{
return ownerComponent;
}
/**
* Gets the value of the path property
*
* @return The Path value
*/
public TreeNode[] getPath()
{
return ancestorPath;
}
/**
* Gets the value of the data property
*
* @return The Data value
*/
public Element getData()
{
return dataElement;
}
/**
* Gets the value of the leaf property
*
* @return The Leaf value
*/
public boolean isLeaf()
{
return dataElement.isLeaf();
}
/**
* Gets the value of the root property
*
* @return The Root value
*/
public boolean isRoot()
{
return ancestorPath.length == 0;
}
/**
* Gets the value of the child filter property
*
* @return The ChildFilter value
*/
public ChildFilter getChildFilter()
{
return childFilter;
}
/**
* Gets the value of the child count property
*
* @return The ChildCount value
*/
public int getChildCount()
{
return 0;
}
/**
* Gets the value of the child nodes property
*
* @return The ChildNodes value
*/
public Iterator getChildNodes()
{
return new WrappingIterator();
}
/**
* Gets the value of the child T nodes property
*
* @return The ChildTNodes value
*/
public Enumeration getChildTNodes()
{
return new WrappingIterator();
}
/**
* Gets the value of the comparator property
*
* @return The Comparator value
*/
public Comparator getComparator()
{
return childComparator;
}
/**
* Gets the value of the ancestor T node property
*
* @param c Description of Parameter
* @param inheriting Description of Parameter
* @return The AncestorTNode value
*/
public TNode getAncestorTNode(Class c, boolean inheriting)
{
for (int i = 0; i < ancestorPath.length; i++) {
final Element data = ancestorPath[i].getData();
if (inheriting ? c.isInstance(data) : c.equals(data.getClass())) {
return ancestorPath[i];
}
}
return null;
}
/**
* Gets the value of the ancestor property
*
* @param c Description of Parameter
* @param subtyping Description of Parameter
* @return The Ancestor value
*/
public Element getAncestor(Class c, boolean subtyping)
{
for (int i = 0; i < ancestorPath.length; i++) {
final Element data = ancestorPath[i].getData();
if (subtyping ? c.isInstance(data) : c.equals(data.getClass())) {
return data;
}
}
return null;
}
/**
* Gets the value of the ancestor property
*
* @param c Description of Parameter
* @return The Ancestor value
*/
public Element getAncestor(Class c)
{
return getAncestor(c, false);
}
/**
* Gets the value of the set property
*
* @param bit Description of Parameter
* @return The Set value
*/
public boolean isSet(int bit)
{
return dataElement.getAttributes().isSet(bit);
}
/**
* Gets the value of the child at property
*
* @param i Description of Parameter
* @return The ChildAt value
*/
public TreeNode getChildAt(int i)
{
return null;
}
/**
* Gets the value of the parent property
*
* @return The Parent value
*/
public TreeNode getParent()
{
try {
return ancestorPath[0];
} catch (ArrayIndexOutOfBoundsException e) {
return null; // no parent
}
}
/**
* Gets the value of the index property
*
* @param child Description of Parameter
* @return The Index value
*/
public int getIndex(TreeNode child)
{
return -1;
}
/**
* Gets the value of the allows children property
*
* @return The AllowsChildren value
*/
public boolean getAllowsChildren()
{
return false;
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
public ChildFilter findChildFilter() {
if (childFilter != null) return childFilter;
for (int i = 0; i < ancestorPath.length; i++) {
final ChildFilter cf = ancestorPath[i].getChildFilter();
if (cf != null) return cf;
}
return null;
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
public Enumeration breadthFirstEnumeration()
{
return null;
}
/**
* Description of the Method
*
* @param bit Description of Parameter
*/
public void unsetBit(int bit)
{
dataElement.getAttributes().unset(bit);
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
public Enumeration children()
{
return getChildTNodes();
}
class WrappingIterator implements Enumeration, Iterator {
/** Description of the Field */
private final Iterator dataElementi = dataElement.getChildren();
/** Description of the Field */
private final P4TNode[] childAncestors =
new P4TNode[1 + ancestorPath.length];
{
childAncestors[0] = P4TNode.this;
System.arraycopy(ancestorPath, 0, childAncestors, 1, ancestorPath.length);
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
public boolean hasNext()
{
return dataElementi.hasNext();
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
public Object next()
{
return new P4TNode((P4Node) dataElementi.next(), childAncestors);
}
/** Description of the Method */
public void remove()
{
dataElementi.remove();
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
public boolean hasMoreElements()
{
return dataElementi.hasNext();
}
/**
* Description of the Method
*
* @return Description of the Returned Value
*/
public Object nextElement()
{
return new P4TNode((P4Node) dataElementi.next(), childAncestors);
}
}
}