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
;
8 * Map the tree of accessibility objects into their
9 * AccessibilityTreeModel counterparts.
11 class AccessibleTreeHandler
14 protected XAccessibleContext mxContext
;
16 public NodeHandler
createHandler (XAccessibleContext xContext
)
19 return new AccessibleTreeHandler (xContext
);
24 public AccessibleTreeHandler ()
30 public AccessibleTreeHandler (XAccessibleContext 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)
49 aChild
= new StringNode ("Child count: " + mxContext
.getAccessibleChildCount(),
53 // Lower index to skip the string node.
57 XAccessible xChild
= mxContext
.getAccessibleChild (nIndex
);
58 aChild
= NodeFactory
.Instance().createDefaultNode (
61 catch( IndexOutOfBoundsException e
)
63 aChild
= new StringNode ("ERROR: no child with index " + nIndex
, aParent
);
68 aChild
= new StringNode ("XAccessibleContext interface not supported", aParent
);
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;
82 XAccessibleContext xContext
= xChild
.getAccessibleContext();
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
);
100 /** Update only the child count node. Trust on other ways to update the
103 public void update (AccessibleTreeNode aNode
)
105 synchronized (maChildList
)
107 maChildList
.setElementAt (null, 0);