2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import com
.sun
.star
.accessibility
.XAccessible
;
20 import com
.sun
.star
.accessibility
.XAccessibleContext
;
21 import com
.sun
.star
.lang
.IndexOutOfBoundsException
;
25 * Map the tree of accessibility objects into their
26 * AccessibilityTreeModel counterparts.
28 class AccessibleTreeHandler
31 private XAccessibleContext mxContext
;
34 public NodeHandler
createHandler (XAccessibleContext xContext
)
37 return new AccessibleTreeHandler (xContext
);
42 public AccessibleTreeHandler ()
48 private AccessibleTreeHandler (XAccessibleContext xContext
)
52 if (mxContext
!= null)
53 // Add one to the number of children to include the string node
54 // that tells you how many children there are.
55 synchronized (maChildList
)
57 maChildList
.setSize (1 + mxContext
.getAccessibleChildCount());
62 public AccessibleTreeNode
createChild (AccessibleTreeNode aParent
, int nIndex
)
64 AccessibleTreeNode aChild
= null;
65 if (mxContext
!= null)
68 aChild
= new StringNode ("Child count: " + mxContext
.getAccessibleChildCount(),
72 // Lower index to skip the string node.
76 XAccessible xChild
= mxContext
.getAccessibleChild (nIndex
);
77 aChild
= NodeFactory
.Instance().createDefaultNode (
80 catch( IndexOutOfBoundsException e
)
82 aChild
= new StringNode ("ERROR: no child with index " + nIndex
, aParent
);
87 aChild
= new StringNode ("XAccessibleContext interface not supported", aParent
);
91 /** Try to add the specified accessible child into the lists of
92 children. The insertion position is determined from the
93 getIndexInParent method of the child.
95 public AccessibleTreeNode
addAccessibleChild (AccessibleTreeNode aParent
, XAccessible xChild
)
97 AccessibleTreeNode aChild
= null;
101 XAccessibleContext xContext
= xChild
.getAccessibleContext();
102 if (xContext
!= null)
104 int nIndex
= xContext
.getAccessibleIndexInParent() + 1;
105 synchronized (maChildList
)
107 if ((nIndex
>= 0) || (nIndex
<= maChildList
.size()))
109 aChild
= NodeFactory
.Instance().createDefaultNode (xChild
, aParent
);
110 maChildList
.add (nIndex
, aChild
);
119 /** Update only the child count node. Trust on other ways to update the
123 public void update (AccessibleTreeNode aNode
)
125 synchronized (maChildList
)
127 maChildList
.set (0, null);