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