merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _forms / OListBoxControl.java
blobf598c9bed01017f426976af83366095e1a1304e6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OListBoxControl.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._forms;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.FormTools;
40 import util.SOfficeFactory;
41 import util.WriterTools;
43 import com.sun.star.awt.XControlModel;
44 import com.sun.star.awt.XDevice;
45 import com.sun.star.awt.XGraphics;
46 import com.sun.star.awt.XListBox;
47 import com.sun.star.awt.XToolkit;
48 import com.sun.star.awt.XWindow;
49 import com.sun.star.awt.XWindowPeer;
50 import com.sun.star.drawing.XControlShape;
51 import com.sun.star.drawing.XShape;
52 import com.sun.star.lang.XMultiServiceFactory;
53 import com.sun.star.text.XTextDocument;
54 import com.sun.star.uno.UnoRuntime;
55 import com.sun.star.uno.XInterface;
56 import com.sun.star.util.XCloseable;
57 import com.sun.star.view.XControlAccess;
59 public class OListBoxControl extends TestCase {
61 XTextDocument xTextDoc;
63 protected void initialize ( TestParameters Param, PrintWriter log) {
64 SOfficeFactory SOF = SOfficeFactory.getFactory( ((XMultiServiceFactory) Param.getMSF()) );
66 try {
67 log.println( "creating a textdocument" );
68 xTextDoc = SOF.createTextDoc( null );
69 } catch ( com.sun.star.uno.Exception e ) {
70 // Some exception occures.FAILED
71 e.printStackTrace( log );
72 throw new StatusException( "Couldn't create document", e );
76 protected void cleanup(TestParameters tParam, PrintWriter log) {
77 log.println(" disposing xTextDoc ");
79 try {
80 XCloseable closer = (XCloseable) UnoRuntime.queryInterface(
81 XCloseable.class, xTextDoc);
82 closer.close(true);
83 } catch (com.sun.star.util.CloseVetoException e) {
84 log.println("couldn't close document");
85 } catch (com.sun.star.lang.DisposedException e) {
86 log.println("couldn't close document");
90 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
91 XInterface oObj = null;
92 Object anotherCtrl = null ;
93 XWindowPeer the_win = null;
94 XToolkit the_kit = null;
95 XDevice aDevice = null;
96 XGraphics aGraphic = null;
97 //Insert a ControlShape and get the ControlModel
98 XControlShape aShape = FormTools.createControlShape(
99 xTextDoc,3000,4500,15000,10000,"ListBox");
101 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
103 XControlModel the_Model = aShape.getControl();
105 XControlShape aShape2 = FormTools.createControlShape(
106 xTextDoc,3000,4500,5000,10000,"TextField");
108 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape2);
110 XControlModel the_Model2 = aShape2.getControl();
112 //Try to query XControlAccess
113 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
114 XControlAccess.class,xTextDoc.getCurrentController());
116 //now get the OListBoxControl
117 try {
118 oObj = the_access.getControl(the_Model);
119 anotherCtrl = the_access.getControl(the_Model2);
120 the_win = the_access.getControl(the_Model).getPeer();
121 the_kit = the_win.getToolkit();
122 aDevice = the_kit.createScreenCompatibleDevice(200,200);
123 aGraphic = aDevice.createGraphics();
124 } catch (Exception e) {
125 log.println("Couldn't get OListBoxControl");
126 e.printStackTrace(log);
127 throw new StatusException("Couldn't get OListBoxControl", e );
130 log.println( "creating a new environment for OListBoxControl object" );
131 TestEnvironment tEnv = new TestEnvironment( oObj );
133 //Adding ObjRelation for XView
134 tEnv.addObjRelation("GRAPHICS",aGraphic);
136 //Adding ObjRelation for XControl
137 tEnv.addObjRelation("CONTEXT",xTextDoc);
138 tEnv.addObjRelation("WINPEER",the_win);
139 tEnv.addObjRelation("TOOLKIT",the_kit);
140 tEnv.addObjRelation("MODEL",the_Model);
142 // Adding relation for XItemListener
143 ifc.awt._XItemListener.TestItemListener listener =
144 new ifc.awt._XItemListener.TestItemListener() ;
145 final XListBox box = (XListBox) UnoRuntime.queryInterface(XListBox.class, oObj) ;
146 box.addItemListener(listener) ;
147 tEnv.addObjRelation("TestItemListener", listener) ;
149 // Adding relation for XWindow
150 XWindow forObjRel = (XWindow)
151 UnoRuntime.queryInterface(XWindow.class, anotherCtrl);
153 XWindow objWin = (XWindow)
154 UnoRuntime.queryInterface(XWindow.class, oObj);
156 tEnv.addObjRelation("XWindow.AnotherWindow",forObjRel);
157 tEnv.addObjRelation("XWindow.ControlShape",aShape);
159 tEnv.addObjRelation("Win1",objWin);
160 tEnv.addObjRelation("Win2",forObjRel);
162 tEnv.addObjRelation("CONTROL",anotherCtrl);
164 // adding relation for XChangeBroadcaster
165 box.addItem("Item1", (short) 0);
166 box.addItem("Item2", (short) 1);
168 tEnv.addObjRelation("XChangeBroadcaster.Changer",
169 new ifc.form._XChangeBroadcaster.Changer() {
170 public void change(){
171 box.addItem("Item1", (short) 0);
172 box.addItem("Item2", (short) 1);
173 box.selectItemPos((short) 0, true);
174 box.selectItemPos((short) 1, true);
179 return tEnv;
180 } // finish method getTestEnvironment
182 } // finish class OListBoxControl