1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 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; 25 26 import tools.NameProvider; 27 28 class AccessibleRelationHandler 29 extends NodeHandler 30 { 31 @Override createHandler( XAccessibleContext xContext )32 public NodeHandler createHandler( XAccessibleContext xContext ) 33 { 34 AccessibleRelationHandler aHandler = null; 35 if (xContext != null) 36 { 37 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet(); 38 if (xRelation != null) 39 aHandler = new AccessibleRelationHandler(xContext); 40 } 41 return aHandler; 42 } 43 AccessibleRelationHandler()44 public AccessibleRelationHandler() 45 { 46 } 47 AccessibleRelationHandler( XAccessibleContext xContext )48 private AccessibleRelationHandler( XAccessibleContext xContext ) 49 { 50 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet(); 51 if (xRelation != null) 52 maChildList.setSize( 1 ); 53 } 54 55 @Override createChild( AccessibleTreeNode aParent, int nIndex )56 public AccessibleTreeNode createChild( AccessibleTreeNode aParent, 57 int nIndex ) 58 { 59 XAccessibleRelationSet xRelation = null; 60 AccessibleTreeNode aChild = null; 61 62 if( aParent instanceof AccTreeNode ) 63 { 64 xRelation = 65 ((AccTreeNode)aParent).getContext().getAccessibleRelationSet(); 66 } 67 if( xRelation == null ) 68 return aChild; 69 70 71 VectorNode aVNode = new VectorNode( "RelationSet", aParent); 72 int nCount = xRelation.getRelationCount(); 73 try 74 { 75 for( int i = 0; i < nCount; i++ ) 76 { 77 AccessibleRelation aRelation = xRelation.getRelation( i ); 78 79 StringBuffer aBuffer = new StringBuffer(); 80 aBuffer.append (NameProvider.getRelationName (aRelation.RelationType)); 81 aBuffer.append( ": " ); 82 83 for( int j = 0; j < aRelation.TargetSet.length; j++ ) 84 { 85 Object aTarget = aRelation.TargetSet[j]; 86 XAccessible xAccTarget = 87 UnoRuntime.queryInterface( 88 XAccessible.class, aTarget ); 89 if( xAccTarget == null ) 90 { 91 aBuffer.append( aTarget.toString() ); 92 } 93 else 94 { 95 aBuffer.append( xAccTarget.getAccessibleContext(). 96 getAccessibleName() ); 97 } 98 aBuffer.append( ", " ); 99 } 100 aBuffer.delete( aBuffer.length() - 2, aBuffer.length() ); 101 102 aVNode.addChild( new StringNode( aBuffer.toString(), 103 aParent ) ); 104 } 105 106 aChild = aVNode; 107 } 108 catch( IndexOutOfBoundsException e ) 109 { 110 aChild = new StringNode( "IndexOutOfBounds", aParent ); 111 } 112 113 return aChild; 114 } 115 } 116