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 package mod._toolkit;
24 
25 import com.sun.star.awt.PosSize;
26 import com.sun.star.awt.XControl;
27 import com.sun.star.awt.XControlContainer;
28 import com.sun.star.awt.XControlModel;
29 import com.sun.star.awt.XDevice;
30 import com.sun.star.awt.XGraphics;
31 import com.sun.star.awt.XTabController;
32 import com.sun.star.awt.XToolkit;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.awt.XWindowPeer;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 import java.io.PrintWriter;
41 
42 import lib.StatusException;
43 import lib.TestCase;
44 import lib.TestEnvironment;
45 import lib.TestParameters;
46 
47 import util.SOfficeFactory;
48 
49 
50 /**
51 * Test for object which is represented by service
52 * <code>com.sun.star.awt.UnoControlDialog</code>. <p>
53 * Object implements the following interfaces :
54 * <ul>
55 *  <li> <code>com::sun::star::lang::XComponent</code></li>
56 *  <li> <code>com::sun::star::awt::XWindow</code></li>
57 *  <li> <code>com::sun::star::awt::XDialog</code></li>
58 *  <li> <code>com::sun::star::awt::XControl</code></li>
59 *  <li> <code>com::sun::star::awt::XTopWindow</code></li>
60 *  <li> <code>com::sun::star::awt::XControlContainer</code></li>
61 *  <li> <code>com::sun::star::awt::XView</code></li>
62 * </ul>
63 * This object test <b> is NOT </b> designed to be run in several
64 * threads concurently.
65 * @see com.sun.star.lang.XComponent
66 * @see com.sun.star.awt.XWindow
67 * @see com.sun.star.awt.XDialog
68 * @see com.sun.star.awt.XControl
69 * @see com.sun.star.awt.XTopWindow
70 * @see com.sun.star.awt.XControlContainer
71 * @see com.sun.star.awt.XView
72 * @see ifc.lang._XComponent
73 * @see ifc.awt._XWindow
74 * @see ifc.awt._XDialog
75 * @see ifc.awt._XControl
76 * @see ifc.awt._XTopWindow
77 * @see ifc.awt._XControlContainer
78 * @see ifc.awt._XView
79 */
80 public class UnoControlDialog extends TestCase {
81     private static XWindow xWinDlg = null;
82     private static XTextDocument xTextDoc;
83 
84     /**
85     * Creating a Testenvironment for the interfaces to be tested.
86     * Creates a Dialog Control and Model instance defines Model
87     * for Control, adds to Dialog a button, sets its size and
88     * sets the dialog visible. <p>
89     */
90     public synchronized TestEnvironment createTestEnvironment(TestParameters Param,
91                                                               PrintWriter log) {
92         XInterface oObj = null;
93         XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
94         XControlModel dlgModel = null;
95 
96         XWindowPeer the_win = null;
97         XToolkit the_kit = null;
98         XDevice aDevice = null;
99         XGraphics aGraphic = null;
100 
101         XControl butControl = null;
102         XControl butControl1 = null;
103         XControl butControl2 = null;
104         XTabController tabControl1 = null;
105         XTabController tabControl2 = null;
106 
107         XControlContainer ctrlCont = null;
108 
109         if (xWinDlg != null) {
110             xWinDlg.dispose();
111         }
112 
113         try {
114             dlgModel = (XControlModel) UnoRuntime.queryInterface(
115                                XControlModel.class,
116                                xMSF.createInstance(
117                                        "com.sun.star.awt.UnoControlDialogModel"));
118 
119             XControl dlgControl = (XControl) UnoRuntime.queryInterface(
120                                           XControl.class,
121                                           xMSF.createInstance(
122                                                   "com.sun.star.awt.UnoControlDialog"));
123 
124             dlgControl.setModel(dlgModel);
125 
126             XControlModel butModel = (XControlModel) UnoRuntime.queryInterface(
127                                              XControlModel.class,
128                                              xMSF.createInstance(
129                                                      "com.sun.star.awt.UnoControlButtonModel"));
130 
131             butControl = (XControl) UnoRuntime.queryInterface(XControl.class,
132                                                               xMSF.createInstance(
133                                                                       "com.sun.star.awt.UnoControlButton"));
134 
135             butControl.setModel(butModel);
136 
137 
138             // creating additional controls for XUnoControlContainer
139             tabControl1 = (XTabController) UnoRuntime.queryInterface(
140                                   XTabController.class,
141                                   xMSF.createInstance(
142                                           "com.sun.star.awt.TabController"));
143 
144             tabControl2 = (XTabController) UnoRuntime.queryInterface(
145                                   XTabController.class,
146                                   xMSF.createInstance(
147                                           "com.sun.star.awt.TabController"));
148 
149 
150             // creating additional controls for XControlContainer
151             butModel = (XControlModel) UnoRuntime.queryInterface(
152                                XControlModel.class,
153                                xMSF.createInstance(
154                                        "com.sun.star.awt.UnoControlButtonModel"));
155 
156             butControl1 = (XControl) UnoRuntime.queryInterface(XControl.class,
157                                                                xMSF.createInstance(
158                                                                        "com.sun.star.awt.UnoControlButton"));
159 
160             butControl1.setModel(butModel);
161 
162             butModel = (XControlModel) UnoRuntime.queryInterface(
163                                XControlModel.class,
164                                xMSF.createInstance(
165                                        "com.sun.star.awt.UnoControlButtonModel"));
166 
167             butControl2 = (XControl) UnoRuntime.queryInterface(XControl.class,
168                                                                xMSF.createInstance(
169                                                                        "com.sun.star.awt.UnoControlButton"));
170 
171             butControl2.setModel(butModel);
172 
173             ctrlCont = (XControlContainer) UnoRuntime.queryInterface(
174                                XControlContainer.class, dlgControl);
175 
176             xWinDlg = (XWindow) UnoRuntime.queryInterface(XWindow.class,
177                                                           dlgControl);
178 
179             xWinDlg.setVisible(true);
180 
181             xWinDlg.setPosSize(10, 10, 220, 110, PosSize.SIZE);
182 
183             the_win = dlgControl.getPeer();
184             the_kit = the_win.getToolkit();
185             aDevice = the_kit.createScreenCompatibleDevice(220, 220);
186             aGraphic = aDevice.createGraphics();
187 
188             oObj = dlgControl;
189         } catch (com.sun.star.uno.Exception e) {
190             log.println("Error creating dialog :");
191             e.printStackTrace(log);
192         }
193 
194         log.println("creating a new environment for object");
195 
196         TestEnvironment tEnv = new TestEnvironment(oObj);
197 
198 
199         //Adding ObjRelation for XView
200         tEnv.addObjRelation("GRAPHICS", aGraphic);
201 
202 
203         //Adding ObjRelation for XControl
204         tEnv.addObjRelation("CONTEXT", dlgModel);
205         tEnv.addObjRelation("WINPEER", the_win);
206         tEnv.addObjRelation("TOOLKIT", the_kit);
207         tEnv.addObjRelation("MODEL", dlgModel);
208 
209         tEnv.addObjRelation("INSTANCE", butControl);
210         tEnv.addObjRelation("XContainer.Container", ctrlCont);
211 
212 
213         // adding relations for XUnoControlContainer
214         tEnv.addObjRelation("TABCONTROL1", tabControl1);
215         tEnv.addObjRelation("TABCONTROL2", tabControl2);
216 
217 
218         // adding relations for XControlContainer
219         tEnv.addObjRelation("CONTROL1", butControl1);
220         tEnv.addObjRelation("CONTROL2", butControl2);
221 
222         XWindow forObjRel = xTextDoc.getCurrentController().getFrame()
223                                     .getComponentWindow();
224         tEnv.addObjRelation("XWindow.AnotherWindow", forObjRel);
225 
226         return tEnv;
227     } // finish method getTestEnvironment
228 
229     protected void cleanup(TestParameters tParam, PrintWriter log) {
230         log.println("Disposing dialog ...");
231         xWinDlg.dispose();
232         log.println("    disposing xTextDoc ");
233 
234         util.DesktopTools.closeDoc(xTextDoc);
235     }
236 
237     protected void initialize(TestParameters tParam, PrintWriter log) {
238         SOfficeFactory SOF = SOfficeFactory.getFactory(
239                                      (XMultiServiceFactory) tParam.getMSF());
240 
241         try {
242             log.println("creating a textdocument");
243             xTextDoc = SOF.createTextDoc(null);
244         } catch (com.sun.star.uno.Exception e) {
245             // Some exception occures.FAILED
246             e.printStackTrace(log);
247             throw new StatusException("Couldn't create document", e);
248         }
249     }
250 }
251