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 public interface XTreeDataModelListenerEvent
{
88 public class TreeExpansionListenerImpl1
implements XTreeExpansionListener
{
89 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent
) {
90 log
.println("event at ExpansionListener 1: requestChildNodes");
93 public void treeExpanding(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
94 log
.println("event at ExpansionListener 1: treeExpanding");
95 mTreeExpanding1
= true;
98 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
99 log
.println("event at ExpansionListener 1: treeCollapsing");
100 mTreeCollapsing1
= true;
103 public void treeExpanded(TreeExpansionEvent treeExpansionEvent
) {
104 log
.println("event at ExpansionListener 1: treeExpanded");
105 mTreeExpanded1
= true;
108 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent
) {
109 log
.println("event at ExpansionListener 1: treeCollapsed");
110 mTreeCollapsed1
= true;
113 public void disposing(EventObject eventObject
) {
114 log
.println("event at ExpansionListener 1: disposing");
118 public class TreeExpansionListenerImpl2
implements XTreeExpansionListener
{
119 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent
) {
120 log
.println("event at ExpansionListener 2: requestChildNodes");
123 public void treeExpanding(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
124 log
.println("event at ExpansionListener 2: treeExpanding");
125 mTreeExpanding2
= true;
128 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent
) throws ExpandVetoException
{
129 log
.println("event at ExpansionListener 2: treeCollapsing");
130 mTreeCollapsing2
= true;
133 public void treeExpanded(TreeExpansionEvent treeExpansionEvent
) {
134 log
.println("event at ExpansionListener 2: treeExpanded");
135 mTreeExpanded2
= true;
138 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent
) {
139 log
.println("event at ExpansionListener 2: treeCollapsed");
140 mTreeCollapsed2
= true;
143 public void disposing(EventObject eventObject
) {
144 log
.println("event at ExpansionListener 2: disposing");
149 public class TreeEditListenerImpl1
implements XTreeEditListener
{
150 public void nodeEditing(XTreeNode xTreeNode
) throws VetoException
{
151 log
.println("event at EditListener 1: nodeEditing");
154 public void nodeEdited(XTreeNode xTreeNode
, String string
) {
155 log
.println("event at EditListener 1: nodeEdited");
158 public void disposing(EventObject eventObject
) {
159 log
.println("event at EditListener 1: disposing");
163 public class TreeEditListenerImpl2
implements XTreeEditListener
{
164 public void nodeEditing(XTreeNode xTreeNode
) throws VetoException
{
165 log
.println("event at EditListener 2: nodeEditing");
168 public void nodeEdited(XTreeNode xTreeNode
, String string
) {
169 log
.println("event at EditListener 2: nodeEdited");
172 public void disposing(EventObject eventObject
) {
173 log
.println("event at EditListener 2: disposing");
177 private void resetTreeExpandingListener(){
178 mTreeExpanded1
= false;
179 mTreeExpanded2
= false;
180 mTreeCollapsed1
= false;
181 mTreeCollapsed2
= false;
182 mTreeExpanding1
= false;
183 mTreeExpanding2
= false;
184 mTreeCollapsing1
= false;
185 mTreeCollapsing2
= false;
189 public void before(){
190 mXNode
= (XMutableTreeNode
) tEnv
.getObjRelation("XTreeControl_Node");
191 if (mXNode
== null) {
192 throw new StatusException(Status
.failed("ERROR: could not get object relation 'XTreeControl_Node'"));
196 public void _isNodeExpanded() {
200 boolean isExpanded
= false;
203 isExpanded
= oObj
.isNodeExpanded(mXNode
);
204 log
.println("node is expanded: " + isExpanded
);
206 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
208 log
.println("ERROR: could not query for 'isNodeExpanded()': " + ex
.toString());
214 log
.println("try to collapse node...");
215 oObj
.collapseNode(mXNode
);
217 } catch (ExpandVetoException ex
) {
219 log
.println("ERROR: could not collapse node: " + ex
.toString());
220 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
222 log
.println("ERROR: could not collapse node: " + ex
.toString());
227 log
.println("try to expand node...");
228 oObj
.expandNode(mXNode
);
230 } catch (ExpandVetoException ex
) {
232 log
.println("ERROR: could not expand node: " + ex
.toString());
233 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
235 log
.println("ERROR: could not expand node: " + ex
.toString());
240 boolean isAlsoExpanded
= oObj
.isNodeExpanded(mXNode
);
242 bOK
&= (isExpanded
!= isAlsoExpanded
);
244 log
.println("node is expanded: " + isAlsoExpanded
+ " => " + bOK
);
246 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
248 log
.println("ERROR: could not query for 'isNodeExpanded()': " + ex
.toString());
251 tRes
.tested("isNodeExpanded()", bOK
);
254 public void _isNodeCollapsed(){
258 boolean isCollapsed
= false;
261 isCollapsed
= oObj
.isNodeCollapsed(mXNode
);
262 log
.println("node is Collapsed: " + isCollapsed
);
264 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
266 log
.println("ERROR: could not query for 'isNodeCollapsed()': " + ex
.toString());
272 log
.println("try to collapse node...");
273 oObj
.collapseNode(mXNode
);
275 } catch (ExpandVetoException ex
) {
277 log
.println("ERROR: could not collapse node: " + ex
.toString());
278 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
280 log
.println("ERROR: could not collapse node: " + ex
.toString());
285 log
.println("try to expand node...");
286 oObj
.expandNode(mXNode
);
288 } catch (ExpandVetoException ex
) {
290 log
.println("ERROR: could not expand node: " + ex
.toString());
291 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
293 log
.println("ERROR: could not expand node: " + ex
.toString());
298 boolean isAlsoCollapsed
= oObj
.isNodeCollapsed(mXNode
);
300 bOK
&= (isCollapsed
!= isAlsoCollapsed
);
302 log
.println("node is Collapsed: " + isAlsoCollapsed
+ " => " + bOK
);
304 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
306 log
.println("ERROR: could not query for 'isNodeCollapsed()': " + ex
.toString());
309 tRes
.tested("isNodeCollapsed()", bOK
);
312 public void _makeNodeVisible(){
317 oObj
.makeNodeVisible(mXNode
);
318 } catch (ExpandVetoException ex
) {
320 log
.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex
.toString());
321 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
323 log
.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex
.toString());
327 bOK
&= oObj
.isNodeVisible(mXNode
);
328 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
330 log
.println("ERROR: could not call method 'isNodeVisible()' successfully: " + ex
.toString());
333 tRes
.tested("makeNodeVisible()", bOK
);
336 public void _isNodeVisible(){
338 this.requiredMethod("makeNodeVisible()");
341 log
.println("since required method 'makeNodeVisible()' uses method 'isNodeVisible()' this test is ok.");
342 tRes
.tested("isNodeVisible()", bOK
);
346 public void _expandNode(){
348 this.requiredMethod("isNodeExpanded()");
351 log
.println("since required method 'isnodeExpanded()' uses method 'expandNode()' this test is ok.");
352 tRes
.tested("expandNode()", bOK
);
356 public void _collapseNode(){
358 this.requiredMethod("isNodeCollapsed()");
361 log
.println("since required method 'isnodeCollapsed()' uses method 'expandNode()' this test is ok.");
362 tRes
.tested("collapseNode()", bOK
);
366 public void _addTreeExpansionListener(){
370 log
.println("collapse Node to get an initial status...");
373 oObj
.collapseNode(mXNode
);
374 } catch (ExpandVetoException ex
) {
376 log
.println("ERROR: could not collapse node: " + ex
.toString());
377 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
379 log
.println("ERROR: could not collapse node: " + ex
.toString());
382 log
.println("add mTreeExpansionListener1...");
383 oObj
.addTreeExpansionListener(mTreeExpansionListener1
);
385 log
.println("add mTreeExpansionListener2");
386 oObj
.addTreeExpansionListener(mTreeExpansionListener2
);
388 resetTreeExpandingListener();
390 log
.println("expand Node...");
393 oObj
.expandNode(mXNode
);
395 } catch (ExpandVetoException ex
) {
397 log
.println("ERROR: could not expand node: " + ex
.toString());
398 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
400 log
.println("ERROR: could not expand node: " + ex
.toString());
403 bOK
&= mTreeExpanded1
& mTreeExpanded2
& ! mTreeCollapsed1
& ! mTreeCollapsed2
404 & mTreeExpanding1
& mTreeExpanding2
& ! mTreeCollapsing1
& ! mTreeCollapsing2
;
406 resetTreeExpandingListener();
408 log
.println("collapse Node...");
411 oObj
.collapseNode(mXNode
);
412 } catch (ExpandVetoException ex
) {
414 log
.println("ERROR: could not collapse node: " + ex
.toString());
415 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
417 log
.println("ERROR: could not collapse node: " + ex
.toString());
420 bOK
&= ! mTreeExpanded1
& ! mTreeExpanded2
& mTreeCollapsed1
& mTreeCollapsed2
421 & ! mTreeExpanding1
& ! mTreeExpanding2
& mTreeCollapsing1
& mTreeCollapsing2
;
423 tRes
.tested("addTreeExpansionListener()", bOK
);
427 public void _removeTreeExpansionListener(){
429 this.requiredMethod("addTreeExpansionListener()");
433 log
.println("collapse Node to get an initial status...");
436 oObj
.collapseNode(mXNode
);
437 } catch (ExpandVetoException ex
) {
439 log
.println("ERROR: could not collapse node: " + ex
.toString());
440 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
442 log
.println("ERROR: could not collapse node: " + ex
.toString());
445 resetTreeExpandingListener();
447 log
.println("remove mTreeExpansionListener2 ...");
448 oObj
.removeTreeExpansionListener(mTreeExpansionListener2
);
450 log
.println("expand Node...");
453 oObj
.expandNode(mXNode
);
455 } catch (ExpandVetoException ex
) {
457 log
.println("ERROR: could not expand node: " + ex
.toString());
458 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
460 log
.println("ERROR: could not expand node: " + ex
.toString());
463 bOK
&= mTreeExpanded1
& ! mTreeExpanded2
& ! mTreeCollapsed1
& ! mTreeCollapsed2
464 & mTreeExpanding1
& ! mTreeExpanding2
& ! mTreeCollapsing1
& ! mTreeCollapsing2
;
466 resetTreeExpandingListener();
468 log
.println("collapse Node...");
471 oObj
.collapseNode(mXNode
);
472 } catch (ExpandVetoException ex
) {
474 log
.println("ERROR: could not collapse node: " + ex
.toString());
475 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
477 log
.println("ERROR: could not collapse node: " + ex
.toString());
480 bOK
&= ! mTreeExpanded1
& ! mTreeExpanded2
& mTreeCollapsed1
& ! mTreeCollapsed2
481 & ! mTreeExpanding1
& ! mTreeExpanding2
& mTreeCollapsing1
& ! mTreeCollapsing2
;
483 log
.println("remove mTreeExpansionListener2 ...");
484 oObj
.removeTreeExpansionListener(mTreeExpansionListener2
);
486 tRes
.tested("removeTreeExpansionListener()", bOK
);
490 public void _getNodeForLocation(){
495 tRes
.tested("getNodeForLocation()", bOK
);
499 public void _getClosestNodeForLocation(){
503 log
.println("try to get Node for location 100,100");
504 XTreeNode myNode
= oObj
.getClosestNodeForLocation(100,100);
506 bOK
&= (myNode
!= null);
508 tRes
.tested("getClosestNodeForLocation()", bOK
);
512 public void _isEditing(){
516 log
.println("not ready because of i78701");
518 tRes
.tested("isEditing()", bOK
);
522 public void _stopEditing(){
525 log
.println("not ready because of i78701");
528 tRes
.tested("stopEditing()", bOK
);
532 public void _cancelEditing(){
536 log
.println("not ready because of i78701");
538 tRes
.tested("cancelEditing()", bOK
);
542 public void _startEditingAtNode(){
546 log
.println("not ready because of i78701");
548 tRes
.tested("startEditingAtNode()", bOK
);
552 public void _addTreeEditListener(){
556 log
.println("add EditListener 1...");
557 oObj
.addTreeEditListener(mTreeEditListener1
);
559 log
.println("add EditListener 2...");
560 oObj
.addTreeEditListener(mTreeEditListener2
);
563 oObj
.startEditingAtNode(mXNode
);
564 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
565 log
.println("ERROR: could not start editing at node: " + ex
.toString());
569 log
.println("not ready because of i78701");
573 tRes
.tested("addTreeEditListener()", bOK
);
577 public void _removeTreeEditListener(){
581 log
.println("not ready because of i78701");
583 tRes
.tested("removeTreeEditListener()", bOK
);
587 public void _DefaultExpandedGraphicURL(){
591 String current
= oObj
.getDefaultExpandedGraphicURL();
592 log
.println("current DefaultExpandedGraphicURL: " + current
);
594 String changeUrl
= null;
596 if (current
.equals("private:graphicrepository/sd/res/triangle_right.png"))
597 changeUrl
= "private:graphicrepository/sd/res/triangle_down.png";
598 else changeUrl
= "private:graphicrepository/sd/res/triangle_right.png";
600 log
.println("try to set '" + changeUrl
+ "' as new DefaultExpandedGraphicURL");
602 oObj
.setDefaultExpandedGraphicURL(changeUrl
);
604 String newUrl
= oObj
.getDefaultExpandedGraphicURL();
606 log
.println("new DefaultExpandedGraphicURL: " + newUrl
);
608 bOK
&= ! newUrl
.equals(current
);
610 tRes
.tested("DefaultExpandedGraphicURL()", bOK
);
614 public void _DefaultCollapsedGraphicURL(){
618 String current
= oObj
.getDefaultCollapsedGraphicURL();
619 log
.println("current DefaultCollapsedGraphicURL: " + current
);
621 String changeUrl
= null;
623 if (current
.equals("private:graphicrepository/sd/res/triangle_right.png"))
624 changeUrl
= "private:graphicrepository/sd/res/triangle_down.png";
625 else changeUrl
= "private:graphicrepository/sd/res/triangle_right.png";
627 log
.println("try to set '" + changeUrl
+ "' as new DefaultCollapsedGraphicURL");
628 oObj
.setDefaultCollapsedGraphicURL(changeUrl
);
630 String newUrl
= oObj
.getDefaultCollapsedGraphicURL();
632 log
.println("new DefaultCollapsedGraphicURL: " + newUrl
);
634 bOK
&= ! newUrl
.equals(current
);
636 tRes
.tested("DefaultCollapsedGraphicURL()", bOK
);