1 import com
.sun
.star
.uno
.UnoRuntime
;
2 import com
.sun
.star
.accessibility
.*;
3 import java
.util
.Vector
;
6 * The node type for the AccessibleTreeModel.
7 * This implements all the child-handling based on the appropriate
8 * NodeHandlers. Trivial nodes can be implemented by any Object
12 extends AccessibleTreeNode
14 class HandlerDescriptor
16 public HandlerDescriptor (NodeHandler aHandler
)
21 public NodeHandler maHandler
;
22 public int mnChildCount
;
24 /// NodeHandlers for this node
25 private Vector maHandlers
;
27 // The accessible context of this node.
28 private XAccessible mxAccessible
;
29 private XAccessibleContext mxContext
;
30 private XAccessibleComponent mxComponent
;
31 private XAccessibleText mxText
;
32 private XAccessibleTable mxTable
;
34 public AccTreeNode (XAccessible xAccessible
, XAccessibleContext xContext
, AccessibleTreeNode aParent
)
36 this (xAccessible
, xContext
, xContext
, aParent
);
39 public AccTreeNode (XAccessible xAccessible
, XAccessibleContext xContext
, Object aDisplay
, AccessibleTreeNode aParent
)
41 super (aDisplay
, aParent
);
43 maHandlers
= new Vector(5);
45 mxAccessible
= xAccessible
;
48 /** Update the internal data extracted from the corresponding accessible
49 object. This is done by replacing every handler by a new one. An
50 update method at each handler would be better of course.
54 for (int i
=0; i
<maHandlers
.size(); i
++)
56 System
.out
.println ("replacing handler " + i
);
57 HandlerDescriptor aDescriptor
= (HandlerDescriptor
)maHandlers
.get(i
);
58 aDescriptor
.maHandler
= aDescriptor
.maHandler
.createHandler (mxContext
);
59 aDescriptor
.mnChildCount
=
60 aDescriptor
.maHandler
.getChildCount (this);
64 public XAccessibleContext
getContext ()
69 public XAccessibleComponent
getComponent ()
71 if (mxComponent
== null && mxContext
!= null)
72 mxComponent
= (XAccessibleComponent
)UnoRuntime
.queryInterface(
73 XAccessibleComponent
.class, mxContext
);
77 public XAccessibleExtendedComponent
getExtendedComponent ()
79 if (mxComponent
== null)
81 if (mxComponent
!= null)
82 return (XAccessibleExtendedComponent
)UnoRuntime
.queryInterface(
83 XAccessibleExtendedComponent
.class, mxComponent
);
88 public XAccessibleText
getText ()
90 if (mxText
== null && mxContext
!= null)
91 mxText
= (XAccessibleText
)UnoRuntime
.queryInterface(
92 XAccessibleText
.class, mxContext
);
96 public XAccessibleEditableText
getEditText ()
98 return (XAccessibleEditableText
)UnoRuntime
.queryInterface(
99 XAccessibleEditableText
.class, mxContext
);
102 public XAccessibleTable
getTable ()
104 if (mxTable
== null && mxContext
!= null)
105 mxTable
= (XAccessibleTable
)UnoRuntime
.queryInterface(
106 XAccessibleTable
.class, mxContext
);
111 public XAccessible
getAccessible()
113 if ((mxAccessible
== null) && (mxContext
!= null))
114 mxAccessible
= (XAccessible
)UnoRuntime
.queryInterface(
115 XAccessible
.class, mxContext
);
119 public XAccessibleSelection
getSelection ()
121 return (XAccessibleSelection
)UnoRuntime
.queryInterface(
122 XAccessibleSelection
.class, mxContext
);
125 public void addHandler( NodeHandler aHandler
)
127 if (aHandler
!= null)
128 maHandlers
.add (new HandlerDescriptor (aHandler
));
132 /** iterate over handlers and return child sum */
133 protected HandlerDescriptor
getHandlerDescriptor (int i
)
135 HandlerDescriptor aDescriptor
= (HandlerDescriptor
)maHandlers
.get(i
);
136 if (aDescriptor
.mnChildCount
< 0)
137 aDescriptor
.mnChildCount
=
138 aDescriptor
.maHandler
.getChildCount (this);
142 public int getChildCount()
145 for (int i
= 0; i
< maHandlers
.size(); i
++)
147 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
148 nChildCount
+= aDescriptor
.mnChildCount
;
153 /** iterate over handlers until the child is found */
154 public AccessibleTreeNode
getChild (int nIndex
)
155 throws IndexOutOfBoundsException
159 for(int i
= 0; i
< maHandlers
.size(); i
++)
161 // check if this handler has the child, and if not
162 // search with next handler
163 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
164 if (nIndex
< aDescriptor
.mnChildCount
)
165 return aDescriptor
.maHandler
.getChild (this, nIndex
);
167 nIndex
-= aDescriptor
.mnChildCount
;
171 throw new IndexOutOfBoundsException();
177 public AccessibleTreeNode
getChildNoCreate (int nIndex
)
178 throws IndexOutOfBoundsException
182 for(int i
= 0; i
< maHandlers
.size(); i
++)
184 // check if this handler has the child, and if not
185 // search with next handler
186 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
187 if (nIndex
< aDescriptor
.mnChildCount
)
188 return aDescriptor
.maHandler
.getChildNoCreate (this, nIndex
);
190 nIndex
-= aDescriptor
.mnChildCount
;
194 throw new IndexOutOfBoundsException();
200 public boolean removeChild (int nIndex
)
201 throws IndexOutOfBoundsException
203 boolean bStatus
= false;
206 for (int i
=0; i
<maHandlers
.size(); i
++)
208 // check if this handler has the child, and if not
209 // search with next handler
210 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
211 if (nIndex
< aDescriptor
.mnChildCount
)
213 bStatus
= aDescriptor
.maHandler
.removeChild (this, nIndex
);
214 aDescriptor
.mnChildCount
= aDescriptor
.maHandler
.getChildCount (this);
218 nIndex
-= aDescriptor
.mnChildCount
;
222 throw new IndexOutOfBoundsException();
228 public int indexOf (AccessibleTreeNode aNode
)
233 for (int i
=0; i
<maHandlers
.size(); i
++)
235 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
236 int nIndex
= aDescriptor
.maHandler
.indexOf (aNode
);
238 return nBaseIndex
+ nIndex
;
240 nBaseIndex
+= aDescriptor
.mnChildCount
;
247 /** this node is a leaf if have no handlers, or is those
248 handlers show no children */
249 public boolean isLeaf()
251 return (maHandlers
.size() == 0);// || (getChildCount() == 0);
254 public boolean equals (Object aOther
)
256 return (this == aOther
) || (aOther
!=null && aOther
.equals(mxContext
));
260 /** iterate over handlers until the child is found */
261 public void getActions(Vector aActions
)
263 for(int i
= 0; i
< maHandlers
.size(); i
++)
265 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
266 NodeHandler aHandler
= aDescriptor
.maHandler
;
267 String
[] aHandlerActions
= aHandler
.getActions (this);
268 for(int j
= 0; j
< aHandlerActions
.length
; j
++ )
270 aActions
.add( aHandlerActions
[j
] );
275 public void performAction( int nIndex
)
279 for(int i
= 0; i
< maHandlers
.size(); i
++)
281 // check if this handler has the child, and if not
282 // search with next handler
283 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
284 NodeHandler aHandler
= aDescriptor
.maHandler
;
285 int nCount
= aHandler
.getActions(this).length
;
286 if( nCount
> nIndex
)
288 aHandler
.performAction(this, nIndex
);
297 /** Try to add the specified accessible object as new accessible child of the
298 AccessibleTreeHandler.
299 Note that child is used in another context than
300 it is used in the other methods of this class.
302 public AccessibleTreeNode
addAccessibleChild (XAccessible xChild
)
304 for(int i
= 0; i
< maHandlers
.size(); i
++)
306 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
307 if (aDescriptor
.maHandler
instanceof AccessibleTreeHandler
)
309 AccessibleTreeHandler aHandler
= (AccessibleTreeHandler
)aDescriptor
.maHandler
;
310 AccessibleTreeNode aNode
= aHandler
.addAccessibleChild (this, xChild
);
311 aDescriptor
.mnChildCount
= aHandler
.getChildCount (this);
318 /** Update the specified handlers.
320 The returned array containes the indices of the updated children
321 and can be used to create a TreeModelEvent.
323 public Vector
updateChildren (java
.lang
.Class class1
)
325 return updateChildren (class1
, null);
328 public Vector
updateChildren (java
.lang
.Class class1
, java
.lang
.Class class2
)
330 Vector aChildIndices
= new Vector();
332 for(int i
=0; i
< maHandlers
.size(); i
++)
334 HandlerDescriptor aDescriptor
= getHandlerDescriptor (i
);
335 if ((class1
.isInstance(aDescriptor
.maHandler
))
336 || (class2
!=null && class2
.isInstance(aDescriptor
.maHandler
)))
338 aDescriptor
.maHandler
.update(this);
339 // Get updated number of children.
340 int nChildCount
= aDescriptor
.maHandler
.getChildCount (this);
341 aDescriptor
.mnChildCount
= nChildCount
;
342 // Fill in the indices of the updated children.
343 for (int j
=0; j
<nChildCount
; j
++)
344 aChildIndices
.add(new Integer(j
+nOffset
));
346 nOffset
+= aDescriptor
.mnChildCount
;
348 return aChildIndices
;