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