1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package mod._sch;
28 
29 import java.io.PrintWriter;
30 
31 import lib.StatusException;
32 import lib.TestCase;
33 import lib.TestEnvironment;
34 import lib.TestParameters;
35 import util.AccessibilityTools;
36 import util.SOfficeFactory;
37 import util.utils;
38 
39 import com.sun.star.accessibility.AccessibleRole;
40 import com.sun.star.accessibility.XAccessible;
41 import com.sun.star.accessibility.XAccessibleComponent;
42 import com.sun.star.accessibility.XAccessibleContext;
43 import com.sun.star.awt.XWindow;
44 import com.sun.star.beans.XPropertySet;
45 import com.sun.star.chart.XChartDocument;
46 import com.sun.star.frame.XModel;
47 import com.sun.star.lang.XMultiServiceFactory;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 
51 public class AccWall extends TestCase {
52 
53     XChartDocument xChartDoc = null;
54 
55     protected TestEnvironment createTestEnvironment(
56         TestParameters Param, PrintWriter log) {
57 
58         if (xChartDoc != null) cleanup(Param, log);
59         log.println( "creating a chart document" );
60         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
61         try {
62             log.println( "creating a chartdocument" );
63             xChartDoc = SOF.createChartDoc(null);
64         } catch (com.sun.star.uno.Exception e) {
65             // Some exception occures.FAILED
66             e.printStackTrace( log );
67             throw new StatusException( "Couldn't create document", e );
68         }
69 
70         log.println("Change Diagram to 3D");
71         XPropertySet ChartProps = (XPropertySet)
72             UnoRuntime.queryInterface( XPropertySet.class, xChartDoc.getDiagram() );
73         try {
74             ChartProps.setPropertyValue("Dim3D", new Boolean(true));
75         } catch(com.sun.star.lang.WrappedTargetException e) {
76             log.println("Couldn't change Diagram to 3D");
77             e.printStackTrace(log);
78             throw new StatusException("Couldn't change Diagram to 3D", e);
79         } catch(com.sun.star.lang.IllegalArgumentException e) {
80             log.println("Couldn't change Diagram to 3D");
81             e.printStackTrace(log);
82             throw new StatusException("Couldn't change Diagram to 3D", e);
83         } catch(com.sun.star.beans.PropertyVetoException e) {
84             log.println("Couldn't change Diagram to 3D");
85             e.printStackTrace(log);
86             throw new StatusException("Couldn't change Diagram to 3D", e);
87         } catch(com.sun.star.beans.UnknownPropertyException e) {
88             log.println("Couldn't change Diagram to 3D");
89             e.printStackTrace(log);
90             throw new StatusException("Couldn't change Diagram to 3D", e);
91         }
92 
93         XInterface oObj = null;
94 
95         XModel aModel = (XModel)
96             UnoRuntime.queryInterface(XModel.class, xChartDoc);
97 
98         AccessibilityTools at = new AccessibilityTools();
99 
100         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
101         XAccessible xRoot = at.getAccessibleObject(xWindow);
102 
103         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
104 
105         XAccessibleContext cont = at.getAccessibleObjectForRole(
106                 xRoot, AccessibleRole.SHAPE, "", "AccWall");
107 
108         oObj = cont;
109 
110         log.println("ImplementationName " + utils.getImplName(oObj));
111         log.println("AccessibleName " + cont.getAccessibleName());
112 
113         TestEnvironment tEnv = new TestEnvironment(oObj);
114 
115         final XAccessibleComponent acc = (XAccessibleComponent)
116                 UnoRuntime.queryInterface(
117                     XAccessibleComponent.class,oObj);
118         tEnv.addObjRelation("EventProducer",
119             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
120                 public void fireEvent() {
121                         acc.grabFocus();
122                 }
123             });
124 
125         return tEnv;
126 
127     }
128 
129     /**
130     * Called while disposing a <code>TestEnvironment</code>.
131     * Disposes text document.
132     * @param tParam test parameters
133     * @param tEnv the environment to cleanup
134     * @param log writer to log information while testing
135     */
136     protected void cleanup( TestParameters Param, PrintWriter log) {
137         if( xChartDoc!=null ) {
138             log.println( "    closing xChartDoc" );
139             util.DesktopTools.closeDoc(xChartDoc);
140             xChartDoc = null;
141         }
142     }
143 
144 }
145