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.XAccessibleAction;
26 import com.sun.star.lang.IndexOutOfBoundsException;
27 
28 class AccessibleActionHandler
29     extends NodeHandler
30 {
createHandler(XAccessibleContext xContext)31     public NodeHandler createHandler (XAccessibleContext xContext)
32     {
33         XAccessibleAction xEComponent =
34             (XAccessibleAction) UnoRuntime.queryInterface (
35                 XAccessibleAction.class, xContext);
36         if (xEComponent != null)
37             return new AccessibleActionHandler (xEComponent);
38         else
39             return null;
40     }
41 
AccessibleActionHandler()42     public AccessibleActionHandler ()
43     {
44     }
45 
AccessibleActionHandler(XAccessibleAction xAction)46     public AccessibleActionHandler (XAccessibleAction xAction)
47     {
48         if (xAction != null)
49             maChildList.setSize (1 + xAction.getAccessibleActionCount());
50     }
51 
getAction(AccTreeNode aParent)52     protected static XAccessibleAction getAction (AccTreeNode aParent)
53     {
54         return (XAccessibleAction) UnoRuntime.queryInterface (
55             XAccessibleAction.class, aParent.getContext());
56     }
57 
createChild( AccessibleTreeNode aParent, int nIndex)58     public AccessibleTreeNode createChild (
59         AccessibleTreeNode aParent,
60         int nIndex)
61     {
62         AccessibleTreeNode aChild = null;
63 
64         if (aParent instanceof AccTreeNode)
65         {
66             XAccessibleAction xAction = getAction ((AccTreeNode)aParent);
67             if( xAction != null )
68             {
69                 if (nIndex == 0)
70                     aChild = new StringNode ("Number of actions: " + xAction.getAccessibleActionCount(),
71                         aParent);
72                 else
73                 {
74                     nIndex -= 1;
75                     try
76                     {
77                         aChild = new AccessibleActionNode (
78                             "Action " + nIndex + " : "
79                             + xAction.getAccessibleActionDescription (nIndex),
80                             aParent,
81                             nIndex);
82                     }
83                     catch( IndexOutOfBoundsException e )
84                     {
85                         aChild = new StringNode ("ERROR", aParent);
86                     }
87                 }
88             }
89         }
90 
91         return aChild;
92     }
93 }
94