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.view;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 import util.FormTools;
30 
31 import com.sun.star.awt.XControl;
32 import com.sun.star.awt.XControlModel;
33 import com.sun.star.drawing.XControlShape;
34 import com.sun.star.drawing.XDrawPage;
35 import com.sun.star.drawing.XDrawPageSupplier;
36 import com.sun.star.drawing.XDrawPagesSupplier;
37 import com.sun.star.drawing.XShape;
38 import com.sun.star.drawing.XShapes;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.view.XControlAccess;
42 
43 /**
44  * Testing <code>com.sun.star.view.XControlAccess</code>
45  * interface methods :
46  * <ul>
47  *  <li><code> getControl()</code></li>
48  * </ul> <p>
49  * This test needs the following object relations :
50  * <ul>
51  *  <li> <code>'DOCUMENT'</code> (of type <code>XComponent</code>):
52  *   the document, which controller is tested here. Is used
53  *   for adding a component (such as CommandButton) and obtaining
54  *   its control via tested interface. </li>
55  * <ul> <p>
56  * Test is <b> NOT </b> multithread compilant. <p>
57  * @see com.sun.star.view.XControlAccess
58  */
59 public class _XControlAccess extends MultiMethodTest {
60 
61     public XControlAccess oObj = null;
62 
63     /**
64      * Retrieves a document from relation, then using it adds
65      * a CommandButton to a document and obtains button model.
66      * After that button control is tried to get using the
67      * tested interface. <p>
68      * Has <b> OK </b> status if non <code>null</code> control
69      * is returned. <p>
70      * @throws StatusException If the relation was not found.
71      */
_getControl()72     public void _getControl(){
73         boolean bResult = true;
74         try {
75             XComponent oDoc = (XComponent)tEnv.getObjRelation("DOCUMENT");
76             if (oDoc == null) {
77                 throw new StatusException
78                     (Status.failed("NO 'DOCUMENT' ObjRelation!"));
79             }
80             Boolean isSheet = (Boolean) tEnv.getObjRelation("XControlAccess.isSheet");
81             XDrawPage oDP = null;
82             if (isSheet != null) {
83                 XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
84                 UnoRuntime.queryInterface(XDrawPagesSupplier.class, oDoc);
85                 oDP = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, oDPS.getDrawPages().getByIndex(0));
86             } else {
87 
88 
89             XDrawPageSupplier oDPS = (XDrawPageSupplier)
90                 UnoRuntime.queryInterface(XDrawPageSupplier.class, oDoc);
91             oDP = oDPS.getDrawPage();
92             }
93             XShapes shapes = (XShapes) UnoRuntime.queryInterface
94                 (XShapes.class, oDP);
95             XShape button = FormTools.createControlShape
96                 (oDoc, 100, 100, 10000, 50000, "CommandButton");
97             shapes.add(button);
98 
99             XControlModel CM = ((XControlShape)button).getControl();
100             log.println("Getting ControlModel "
101                 + ((CM == null) ? "FAILED" : "OK"));
102 
103             XControl oControl = oObj.getControl(CM);
104             log.println("Getting Control " + ((CM == null) ? "FAILED" : "OK"));
105 
106             bResult &= oControl != null;
107         } catch (com.sun.star.container.NoSuchElementException e) {
108             log.println("Exception occurred calling the method: " + e);
109             bResult = false;
110         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
111             log.println("Exception occurred calling the method: " + e);
112             bResult = false;
113         } catch (com.sun.star.lang.WrappedTargetException e) {
114             log.println("Exception occurred calling the method: " + e);
115             bResult = false;
116         }
117         tRes.tested("getControl()", bResult);
118     }
119 }
120 
121