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; 8 9 import tools.NameProvider; 10 11 class AccessibleRelationHandler 12 extends NodeHandler 13 { 14 public NodeHandler createHandler( XAccessibleContext xContext ) 15 { 16 AccessibleRelationHandler aHandler = null; 17 if (xContext != null) 18 { 19 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet(); 20 if (xRelation != null) 21 aHandler = new AccessibleRelationHandler(xContext); 22 } 23 return aHandler; 24 } 25 26 public AccessibleRelationHandler() 27 { 28 } 29 30 public AccessibleRelationHandler( XAccessibleContext xContext ) 31 { 32 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet(); 33 if (xRelation != null) 34 maChildList.setSize( 1 ); 35 } 36 37 public AccessibleTreeNode createChild( AccessibleTreeNode aParent, 38 int nIndex ) 39 { 40 XAccessibleRelationSet xRelation = null; 41 AccessibleTreeNode aChild = null; 42 43 if( aParent instanceof AccTreeNode ) 44 { 45 xRelation = 46 ((AccTreeNode)aParent).getContext().getAccessibleRelationSet(); 47 } 48 if( xRelation == null ) 49 return aChild; 50 51 52 VectorNode aVNode = new VectorNode( "RelationSet", aParent); 53 int nCount = xRelation.getRelationCount(); 54 try 55 { 56 for( int i = 0; i < nCount; i++ ) 57 { 58 AccessibleRelation aRelation = xRelation.getRelation( i ); 59 60 StringBuffer aBuffer = new StringBuffer(); 61 aBuffer.append (NameProvider.getRelationName (aRelation.RelationType)); 62 aBuffer.append( ": " ); 63 64 for( int j = 0; j < aRelation.TargetSet.length; j++ ) 65 { 66 Object aTarget = aRelation.TargetSet[j]; 67 XAccessible xAccTarget = 68 (XAccessible)UnoRuntime.queryInterface( 69 XAccessible.class, aTarget ); 70 if( xAccTarget == null ) 71 { 72 aBuffer.append( aTarget.toString() ); 73 } 74 else 75 { 76 aBuffer.append( xAccTarget.getAccessibleContext(). 77 getAccessibleName() ); 78 } 79 aBuffer.append( ", " ); 80 } 81 aBuffer.delete( aBuffer.length() - 2, aBuffer.length() ); 82 83 aVNode.addChild( new StringNode( aBuffer.toString(), 84 aParent ) ); 85 } 86 87 aChild = aVNode; 88 } 89 catch( IndexOutOfBoundsException e ) 90 { 91 aChild = new StringNode( "IndexOutOfBounds", aParent ); 92 } 93 94 return aChild; 95 } 96 } 97