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