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 initialize(TestParameters param, PrintWriter log)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 cleanup(TestParameters param, PrintWriter log)67 protected void cleanup(TestParameters param, PrintWriter log) { 68 log.println("disposing xTextDoc"); 69 util.DesktopTools.closeDoc(xTextDoc); 70 } 71 createTestEnvironment(TestParameters param, PrintWriter log)72 public TestEnvironment createTestEnvironment(TestParameters param, 73 PrintWriter log) { 74 XInterface oObj = null; 75 XControl xCtrl1 = null; 76 XTabControllerModel tabCtrlModel = null; 77 XControlContainer aCtrlContainer = null; 78 79 80 // create object relations 81 FormTools.insertForm(xTextDoc, 82 FormTools.getForms(WriterTools.getDrawPage( 83 xTextDoc)), "MyForm"); 84 85 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 86 4500, 15000, 87 10000, 88 "CommandButton", 89 "UnoControlButton"); 90 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 91 92 XControlModel model = aShape.getControl(); 93 XControlAccess access = (XControlAccess) UnoRuntime.queryInterface( 94 XControlAccess.class, 95 xTextDoc.getCurrentController()); 96 97 try { 98 xCtrl1 = access.getControl(model); 99 } catch (Exception e) { 100 } 101 102 XForm form = null; 103 104 try { 105 form = (XForm) AnyConverter.toObject(new Type(XForm.class), 106 (FormTools.getForms( 107 WriterTools.getDrawPage( 108 xTextDoc))) 109 .getByName("MyForm")); 110 } catch (Exception e) { 111 log.println("Couldn't get Form"); 112 e.printStackTrace(log); 113 } 114 115 tabCtrlModel = (XTabControllerModel) UnoRuntime.queryInterface( 116 XTabControllerModel.class, form); 117 118 aCtrlContainer = (XControlContainer) UnoRuntime.queryInterface( 119 XControlContainer.class, xCtrl1.getContext()); 120 121 // create object 122 try { 123 oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance( 124 "com.sun.star.awt.TabController"); 125 } catch (Exception e) { 126 } 127 128 TestEnvironment tEnv = new TestEnvironment(oObj); 129 130 String objName = "TabController"; 131 tEnv.addObjRelation("OBJNAME", "toolkit." + objName); 132 tEnv.addObjRelation("MODEL", tabCtrlModel); 133 tEnv.addObjRelation("CONTAINER", aCtrlContainer); 134 System.out.println("ImplementationName: " + utils.getImplName(oObj)); 135 136 return tEnv; 137 } 138 } 139