merge the formfield patch from ooo-build
[ooovba.git] / toolkit / test / accessibility / AccessibleSelectionHandler.java
blobbf6fbade0762d73990e8e6866896839e481ae2c6
2 import com.sun.star.uno.UnoRuntime;
3 import com.sun.star.accessibility.XAccessible;
4 import com.sun.star.accessibility.XAccessibleContext;
5 import com.sun.star.accessibility.XAccessibleSelection;
6 import com.sun.star.lang.IndexOutOfBoundsException;
8 import javax.swing.*;
9 import java.awt.*;
10 import java.util.Vector;
11 import java.awt.event.ActionListener;
12 import java.awt.event.ActionEvent;
16 class AccessibleSelectionHandler
17 extends NodeHandler
19 public NodeHandler createHandler( XAccessibleContext xContext )
21 XAccessibleSelection xSelection =
22 (XAccessibleSelection) UnoRuntime.queryInterface(
23 XAccessibleSelection.class, xContext);
24 return (xSelection == null) ? null :
25 new AccessibleSelectionHandler(xSelection);
28 public AccessibleSelectionHandler()
32 public AccessibleSelectionHandler( XAccessibleSelection xSelection )
34 if (xSelection != null)
35 maChildList.setSize( 2 );
38 public AccessibleTreeNode createChild( AccessibleTreeNode aParent,
39 int nIndex )
41 AccessibleTreeNode aChild = null;
43 if( aParent instanceof AccTreeNode )
45 XAccessibleSelection xSelection =
46 ((AccTreeNode)aParent).getSelection();
47 if( xSelection != null )
49 switch( nIndex )
51 case 0:
52 aChild = new StringNode(
53 "getSelectedAccessibleChildCount: " +
54 xSelection.getSelectedAccessibleChildCount(),
55 aParent );
56 break;
57 case 1:
59 VectorNode aVNode =
60 new VectorNode( "Selected Children", aParent);
61 int nSelected = 0;
62 int nCount = ((AccTreeNode)aParent).getContext().
63 getAccessibleChildCount();
64 try
66 for( int i = 0; i < nCount; i++ )
68 try
70 if( xSelection.isAccessibleChildSelected( i ) )
72 XAccessible xSelChild = xSelection.
73 getSelectedAccessibleChild(nSelected);
74 XAccessible xNChild =
75 ((AccTreeNode)aParent).
76 getContext().getAccessibleChild( i );
77 aVNode.addChild( new StringNode(
78 i + ": " +
79 xNChild.getAccessibleContext().
80 getAccessibleDescription() + " (" +
81 (xSelChild.equals(xNChild) ? "OK" : "XXX") +
82 ")", aParent ) );
85 catch (com.sun.star.lang.DisposedException e)
87 aVNode.addChild( new StringNode(
88 i + ": caught DisposedException while creating",
89 aParent ));
92 aChild = aVNode;
94 catch( IndexOutOfBoundsException e )
96 aChild = new StringNode( "IndexOutOfBounds",
97 aParent );
100 break;
101 default:
102 aChild = new StringNode( "ERROR", aParent );
103 break;
108 return aChild;
112 public String[] getActions (AccessibleTreeNode aNode)
114 if( aNode instanceof AccTreeNode )
116 XAccessibleSelection xSelection =
117 ((AccTreeNode)aNode).getSelection();
118 if( xSelection != null )
120 return new String[] { "Select..." };
123 return new String[0];
126 public void performAction (AccessibleTreeNode aNode, int nIndex)
128 new SelectionDialog( (AccTreeNode)aNode ).show();