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 .
21 import com
.sun
.star
.awt
.tree
.ExpandVetoException
;
22 import com
.sun
.star
.awt
.tree
.TreeExpansionEvent
;
23 import com
.sun
.star
.awt
.tree
.XMutableTreeNode
;
24 import com
.sun
.star
.awt
.tree
.XTreeControl
;
25 import com
.sun
.star
.awt
.tree
.XTreeEditListener
;
26 import com
.sun
.star
.awt
.tree
.XTreeExpansionListener
;
27 import com
.sun
.star
.awt
.tree
.XTreeNode
;
28 import com
.sun
.star
.lang
.EventObject
;
29 import com
.sun
.star
.util
.VetoException
;
30 import lib
.MultiMethodTest
;
32 import lib
.StatusException
;
35 * Testing <code>com.sun.star.awt.tree.XTreeControl</code>
38 * <li><code> isNodeExpanded()</code></li>
39 * <li><code> isNodeCollapsed()</code></li>
40 * <li><code> makeNodeVisible()</code></li>
41 * <li><code> isNodeVisible()</code></li>
42 * <li><code> expandNode()</code></li>
43 * <li><code> collapseNode()</code></li>
44 * <li><code> addTreeExpansionListener()</code></li>
45 * <li><code> removeTreeExpansionListener()</code></li>
46 * <li><code> getNodeForLocation()</code></li>
47 * <li><code> getClosestNodeForLocation()</code></li>
48 * <li><code> isEditing()</code></li>
49 * <li><code> stopEditing()</code></li>
50 * <li><code> cancelEditing()</code></li>
51 * <li><code> startEditingAtNode()</code></li>
52 * <li><code> addTreeEditListener()</code></li>
53 * <li><code> removeTreeEditListener()</code></li>
54 * <li><code> DefaultExpandedGraphicURL()</code></li>
55 * <li><code> DefaultCollapsedGraphicURL()</code></li>* </ul> <p>
56 * Test is <b> NOT </b> multithread compliant. <p>
58 * @see com.sun.star.awt.tree.XTreeControl
60 public class _XTreeControl
extends MultiMethodTest
{
62 public XTreeControl oObj
= null;
64 private XMutableTreeNode mXNode
= null;
66 XTreeExpansionListener mTreeExpansionListener1
= new TreeExpansionListenerImpl1();
68 XTreeExpansionListener mTreeExpansionListener2
= new TreeExpansionListenerImpl2();
70 XTreeEditListener mTreeEditListener1
= new TreeEditListenerImpl1();
72 XTreeEditListener mTreeEditListener2
= new TreeEditListenerImpl2();
74 boolean mTreeExpanded1
= false;
75 boolean mTreeExpanding1
= false;
76 boolean mTreeCollapsed1
= false;
77 boolean mTreeCollapsing1
= false;
79 boolean mTreeExpanded2
= false;
80 boolean mTreeExpanding2
= false;
81 boolean mTreeCollapsed2
= false;
82 boolean mTreeCollapsing2
= false;
84 boolean mTreeNodeEditing1
= false;
85 boolean mTreeNodeEdit1
= false;
87 boolean mTreeNodeEditing2
= false;
88 boolean mTreeNodeEdit2
= false;
90 public interface XTreeDataModelListenerEvent
{
94 public class TreeExpansionListenerImpl1
implements XTreeExpansionListener
{
95 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent
) {
96 log
.println("event at ExpansionListener 1: requestChildNodes");
99 public void treeExpanding(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
100 log
.println("event at ExpansionListener 1: treeExpanding");
101 mTreeExpanding1
= true;
104 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
105 log
.println("event at ExpansionListener 1: treeCollapsing");
106 mTreeCollapsing1
= true;
109 public void treeExpanded(TreeExpansionEvent treeExpansionEvent
) {
110 log
.println("event at ExpansionListener 1: treeExpanded");
111 mTreeExpanded1
= true;
114 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent
) {
115 log
.println("event at ExpansionListener 1: treeCollapsed");
116 mTreeCollapsed1
= true;
119 public void disposing(EventObject eventObject
) {
120 log
.println("event at ExpansionListener 1: disposing");
124 public class TreeExpansionListenerImpl2
implements XTreeExpansionListener
{
125 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent
) {
126 log
.println("event at ExpansionListener 2: requestChildNodes");
129 public void treeExpanding(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
130 log
.println("event at ExpansionListener 2: treeExpanding");
131 mTreeExpanding2
= true;
134 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
135 log
.println("event at ExpansionListener 2: treeCollapsing");
136 mTreeCollapsing2
= true;
139 public void treeExpanded(TreeExpansionEvent treeExpansionEvent
) {
140 log
.println("event at ExpansionListener 2: treeExpanded");
141 mTreeExpanded2
= true;
144 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent
) {
145 log
.println("event at ExpansionListener 2: treeCollapsed");
146 mTreeCollapsed2
= true;
149 public void disposing(EventObject eventObject
) {
150 log
.println("event at ExpansionListener 2: disposing");
155 public class TreeEditListenerImpl1
implements XTreeEditListener
{
156 public void nodeEditing(XTreeNode xTreeNode
) throws VetoException
{
157 log
.println("event at EditListener 1: nodeEditing");
158 mTreeNodeEditing1
= true;
161 public void nodeEdited(XTreeNode xTreeNode
, String string
) {
162 log
.println("event at EditListener 1: nodeEdited");
163 mTreeNodeEdit1
= true;
166 public void disposing(EventObject eventObject
) {
167 log
.println("event at EditListener 1: disposing");
171 public class TreeEditListenerImpl2
implements XTreeEditListener
{
172 public void nodeEditing(XTreeNode xTreeNode
) throws VetoException
{
173 log
.println("event at EditListener 2: nodeEditing");
174 mTreeNodeEditing2
= true;
178 public void nodeEdited(XTreeNode xTreeNode
, String string
) {
179 log
.println("event at EditListener 2: nodeEdited");
180 mTreeNodeEdit2
= true;
183 public void disposing(EventObject eventObject
) {
184 log
.println("event at EditListener 2: disposing");
188 private void resetTreeExpandingListener(){
189 mTreeExpanded1
= false;
190 mTreeExpanded2
= false;
191 mTreeCollapsed1
= false;
192 mTreeCollapsed2
= false;
193 mTreeExpanding1
= false;
194 mTreeExpanding2
= false;
195 mTreeCollapsing1
= false;
196 mTreeCollapsing2
= false;
199 private void resetEditListener(){
200 mTreeNodeEditing1
= false;
201 mTreeNodeEdit1
= false;
202 mTreeNodeEditing2
= false;
203 mTreeNodeEdit2
= false;
207 public void before(){
208 mXNode
= (XMutableTreeNode
) tEnv
.getObjRelation("XTreeControl_Node");
209 if (mXNode
== null) {
210 throw new StatusException(Status
.failed("ERROR: could not get object relation 'XTreeControl_Node'"));
214 public void _isNodeExpanded() {
218 boolean isExpanded
= false;
221 isExpanded
= oObj
.isNodeExpanded(mXNode
);
222 log
.println("node is expanded: " + isExpanded
);
224 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
226 log
.println("ERROR: could not query for 'isNodeExpanded()': " + ex
.toString());
232 log
.println("try to collapse node...");
233 oObj
.collapseNode(mXNode
);
235 } catch (ExpandVetoException ex
) {
237 log
.println("ERROR: could not collapse node: " + ex
.toString());
238 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
240 log
.println("ERROR: could not collapse node: " + ex
.toString());
245 log
.println("try to expand node...");
246 oObj
.expandNode(mXNode
);
248 } catch (ExpandVetoException ex
) {
250 log
.println("ERROR: could not expand node: " + ex
.toString());
251 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
253 log
.println("ERROR: could not expand node: " + ex
.toString());
258 boolean isAlsoExpanded
= oObj
.isNodeExpanded(mXNode
);
260 bOK
&= (isExpanded
!= isAlsoExpanded
);
262 log
.println("node is expanded: " + isAlsoExpanded
+ " => " + bOK
);
264 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
266 log
.println("ERROR: could not query for 'isNodeExpanded()': " + ex
.toString());
269 tRes
.tested("isNodeExpanded()", bOK
);
272 public void _isNodeCollapsed(){
276 boolean isCollapsed
= false;
279 isCollapsed
= oObj
.isNodeCollapsed(mXNode
);
280 log
.println("node is Collapsed: " + isCollapsed
);
282 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
284 log
.println("ERROR: could not query for 'isNodeCollapsed()': " + ex
.toString());
290 log
.println("try to collapse node...");
291 oObj
.collapseNode(mXNode
);
293 } catch (ExpandVetoException ex
) {
295 log
.println("ERROR: could not collapse node: " + ex
.toString());
296 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
298 log
.println("ERROR: could not collapse node: " + ex
.toString());
303 log
.println("try to expand node...");
304 oObj
.expandNode(mXNode
);
306 } catch (ExpandVetoException ex
) {
308 log
.println("ERROR: could not expand node: " + ex
.toString());
309 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
311 log
.println("ERROR: could not expand node: " + ex
.toString());
316 boolean isAlsoCollapsed
= oObj
.isNodeCollapsed(mXNode
);
318 bOK
&= (isCollapsed
!= isAlsoCollapsed
);
320 log
.println("node is Collapsed: " + isAlsoCollapsed
+ " => " + bOK
);
322 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
324 log
.println("ERROR: could not query for 'isNodeCollapsed()': " + ex
.toString());
327 tRes
.tested("isNodeCollapsed()", bOK
);
330 public void _makeNodeVisible(){
335 oObj
.makeNodeVisible(mXNode
);
336 } catch (ExpandVetoException ex
) {
338 log
.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex
.toString());
339 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
341 log
.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex
.toString());
345 bOK
&= oObj
.isNodeVisible(mXNode
);
346 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
348 log
.println("ERROR: could not call method 'isNodeVisible()' successfully: " + ex
.toString());
351 tRes
.tested("makeNodeVisible()", bOK
);
354 public void _isNodeVisible(){
356 this.requiredMethod("makeNodeVisible()");
359 log
.println("since required method 'makeNodeVisible()' uses method 'isNodeVisible()' this test is ok.");
360 tRes
.tested("isNodeVisible()", bOK
);
364 public void _expandNode(){
366 this.requiredMethod("isNodeExpanded()");
369 log
.println("since required method 'isnodeExpanded()' uses method 'expandNode()' this test is ok.");
370 tRes
.tested("expandNode()", bOK
);
374 public void _collapseNode(){
376 this.requiredMethod("isNodeCollapsed()");
379 log
.println("since required method 'isnodeCollapsed()' uses method 'expandNode()' this test is ok.");
380 tRes
.tested("collapseNode()", bOK
);
384 public void _addTreeExpansionListener(){
388 log
.println("collapse Node to get an initial status...");
391 oObj
.collapseNode(mXNode
);
392 } catch (ExpandVetoException ex
) {
394 log
.println("ERROR: could not collapse node: " + ex
.toString());
395 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
397 log
.println("ERROR: could not collapse node: " + ex
.toString());
400 log
.println("add mTreeExpansionListener1...");
401 oObj
.addTreeExpansionListener(mTreeExpansionListener1
);
403 log
.println("add mTreeExpansionListener2");
404 oObj
.addTreeExpansionListener(mTreeExpansionListener2
);
406 resetTreeExpandingListener();
408 log
.println("expand Node...");
411 oObj
.expandNode(mXNode
);
413 } catch (ExpandVetoException ex
) {
415 log
.println("ERROR: could not expand node: " + ex
.toString());
416 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
418 log
.println("ERROR: could not expand node: " + ex
.toString());
421 bOK
&= mTreeExpanded1
& mTreeExpanded2
& ! mTreeCollapsed1
& ! mTreeCollapsed2
422 & mTreeExpanding1
& mTreeExpanding2
& ! mTreeCollapsing1
& ! mTreeCollapsing2
;
424 resetTreeExpandingListener();
426 log
.println("collapse Node...");
429 oObj
.collapseNode(mXNode
);
430 } catch (ExpandVetoException ex
) {
432 log
.println("ERROR: could not collapse node: " + ex
.toString());
433 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
435 log
.println("ERROR: could not collapse node: " + ex
.toString());
438 bOK
&= ! mTreeExpanded1
& ! mTreeExpanded2
& mTreeCollapsed1
& mTreeCollapsed2
439 & ! mTreeExpanding1
& ! mTreeExpanding2
& mTreeCollapsing1
& mTreeCollapsing2
;
441 tRes
.tested("addTreeExpansionListener()", bOK
);
445 public void _removeTreeExpansionListener(){
447 this.requiredMethod("addTreeExpansionListener()");
451 log
.println("collapse Node to get an initial status...");
454 oObj
.collapseNode(mXNode
);
455 } catch (ExpandVetoException ex
) {
457 log
.println("ERROR: could not collapse node: " + ex
.toString());
458 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
460 log
.println("ERROR: could not collapse node: " + ex
.toString());
463 resetTreeExpandingListener();
465 log
.println("remove mTreeExpansionListener2 ...");
466 oObj
.removeTreeExpansionListener(mTreeExpansionListener2
);
468 log
.println("expand Node...");
471 oObj
.expandNode(mXNode
);
473 } catch (ExpandVetoException ex
) {
475 log
.println("ERROR: could not expand node: " + ex
.toString());
476 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
478 log
.println("ERROR: could not expand node: " + ex
.toString());
481 bOK
&= mTreeExpanded1
& ! mTreeExpanded2
& ! mTreeCollapsed1
& ! mTreeCollapsed2
482 & mTreeExpanding1
& ! mTreeExpanding2
& ! mTreeCollapsing1
& ! mTreeCollapsing2
;
484 resetTreeExpandingListener();
486 log
.println("collapse Node...");
489 oObj
.collapseNode(mXNode
);
490 } catch (ExpandVetoException ex
) {
492 log
.println("ERROR: could not collapse node: " + ex
.toString());
493 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
495 log
.println("ERROR: could not collapse node: " + ex
.toString());
498 bOK
&= ! mTreeExpanded1
& ! mTreeExpanded2
& mTreeCollapsed1
& ! mTreeCollapsed2
499 & ! mTreeExpanding1
& ! mTreeExpanding2
& mTreeCollapsing1
& ! mTreeCollapsing2
;
501 log
.println("remove mTreeExpansionListener2 ...");
502 oObj
.removeTreeExpansionListener(mTreeExpansionListener2
);
504 tRes
.tested("removeTreeExpansionListener()", bOK
);
508 public void _getNodeForLocation(){
513 tRes
.tested("getNodeForLocation()", bOK
);
517 public void _getClosestNodeForLocation(){
521 log
.println("try to get Node for location 100,100");
522 XTreeNode myNode
= oObj
.getClosestNodeForLocation(100,100);
524 bOK
&= (myNode
!= null);
526 tRes
.tested("getClosestNodeForLocation()", bOK
);
530 public void _isEditing(){
534 log
.println("not ready because of i78701");
536 tRes
.tested("isEditing()", bOK
);
540 public void _stopEditing(){
543 log
.println("not ready because of i78701");
546 tRes
.tested("stopEditing()", bOK
);
550 public void _cancelEditing(){
554 log
.println("not ready because of i78701");
556 tRes
.tested("cancelEditing()", bOK
);
560 public void _startEditingAtNode(){
564 log
.println("not ready because of i78701");
566 tRes
.tested("startEditingAtNode()", bOK
);
570 public void _addTreeEditListener(){
574 log
.println("add EditListener 1....");
575 oObj
.addTreeEditListener(mTreeEditListener1
);
577 log
.println("add EditListener 2....");
578 oObj
.addTreeEditListener(mTreeEditListener2
);
584 oObj
.startEditingAtNode(mXNode
);
585 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
586 log
.println("ERROR: could not start editing at node: " + ex
.toString());
590 log
.println("not ready because of i78701");
594 tRes
.tested("addTreeEditListener()", bOK
);
598 public void _removeTreeEditListener(){
602 log
.println("not ready because of i78701");
604 tRes
.tested("removeTreeEditListener()", bOK
);
608 public void _DefaultExpandedGraphicURL(){
612 String current
= oObj
.getDefaultExpandedGraphicURL();
613 log
.println("current DefaultExpandedGraphicURL: " + current
);
615 String changeUrl
= null;
617 if (current
.equals("private:graphicrepository/sd/res/triangle_right.png"))
618 changeUrl
= "private:graphicrepository/sd/res/triangle_down.png";
619 else changeUrl
= "private:graphicrepository/sd/res/triangle_right.png";
621 log
.println("try to set '" + changeUrl
+ "' as new DefaultExpandedGraphicURL");
623 oObj
.setDefaultExpandedGraphicURL(changeUrl
);
625 String newUrl
= oObj
.getDefaultExpandedGraphicURL();
627 log
.println("new DefaultExpandedGraphicURL: " + newUrl
);
629 bOK
&= ! newUrl
.equals(current
);
631 tRes
.tested("DefaultExpandedGraphicURL()", bOK
);
635 public void _DefaultCollapsedGraphicURL(){
639 String current
= oObj
.getDefaultCollapsedGraphicURL();
640 log
.println("current DefaultCollapsedGraphicURL: " + current
);
642 String changeUrl
= null;
644 if (current
.equals("private:graphicrepository/sd/res/triangle_right.png"))
645 changeUrl
= "private:graphicrepository/sd/res/triangle_down.png";
646 else changeUrl
= "private:graphicrepository/sd/res/triangle_right.png";
648 log
.println("try to set '" + changeUrl
+ "' as new DefaultCollapsedGraphicURL");
649 oObj
.setDefaultCollapsedGraphicURL(changeUrl
);
651 String newUrl
= oObj
.getDefaultCollapsedGraphicURL();
653 log
.println("new DefaultCollapsedGraphicURL: " + newUrl
);
655 bOK
&= ! newUrl
.equals(current
);
657 tRes
.tested("DefaultCollapsedGraphicURL()", bOK
);