import com.sun.star.uno.UnoRuntime; import drafts.com.sun.star.accessibility.XAccessible; import drafts.com.sun.star.accessibility.XAccessibleContext; import java.util.Vector; /** * The node type for the AccessibleTreeModel. * This implements all the child-handling based on the appropriate * NodeHandlers. Trivial nodes can be implemented by any Object * type. */ class AccTreeNode extends AccessibleTreeNode { class HandlerDescriptor { public HandlerDescriptor (NodeHandler aHandler) { maHandler = aHandler; mnChildCount = -1; } public NodeHandler maHandler; public int mnChildCount; } /// NodeHandlers for this node private Vector maHandlers; // The accessible context of this node. private XAccessible mxAccessible; private XAccessibleContext mxContext; public AccTreeNode (XAccessibleContext xContext, AccessibleTreeNode aParent) { this (xContext, xContext, aParent); } public AccTreeNode (XAccessibleContext xContext, Object aDisplay, AccessibleTreeNode aParent) { super (aDisplay, aParent); maHandlers = new Vector(5); mxContext = xContext; mxAccessible = null; } /** Update the internal data extracted from the corresponding accessible object. This is done by replacing every handler by a new one. An update method at each handler would be better of course. */ public void update () { for (int i=0; i= 0 ) { for(int i = 0; i < maHandlers.size(); i++) { // check if this handler has the child, and if not // search with next handler HandlerDescriptor aDescriptor = getHandlerDescriptor (i); if (nIndex < aDescriptor.mnChildCount) return aDescriptor.maHandler.getChild (this, nIndex); else nIndex -= aDescriptor.mnChildCount; } } else throw new IndexOutOfBoundsException(); // nothing found? return null; } public boolean removeChild (int nIndex) throws IndexOutOfBoundsException { boolean bStatus = false; if (nIndex >= 0) { for (int i=0; i= 0) return nBaseIndex + nIndex; else nBaseIndex += aDescriptor.mnChildCount; } } return -1; } /** this node is a leaf if have no handlers, or is those handlers show no children */ public boolean isLeaf() { return (maHandlers.size() == 0);// || (getChildCount() == 0); } public boolean equals (Object aOther) { return (this == aOther) || aOther.equals(mxContext); } /** iterate over handlers until the child is found */ public void getActions(Vector aActions) { for(int i = 0; i < maHandlers.size(); i++) { HandlerDescriptor aDescriptor = getHandlerDescriptor (i); NodeHandler aHandler = aDescriptor.maHandler; String[] aHandlerActions = aHandler.getActions (this); for(int j = 0; j < aHandlerActions.length; j++ ) { aActions.add( aHandlerActions[j] ); } } } public void performAction( int nIndex ) { if( nIndex >= 0 ) { for(int i = 0; i < maHandlers.size(); i++) { // check if this handler has the child, and if not // search with next handler HandlerDescriptor aDescriptor = getHandlerDescriptor (i); NodeHandler aHandler = aDescriptor.maHandler; int nCount = aHandler.getActions(this).length; if( nCount > nIndex ) { aHandler.performAction(this, nIndex ); return; } else nIndex -= nCount; } } } /** Try to add the specified accessible object as new accessible child of the AccessibleTreeHandler. Note that child is used in another context than it is used in the other methods of this class. */ public AccessibleTreeNode addAccessibleChild (XAccessible xChild) { for(int i = 0; i < maHandlers.size(); i++) { HandlerDescriptor aDescriptor = getHandlerDescriptor (i); if (aDescriptor.maHandler instanceof AccessibleTreeHandler) { AccessibleTreeHandler aHandler = (AccessibleTreeHandler)aDescriptor.maHandler; AccessibleTreeNode aNode = aHandler.addAccessibleChild (this, xChild); aDescriptor.mnChildCount = aHandler.getChildCount (this); return aNode; } } return null; } }