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 23 import com.sun.star.uno.UnoRuntime; 24 import com.sun.star.accessibility.XAccessibleContext; 25 import com.sun.star.accessibility.XAccessibleTable; 26 27 28 class AccessibleTableHandler extends NodeHandler 29 { createHandler(XAccessibleContext xContext)30 public NodeHandler createHandler (XAccessibleContext xContext) 31 { 32 XAccessibleTable xTable = 33 (XAccessibleTable) UnoRuntime.queryInterface ( 34 XAccessibleTable.class, xContext); 35 if (xTable != null) 36 return new AccessibleTableHandler (xTable); 37 else 38 return null; 39 } 40 AccessibleTableHandler()41 public AccessibleTableHandler () 42 { 43 } 44 AccessibleTableHandler(XAccessibleTable xTable)45 public AccessibleTableHandler (XAccessibleTable xTable) 46 { 47 if (xTable != null) 48 maChildList.setSize (4); 49 } 50 getTable(Object aObject)51 protected static XAccessibleTable getTable(Object aObject) 52 { 53 return (XAccessibleTable) UnoRuntime.queryInterface ( 54 XAccessibleTable.class, aObject); 55 } 56 createChild(AccessibleTreeNode aParent, int nIndex)57 public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) 58 { 59 AccessibleTreeNode aChild = null; 60 XAccessibleTable xTable = null; 61 if (aParent instanceof AccTreeNode) 62 xTable = ((AccTreeNode)aParent).getTable(); 63 try 64 { 65 if( xTable != null ) 66 { 67 switch( nIndex ) 68 { 69 case 0: 70 aChild = new StringNode ("# table rows: " + xTable.getAccessibleRowCount(), aParent); 71 break; 72 case 1: 73 aChild = new StringNode ("# table columns: " + xTable.getAccessibleColumnCount(), aParent); 74 break; 75 case 2: 76 { 77 String sText = "selected rows: "; 78 int[] aSelected = xTable.getSelectedAccessibleRows(); 79 for( int i=0; i < aSelected.length; i++ ) 80 { 81 sText += aSelected[i]; 82 sText += " "; 83 } 84 aChild = new StringNode (sText, aParent); 85 } 86 break; 87 case 3: 88 { 89 String sText = "selected columns: "; 90 int[] aSelected = xTable.getSelectedAccessibleColumns(); 91 for( int i=0; i < aSelected.length; i++ ) 92 { 93 sText += aSelected[i]; 94 sText += " "; 95 } 96 aChild = new StringNode (sText, aParent); 97 } 98 break; 99 default: 100 aChild = new StringNode ("unknown child index " + nIndex, aParent); 101 } 102 } 103 } 104 catch (Exception e) 105 { 106 // Return empty child. 107 } 108 109 return aChild; 110 } 111 } 112