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