1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.view; 29 30 import lib.MultiMethodTest; 31 import lib.Status; 32 import lib.StatusException; 33 import util.FormTools; 34 35 import com.sun.star.awt.XControl; 36 import com.sun.star.awt.XControlModel; 37 import com.sun.star.drawing.XControlShape; 38 import com.sun.star.drawing.XDrawPage; 39 import com.sun.star.drawing.XDrawPageSupplier; 40 import com.sun.star.drawing.XDrawPagesSupplier; 41 import com.sun.star.drawing.XShape; 42 import com.sun.star.drawing.XShapes; 43 import com.sun.star.lang.XComponent; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.view.XControlAccess; 46 47 /** 48 * Testing <code>com.sun.star.view.XControlAccess</code> 49 * interface methods : 50 * <ul> 51 * <li><code> getControl()</code></li> 52 * </ul> <p> 53 * This test needs the following object relations : 54 * <ul> 55 * <li> <code>'DOCUMENT'</code> (of type <code>XComponent</code>): 56 * the document, which controller is tested here. Is used 57 * for adding a component (such as CommandButton) and obtaining 58 * its control via tested interface. </li> 59 * <ul> <p> 60 * Test is <b> NOT </b> multithread compilant. <p> 61 * @see com.sun.star.view.XControlAccess 62 */ 63 public class _XControlAccess extends MultiMethodTest { 64 65 public XControlAccess oObj = null; 66 67 /** 68 * Retrieves a document from relation, then using it adds 69 * a CommandButton to a document and obtains button model. 70 * After that button control is tried to get using the 71 * tested interface. <p> 72 * Has <b> OK </b> status if non <code>null</code> control 73 * is returned. <p> 74 * @throws StatusException If the relation was not found. 75 */ 76 public void _getControl(){ 77 boolean bResult = true; 78 try { 79 XComponent oDoc = (XComponent)tEnv.getObjRelation("DOCUMENT"); 80 if (oDoc == null) { 81 throw new StatusException 82 (Status.failed("NO 'DOCUMENT' ObjRelation!")); 83 } 84 Boolean isSheet = (Boolean) tEnv.getObjRelation("XControlAccess.isSheet"); 85 XDrawPage oDP = null; 86 if (isSheet != null) { 87 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 88 UnoRuntime.queryInterface(XDrawPagesSupplier.class, oDoc); 89 oDP = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, oDPS.getDrawPages().getByIndex(0)); 90 } else { 91 92 93 XDrawPageSupplier oDPS = (XDrawPageSupplier) 94 UnoRuntime.queryInterface(XDrawPageSupplier.class, oDoc); 95 oDP = oDPS.getDrawPage(); 96 } 97 XShapes shapes = (XShapes) UnoRuntime.queryInterface 98 (XShapes.class, oDP); 99 XShape button = FormTools.createControlShape 100 (oDoc, 100, 100, 10000, 50000, "CommandButton"); 101 shapes.add(button); 102 103 XControlModel CM = ((XControlShape)button).getControl(); 104 log.println("Getting ControlModel " 105 + ((CM == null) ? "FAILED" : "OK")); 106 107 XControl oControl = oObj.getControl(CM); 108 log.println("Getting Control " + ((CM == null) ? "FAILED" : "OK")); 109 110 bResult &= oControl != null; 111 } catch (com.sun.star.container.NoSuchElementException e) { 112 log.println("Exception occured calling the method: " + e); 113 bResult = false; 114 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 115 log.println("Exception occured calling the method: " + e); 116 bResult = false; 117 } catch (com.sun.star.lang.WrappedTargetException e) { 118 log.println("Exception occured calling the method: " + e); 119 bResult = false; 120 } 121 tRes.tested("getControl()", bResult); 122 } 123 } 124 125