fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / toolkit / test / accessibility / AccessibleRelationHandler.java
blob6882f2648f7187f4d7abc459e0d01760cfc1422e
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.uno.UnoRuntime;
20 import com.sun.star.accessibility.XAccessible;
21 import com.sun.star.accessibility.XAccessibleContext;
22 import com.sun.star.accessibility.AccessibleRelation;
23 import com.sun.star.accessibility.XAccessibleRelationSet;
24 import com.sun.star.lang.IndexOutOfBoundsException;
26 import tools.NameProvider;
28 class AccessibleRelationHandler
29 extends NodeHandler
31 public NodeHandler createHandler( XAccessibleContext xContext )
33 AccessibleRelationHandler aHandler = null;
34 if (xContext != null)
36 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet();
37 if (xRelation != null)
38 aHandler = new AccessibleRelationHandler(xContext);
40 return aHandler;
43 public AccessibleRelationHandler()
47 public AccessibleRelationHandler( XAccessibleContext xContext )
49 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet();
50 if (xRelation != null)
51 maChildList.setSize( 1 );
54 public AccessibleTreeNode createChild( AccessibleTreeNode aParent,
55 int nIndex )
57 XAccessibleRelationSet xRelation = null;
58 AccessibleTreeNode aChild = null;
60 if( aParent instanceof AccTreeNode )
62 xRelation =
63 ((AccTreeNode)aParent).getContext().getAccessibleRelationSet();
65 if( xRelation == null )
66 return aChild;
69 VectorNode aVNode = new VectorNode( "RelationSet", aParent);
70 int nCount = xRelation.getRelationCount();
71 try
73 for( int i = 0; i < nCount; i++ )
75 AccessibleRelation aRelation = xRelation.getRelation( i );
77 StringBuffer aBuffer = new StringBuffer();
78 aBuffer.append (NameProvider.getRelationName (aRelation.RelationType));
79 aBuffer.append( ": " );
81 for( int j = 0; j < aRelation.TargetSet.length; j++ )
83 Object aTarget = aRelation.TargetSet[j];
84 XAccessible xAccTarget =
85 UnoRuntime.queryInterface(
86 XAccessible.class, aTarget );
87 if( xAccTarget == null )
89 aBuffer.append( aTarget.toString() );
91 else
93 aBuffer.append( xAccTarget.getAccessibleContext().
94 getAccessibleName() );
96 aBuffer.append( ", " );
98 aBuffer.delete( aBuffer.length() - 2, aBuffer.length() );
100 aVNode.addChild( new StringNode( aBuffer.toString(),
101 aParent ) );
104 aChild = aVNode;
106 catch( IndexOutOfBoundsException e )
108 aChild = new StringNode( "IndexOutOfBounds", aParent );
111 return aChild;