1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package mod._toolkit; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.awt.XControl; 30*cdf0e10cSrcweir import com.sun.star.awt.XControlModel; 31*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 32*cdf0e10cSrcweir import com.sun.star.container.XNameContainer; 33*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 34*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 35*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir import java.io.PrintWriter; 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir import lib.StatusException; 40*cdf0e10cSrcweir import lib.TestCase; 41*cdf0e10cSrcweir import lib.TestEnvironment; 42*cdf0e10cSrcweir import lib.TestParameters; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir import util.utils; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir /** 48*cdf0e10cSrcweir * Test for object which is represented by service 49*cdf0e10cSrcweir * <code>com.sun.star.awt.UnoControlDialogModel</code>. <p> 50*cdf0e10cSrcweir * Object implements the following interfaces : 51*cdf0e10cSrcweir * <ul> 52*cdf0e10cSrcweir * <li> <code>com::sun::star::awt::UnoControlDialogModel</code></li> 53*cdf0e10cSrcweir * <li> <code>com::sun::star::io::XPersistObject</code></li> 54*cdf0e10cSrcweir * <li> <code>com::sun::star::lang::XComponent</code></li> 55*cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XPropertySet</code></li> 56*cdf0e10cSrcweir * <li> <code>com::sun::star::beans::XMultiPropertySet</code></li> 57*cdf0e10cSrcweir * </ul> 58*cdf0e10cSrcweir * This object test <b> is NOT </b> designed to be run in several 59*cdf0e10cSrcweir * threads concurently. 60*cdf0e10cSrcweir * @see com.sun.star.awt.UnoControlDialogModel 61*cdf0e10cSrcweir * @see com.sun.star.io.XPersistObject 62*cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 63*cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 64*cdf0e10cSrcweir * @see com.sun.star.beans.XMultiPropertySet 65*cdf0e10cSrcweir * @see ifc.awt._UnoControlDialogModel 66*cdf0e10cSrcweir * @see ifc.io._XPersistObject 67*cdf0e10cSrcweir * @see ifc.lang._XComponent 68*cdf0e10cSrcweir * @see ifc.beans._XPropertySet 69*cdf0e10cSrcweir * @see ifc.beans._XMultiPropertySet 70*cdf0e10cSrcweir */ 71*cdf0e10cSrcweir public class UnoControlDialogModel extends TestCase { 72*cdf0e10cSrcweir /** 73*cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 74*cdf0e10cSrcweir * Creates an instance of the service 75*cdf0e10cSrcweir * <code>com.sun.star.awt.UnoControlDialogModel</code>. 76*cdf0e10cSrcweir * Object relations created : 77*cdf0e10cSrcweir * <ul> 78*cdf0e10cSrcweir * <li> <code>'OBJNAME'</code> for 79*cdf0e10cSrcweir * {@link ifc.io._XPersistObject} </li> 80*cdf0e10cSrcweir * </ul> 81*cdf0e10cSrcweir */ 82*cdf0e10cSrcweir protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 83*cdf0e10cSrcweir PrintWriter log) { 84*cdf0e10cSrcweir XInterface oObj = null; 85*cdf0e10cSrcweir XInterface dialogModel = null; 86*cdf0e10cSrcweir String _buttonName = "MyButton"; 87*cdf0e10cSrcweir String _labelName = "MyLabel"; 88*cdf0e10cSrcweir String _labelPrefix = "MyLabelPrefix"; 89*cdf0e10cSrcweir XMultiServiceFactory xMultiServiceFactory = null; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir try { 92*cdf0e10cSrcweir dialogModel = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance( 93*cdf0e10cSrcweir "com.sun.star.awt.UnoControlDialogModel"); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // create the dialog model and set the properties 96*cdf0e10cSrcweir XPropertySet xPSetDialog = (XPropertySet) UnoRuntime.queryInterface( 97*cdf0e10cSrcweir XPropertySet.class, dialogModel); 98*cdf0e10cSrcweir xPSetDialog.setPropertyValue("PositionX", new Integer(100)); 99*cdf0e10cSrcweir xPSetDialog.setPropertyValue("PositionY", new Integer(100)); 100*cdf0e10cSrcweir xPSetDialog.setPropertyValue("Width", new Integer(150)); 101*cdf0e10cSrcweir xPSetDialog.setPropertyValue("Height", new Integer(100)); 102*cdf0e10cSrcweir xPSetDialog.setPropertyValue("Title", 103*cdf0e10cSrcweir new String("Runtime Dialog Demo")); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // get the service manager from the dialog model 107*cdf0e10cSrcweir xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( 108*cdf0e10cSrcweir XMultiServiceFactory.class, 109*cdf0e10cSrcweir dialogModel); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // create the button model and set the properties 112*cdf0e10cSrcweir Object buttonModel = xMultiServiceFactory.createInstance( 113*cdf0e10cSrcweir "com.sun.star.awt.UnoControlButtonModel"); 114*cdf0e10cSrcweir XPropertySet xPSetButton = (XPropertySet) UnoRuntime.queryInterface( 115*cdf0e10cSrcweir XPropertySet.class, buttonModel); 116*cdf0e10cSrcweir xPSetButton.setPropertyValue("PositionX", new Integer(50)); 117*cdf0e10cSrcweir xPSetButton.setPropertyValue("PositionY", new Integer(30)); 118*cdf0e10cSrcweir xPSetButton.setPropertyValue("Width", new Integer(50)); 119*cdf0e10cSrcweir xPSetButton.setPropertyValue("Height", new Integer(14)); 120*cdf0e10cSrcweir xPSetButton.setPropertyValue("Name", _buttonName); 121*cdf0e10cSrcweir xPSetButton.setPropertyValue("TabIndex", new Short((short) 0)); 122*cdf0e10cSrcweir xPSetButton.setPropertyValue("Label", new String("Click Me")); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir // create the label model and set the properties 125*cdf0e10cSrcweir Object labelModel = xMultiServiceFactory.createInstance( 126*cdf0e10cSrcweir "com.sun.star.awt.UnoControlFixedTextModel"); 127*cdf0e10cSrcweir XPropertySet xPSetLabel = (XPropertySet) UnoRuntime.queryInterface( 128*cdf0e10cSrcweir XPropertySet.class, labelModel); 129*cdf0e10cSrcweir xPSetLabel.setPropertyValue("PositionX", new Integer(40)); 130*cdf0e10cSrcweir xPSetLabel.setPropertyValue("PositionY", new Integer(60)); 131*cdf0e10cSrcweir xPSetLabel.setPropertyValue("Width", new Integer(100)); 132*cdf0e10cSrcweir xPSetLabel.setPropertyValue("Height", new Integer(14)); 133*cdf0e10cSrcweir xPSetLabel.setPropertyValue("Name", _labelName); 134*cdf0e10cSrcweir xPSetLabel.setPropertyValue("TabIndex", new Short((short) 1)); 135*cdf0e10cSrcweir xPSetLabel.setPropertyValue("Label", _labelPrefix); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // insert the control models into the dialog model 138*cdf0e10cSrcweir XNameContainer xNameCont = (XNameContainer) UnoRuntime.queryInterface( 139*cdf0e10cSrcweir XNameContainer.class, 140*cdf0e10cSrcweir dialogModel); 141*cdf0e10cSrcweir xNameCont.insertByName(_buttonName, buttonModel); 142*cdf0e10cSrcweir xNameCont.insertByName(_labelName, labelModel); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // create the dialog control and set the model 145*cdf0e10cSrcweir XControl dialog = (XControl) UnoRuntime.queryInterface( 146*cdf0e10cSrcweir XControl.class, 147*cdf0e10cSrcweir ((XMultiServiceFactory) Param.getMSF()).createInstance( 148*cdf0e10cSrcweir "com.sun.star.awt.UnoControlDialog")); 149*cdf0e10cSrcweir XControl xControl = (XControl) UnoRuntime.queryInterface( 150*cdf0e10cSrcweir XControl.class, dialog); 151*cdf0e10cSrcweir XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface( 152*cdf0e10cSrcweir XControlModel.class, 153*cdf0e10cSrcweir dialogModel); 154*cdf0e10cSrcweir xControl.setModel(xControlModel); 155*cdf0e10cSrcweir } catch (Exception e) { 156*cdf0e10cSrcweir throw new StatusException("Could no create test object", e); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir oObj = dialogModel; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir log.println("creating a new environment for object"); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir XMultiServiceFactory oMSF = (XMultiServiceFactory) UnoRuntime.queryInterface( 164*cdf0e10cSrcweir XMultiServiceFactory.class, oObj); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment(oObj); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir try { 169*cdf0e10cSrcweir // XNameReplace 170*cdf0e10cSrcweir tEnv.addObjRelation("INSTANCE1", 171*cdf0e10cSrcweir xMultiServiceFactory.createInstance( 172*cdf0e10cSrcweir "com.sun.star.awt.UnoControlFixedTextModel")); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir //XContainer 176*cdf0e10cSrcweir tEnv.addObjRelation("INSTANCE", 177*cdf0e10cSrcweir xMultiServiceFactory.createInstance( 178*cdf0e10cSrcweir "com.sun.star.awt.UnoControlFixedTextModel")); 179*cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 180*cdf0e10cSrcweir log.println("Could not add object relations 'INSTANCEn'"); 181*cdf0e10cSrcweir e.printStackTrace(log); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir tEnv.addObjRelation("OBJNAME", "stardiv.vcl.controlmodel.Dialog"); 185*cdf0e10cSrcweir System.out.println("ImplementationName: " + utils.getImplName(oObj)); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir return tEnv; 188*cdf0e10cSrcweir } // finish method getTestEnvironment 189*cdf0e10cSrcweir }