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 AccStatisticsObject 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             log.println("Display MeanValue");
65             XPropertySet diagProps = (XPropertySet)
66                 UnoRuntime.queryInterface(XPropertySet.class, xChartDoc.getDiagram());
67             diagProps.setPropertyValue("MeanValue",new Boolean(true));
68         } catch (com.sun.star.uno.Exception e) {
69             // Some exception occures.FAILED
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73 
74         XInterface oObj = null;
75 
76         XModel aModel = (XModel)
77             UnoRuntime.queryInterface(XModel.class, xChartDoc);
78 
79         AccessibilityTools at = new AccessibilityTools();
80 
81         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
82         XAccessible xRoot = at.getAccessibleObject(xWindow);
83 
84         XAccessibleContext cont = at.getAccessibleObjectForRole(
85                 xRoot, AccessibleRole.SHAPE, "", "AccStatisticsObject");
86 
87 
88         oObj = cont;
89 
90         log.println("ImplementationName " + utils.getImplName(oObj));
91         log.println("AccessibleName " + cont.getAccessibleName());
92 
93         TestEnvironment tEnv = new TestEnvironment(oObj);
94 
95         final XAccessibleComponent acc = (XAccessibleComponent)
96                 UnoRuntime.queryInterface(
97                     XAccessibleComponent.class,oObj);
98         tEnv.addObjRelation("EventProducer",
99             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
100                 public void fireEvent() {
101                         acc.grabFocus();
102                 }
103             });
104 
105         return tEnv;
106 
107     }
108 
109     /**
110     * Called while disposing a <code>TestEnvironment</code>.
111     * Disposes text document.
112     * @param tParam test parameters
113     * @param tEnv the environment to cleanup
114     * @param log writer to log information while testing
115     */
116     protected void cleanup( TestParameters Param, PrintWriter log) {
117         if( xChartDoc!=null ) {
118             log.println( "    closing xChartDoc" );
119             util.DesktopTools.closeDoc(xChartDoc);
120             xChartDoc = null;
121         }
122     }
123 
124 }
125