1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.view;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir import util.FormTools;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir import com.sun.star.awt.XControl;
32cdf0e10cSrcweir import com.sun.star.awt.XControlModel;
33cdf0e10cSrcweir import com.sun.star.drawing.XControlShape;
34cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
35cdf0e10cSrcweir import com.sun.star.drawing.XDrawPageSupplier;
36cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier;
37cdf0e10cSrcweir import com.sun.star.drawing.XShape;
38cdf0e10cSrcweir import com.sun.star.drawing.XShapes;
39cdf0e10cSrcweir import com.sun.star.lang.XComponent;
40cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
41cdf0e10cSrcweir import com.sun.star.view.XControlAccess;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir /**
44cdf0e10cSrcweir  * Testing <code>com.sun.star.view.XControlAccess</code>
45cdf0e10cSrcweir  * interface methods :
46cdf0e10cSrcweir  * <ul>
47cdf0e10cSrcweir  *  <li><code> getControl()</code></li>
48cdf0e10cSrcweir  * </ul> <p>
49cdf0e10cSrcweir  * This test needs the following object relations :
50cdf0e10cSrcweir  * <ul>
51cdf0e10cSrcweir  *  <li> <code>'DOCUMENT'</code> (of type <code>XComponent</code>):
52cdf0e10cSrcweir  *   the document, which controller is tested here. Is used
53cdf0e10cSrcweir  *   for adding a component (such as CommandButton) and obtaining
54cdf0e10cSrcweir  *   its control via tested interface. </li>
55cdf0e10cSrcweir  * <ul> <p>
56cdf0e10cSrcweir  * Test is <b> NOT </b> multithread compilant. <p>
57cdf0e10cSrcweir  * @see com.sun.star.view.XControlAccess
58cdf0e10cSrcweir  */
59cdf0e10cSrcweir public class _XControlAccess extends MultiMethodTest {
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     public XControlAccess oObj = null;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     /**
64cdf0e10cSrcweir      * Retrieves a document from relation, then using it adds
65cdf0e10cSrcweir      * a CommandButton to a document and obtains button model.
66cdf0e10cSrcweir      * After that button control is tried to get using the
67cdf0e10cSrcweir      * tested interface. <p>
68cdf0e10cSrcweir      * Has <b> OK </b> status if non <code>null</code> control
69cdf0e10cSrcweir      * is returned. <p>
70cdf0e10cSrcweir      * @throws StatusException If the relation was not found.
71cdf0e10cSrcweir      */
_getControl()72cdf0e10cSrcweir     public void _getControl(){
73cdf0e10cSrcweir         boolean bResult = true;
74cdf0e10cSrcweir         try {
75cdf0e10cSrcweir             XComponent oDoc = (XComponent)tEnv.getObjRelation("DOCUMENT");
76cdf0e10cSrcweir             if (oDoc == null) {
77cdf0e10cSrcweir                 throw new StatusException
78cdf0e10cSrcweir                     (Status.failed("NO 'DOCUMENT' ObjRelation!"));
79cdf0e10cSrcweir             }
80cdf0e10cSrcweir             Boolean isSheet = (Boolean) tEnv.getObjRelation("XControlAccess.isSheet");
81cdf0e10cSrcweir             XDrawPage oDP = null;
82cdf0e10cSrcweir             if (isSheet != null) {
83cdf0e10cSrcweir                 XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
84cdf0e10cSrcweir                 UnoRuntime.queryInterface(XDrawPagesSupplier.class, oDoc);
85cdf0e10cSrcweir                 oDP = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, oDPS.getDrawPages().getByIndex(0));
86cdf0e10cSrcweir             } else {
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             XDrawPageSupplier oDPS = (XDrawPageSupplier)
90cdf0e10cSrcweir                 UnoRuntime.queryInterface(XDrawPageSupplier.class, oDoc);
91cdf0e10cSrcweir             oDP = oDPS.getDrawPage();
92cdf0e10cSrcweir             }
93cdf0e10cSrcweir             XShapes shapes = (XShapes) UnoRuntime.queryInterface
94cdf0e10cSrcweir                 (XShapes.class, oDP);
95cdf0e10cSrcweir             XShape button = FormTools.createControlShape
96cdf0e10cSrcweir                 (oDoc, 100, 100, 10000, 50000, "CommandButton");
97cdf0e10cSrcweir             shapes.add(button);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir             XControlModel CM = ((XControlShape)button).getControl();
100cdf0e10cSrcweir             log.println("Getting ControlModel "
101cdf0e10cSrcweir                 + ((CM == null) ? "FAILED" : "OK"));
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             XControl oControl = oObj.getControl(CM);
104cdf0e10cSrcweir             log.println("Getting Control " + ((CM == null) ? "FAILED" : "OK"));
105cdf0e10cSrcweir 
106cdf0e10cSrcweir             bResult &= oControl != null;
107cdf0e10cSrcweir         } catch (com.sun.star.container.NoSuchElementException e) {
108cdf0e10cSrcweir             log.println("Exception occured calling the method: " + e);
109cdf0e10cSrcweir             bResult = false;
110cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
111cdf0e10cSrcweir             log.println("Exception occured calling the method: " + e);
112cdf0e10cSrcweir             bResult = false;
113cdf0e10cSrcweir         } catch (com.sun.star.lang.WrappedTargetException e) {
114cdf0e10cSrcweir             log.println("Exception occured calling the method: " + e);
115cdf0e10cSrcweir             bResult = false;
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir         tRes.tested("getControl()", bResult);
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121