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.chart.XChartDocument;
45 import com.sun.star.frame.XModel;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 
50 public class AccDiagram extends TestCase {
51 
52     XChartDocument xChartDoc = null;
53 
54     protected TestEnvironment createTestEnvironment(
55         TestParameters Param, PrintWriter log) {
56 
57         if (xChartDoc != null) cleanup(Param, log);
58         log.println( "creating a chart document" );
59         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
60         try {
61             log.println( "creating a chartdocument" );
62             xChartDoc = SOF.createChartDoc(null);
63         } catch (com.sun.star.uno.Exception e) {
64             // Some exception occures.FAILED
65             e.printStackTrace( log );
66             throw new StatusException( "Couldn't create document", e );
67         }
68 
69         XInterface oObj = null;
70 
71         XModel aModel = (XModel)
72             UnoRuntime.queryInterface(XModel.class, xChartDoc);
73 
74         AccessibilityTools at = new AccessibilityTools();
75 
76         XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
77         XAccessible xRoot = at.getAccessibleObject(xWindow);
78 
79         at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
80 
81         XAccessibleContext cont = at.getAccessibleObjectForRole(
82                 xRoot, AccessibleRole.SHAPE, "", "AccDiagram");
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 tParam test parameters
109     * @param tEnv the environment to cleanup
110     * @param log writer to log information while testing
111     */
112     protected void cleanup( TestParameters Param, PrintWriter log) {
113         if( xChartDoc!=null ) {
114             log.println( "    closing xChartDoc" );
115             util.DesktopTools.closeDoc(xChartDoc);
116             xChartDoc = null;
117         }
118     }
119 
120 }
121