1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package mod._sch;
24 
25 import java.io.PrintWriter;
26 
27 import lib.StatusException;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.AccessibilityTools;
32 import util.SOfficeFactory;
33 import util.utils;
34 
35 import com.sun.star.accessibility.AccessibleRole;
36 import com.sun.star.accessibility.XAccessible;
37 import com.sun.star.accessibility.XAccessibleComponent;
38 import com.sun.star.accessibility.XAccessibleContext;
39 import com.sun.star.awt.XWindow;
40 import com.sun.star.beans.XPropertySet;
41 import com.sun.star.chart.XChartDocument;
42 import com.sun.star.frame.XModel;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 public class AccStatisticsObject extends TestCase {
48 
49     XChartDocument xChartDoc = null;
50 
createTestEnvironment( TestParameters Param, PrintWriter log)51     protected TestEnvironment createTestEnvironment(
52         TestParameters Param, PrintWriter log) {
53 
54         if (xChartDoc != null) cleanup(Param, log);
55         log.println( "creating a chart document" );
56         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
57         try {
58             log.println( "creating a chartdocument" );
59             xChartDoc = SOF.createChartDoc(null);
60             log.println("Display MeanValue");
61             XPropertySet diagProps = (XPropertySet)
62                 UnoRuntime.queryInterface(XPropertySet.class, xChartDoc.getDiagram());
63             diagProps.setPropertyValue("MeanValue",new Boolean(true));
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         XInterface oObj = null;
71 
72         XModel aModel = (XModel)
73             UnoRuntime.queryInterface(XModel.class, xChartDoc);
74 
75         AccessibilityTools at = new AccessibilityTools();
76 
77         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
78         XAccessible xRoot = at.getAccessibleObject(xWindow);
79 
80         XAccessibleContext cont = at.getAccessibleObjectForRole(
81                 xRoot, AccessibleRole.SHAPE, "", "AccStatisticsObject");
82 
83 
84         oObj = cont;
85 
86         log.println("ImplementationName " + utils.getImplName(oObj));
87         log.println("AccessibleName " + cont.getAccessibleName());
88 
89         TestEnvironment tEnv = new TestEnvironment(oObj);
90 
91         final XAccessibleComponent acc = (XAccessibleComponent)
92                 UnoRuntime.queryInterface(
93                     XAccessibleComponent.class,oObj);
94         tEnv.addObjRelation("EventProducer",
95             new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
96                 public void fireEvent() {
97                         acc.grabFocus();
98                 }
99             });
100 
101         return tEnv;
102 
103     }
104 
105     /**
106     * Called while disposing a <code>TestEnvironment</code>.
107     * Disposes text document.
108     * @param Param test parameters
109     * @param log writer to log information while testing
110     */
cleanup( TestParameters Param, PrintWriter log)111     protected void cleanup( TestParameters Param, PrintWriter log) {
112         if( xChartDoc!=null ) {
113             log.println( "    closing xChartDoc" );
114             util.DesktopTools.closeDoc(xChartDoc);
115             xChartDoc = null;
116         }
117     }
118 
119 }
120