fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / toolkit / test / accessibility / AccessibleSelectionHandler.java
blob4791444d5a6a99b13419b258f80d63e82e4a0d67
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
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.XAccessibleSelection;
23 import com.sun.star.lang.IndexOutOfBoundsException;
27 class AccessibleSelectionHandler
28 extends NodeHandler
30 public NodeHandler createHandler( XAccessibleContext xContext )
32 XAccessibleSelection xSelection =
33 UnoRuntime.queryInterface(
34 XAccessibleSelection.class, xContext);
35 return (xSelection == null) ? null :
36 new AccessibleSelectionHandler(xSelection);
39 public AccessibleSelectionHandler()
43 public AccessibleSelectionHandler( XAccessibleSelection xSelection )
45 if (xSelection != null)
46 maChildList.setSize( 2 );
49 public AccessibleTreeNode createChild( AccessibleTreeNode aParent,
50 int nIndex )
52 AccessibleTreeNode aChild = null;
54 if( aParent instanceof AccTreeNode )
56 XAccessibleSelection xSelection =
57 ((AccTreeNode)aParent).getSelection();
58 if( xSelection != null )
60 switch( nIndex )
62 case 0:
63 aChild = new StringNode(
64 "getSelectedAccessibleChildCount: " +
65 xSelection.getSelectedAccessibleChildCount(),
66 aParent );
67 break;
68 case 1:
70 VectorNode aVNode =
71 new VectorNode( "Selected Children", aParent);
72 int nSelected = 0;
73 int nCount = ((AccTreeNode)aParent).getContext().
74 getAccessibleChildCount();
75 try
77 for( int i = 0; i < nCount; i++ )
79 try
81 if( xSelection.isAccessibleChildSelected( i ) )
83 XAccessible xSelChild = xSelection.
84 getSelectedAccessibleChild(nSelected);
85 XAccessible xNChild =
86 ((AccTreeNode)aParent).
87 getContext().getAccessibleChild( i );
88 aVNode.addChild( new StringNode(
89 i + ": " +
90 xNChild.getAccessibleContext().
91 getAccessibleDescription() + " (" +
92 (xSelChild.equals(xNChild) ? "OK" : "XXX") +
93 ")", aParent ) );
96 catch (com.sun.star.lang.DisposedException e)
98 aVNode.addChild( new StringNode(
99 i + ": caught DisposedException while creating",
100 aParent ));
103 aChild = aVNode;
105 catch( IndexOutOfBoundsException e )
107 aChild = new StringNode( "IndexOutOfBounds",
108 aParent );
111 break;
112 default:
113 aChild = new StringNode( "ERROR", aParent );
114 break;
119 return aChild;
123 public String[] getActions (AccessibleTreeNode aNode)
125 if( aNode instanceof AccTreeNode )
127 XAccessibleSelection xSelection =
128 ((AccTreeNode)aNode).getSelection();
129 if( xSelection != null )
131 return new String[] { "Select..." };
134 return new String[0];
137 public void performAction (AccessibleTreeNode aNode, int nIndex)
139 new SelectionDialog( (AccTreeNode)aNode ).show();