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 java
.util
.Vector
;
23 * Map an arbitrary object into parts of a tree node.
25 abstract class NodeHandler
27 /** This vector is used as cache for the child objects.
29 protected Vector
<AccessibleTreeNode
> maChildList
;
32 public abstract NodeHandler
createHandler (
33 com
.sun
.star
.accessibility
.XAccessibleContext xContext
);
37 maChildList
= new Vector
<AccessibleTreeNode
> ();
40 /** return the number of children this object has */
41 public int getChildCount()
43 synchronized (maChildList
)
45 return maChildList
.size();
50 * return a child object. Complex
51 * children have to be AccTreeNode instances.
54 public AccessibleTreeNode
getChild (AccessibleTreeNode aParent
, int nIndex
)
56 synchronized (maChildList
)
58 AccessibleTreeNode aChild
= maChildList
.get(nIndex
);
61 aChild
= createChild (aParent
, nIndex
);
63 aChild
= new StringNode ("could not create child", aParent
);
64 maChildList
.set (nIndex
, aChild
);
70 public AccessibleTreeNode
getChildNoCreate (int nIndex
)
72 synchronized (maChildList
)
74 return maChildList
.get(nIndex
);
78 /** Remove the specified child from the list of children.
80 public boolean removeChild (int nIndex
)
84 synchronized (maChildList
)
86 System
.out
.println (" removing child at position " + nIndex
+ ": "
87 + maChildList
.get (nIndex
));
88 maChildList
.remove (nIndex
);
98 public int indexOf (AccessibleTreeNode aNode
)
100 synchronized (maChildList
)
102 return maChildList
.indexOf (aNode
);
106 /** Create a child object for the specified data. This method is called
107 usually from getChild and put there into the cache.
109 public abstract AccessibleTreeNode
createChild (
110 AccessibleTreeNode aParent
, int nIndex
);
113 // The following methods support editing of children and actions.
114 // They have default implementations for no actions and read-only.
117 /** get names of supported actions */
118 public String
[] getActions (AccessibleTreeNode aNode
)
120 return new String
[] {};
123 /** perform action */
124 public void performAction (AccessibleTreeNode aNode
, int nIndex
)
128 /** Update all children.
130 public void update (AccessibleTreeNode aNode
)