1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 import com.sun.star.uno.UnoRuntime; 23 import com.sun.star.accessibility.XAccessible; 24 import com.sun.star.accessibility.XAccessibleContext; 25 import com.sun.star.accessibility.AccessibleRelation; 26 import com.sun.star.accessibility.XAccessibleRelationSet; 27 import com.sun.star.accessibility.AccessibleRelationType; 28 import com.sun.star.lang.IndexOutOfBoundsException; 29 30 import tools.NameProvider; 31 32 class AccessibleRelationHandler 33 extends NodeHandler 34 { createHandler( XAccessibleContext xContext )35 public NodeHandler createHandler( XAccessibleContext xContext ) 36 { 37 AccessibleRelationHandler aHandler = null; 38 if (xContext != null) 39 { 40 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet(); 41 if (xRelation != null) 42 aHandler = new AccessibleRelationHandler(xContext); 43 } 44 return aHandler; 45 } 46 AccessibleRelationHandler()47 public AccessibleRelationHandler() 48 { 49 } 50 AccessibleRelationHandler( XAccessibleContext xContext )51 public AccessibleRelationHandler( XAccessibleContext xContext ) 52 { 53 XAccessibleRelationSet xRelation = xContext.getAccessibleRelationSet(); 54 if (xRelation != null) 55 maChildList.setSize( 1 ); 56 } 57 createChild( AccessibleTreeNode aParent, int nIndex )58 public AccessibleTreeNode createChild( AccessibleTreeNode aParent, 59 int nIndex ) 60 { 61 XAccessibleRelationSet xRelation = null; 62 AccessibleTreeNode aChild = null; 63 64 if( aParent instanceof AccTreeNode ) 65 { 66 xRelation = 67 ((AccTreeNode)aParent).getContext().getAccessibleRelationSet(); 68 } 69 if( xRelation == null ) 70 return aChild; 71 72 73 VectorNode aVNode = new VectorNode( "RelationSet", aParent); 74 int nCount = xRelation.getRelationCount(); 75 try 76 { 77 for( int i = 0; i < nCount; i++ ) 78 { 79 AccessibleRelation aRelation = xRelation.getRelation( i ); 80 81 StringBuffer aBuffer = new StringBuffer(); 82 aBuffer.append (NameProvider.getRelationName (aRelation.RelationType)); 83 aBuffer.append( ": " ); 84 85 for( int j = 0; j < aRelation.TargetSet.length; j++ ) 86 { 87 Object aTarget = aRelation.TargetSet[j]; 88 XAccessible xAccTarget = 89 (XAccessible)UnoRuntime.queryInterface( 90 XAccessible.class, aTarget ); 91 if( xAccTarget == null ) 92 { 93 aBuffer.append( aTarget.toString() ); 94 } 95 else 96 { 97 aBuffer.append( xAccTarget.getAccessibleContext(). 98 getAccessibleName() ); 99 } 100 aBuffer.append( ", " ); 101 } 102 aBuffer.delete( aBuffer.length() - 2, aBuffer.length() ); 103 104 aVNode.addChild( new StringNode( aBuffer.toString(), 105 aParent ) ); 106 } 107 108 aChild = aVNode; 109 } 110 catch( IndexOutOfBoundsException e ) 111 { 112 aChild = new StringNode( "IndexOutOfBounds", aParent ); 113 } 114 115 return aChild; 116 } 117 } 118