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 .
21 import java
.io
.PrintWriter
;
22 import java
.util
.Comparator
;
25 import lib
.StatusException
;
27 import lib
.TestEnvironment
;
28 import lib
.TestParameters
;
29 import util
.DesktopTools
;
30 import util
.SOfficeFactory
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.container
.XIndexAccess
;
35 import com
.sun
.star
.drawing
.XDrawPage
;
36 import com
.sun
.star
.drawing
.XDrawPages
;
37 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
38 import com
.sun
.star
.drawing
.XShape
;
39 import com
.sun
.star
.drawing
.XShapes
;
40 import com
.sun
.star
.frame
.XController
;
41 import com
.sun
.star
.frame
.XDesktop
;
42 import com
.sun
.star
.frame
.XFrame
;
43 import com
.sun
.star
.frame
.XModel
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.uno
.AnyConverter
;
47 import com
.sun
.star
.uno
.Type
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
50 import com
.sun
.star
.util
.XModifiable
;
53 * Test for object which is represented by service
54 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
55 * The view was switched to <b>HandoutMode</b>. <p>
56 * Object implements the following interfaces :
58 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
61 * <li> <code>com::sun::star::frame::XController</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
64 * <li> <code>com::sun::star::drawing::XDrawView</code></li>
66 * @see com.sun.star.drawing.DrawingDocumentDrawView
67 * @see com.sun.star.lang.XComponent
68 * @see com.sun.star.lang.XServiceInfo
69 * @see com.sun.star.frame.XController
70 * @see com.sun.star.beans.XPropertySet
71 * @see com.sun.star.view.XSelectionSupplier
72 * @see com.sun.star.drawing.XDrawView
73 * @see ifc.drawing._DrawingDocumentDrawView
74 * @see ifc.lang._XComponent
75 * @see ifc.lang._XServiceInfo
76 * @see ifc.frame._XController
77 * @see ifc.beans._XPropertySet
78 * @see ifc.view._XSelectionSupplier
79 * @see ifc.drawing._XDrawView
81 public class DrawController_HandoutView
extends TestCase
{
82 static XDesktop the_Desk
;
83 static XComponent xDrawDoc
;
84 static XComponent xSecondDrawDoc
;
87 * Creates the instance of the service
88 * <code>com.sun.star.frame.Desktop</code>.
89 * @see com.sun.star.frame.Desktop
92 protected void initialize(TestParameters Param
, PrintWriter log
) {
93 the_Desk
= UnoRuntime
.queryInterface(
94 XDesktop
.class, DesktopTools
.createDesktop(
99 * Called while disposing a <code>TestEnvironment</code>.
100 * Disposes Impress documents.
101 * @param Param test parameters
102 * @param log writer to log information while testing
105 protected void cleanup( TestParameters Param
, PrintWriter log
) {
106 log
.println("disposing impress documents");
107 util
.DesktopTools
.closeDoc(xDrawDoc
);
108 util
.DesktopTools
.closeDoc(xSecondDrawDoc
);
112 * Creating a TestEnvironment for the interfaces to be tested.
113 * Creates two impress documents. After creating
114 * of the documents makes short
115 * wait to allow frames to be loaded. Retrieves
116 * the collection of the draw pages
117 * from the first document and takes one of them. Inserts some shapes to the
118 * retrieved draw page.
119 * Switch to the <b>HandoutMode</b>.
120 * Obtains a current controller from the first document
121 * using the interface <code>XModel</code>. The obtained controller is the
122 * instance of the service
123 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
124 * Object relations created :
126 * <li> <code>'Pages'</code> for
127 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
129 * <li> <code>'FirstModel'</code> for
130 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
131 * the first created document) </li>
132 * <li> <code>'Frame'</code> for
133 * {@link ifc.frame._XController}(the frame of the created
135 * <li> <code>'SecondModel'</code> for
136 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
137 * the second created document) </li>
138 * <li> <code>'SecondController'</code> for
139 * {@link ifc.frame._XController}(the current controller of the second
140 * created document) </li>
141 * <li> <code>'DrawPage'</code> for
142 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
143 * be new current page) </li>
145 * @see com.sun.star.frame.XModel
146 * @see com.sun.star.drawing.DrawingDocumentDrawView
149 protected synchronized TestEnvironment createTestEnvironment
150 (TestParameters Param
, PrintWriter log
) {
152 log
.println( "creating a test environment" );
153 XMultiServiceFactory xMSF
= Param
.getMSF();
154 // get a soffice factory object
155 SOfficeFactory SOF
= SOfficeFactory
.getFactory(xMSF
);
158 log
.println( "creating two impress documents" );
159 xSecondDrawDoc
= SOF
.createImpressDoc(null);
160 util
.utils
.pause(1000);
161 xDrawDoc
= SOF
.createImpressDoc(null);
162 util
.utils
.pause(1000);
163 } catch (com
.sun
.star
.uno
.Exception e
) {
164 e
.printStackTrace( log
);
165 throw new StatusException("Couldn't create document", e
);
168 // get the drawpage of drawing here
169 log
.println( "getting Drawpage" );
170 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xDrawDoc
);
171 XDrawPages the_pages
= oDPS
.getDrawPages();
172 for (int i
= 1; i
< 10; i
++){
173 the_pages
.insertNewByIndex(i
);
175 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,the_pages
);
177 XDrawPage oDrawPage
= null;
179 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
180 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
181 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
182 e
.printStackTrace( log
);
183 throw new StatusException("Couldn't get DrawPage", e
);
184 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
185 e
.printStackTrace( log
);
186 throw new StatusException("Couldn't get DrawPage", e
);
187 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
188 e
.printStackTrace( log
);
189 throw new StatusException("Couldn't get DrawPage", e
);
192 //put something on the drawpage
193 log
.println( "inserting some Shapes" );
194 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oDrawPage
);
195 XShape shape1
= SOF
.createShape(
196 xDrawDoc
, 3000, 4500, 15000, 1000, "Ellipse");
197 XShape shape2
= SOF
.createShape(
198 xDrawDoc
, 5000, 3500, 7500, 5000, "Rectangle");
199 XShape shape3
= SOF
.createShape(
200 xDrawDoc
, 3000, 500, 5000, 1000, "Line");
204 util
.utils
.pause(1000);
206 log
.println("switch to HandoutView...");
208 utils
.dispatchURL(xMSF
, xDrawDoc
, ".uno:HandoutMode");
209 } catch (Exception e
){
210 e
.printStackTrace(log
);
211 throw new StatusException(e
, Status
.failed(e
.getMessage()));
216 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
218 XInterface oObj
= aModel
.getCurrentController();
220 log
.println("bring first document to front...");
221 DesktopTools
.bringWindowToFront(aModel
);
223 XModel aModel2
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
225 XWindow anotherWindow
= UnoRuntime
.queryInterface(
226 XWindow
.class,aModel2
.getCurrentController());
228 log
.println( "creating a new environment for impress view object" );
229 TestEnvironment tEnv
= new TestEnvironment( oObj
);
231 if (anotherWindow
!= null) {
232 tEnv
.addObjRelation("XWindow.AnotherWindow",anotherWindow
);
235 Object oShapeCol1
= null;
236 Object oShapeCol2
= null;
239 createInstance("com.sun.star.drawing.ShapeCollection");
241 createInstance("com.sun.star.drawing.ShapeCollection");
242 } catch(com
.sun
.star
.uno
.Exception e
) {
243 throw new StatusException(e
, Status
.failed("Couldn't create instance"));
246 XShapes xShapes1
= UnoRuntime
.queryInterface(XShapes
.class, oShapeCol1
);
247 XShapes xShapes2
= UnoRuntime
.queryInterface(XShapes
.class, oShapeCol2
);
248 xShapes1
.add(shape2
);
249 xShapes1
.add(shape3
);
250 xShapes2
.add(shape1
);
251 util
.utils
.pause(1000);
253 tEnv
.addObjRelation("Selections", new Object
[] {
254 oDrawPage
, oShapeCol1
, oShapeCol2
});
255 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
256 public int compare(Object o1
, Object o2
) {
257 XIndexAccess indAc1
= UnoRuntime
.queryInterface(XIndexAccess
.class, o1
);
258 XIndexAccess indAc2
= UnoRuntime
.queryInterface(XIndexAccess
.class, o2
);
259 if (indAc1
== null || indAc2
== null) return -1;
260 if (indAc1
.getCount() == indAc2
.getCount()) {
268 tEnv
.addObjRelation("Pages", the_pages
);
270 //Adding ObjRelations for XController
271 tEnv
.addObjRelation("FirstModel", aModel
);
273 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
275 XFrame the_frame
= the_Desk
.getCurrentFrame();
276 tEnv
.addObjRelation("Frame", the_frame
);
278 aModel
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
279 //Adding ObjRelations for XController
280 tEnv
.addObjRelation("SecondModel", aModel
);
282 XController secondController
= aModel
.getCurrentController();
283 tEnv
.addObjRelation("SecondController", secondController
);
284 tEnv
.addObjRelation("XDispatchProvider.URL",
287 //Adding relations for DrawingDocumentDrawView
288 XDrawPage new_page
= the_pages
.insertNewByIndex(1);
289 tEnv
.addObjRelation("DrawPage", new_page
);
291 log
.println("Implementation Name: "+utils
.getImplName(oObj
));
293 XModifiable modify
= UnoRuntime
.queryInterface(XModifiable
.class,xDrawDoc
);
295 tEnv
.addObjRelation("Modifiable",modify
);
297 tEnv
.addObjRelation("XComponent.DisposeThis", xDrawDoc
);
302 } // finish method getTestEnvironment