merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / AccessibleRelationHandler.java
blobea3be4c16264f15401870b51038a3fd551f86b2d
1 import com.sun.star.uno.UnoRuntime;
2 import com.sun.star.accessibility.XAccessible;
3 import com.sun.star.accessibility.XAccessibleContext;
4 import com.sun.star.accessibility.AccessibleRelation;
5 import com.sun.star.accessibility.XAccessibleRelationSet;
6 import com.sun.star.accessibility.AccessibleRelationType;
7 import com.sun.star.lang.IndexOutOfBoundsException;
9 import tools.NameProvider;
11 class AccessibleRelationHandler
12 extends NodeHandler
14 public NodeHandler createHandler( XAccessibleContext xContext )
16 AccessibleRelationHandler aHandler = null;
17 if (xContext != null)
19 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet();
20 if (xRelation != null)
21 aHandler = new AccessibleRelationHandler(xContext);
23 return aHandler;
26 public AccessibleRelationHandler()
30 public AccessibleRelationHandler( XAccessibleContext xContext )
32 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet();
33 if (xRelation != null)
34 maChildList.setSize( 1 );
37 public AccessibleTreeNode createChild( AccessibleTreeNode aParent,
38 int nIndex )
40 XAccessibleRelationSet xRelation = null;
41 AccessibleTreeNode aChild = null;
43 if( aParent instanceof AccTreeNode )
45 xRelation =
46 ((AccTreeNode)aParent).getContext().getAccessibleRelationSet();
48 if( xRelation == null )
49 return aChild;
52 VectorNode aVNode = new VectorNode( "RelationSet", aParent);
53 int nCount = xRelation.getRelationCount();
54 try
56 for( int i = 0; i < nCount; i++ )
58 AccessibleRelation aRelation = xRelation.getRelation( i );
60 StringBuffer aBuffer = new StringBuffer();
61 aBuffer.append (NameProvider.getRelationName (aRelation.RelationType));
62 aBuffer.append( ": " );
64 for( int j = 0; j < aRelation.TargetSet.length; j++ )
66 Object aTarget = aRelation.TargetSet[j];
67 XAccessible xAccTarget =
68 (XAccessible)UnoRuntime.queryInterface(
69 XAccessible.class, aTarget );
70 if( xAccTarget == null )
72 aBuffer.append( aTarget.toString() );
74 else
76 aBuffer.append( xAccTarget.getAccessibleContext().
77 getAccessibleName() );
79 aBuffer.append( ", " );
81 aBuffer.delete( aBuffer.length() - 2, aBuffer.length() );
83 aVNode.addChild( new StringNode( aBuffer.toString(),
84 aParent ) );
87 aChild = aVNode;
89 catch( IndexOutOfBoundsException e )
91 aChild = new StringNode( "IndexOutOfBounds", aParent );
94 return aChild;