Branch libreoffice-5-0-4
[LibreOffice.git] / toolkit / test / accessibility / AccessibleRelationHandler.java
blob1f7eebada20f1195781a6d89bab3e0a8856e4766
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 @Override
32 public NodeHandler createHandler( XAccessibleContext xContext )
34 AccessibleRelationHandler aHandler = null;
35 if (xContext != null)
37 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet();
38 if (xRelation != null)
39 aHandler = new AccessibleRelationHandler(xContext);
41 return aHandler;
44 public AccessibleRelationHandler()
48 private AccessibleRelationHandler( XAccessibleContext xContext )
50 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet();
51 if (xRelation != null)
52 maChildList.setSize( 1 );
55 @Override
56 public AccessibleTreeNode createChild( AccessibleTreeNode aParent,
57 int nIndex )
59 XAccessibleRelationSet xRelation = null;
60 AccessibleTreeNode aChild = null;
62 if( aParent instanceof AccTreeNode )
64 xRelation =
65 ((AccTreeNode)aParent).getContext().getAccessibleRelationSet();
67 if( xRelation == null )
68 return aChild;
71 VectorNode aVNode = new VectorNode( "RelationSet", aParent);
72 int nCount = xRelation.getRelationCount();
73 try
75 for( int i = 0; i < nCount; i++ )
77 AccessibleRelation aRelation = xRelation.getRelation( i );
79 StringBuffer aBuffer = new StringBuffer();
80 aBuffer.append (NameProvider.getRelationName (aRelation.RelationType));
81 aBuffer.append( ": " );
83 for( int j = 0; j < aRelation.TargetSet.length; j++ )
85 Object aTarget = aRelation.TargetSet[j];
86 XAccessible xAccTarget =
87 UnoRuntime.queryInterface(
88 XAccessible.class, aTarget );
89 if( xAccTarget == null )
91 aBuffer.append( aTarget.toString() );
93 else
95 aBuffer.append( xAccTarget.getAccessibleContext().
96 getAccessibleName() );
98 aBuffer.append( ", " );
100 aBuffer.delete( aBuffer.length() - 2, aBuffer.length() );
102 aVNode.addChild( new StringNode( aBuffer.toString(),
103 aParent ) );
106 aChild = aVNode;
108 catch( IndexOutOfBoundsException e )
110 aChild = new StringNode( "IndexOutOfBounds", aParent );
113 return aChild;