1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski 23*b1cdbd2cSJim Jagielski package mod._toolkit; 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControl; 26*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControlContainer; 27*b1cdbd2cSJim Jagielski import com.sun.star.awt.XControlModel; 28*b1cdbd2cSJim Jagielski import com.sun.star.awt.XTabControllerModel; 29*b1cdbd2cSJim Jagielski import com.sun.star.drawing.XControlShape; 30*b1cdbd2cSJim Jagielski import com.sun.star.drawing.XShape; 31*b1cdbd2cSJim Jagielski import com.sun.star.form.XForm; 32*b1cdbd2cSJim Jagielski import com.sun.star.lang.XMultiServiceFactory; 33*b1cdbd2cSJim Jagielski import com.sun.star.text.XTextDocument; 34*b1cdbd2cSJim Jagielski import com.sun.star.uno.AnyConverter; 35*b1cdbd2cSJim Jagielski import com.sun.star.uno.Type; 36*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 37*b1cdbd2cSJim Jagielski import com.sun.star.uno.XInterface; 38*b1cdbd2cSJim Jagielski import com.sun.star.view.XControlAccess; 39*b1cdbd2cSJim Jagielski 40*b1cdbd2cSJim Jagielski import java.io.PrintWriter; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski import lib.StatusException; 43*b1cdbd2cSJim Jagielski import lib.TestCase; 44*b1cdbd2cSJim Jagielski import lib.TestEnvironment; 45*b1cdbd2cSJim Jagielski import lib.TestParameters; 46*b1cdbd2cSJim Jagielski 47*b1cdbd2cSJim Jagielski import util.FormTools; 48*b1cdbd2cSJim Jagielski import util.WriterTools; 49*b1cdbd2cSJim Jagielski import util.utils; 50*b1cdbd2cSJim Jagielski 51*b1cdbd2cSJim Jagielski 52*b1cdbd2cSJim Jagielski public class TabController extends TestCase { 53*b1cdbd2cSJim Jagielski private static XTextDocument xTextDoc = null; 54*b1cdbd2cSJim Jagielski initialize(TestParameters param, PrintWriter log)55*b1cdbd2cSJim Jagielski protected void initialize(TestParameters param, PrintWriter log) { 56*b1cdbd2cSJim Jagielski try { 57*b1cdbd2cSJim Jagielski log.println("creating a textdocument"); 58*b1cdbd2cSJim Jagielski xTextDoc = WriterTools.createTextDoc( 59*b1cdbd2cSJim Jagielski (XMultiServiceFactory) param.getMSF()); 60*b1cdbd2cSJim Jagielski } catch (Exception e) { 61*b1cdbd2cSJim Jagielski // Some exception occures.FAILED 62*b1cdbd2cSJim Jagielski e.printStackTrace(log); 63*b1cdbd2cSJim Jagielski throw new StatusException("Couldn't create document", e); 64*b1cdbd2cSJim Jagielski } 65*b1cdbd2cSJim Jagielski } 66*b1cdbd2cSJim Jagielski cleanup(TestParameters param, PrintWriter log)67*b1cdbd2cSJim Jagielski protected void cleanup(TestParameters param, PrintWriter log) { 68*b1cdbd2cSJim Jagielski log.println("disposing xTextDoc"); 69*b1cdbd2cSJim Jagielski util.DesktopTools.closeDoc(xTextDoc); 70*b1cdbd2cSJim Jagielski } 71*b1cdbd2cSJim Jagielski createTestEnvironment(TestParameters param, PrintWriter log)72*b1cdbd2cSJim Jagielski public TestEnvironment createTestEnvironment(TestParameters param, 73*b1cdbd2cSJim Jagielski PrintWriter log) { 74*b1cdbd2cSJim Jagielski XInterface oObj = null; 75*b1cdbd2cSJim Jagielski XControl xCtrl1 = null; 76*b1cdbd2cSJim Jagielski XTabControllerModel tabCtrlModel = null; 77*b1cdbd2cSJim Jagielski XControlContainer aCtrlContainer = null; 78*b1cdbd2cSJim Jagielski 79*b1cdbd2cSJim Jagielski 80*b1cdbd2cSJim Jagielski // create object relations 81*b1cdbd2cSJim Jagielski FormTools.insertForm(xTextDoc, 82*b1cdbd2cSJim Jagielski FormTools.getForms(WriterTools.getDrawPage( 83*b1cdbd2cSJim Jagielski xTextDoc)), "MyForm"); 84*b1cdbd2cSJim Jagielski 85*b1cdbd2cSJim Jagielski XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 86*b1cdbd2cSJim Jagielski 4500, 15000, 87*b1cdbd2cSJim Jagielski 10000, 88*b1cdbd2cSJim Jagielski "CommandButton", 89*b1cdbd2cSJim Jagielski "UnoControlButton"); 90*b1cdbd2cSJim Jagielski WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 91*b1cdbd2cSJim Jagielski 92*b1cdbd2cSJim Jagielski XControlModel model = aShape.getControl(); 93*b1cdbd2cSJim Jagielski XControlAccess access = (XControlAccess) UnoRuntime.queryInterface( 94*b1cdbd2cSJim Jagielski XControlAccess.class, 95*b1cdbd2cSJim Jagielski xTextDoc.getCurrentController()); 96*b1cdbd2cSJim Jagielski 97*b1cdbd2cSJim Jagielski try { 98*b1cdbd2cSJim Jagielski xCtrl1 = access.getControl(model); 99*b1cdbd2cSJim Jagielski } catch (Exception e) { 100*b1cdbd2cSJim Jagielski } 101*b1cdbd2cSJim Jagielski 102*b1cdbd2cSJim Jagielski XForm form = null; 103*b1cdbd2cSJim Jagielski 104*b1cdbd2cSJim Jagielski try { 105*b1cdbd2cSJim Jagielski form = (XForm) AnyConverter.toObject(new Type(XForm.class), 106*b1cdbd2cSJim Jagielski (FormTools.getForms( 107*b1cdbd2cSJim Jagielski WriterTools.getDrawPage( 108*b1cdbd2cSJim Jagielski xTextDoc))) 109*b1cdbd2cSJim Jagielski .getByName("MyForm")); 110*b1cdbd2cSJim Jagielski } catch (Exception e) { 111*b1cdbd2cSJim Jagielski log.println("Couldn't get Form"); 112*b1cdbd2cSJim Jagielski e.printStackTrace(log); 113*b1cdbd2cSJim Jagielski } 114*b1cdbd2cSJim Jagielski 115*b1cdbd2cSJim Jagielski tabCtrlModel = (XTabControllerModel) UnoRuntime.queryInterface( 116*b1cdbd2cSJim Jagielski XTabControllerModel.class, form); 117*b1cdbd2cSJim Jagielski 118*b1cdbd2cSJim Jagielski aCtrlContainer = (XControlContainer) UnoRuntime.queryInterface( 119*b1cdbd2cSJim Jagielski XControlContainer.class, xCtrl1.getContext()); 120*b1cdbd2cSJim Jagielski 121*b1cdbd2cSJim Jagielski // create object 122*b1cdbd2cSJim Jagielski try { 123*b1cdbd2cSJim Jagielski oObj = (XInterface) ((XMultiServiceFactory) param.getMSF()).createInstance( 124*b1cdbd2cSJim Jagielski "com.sun.star.awt.TabController"); 125*b1cdbd2cSJim Jagielski } catch (Exception e) { 126*b1cdbd2cSJim Jagielski } 127*b1cdbd2cSJim Jagielski 128*b1cdbd2cSJim Jagielski TestEnvironment tEnv = new TestEnvironment(oObj); 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski String objName = "TabController"; 131*b1cdbd2cSJim Jagielski tEnv.addObjRelation("OBJNAME", "toolkit." + objName); 132*b1cdbd2cSJim Jagielski tEnv.addObjRelation("MODEL", tabCtrlModel); 133*b1cdbd2cSJim Jagielski tEnv.addObjRelation("CONTAINER", aCtrlContainer); 134*b1cdbd2cSJim Jagielski System.out.println("ImplementationName: " + utils.getImplName(oObj)); 135*b1cdbd2cSJim Jagielski 136*b1cdbd2cSJim Jagielski return tEnv; 137*b1cdbd2cSJim Jagielski } 138*b1cdbd2cSJim Jagielski } 139