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 import com.sun.star.accessibility.XAccessible;
23 import com.sun.star.accessibility.AccessibleEventObject;
24 import com.sun.star.uno.UnoRuntime;
25 
26 import java.io.PrintStream;
27 
28 class ChildEventHandler
29     extends EventHandler
30 {
ChildEventHandler(AccessibleEventObject aEvent, AccessibilityTreeModel aTreeModel)31     public ChildEventHandler (AccessibleEventObject aEvent, AccessibilityTreeModel aTreeModel)
32     {
33         super (aEvent, aTreeModel);
34         mxOldChild = (XAccessible)UnoRuntime.queryInterface(
35             XAccessible.class, aEvent.OldValue);
36         mxNewChild = (XAccessible)UnoRuntime.queryInterface(
37             XAccessible.class, aEvent.NewValue);
38     }
39 
PrintOldAndNew(PrintStream out)40     public void PrintOldAndNew (PrintStream out)
41     {
42         if (mxOldChild != null)
43             out.println ("   removing child " + mxOldChild);
44         if (mxNewChild != null)
45             out.println ("   adding child " + mxNewChild);
46     }
47 
Process()48     public void Process ()
49     {
50         // Insertion and removal of children should be mutually exclusive.
51         // But this is a test tool and should take everything into account.
52         if (mxOldChild != null)
53         {
54             maTreeModel.removeNode (mxOldChild.getAccessibleContext());
55             maTreeModel.updateNode (mxEventSource, AccessibleTreeHandler.class);
56         }
57 
58         if (mxNewChild != null)
59         {
60             maTreeModel.addChild (mxEventSource, mxNewChild);
61         }
62     }
63 
64 
65     private XAccessible mxOldChild;
66     private XAccessible mxNewChild;
67 }
68