1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.awt.tree; 25 26 import com.sun.star.awt.tree.ExpandVetoException; 27 import com.sun.star.awt.tree.TreeExpansionEvent; 28 import com.sun.star.awt.tree.XMutableTreeNode; 29 import com.sun.star.awt.tree.XTreeControl; 30 import com.sun.star.awt.tree.XTreeEditListener; 31 import com.sun.star.awt.tree.XTreeExpansionListener; 32 import com.sun.star.awt.tree.XTreeNode; 33 import com.sun.star.lang.EventObject; 34 import com.sun.star.util.VetoException; 35 import lib.MultiMethodTest; 36 import lib.Status; 37 import lib.StatusException; 38 39 /** 40 * Testing <code>com.sun.star.awt.tree.XTreeControl</code> 41 * interface methods : 42 * <ul> 43 * <li><code> isNodeExpanded()</code></li> 44 * <li><code> isNodeCollapsed()</code></li> 45 * <li><code> makeNodeVisible()</code></li> 46 * <li><code> isNodeVisible()</code></li> 47 * <li><code> expandNode()</code></li> 48 * <li><code> collapseNode()</code></li> 49 * <li><code> addTreeExpansionListener()</code></li> 50 * <li><code> removeTreeExpansionListener()</code></li> 51 * <li><code> getNodeForLocation()</code></li> 52 * <li><code> getClosestNodeForLocation()</code></li> 53 * <li><code> isEditing()</code></li> 54 * <li><code> stopEditing()</code></li> 55 * <li><code> cancelEditing()</code></li> 56 * <li><code> startEditingAtNode()</code></li> 57 * <li><code> addTreeEditListener()</code></li> 58 * <li><code> removeTreeEditListener()</code></li> 59 * <li><code> DefaultExpandedGraphicURL()</code></li> 60 * <li><code> DefaultCollapsedGraphicURL()</code></li>* </ul> <p> 61 * Test is <b> NOT </b> multithread compilant. <p> 62 * 63 * @see com.sun.star.awt.tree.XTreeControl 64 */ 65 public class _XTreeControl extends MultiMethodTest { 66 67 public XTreeControl oObj = null; 68 69 private XMutableTreeNode mNewNode = null; 70 71 private XMutableTreeNode mXNode = null; 72 73 XTreeExpansionListener mTreeExpansionListener1 = new TreeExpansionListenerImpl1(); 74 75 XTreeExpansionListener mTreeExpansionListener2 = new TreeExpansionListenerImpl2(); 76 77 XTreeEditListener mTreeEditListener1 = new TreeEditListenerImpl1(); 78 79 XTreeEditListener mTreeEditListener2 = new TreeEditListenerImpl2(); 80 81 boolean mTreeExpanded1 = false; 82 boolean mTreeExpanding1 = false; 83 boolean mTreeCollapsed1 = false; 84 boolean mTreeCollapsing1 = false; 85 86 boolean mTreeExpanded2 = false; 87 boolean mTreeExpanding2 = false; 88 boolean mTreeCollapsed2 = false; 89 boolean mTreeCollapsing2 = false; 90 91 boolean mTreeNodeEditing1 = false; 92 boolean mTreeNodeEdit1 = false; 93 94 boolean mTreeNodeEditing2 = false; 95 boolean mTreeNodeEdit2 = false; 96 97 public static interface XTreeDataModelListenerEvent{ fireEvent()98 public void fireEvent(); 99 } 100 101 public class TreeExpansionListenerImpl1 implements XTreeExpansionListener{ requestChildNodes(TreeExpansionEvent treeExpansionEvent)102 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent) { 103 log.println("event at ExpansionListener 1: requestChildNodes"); 104 } 105 treeExpanding(TreeExpansionEvent treeExpansionEvent)106 public void treeExpanding(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException { 107 log.println("event at ExpansionListener 1: treeExpanding"); 108 mTreeExpanding1 = true; 109 } 110 treeCollapsing(TreeExpansionEvent treeExpansionEvent)111 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException { 112 log.println("event at ExpansionListener 1: treeCollapsing"); 113 mTreeCollapsing1 = true; 114 } 115 treeExpanded(TreeExpansionEvent treeExpansionEvent)116 public void treeExpanded(TreeExpansionEvent treeExpansionEvent) { 117 log.println("event at ExpansionListener 1: treeExpanded"); 118 mTreeExpanded1 = true; 119 } 120 treeCollapsed(TreeExpansionEvent treeExpansionEvent)121 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent) { 122 log.println("event at ExpansionListener 1: treeCollapsed"); 123 mTreeCollapsed1 = true; 124 } 125 disposing(EventObject eventObject)126 public void disposing(EventObject eventObject) { 127 log.println("event at ExpansionListener 1: disposing"); 128 } 129 } 130 131 public class TreeExpansionListenerImpl2 implements XTreeExpansionListener{ requestChildNodes(TreeExpansionEvent treeExpansionEvent)132 public void requestChildNodes(TreeExpansionEvent treeExpansionEvent) { 133 log.println("event at ExpansionListener 2: requestChildNodes"); 134 } 135 treeExpanding(TreeExpansionEvent treeExpansionEvent)136 public void treeExpanding(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException { 137 log.println("event at ExpansionListener 2: treeExpanding"); 138 mTreeExpanding2 = true; 139 } 140 treeCollapsing(TreeExpansionEvent treeExpansionEvent)141 public void treeCollapsing(TreeExpansionEvent treeExpansionEvent) throws ExpandVetoException { 142 log.println("event at ExpansionListener 2: treeCollapsing"); 143 mTreeCollapsing2 = true; 144 } 145 treeExpanded(TreeExpansionEvent treeExpansionEvent)146 public void treeExpanded(TreeExpansionEvent treeExpansionEvent) { 147 log.println("event at ExpansionListener 2: treeExpanded"); 148 mTreeExpanded2 = true; 149 } 150 treeCollapsed(TreeExpansionEvent treeExpansionEvent)151 public void treeCollapsed(TreeExpansionEvent treeExpansionEvent) { 152 log.println("event at ExpansionListener 2: treeCollapsed"); 153 mTreeCollapsed2 = true; 154 } 155 disposing(EventObject eventObject)156 public void disposing(EventObject eventObject) { 157 log.println("event at ExpansionListener 2: disposing"); 158 } 159 160 } 161 162 public class TreeEditListenerImpl1 implements XTreeEditListener{ nodeEditing(XTreeNode xTreeNode)163 public void nodeEditing(XTreeNode xTreeNode) throws VetoException { 164 log.println("event at EditListener 1: nodeEditing"); 165 mTreeNodeEditing1 = true; 166 } 167 nodeEdited(XTreeNode xTreeNode, String string)168 public void nodeEdited(XTreeNode xTreeNode, String string) { 169 log.println("event at EditListener 1: nodeEdited"); 170 mTreeNodeEdit1 = true; 171 } 172 disposing(EventObject eventObject)173 public void disposing(EventObject eventObject) { 174 log.println("event at EditListener 1: disposing"); 175 } 176 } 177 178 public class TreeEditListenerImpl2 implements XTreeEditListener{ nodeEditing(XTreeNode xTreeNode)179 public void nodeEditing(XTreeNode xTreeNode) throws VetoException { 180 log.println("event at EditListener 2: nodeEditing"); 181 mTreeNodeEditing2 = true; 182 183 } 184 nodeEdited(XTreeNode xTreeNode, String string)185 public void nodeEdited(XTreeNode xTreeNode, String string) { 186 log.println("event at EditListener 2: nodeEdited"); 187 mTreeNodeEdit2 = true; 188 } 189 disposing(EventObject eventObject)190 public void disposing(EventObject eventObject) { 191 log.println("event at EditListener 2: disposing"); 192 } 193 } 194 resetTreeExpandingListener()195 private void resetTreeExpandingListener(){ 196 mTreeExpanded1 = false; 197 mTreeExpanded2 = false; 198 mTreeCollapsed1 = false; 199 mTreeCollapsed2 = false; 200 mTreeExpanding1 = false; 201 mTreeExpanding2 = false; 202 mTreeCollapsing1 = false; 203 mTreeCollapsing2 = false; 204 } 205 resetEditListener()206 private void resetEditListener(){ 207 mTreeNodeEditing1 = false; 208 mTreeNodeEdit1 = false; 209 mTreeNodeEditing2 = false; 210 mTreeNodeEdit2 = false; 211 } 212 before()213 public void before(){ 214 mXNode = (XMutableTreeNode) tEnv.getObjRelation("XTreeControl_Node"); 215 if (mXNode == null) { 216 throw new StatusException(Status.failed("ERROR: could not get object relation 'XTreeControl_Node'")); 217 } 218 } 219 _isNodeExpanded()220 public void _isNodeExpanded() throws ExpandVetoException{ 221 222 boolean bOK = true; 223 224 boolean isExpanded = false; 225 226 try { 227 isExpanded = oObj.isNodeExpanded(mXNode); 228 log.println("node is expanded: " + isExpanded); 229 230 } catch (com.sun.star.lang.IllegalArgumentException ex) { 231 bOK = false; 232 log.println("ERROR: could not query for 'isNodeExpanded()': " + ex.toString()); 233 } 234 235 if (isExpanded) 236 try { 237 238 log.println("try to collapse node..."); 239 oObj.collapseNode(mXNode); 240 241 } catch (ExpandVetoException ex) { 242 bOK = false; 243 log.println("ERROR: could not collapse node: " + ex.toString()); 244 } catch (com.sun.star.lang.IllegalArgumentException ex) { 245 bOK = false; 246 log.println("ERROR: could not collapse node: " + ex.toString()); 247 } 248 else 249 try { 250 251 log.println("try to expand node..."); 252 oObj.expandNode(mXNode); 253 254 } catch (ExpandVetoException ex) { 255 bOK = false; 256 log.println("ERROR: could not expand node: " + ex.toString()); 257 } catch (com.sun.star.lang.IllegalArgumentException ex) { 258 bOK = false; 259 log.println("ERROR: could not expand node: " + ex.toString()); 260 } 261 262 try { 263 264 boolean isAlsoExpanded = oObj.isNodeExpanded(mXNode); 265 266 bOK &= (isExpanded != isAlsoExpanded); 267 268 log.println("node is expanded: " + isAlsoExpanded + " => " + bOK); 269 270 } catch (com.sun.star.lang.IllegalArgumentException ex) { 271 bOK = false; 272 log.println("ERROR: could not query for 'isNodeExpanded()': " + ex.toString()); 273 } 274 275 tRes.tested("isNodeExpanded()", bOK); 276 277 } _isNodeCollapsed()278 public void _isNodeCollapsed(){ 279 280 boolean bOK = true; 281 282 boolean isCollapsed = false; 283 284 try { 285 isCollapsed = oObj.isNodeCollapsed(mXNode); 286 log.println("node is Collapsed: " + isCollapsed); 287 288 } catch (com.sun.star.lang.IllegalArgumentException ex) { 289 bOK = false; 290 log.println("ERROR: could not query for 'isNodeCollapsed()': " + ex.toString()); 291 } 292 293 if ( ! isCollapsed) 294 try { 295 296 log.println("try to collapse node..."); 297 oObj.collapseNode(mXNode); 298 299 } catch (ExpandVetoException ex) { 300 bOK = false; 301 log.println("ERROR: could not collapse node: " + ex.toString()); 302 } catch (com.sun.star.lang.IllegalArgumentException ex) { 303 bOK = false; 304 log.println("ERROR: could not collapse node: " + ex.toString()); 305 } 306 else 307 try { 308 309 log.println("try to expand node..."); 310 oObj.expandNode(mXNode); 311 312 } catch (ExpandVetoException ex) { 313 bOK = false; 314 log.println("ERROR: could not expand node: " + ex.toString()); 315 } catch (com.sun.star.lang.IllegalArgumentException ex) { 316 bOK = false; 317 log.println("ERROR: could not expand node: " + ex.toString()); 318 } 319 320 try { 321 322 boolean isAlsoCollapsed = oObj.isNodeCollapsed(mXNode); 323 324 bOK &= (isCollapsed != isAlsoCollapsed); 325 326 log.println("node is Collapsed: " + isAlsoCollapsed + " => " + bOK); 327 328 } catch (com.sun.star.lang.IllegalArgumentException ex) { 329 bOK = false; 330 log.println("ERROR: could not query for 'isNodeCollapsed()': " + ex.toString()); 331 } 332 333 tRes.tested("isNodeCollapsed()", bOK); 334 335 } _makeNodeVisible()336 public void _makeNodeVisible(){ 337 338 boolean bOK = true; 339 try { 340 341 oObj.makeNodeVisible(mXNode); 342 } catch (ExpandVetoException ex) { 343 bOK = false; 344 log.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex.toString()); 345 } catch (com.sun.star.lang.IllegalArgumentException ex) { 346 bOK = false; 347 log.println("ERROR: could not call method 'makeNodeVisible()' successfully: " + ex.toString()); 348 } 349 try { 350 351 bOK &= oObj.isNodeVisible(mXNode); 352 } catch (com.sun.star.lang.IllegalArgumentException ex) { 353 bOK = false; 354 log.println("ERROR: could not call method 'isNodeVisible()' successfully: " + ex.toString()); 355 } 356 357 tRes.tested("makeNodeVisible()", bOK); 358 359 } _isNodeVisible()360 public void _isNodeVisible(){ 361 362 this.requiredMethod("makeNodeVisible()"); 363 364 boolean bOK = true; 365 log.println("since required method 'makeNodeVisible()' uses method 'isNodeVisible()' this test is ok."); 366 tRes.tested("isNodeVisible()", bOK); 367 368 } 369 _expandNode()370 public void _expandNode(){ 371 372 this.requiredMethod("isNodeExpanded()"); 373 374 boolean bOK = true; 375 log.println("since required method 'isnodeExpanded()' uses method 'expandNode()' this test is ok."); 376 tRes.tested("expandNode()", bOK); 377 378 } 379 _collapseNode()380 public void _collapseNode(){ 381 382 this.requiredMethod("isNodeCollapsed()"); 383 384 boolean bOK = true; 385 log.println("since required method 'isnodeCollapsed()' uses method 'expandNode()' this test is ok."); 386 tRes.tested("collapseNode()", bOK); 387 388 } 389 _addTreeExpansionListener()390 public void _addTreeExpansionListener(){ 391 392 boolean bOK = true; 393 394 log.println("collapse Node to get an initial status..."); 395 try { 396 397 oObj.collapseNode(mXNode); 398 } catch (ExpandVetoException ex) { 399 bOK = false; 400 log.println("ERROR: could not collapse node: " + ex.toString()); 401 } catch (com.sun.star.lang.IllegalArgumentException ex) { 402 bOK = false; 403 log.println("ERROR: could not collapse node: " + ex.toString()); 404 } 405 406 log.println("add mTreeExpansionListener1..."); 407 oObj.addTreeExpansionListener(mTreeExpansionListener1); 408 409 log.println("add mTreeExpansionListener2"); 410 oObj.addTreeExpansionListener(mTreeExpansionListener2); 411 412 resetTreeExpandingListener(); 413 414 log.println("expand Node..."); 415 try { 416 417 oObj.expandNode(mXNode); 418 419 } catch (ExpandVetoException ex) { 420 bOK = false; 421 log.println("ERROR: could not expand node: " + ex.toString()); 422 } catch (com.sun.star.lang.IllegalArgumentException ex) { 423 bOK = false; 424 log.println("ERROR: could not expand node: " + ex.toString()); 425 } 426 427 bOK &= mTreeExpanded1 & mTreeExpanded2 & ! mTreeCollapsed1 & ! mTreeCollapsed2 428 & mTreeExpanding1 & mTreeExpanding2 & ! mTreeCollapsing1 & ! mTreeCollapsing2; 429 430 resetTreeExpandingListener(); 431 432 log.println("collapse Node..."); 433 try { 434 435 oObj.collapseNode(mXNode); 436 } catch (ExpandVetoException ex) { 437 bOK = false; 438 log.println("ERROR: could not collapse node: " + ex.toString()); 439 } catch (com.sun.star.lang.IllegalArgumentException ex) { 440 bOK = false; 441 log.println("ERROR: could not collapse node: " + ex.toString()); 442 } 443 444 bOK &= ! mTreeExpanded1 & ! mTreeExpanded2 & mTreeCollapsed1 & mTreeCollapsed2 445 & ! mTreeExpanding1 & ! mTreeExpanding2 & mTreeCollapsing1 & mTreeCollapsing2; 446 447 tRes.tested("addTreeExpansionListener()", bOK); 448 449 } 450 _removeTreeExpansionListener()451 public void _removeTreeExpansionListener(){ 452 453 this.requiredMethod("addTreeExpansionListener()"); 454 455 boolean bOK = true; 456 457 log.println("collapse Node to get an initial status..."); 458 try { 459 460 oObj.collapseNode(mXNode); 461 } catch (ExpandVetoException ex) { 462 bOK = false; 463 log.println("ERROR: could not collapse node: " + ex.toString()); 464 } catch (com.sun.star.lang.IllegalArgumentException ex) { 465 bOK = false; 466 log.println("ERROR: could not collapse node: " + ex.toString()); 467 } 468 469 resetTreeExpandingListener(); 470 471 log.println("remove mTreeExpansionListener2 ..."); 472 oObj.removeTreeExpansionListener(mTreeExpansionListener2); 473 474 log.println("expand Node..."); 475 try { 476 477 oObj.expandNode(mXNode); 478 479 } catch (ExpandVetoException ex) { 480 bOK = false; 481 log.println("ERROR: could not expand node: " + ex.toString()); 482 } catch (com.sun.star.lang.IllegalArgumentException ex) { 483 bOK = false; 484 log.println("ERROR: could not expand node: " + ex.toString()); 485 } 486 487 bOK &= mTreeExpanded1 & ! mTreeExpanded2 & ! mTreeCollapsed1 & ! mTreeCollapsed2 488 & mTreeExpanding1 & ! mTreeExpanding2 & ! mTreeCollapsing1 & ! mTreeCollapsing2; 489 490 resetTreeExpandingListener(); 491 492 log.println("collapse Node..."); 493 try { 494 495 oObj.collapseNode(mXNode); 496 } catch (ExpandVetoException ex) { 497 bOK = false; 498 log.println("ERROR: could not collapse node: " + ex.toString()); 499 } catch (com.sun.star.lang.IllegalArgumentException ex) { 500 bOK = false; 501 log.println("ERROR: could not collapse node: " + ex.toString()); 502 } 503 504 bOK &= ! mTreeExpanded1 & ! mTreeExpanded2 & mTreeCollapsed1 & ! mTreeCollapsed2 505 & ! mTreeExpanding1 & ! mTreeExpanding2 & mTreeCollapsing1 & ! mTreeCollapsing2; 506 507 log.println("remove mTreeExpansionListener2 ..."); 508 oObj.removeTreeExpansionListener(mTreeExpansionListener2); 509 510 tRes.tested("removeTreeExpansionListener()", bOK); 511 512 } 513 _getNodeForLocation()514 public void _getNodeForLocation(){ 515 516 boolean bOK = false; 517 518 519 tRes.tested("getNodeForLocation()", bOK); 520 521 } 522 _getClosestNodeForLocation()523 public void _getClosestNodeForLocation(){ 524 525 boolean bOK = false; 526 527 log.println("try to get Node for location 100,100"); 528 XTreeNode myNode = oObj.getClosestNodeForLocation(100,100); 529 530 bOK &= (myNode != null); 531 532 tRes.tested("getClosestNodeForLocation()", bOK); 533 534 } 535 _isEditing()536 public void _isEditing(){ 537 538 boolean bOK = false; 539 540 log.println("not ready because of i78701"); 541 542 tRes.tested("isEditing()", bOK); 543 544 } 545 _stopEditing()546 public void _stopEditing(){ 547 548 boolean bOK = false; 549 log.println("not ready because of i78701"); 550 551 552 tRes.tested("stopEditing()", bOK); 553 554 } 555 _cancelEditing()556 public void _cancelEditing(){ 557 558 boolean bOK = false; 559 560 log.println("not ready because of i78701"); 561 562 tRes.tested("cancelEditing()", bOK); 563 564 } 565 _startEditingAtNode()566 public void _startEditingAtNode(){ 567 568 boolean bOK = false; 569 570 log.println("not ready because of i78701"); 571 572 tRes.tested("startEditingAtNode()", bOK); 573 574 } 575 _addTreeEditListener()576 public void _addTreeEditListener(){ 577 578 boolean bOK = true; 579 580 log.println("add EditListener 1...."); 581 oObj.addTreeEditListener(mTreeEditListener1); 582 583 log.println("add EditListener 2...."); 584 oObj.addTreeEditListener(mTreeEditListener2); 585 586 resetEditListener(); 587 588 try { 589 590 oObj.startEditingAtNode(mXNode); 591 } catch (com.sun.star.lang.IllegalArgumentException ex) { 592 log.println("ERROR: could not start editing at node: " + ex.toString()); 593 bOK = false; 594 } 595 596 log.println("not ready because of i78701"); 597 bOK = false; 598 599 600 tRes.tested("addTreeEditListener()", bOK); 601 602 } 603 _removeTreeEditListener()604 public void _removeTreeEditListener(){ 605 606 boolean bOK = false; 607 608 log.println("not ready because of i78701"); 609 610 tRes.tested("removeTreeEditListener()", bOK); 611 612 } 613 _DefaultExpandedGraphicURL()614 public void _DefaultExpandedGraphicURL(){ 615 616 boolean bOK = true; 617 618 String current = oObj.getDefaultExpandedGraphicURL(); 619 log.println("current DefaultExpandedGraphicURL: " + current); 620 621 String changeUrl = null; 622 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"; 626 627 log.println("try to set '" + changeUrl + "' as new DefaultExpandedGraphicURL"); 628 629 oObj.setDefaultExpandedGraphicURL(changeUrl); 630 631 String newUrl = oObj.getDefaultExpandedGraphicURL(); 632 633 log.println("new DefaultExpandedGraphicURL: " + newUrl); 634 635 bOK &= ! newUrl.equals(current); 636 637 tRes.tested("DefaultExpandedGraphicURL()", bOK); 638 639 } 640 _DefaultCollapsedGraphicURL()641 public void _DefaultCollapsedGraphicURL(){ 642 643 boolean bOK = true; 644 645 String current = oObj.getDefaultCollapsedGraphicURL(); 646 log.println("current DefaultCollapsedGraphicURL: " + current); 647 648 String changeUrl = null; 649 650 if (current.equals("private:graphicrepository/sd/res/triangle_right.png")) 651 changeUrl = "private:graphicrepository/sd/res/triangle_down.png"; 652 else changeUrl = "private:graphicrepository/sd/res/triangle_right.png"; 653 654 log.println("try to set '" + changeUrl + "' as new DefaultCollapsedGraphicURL"); 655 oObj.setDefaultCollapsedGraphicURL(changeUrl); 656 657 String newUrl = oObj.getDefaultCollapsedGraphicURL(); 658 659 log.println("new DefaultCollapsedGraphicURL: " + newUrl); 660 661 bOK &= ! newUrl.equals(current); 662 663 tRes.tested("DefaultCollapsedGraphicURL()", bOK); 664 } 665 } 666 667 668