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 package mod._toolkit;
28 
29 import com.sun.star.awt.XControl;
30 import com.sun.star.awt.XControlModel;
31 import com.sun.star.beans.XPropertySet;
32 import com.sun.star.container.XNameContainer;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
36 
37 import java.io.PrintWriter;
38 
39 import lib.StatusException;
40 import lib.TestCase;
41 import lib.TestEnvironment;
42 import lib.TestParameters;
43 
44 import util.utils;
45 
46 
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.awt.UnoControlDialogModel</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 *  <li> <code>com::sun::star::awt::UnoControlDialogModel</code></li>
53 *  <li> <code>com::sun::star::io::XPersistObject</code></li>
54 *  <li> <code>com::sun::star::lang::XComponent</code></li>
55 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
56 *  <li> <code>com::sun::star::beans::XMultiPropertySet</code></li>
57 * </ul>
58 * This object test <b> is NOT </b> designed to be run in several
59 * threads concurently.
60 * @see com.sun.star.awt.UnoControlDialogModel
61 * @see com.sun.star.io.XPersistObject
62 * @see com.sun.star.lang.XComponent
63 * @see com.sun.star.beans.XPropertySet
64 * @see com.sun.star.beans.XMultiPropertySet
65 * @see ifc.awt._UnoControlDialogModel
66 * @see ifc.io._XPersistObject
67 * @see ifc.lang._XComponent
68 * @see ifc.beans._XPropertySet
69 * @see ifc.beans._XMultiPropertySet
70 */
71 public class UnoControlDialogModel extends TestCase {
72     /**
73     * Creating a Testenvironment for the interfaces to be tested.
74     * Creates an instance of the service
75     * <code>com.sun.star.awt.UnoControlDialogModel</code>.
76     *     Object relations created :
77     * <ul>
78     *  <li> <code>'OBJNAME'</code> for
79     *      {@link ifc.io._XPersistObject} </li>
80     * </ul>
81     */
82     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
83                                                                  PrintWriter log) {
84         XInterface oObj = null;
85         XInterface dialogModel = null;
86         String _buttonName = "MyButton";
87         String _labelName = "MyLabel";
88         String _labelPrefix = "MyLabelPrefix";
89         XMultiServiceFactory xMultiServiceFactory = null;
90 
91         try {
92             dialogModel = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
93                                   "com.sun.star.awt.UnoControlDialogModel");
94 
95             // create the dialog model and set the properties
96             XPropertySet xPSetDialog = (XPropertySet) UnoRuntime.queryInterface(
97                                                XPropertySet.class, dialogModel);
98             xPSetDialog.setPropertyValue("PositionX", new Integer(100));
99             xPSetDialog.setPropertyValue("PositionY", new Integer(100));
100             xPSetDialog.setPropertyValue("Width", new Integer(150));
101             xPSetDialog.setPropertyValue("Height", new Integer(100));
102             xPSetDialog.setPropertyValue("Title",
103                                          new String("Runtime Dialog Demo"));
104 
105 
106             // get the service manager from the dialog model
107             xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
108                                            XMultiServiceFactory.class,
109                                            dialogModel);
110 
111             // create the button model and set the properties
112             Object buttonModel = xMultiServiceFactory.createInstance(
113                                          "com.sun.star.awt.UnoControlButtonModel");
114             XPropertySet xPSetButton = (XPropertySet) UnoRuntime.queryInterface(
115                                                XPropertySet.class, buttonModel);
116             xPSetButton.setPropertyValue("PositionX", new Integer(50));
117             xPSetButton.setPropertyValue("PositionY", new Integer(30));
118             xPSetButton.setPropertyValue("Width", new Integer(50));
119             xPSetButton.setPropertyValue("Height", new Integer(14));
120             xPSetButton.setPropertyValue("Name", _buttonName);
121             xPSetButton.setPropertyValue("TabIndex", new Short((short) 0));
122             xPSetButton.setPropertyValue("Label", new String("Click Me"));
123 
124             // create the label model and set the properties
125             Object labelModel = xMultiServiceFactory.createInstance(
126                                         "com.sun.star.awt.UnoControlFixedTextModel");
127             XPropertySet xPSetLabel = (XPropertySet) UnoRuntime.queryInterface(
128                                               XPropertySet.class, labelModel);
129             xPSetLabel.setPropertyValue("PositionX", new Integer(40));
130             xPSetLabel.setPropertyValue("PositionY", new Integer(60));
131             xPSetLabel.setPropertyValue("Width", new Integer(100));
132             xPSetLabel.setPropertyValue("Height", new Integer(14));
133             xPSetLabel.setPropertyValue("Name", _labelName);
134             xPSetLabel.setPropertyValue("TabIndex", new Short((short) 1));
135             xPSetLabel.setPropertyValue("Label", _labelPrefix);
136 
137             // insert the control models into the dialog model
138             XNameContainer xNameCont = (XNameContainer) UnoRuntime.queryInterface(
139                                                XNameContainer.class,
140                                                dialogModel);
141             xNameCont.insertByName(_buttonName, buttonModel);
142             xNameCont.insertByName(_labelName, labelModel);
143 
144             // create the dialog control and set the model
145             XControl dialog = (XControl) UnoRuntime.queryInterface(
146                                       XControl.class,
147                                       ((XMultiServiceFactory) Param.getMSF()).createInstance(
148                                               "com.sun.star.awt.UnoControlDialog"));
149             XControl xControl = (XControl) UnoRuntime.queryInterface(
150                                         XControl.class, dialog);
151             XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface(
152                                                   XControlModel.class,
153                                                   dialogModel);
154             xControl.setModel(xControlModel);
155         } catch (Exception e) {
156             throw new StatusException("Could no create test object", e);
157         }
158 
159         oObj = dialogModel;
160 
161         log.println("creating a new environment for object");
162 
163         XMultiServiceFactory oMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
164                                             XMultiServiceFactory.class, oObj);
165 
166         TestEnvironment tEnv = new TestEnvironment(oObj);
167 
168         try {
169             // XNameReplace
170             tEnv.addObjRelation("INSTANCE1",
171                                 xMultiServiceFactory.createInstance(
172                                         "com.sun.star.awt.UnoControlFixedTextModel"));
173 
174 
175             //XContainer
176             tEnv.addObjRelation("INSTANCE",
177                                 xMultiServiceFactory.createInstance(
178                                         "com.sun.star.awt.UnoControlFixedTextModel"));
179         } catch (com.sun.star.uno.Exception e) {
180             log.println("Could not add object relations 'INSTANCEn'");
181             e.printStackTrace(log);
182         }
183 
184         tEnv.addObjRelation("OBJNAME", "stardiv.vcl.controlmodel.Dialog");
185         System.out.println("ImplementationName: " + utils.getImplName(oObj));
186 
187         return tEnv;
188     } // finish method getTestEnvironment
189 }