merge the formfield patch from ooo-build
[ooovba.git] / toolkit / test / accessibility / AccessibleUNOHandler.java
blobcdd0906ef6146c184449b2d04d216f316b3a4292
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.XServiceInfo;
8 import com.sun.star.lang.XTypeProvider;
9 import com.sun.star.uno.Type;
12 /** This handler displays lower level UNO information. These are the
13 supported services, interfaces, and the implementation name.
15 class AccessibleUNOHandler
16 extends NodeHandler
18 public NodeHandler createHandler (XAccessibleContext xContext)
20 if (xContext == null)
21 return null;
22 else
23 return new AccessibleUNOHandler (xContext);
26 public AccessibleUNOHandler()
30 public AccessibleUNOHandler (XAccessibleContext xContext)
32 maChildList.setSize (3);
35 private XServiceInfo GetServiceInfo (AccessibleTreeNode aNode)
37 XServiceInfo xServiceInfo = null;
38 if (aNode instanceof AccTreeNode)
39 xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(
40 XServiceInfo.class, ((AccTreeNode)aNode).getContext());
41 return xServiceInfo;
43 private XTypeProvider GetTypeProvider (AccessibleTreeNode aNode)
45 XTypeProvider xTypeProvider = null;
46 if (aNode instanceof AccTreeNode)
47 xTypeProvider = (XTypeProvider)UnoRuntime.queryInterface(
48 XTypeProvider.class, ((AccTreeNode)aNode).getContext());
49 return xTypeProvider;
52 public AccessibleTreeNode createChild (AccessibleTreeNode aParent,
53 int nIndex)
55 AccessibleTreeNode aChild = null;
56 XServiceInfo xServiceInfo;
57 switch (nIndex)
59 case 0 : // Implemenation name.
60 xServiceInfo = GetServiceInfo (aParent);
61 aChild = new StringNode ("Implementation name: " +
62 (xServiceInfo!=null ? xServiceInfo.getImplementationName()
63 : "<XServiceInfo not supported>"),
64 aParent);
65 break;
66 case 1 :
67 xServiceInfo = GetServiceInfo (aParent);
68 if (xServiceInfo == null)
69 aChild = new StringNode (
70 "Supported services: <XServiceInfo not supported>",
71 aParent);
72 else
73 aChild = CreateServiceTree (aParent, xServiceInfo);
74 break;
75 case 2 :
76 XTypeProvider xTypeProvider = GetTypeProvider (aParent);
77 if (xTypeProvider == null)
78 aChild = new StringNode (
79 "Supported interfaces: <XTypeProvider not supported>",
80 aParent);
81 else
82 aChild = CreateInterfaceTree (aParent, xTypeProvider);
83 break;
86 return aChild;
90 private AccessibleTreeNode CreateServiceTree (AccessibleTreeNode aParent,
91 XServiceInfo xServiceInfo)
93 String[] aServiceNames = xServiceInfo.getSupportedServiceNames();
94 VectorNode aNode = new VectorNode ("Supported Services", aParent);
96 int nCount = aServiceNames.length;
97 for (int i=0; i<nCount; i++)
98 aNode.addChild (new StringNode (aServiceNames[i], aParent));
100 return aNode;
103 private AccessibleTreeNode CreateInterfaceTree (AccessibleTreeNode aParent,
104 XTypeProvider xTypeProvider)
106 Type[] aTypes = xTypeProvider.getTypes();
107 VectorNode aNode = new VectorNode ("Supported Interfaces", aParent);
109 int nCount = aTypes.length;
110 for (int i=0; i<nCount; i++)
111 aNode.addChild (new StringNode (aTypes[i].getTypeName(), aParent));
113 return aNode;