fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / toolkit / test / accessibility / AccessibleTreeHandler.java
bloba6945a53207983b82d3245826eb044355325db32
1 /*
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;
24 /**
25 * Map the tree of accessibility objects into their
26 * AccessibilityTreeModel counterparts.
28 class AccessibleTreeHandler
29 extends NodeHandler
31 protected XAccessibleContext mxContext;
33 public NodeHandler createHandler (XAccessibleContext xContext)
35 if (xContext != null)
36 return new AccessibleTreeHandler (xContext);
37 else
38 return null;
41 public AccessibleTreeHandler ()
43 super();
44 mxContext = null;
47 public AccessibleTreeHandler (XAccessibleContext xContext)
49 super();
50 mxContext = xContext;
51 if (mxContext != null)
52 // Add one to the number of children to include the string node
53 // that tells you how many children there are.
54 synchronized (maChildList)
56 maChildList.setSize (1 + mxContext.getAccessibleChildCount());
60 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex)
62 AccessibleTreeNode aChild = null;
63 if (mxContext != null)
65 if (nIndex == 0)
66 aChild = new StringNode ("Child count: " + mxContext.getAccessibleChildCount(),
67 aParent);
68 else
70 // Lower index to skip the string node.
71 nIndex -= 1;
72 try
74 XAccessible xChild = mxContext.getAccessibleChild (nIndex);
75 aChild = NodeFactory.Instance().createDefaultNode (
76 xChild, aParent);
78 catch( IndexOutOfBoundsException e )
80 aChild = new StringNode ("ERROR: no child with index " + nIndex, aParent);
84 else
85 aChild = new StringNode ("XAccessibleContext interface not supported", aParent);
86 return aChild;
89 /** Try to add the specified accessible child into the lists of
90 children. The insertion position is determined from the
91 getIndexInParent method of the child.
93 public AccessibleTreeNode addAccessibleChild (AccessibleTreeNode aParent, XAccessible xChild)
95 AccessibleTreeNode aChild = null;
97 if (xChild != null)
99 XAccessibleContext xContext = xChild.getAccessibleContext();
100 if (xContext != null)
102 int nIndex = xContext.getAccessibleIndexInParent() + 1;
103 synchronized (maChildList)
105 if ((nIndex >= 0) || (nIndex <= maChildList.size()))
107 aChild = NodeFactory.Instance().createDefaultNode (xChild, aParent);
108 maChildList.add (nIndex, aChild);
113 return aChild;
117 /** Update only the child count node. Trust on other ways to update the
118 accessible children.
120 public void update (AccessibleTreeNode aNode)
122 synchronized (maChildList)
124 maChildList.set (0, null);