1*1b0aaa91SAndrew Rist /************************************************************** 2*1b0aaa91SAndrew Rist * 3*1b0aaa91SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1b0aaa91SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1b0aaa91SAndrew Rist * distributed with this work for additional information 6*1b0aaa91SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1b0aaa91SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1b0aaa91SAndrew Rist * "License"); you may not use this file except in compliance 9*1b0aaa91SAndrew Rist * with the License. You may obtain a copy of the License at 10*1b0aaa91SAndrew Rist * 11*1b0aaa91SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*1b0aaa91SAndrew Rist * 13*1b0aaa91SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1b0aaa91SAndrew Rist * software distributed under the License is distributed on an 15*1b0aaa91SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1b0aaa91SAndrew Rist * KIND, either express or implied. See the License for the 17*1b0aaa91SAndrew Rist * specific language governing permissions and limitations 18*1b0aaa91SAndrew Rist * under the License. 19*1b0aaa91SAndrew Rist * 20*1b0aaa91SAndrew Rist *************************************************************/ 21*1b0aaa91SAndrew Rist 22cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 23cdf0e10cSrcweir import com.sun.star.accessibility.XAccessible; 24cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleContext; 25cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRelation; 26cdf0e10cSrcweir import com.sun.star.accessibility.XAccessibleRelationSet; 27cdf0e10cSrcweir import com.sun.star.accessibility.AccessibleRelationType; 28cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 29cdf0e10cSrcweir import com.sun.star.lang.XTypeProvider; 30cdf0e10cSrcweir import com.sun.star.uno.Type; 31cdf0e10cSrcweir 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** This handler displays lower level UNO information. These are the 34cdf0e10cSrcweir supported services, interfaces, and the implementation name. 35cdf0e10cSrcweir */ 36cdf0e10cSrcweir class AccessibleUNOHandler 37cdf0e10cSrcweir extends NodeHandler 38cdf0e10cSrcweir { createHandler(XAccessibleContext xContext)39cdf0e10cSrcweir public NodeHandler createHandler (XAccessibleContext xContext) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir if (xContext == null) 42cdf0e10cSrcweir return null; 43cdf0e10cSrcweir else 44cdf0e10cSrcweir return new AccessibleUNOHandler (xContext); 45cdf0e10cSrcweir } 46cdf0e10cSrcweir AccessibleUNOHandler()47cdf0e10cSrcweir public AccessibleUNOHandler() 48cdf0e10cSrcweir { 49cdf0e10cSrcweir } 50cdf0e10cSrcweir AccessibleUNOHandler(XAccessibleContext xContext)51cdf0e10cSrcweir public AccessibleUNOHandler (XAccessibleContext xContext) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir maChildList.setSize (3); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir GetServiceInfo(AccessibleTreeNode aNode)56cdf0e10cSrcweir private XServiceInfo GetServiceInfo (AccessibleTreeNode aNode) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir XServiceInfo xServiceInfo = null; 59cdf0e10cSrcweir if (aNode instanceof AccTreeNode) 60cdf0e10cSrcweir xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface( 61cdf0e10cSrcweir XServiceInfo.class, ((AccTreeNode)aNode).getContext()); 62cdf0e10cSrcweir return xServiceInfo; 63cdf0e10cSrcweir } GetTypeProvider(AccessibleTreeNode aNode)64cdf0e10cSrcweir private XTypeProvider GetTypeProvider (AccessibleTreeNode aNode) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir XTypeProvider xTypeProvider = null; 67cdf0e10cSrcweir if (aNode instanceof AccTreeNode) 68cdf0e10cSrcweir xTypeProvider = (XTypeProvider)UnoRuntime.queryInterface( 69cdf0e10cSrcweir XTypeProvider.class, ((AccTreeNode)aNode).getContext()); 70cdf0e10cSrcweir return xTypeProvider; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir createChild(AccessibleTreeNode aParent, int nIndex)73cdf0e10cSrcweir public AccessibleTreeNode createChild (AccessibleTreeNode aParent, 74cdf0e10cSrcweir int nIndex) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir AccessibleTreeNode aChild = null; 77cdf0e10cSrcweir XServiceInfo xServiceInfo; 78cdf0e10cSrcweir switch (nIndex) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir case 0 : // Implemenation name. 81cdf0e10cSrcweir xServiceInfo = GetServiceInfo (aParent); 82cdf0e10cSrcweir aChild = new StringNode ("Implementation name: " + 83cdf0e10cSrcweir (xServiceInfo!=null ? xServiceInfo.getImplementationName() 84cdf0e10cSrcweir : "<XServiceInfo not supported>"), 85cdf0e10cSrcweir aParent); 86cdf0e10cSrcweir break; 87cdf0e10cSrcweir case 1 : 88cdf0e10cSrcweir xServiceInfo = GetServiceInfo (aParent); 89cdf0e10cSrcweir if (xServiceInfo == null) 90cdf0e10cSrcweir aChild = new StringNode ( 91cdf0e10cSrcweir "Supported services: <XServiceInfo not supported>", 92cdf0e10cSrcweir aParent); 93cdf0e10cSrcweir else 94cdf0e10cSrcweir aChild = CreateServiceTree (aParent, xServiceInfo); 95cdf0e10cSrcweir break; 96cdf0e10cSrcweir case 2 : 97cdf0e10cSrcweir XTypeProvider xTypeProvider = GetTypeProvider (aParent); 98cdf0e10cSrcweir if (xTypeProvider == null) 99cdf0e10cSrcweir aChild = new StringNode ( 100cdf0e10cSrcweir "Supported interfaces: <XTypeProvider not supported>", 101cdf0e10cSrcweir aParent); 102cdf0e10cSrcweir else 103cdf0e10cSrcweir aChild = CreateInterfaceTree (aParent, xTypeProvider); 104cdf0e10cSrcweir break; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir return aChild; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir CreateServiceTree(AccessibleTreeNode aParent, XServiceInfo xServiceInfo)111cdf0e10cSrcweir private AccessibleTreeNode CreateServiceTree (AccessibleTreeNode aParent, 112cdf0e10cSrcweir XServiceInfo xServiceInfo) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir String[] aServiceNames = xServiceInfo.getSupportedServiceNames(); 115cdf0e10cSrcweir VectorNode aNode = new VectorNode ("Supported Services", aParent); 116cdf0e10cSrcweir 117cdf0e10cSrcweir int nCount = aServiceNames.length; 118cdf0e10cSrcweir for (int i=0; i<nCount; i++) 119cdf0e10cSrcweir aNode.addChild (new StringNode (aServiceNames[i], aParent)); 120cdf0e10cSrcweir 121cdf0e10cSrcweir return aNode; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir CreateInterfaceTree(AccessibleTreeNode aParent, XTypeProvider xTypeProvider)124cdf0e10cSrcweir private AccessibleTreeNode CreateInterfaceTree (AccessibleTreeNode aParent, 125cdf0e10cSrcweir XTypeProvider xTypeProvider) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir Type[] aTypes = xTypeProvider.getTypes(); 128cdf0e10cSrcweir VectorNode aNode = new VectorNode ("Supported Interfaces", aParent); 129cdf0e10cSrcweir 130cdf0e10cSrcweir int nCount = aTypes.length; 131cdf0e10cSrcweir for (int i=0; i<nCount; i++) 132cdf0e10cSrcweir aNode.addChild (new StringNode (aTypes[i].getTypeName(), aParent)); 133cdf0e10cSrcweir 134cdf0e10cSrcweir return aNode; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137