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