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._toolkit;
28 
29 import com.sun.star.awt.XControl;
30 import com.sun.star.awt.XControlContainer;
31 import com.sun.star.awt.XControlModel;
32 import com.sun.star.awt.XTabControllerModel;
33 import com.sun.star.drawing.XControlShape;
34 import com.sun.star.drawing.XShape;
35 import com.sun.star.form.XForm;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.text.XTextDocument;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 import com.sun.star.view.XControlAccess;
43 
44 import java.io.PrintWriter;
45 
46 import lib.StatusException;
47 import lib.TestCase;
48 import lib.TestEnvironment;
49 import lib.TestParameters;
50 
51 import util.FormTools;
52 import util.WriterTools;
53 import util.utils;
54 
55 
56 public class TabController extends TestCase {
57     private static XTextDocument xTextDoc = null;
58 
59     protected void initialize(TestParameters param, PrintWriter log) {
60         try {
61             log.println("creating a textdocument");
62             xTextDoc = WriterTools.createTextDoc(
63                                (XMultiServiceFactory) param.getMSF());
64         } catch (Exception e) {
65             // Some exception occures.FAILED
66             e.printStackTrace(log);
67             throw new StatusException("Couldn't create document", e);
68         }
69     }
70 
71     protected void cleanup(TestParameters param, PrintWriter log) {
72         log.println("disposing xTextDoc");
73         util.DesktopTools.closeDoc(xTextDoc);
74         ;
75     }
76 
77     public TestEnvironment createTestEnvironment(TestParameters param,
78                                                  PrintWriter log) {
79         XInterface oObj = null;
80         XControl xCtrl1 = null;
81         XTabControllerModel tabCtrlModel = null;
82         XControlContainer aCtrlContainer = null;
83 
84 
85         // create object relations
86         FormTools.insertForm(xTextDoc,
87                              FormTools.getForms(WriterTools.getDrawPage(
88                                                         xTextDoc)), "MyForm");
89 
90         XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000,
91                                                                4500, 15000,
92                                                                10000,
93                                                                "CommandButton",
94                                                                "UnoControlButton");
95         WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
96 
97         XControlModel model = aShape.getControl();
98         XControlAccess access = (XControlAccess) UnoRuntime.queryInterface(
99                                         XControlAccess.class,
100                                         xTextDoc.getCurrentController());
101 
102         try {
103             xCtrl1 = access.getControl(model);
104         } catch (Exception e) {
105         }
106 
107         XForm form = null;
108 
109         try {
110             form = (XForm) AnyConverter.toObject(new Type(XForm.class),
111                                                  (FormTools.getForms(
112                                                          WriterTools.getDrawPage(
113                                                                  xTextDoc)))
114                                                      .getByName("MyForm"));
115         } catch (Exception e) {
116             log.println("Couldn't get Form");
117             e.printStackTrace(log);
118         }
119 
120         tabCtrlModel = (XTabControllerModel) UnoRuntime.queryInterface(
121                                XTabControllerModel.class, form);
122 
123         aCtrlContainer = (XControlContainer) UnoRuntime.queryInterface(
124                                  XControlContainer.class, xCtrl1.getContext());
125 
126         // create object
127         try {
128             oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance(
129                            "com.sun.star.awt.TabController");
130         } catch (Exception e) {
131         }
132 
133         TestEnvironment tEnv = new TestEnvironment(oObj);
134 
135         String objName = "TabController";
136         tEnv.addObjRelation("OBJNAME", "toolkit." + objName);
137         tEnv.addObjRelation("MODEL", tabCtrlModel);
138         tEnv.addObjRelation("CONTAINER", aCtrlContainer);
139         System.out.println("ImplementationName: " + utils.getImplName(oObj));
140 
141         return tEnv;
142     }
143 }