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 /** Clear the cache of child objects.
44 synchronized (maChildList
)
46 maChildList
= new Vector
<AccessibleTreeNode
> ();
50 /** This factory method creates an individual handler for the specified
51 object that may hold information to accelerate the access to its children.
53 // public abstract NodeHandler createHandler (Object aObject);
55 /** return the number of children this object has */
56 public int getChildCount(Object aObject
)
58 synchronized (maChildList
)
60 return maChildList
.size();
65 * return a child object. Complex
66 * children have to be AccTreeNode instances.
69 public AccessibleTreeNode
getChild (AccessibleTreeNode aParent
, int nIndex
)
71 synchronized (maChildList
)
73 AccessibleTreeNode aChild
= maChildList
.get(nIndex
);
76 aChild
= createChild (aParent
, nIndex
);
78 aChild
= new StringNode ("could not create child", aParent
);
79 maChildList
.set (nIndex
, aChild
);
85 public AccessibleTreeNode
getChildNoCreate (AccessibleTreeNode aParent
, int nIndex
)
87 synchronized (maChildList
)
89 return maChildList
.get(nIndex
);
93 /** Remove the specified child from the list of children.
95 public boolean removeChild (AccessibleTreeNode aNode
, int nIndex
)
99 synchronized (maChildList
)
101 System
.out
.println (" removing child at position " + nIndex
+ ": "
102 + maChildList
.get (nIndex
));
103 maChildList
.remove (nIndex
);
113 public int indexOf (AccessibleTreeNode aNode
)
115 synchronized (maChildList
)
117 return maChildList
.indexOf (aNode
);
121 /** Create a child object for the specified data. This method is called
122 usually from getChild and put there into the cache.
124 public abstract AccessibleTreeNode
createChild (
125 AccessibleTreeNode aParent
, int nIndex
);
128 // The following methods support editing of children and actions.
129 // They have default implementations for no actions and read-only.
132 /** May this child be changed? */
133 public boolean isChildEditable (AccessibleTreeNode aNode
, int nIndex
)
138 /** change this child's value */
139 // public void setChild(Object aObject, int nIndex) { }
142 /** get names of suported actions */
143 public String
[] getActions (AccessibleTreeNode aNode
)
145 return new String
[] {};
148 /** perform action */
149 public void performAction (AccessibleTreeNode aNode
, int nIndex
)
153 /** Update all children.
155 public void update (AccessibleTreeNode aNode
)