merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / AccessibleTreeHandler.java
blobf45db8cb5ab98d051b32eb7ad4935078b5a16ce7
1 import com.sun.star.accessibility.XAccessible;
2 import com.sun.star.accessibility.XAccessibleContext;
3 import com.sun.star.uno.UnoRuntime;
4 import com.sun.star.lang.IndexOutOfBoundsException;
7 /**
8 * Map the tree of accessibility objects into their
9 * AccessibilityTreeModel counterparts.
11 class AccessibleTreeHandler
12 extends NodeHandler
14 protected XAccessibleContext mxContext;
16 public NodeHandler createHandler (XAccessibleContext xContext)
18 if (xContext != null)
19 return new AccessibleTreeHandler (xContext);
20 else
21 return null;
24 public AccessibleTreeHandler ()
26 super();
27 mxContext = null;
30 public AccessibleTreeHandler (XAccessibleContext xContext)
32 super();
33 mxContext = xContext;
34 if (mxContext != null)
35 // Add one to the number of children to include the string node
36 // that tells you how many children there are.
37 synchronized (maChildList)
39 maChildList.setSize (1 + mxContext.getAccessibleChildCount());
43 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
45 AccessibleTreeNode aChild = null;
46 if (mxContext != null)
48 if (nIndex == 0)
49 aChild = new StringNode ("Child count: " + mxContext.getAccessibleChildCount(),
50 aParent);
51 else
53 // Lower index to skip the string node.
54 nIndex -= 1;
55 try
57 XAccessible xChild = mxContext.getAccessibleChild (nIndex);
58 aChild = NodeFactory.Instance().createDefaultNode (
59 xChild, aParent);
61 catch( IndexOutOfBoundsException e )
63 aChild = new StringNode ("ERROR: no child with index " + nIndex, aParent);
67 else
68 aChild = new StringNode ("XAccessibleContext interface not supported", aParent);
69 return aChild;
72 /** Try to add the specified accessible child into the lists of
73 children. The insertion position is determined from the
74 getIndexInParent method of the child.
76 public AccessibleTreeNode addAccessibleChild (AccessibleTreeNode aParent, XAccessible xChild)
78 AccessibleTreeNode aChild = null;
80 if (xChild != null)
82 XAccessibleContext xContext = xChild.getAccessibleContext();
83 if (xContext != null)
85 int nIndex = xContext.getAccessibleIndexInParent() + 1;
86 synchronized (maChildList)
88 if ((nIndex >= 0) || (nIndex <= maChildList.size()))
90 aChild = NodeFactory.Instance().createDefaultNode (xChild, aParent);
91 maChildList.insertElementAt (aChild, nIndex);
96 return aChild;
100 /** Update only the child count node. Trust on other ways to update the
101 accessible children.
103 public void update (AccessibleTreeNode aNode)
105 synchronized (maChildList)
107 maChildList.setElementAt (null, 0);