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.XControlModel; 26 import com.sun.star.awt.XDevice; 27 import com.sun.star.awt.XGraphics; 28 import com.sun.star.awt.XTextComponent; 29 import com.sun.star.awt.XToolkit; 30 import com.sun.star.awt.XWindow; 31 import com.sun.star.awt.XWindowPeer; 32 import com.sun.star.drawing.XControlShape; 33 import com.sun.star.drawing.XShape; 34 import com.sun.star.frame.XController; 35 import com.sun.star.frame.XFrame; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.text.XTextDocument; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.uno.XInterface; 40 import com.sun.star.view.XControlAccess; 41 42 import java.io.PrintWriter; 43 44 import lib.StatusException; 45 import lib.TestCase; 46 import lib.TestEnvironment; 47 import lib.TestParameters; 48 49 import util.FormTools; 50 import util.SOfficeFactory; 51 import util.WriterTools; 52 import util.utils; 53 54 55 public class UnoControlDateField extends TestCase { 56 private static XTextDocument xTextDoc; 57 private static XTextDocument xTD2; 58 initialize(TestParameters Param, PrintWriter log)59 protected void initialize(TestParameters Param, PrintWriter log) { 60 SOfficeFactory SOF = SOfficeFactory.getFactory( 61 (XMultiServiceFactory) Param.getMSF()); 62 63 try { 64 log.println("creating a textdocument"); 65 xTextDoc = SOF.createTextDoc(null); 66 xTD2 = WriterTools.createTextDoc( 67 (XMultiServiceFactory) Param.getMSF()); 68 } catch (com.sun.star.uno.Exception e) { 69 // Some exception occures.FAILED 70 e.printStackTrace(log); 71 throw new StatusException("Couldn't create document", e); 72 } 73 } 74 cleanup(TestParameters tParam, PrintWriter log)75 protected void cleanup(TestParameters tParam, PrintWriter log) { 76 log.println(" disposing xTextDoc "); 77 78 util.DesktopTools.closeDoc(xTextDoc); 79 util.DesktopTools.closeDoc(xTD2); 80 } 81 createTestEnvironment(TestParameters Param, PrintWriter log)82 protected TestEnvironment createTestEnvironment(TestParameters Param, 83 PrintWriter log) { 84 XInterface oObj = null; 85 XWindowPeer the_win = null; 86 XToolkit the_kit = null; 87 XDevice aDevice = null; 88 XGraphics aGraphic = null; 89 XWindow anotherWindow = null; 90 91 //Insert a ControlShape and get the ControlModel 92 XControlShape aShape = FormTools.createUnoControlShape(xTextDoc, 3000, 93 4500, 15000, 94 10000, 95 "DateField", 96 "UnoControlDateField"); 97 98 WriterTools.getDrawPage(xTextDoc).add((XShape) aShape); 99 100 XControlModel the_Model = aShape.getControl(); 101 102 //Try to query XControlAccess 103 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 104 XControlAccess.class, 105 xTextDoc.getCurrentController()); 106 107 //get the DateFieldControl for the needed Object relations 108 try { 109 oObj = the_access.getControl(the_Model); 110 the_win = the_access.getControl(the_Model).getPeer(); 111 the_kit = the_win.getToolkit(); 112 aDevice = the_kit.createScreenCompatibleDevice(200, 200); 113 aGraphic = aDevice.createGraphics(); 114 } catch (Exception e) { 115 log.println("Couldn't get DateFieldControl"); 116 e.printStackTrace(log); 117 throw new StatusException("Couldn't get DateFieldControl", e); 118 } 119 120 log.println( 121 "creating a new environment for UnoControlDateField object"); 122 123 TestEnvironment tEnv = new TestEnvironment(oObj); 124 125 126 //Adding ObjRelation for XView 127 tEnv.addObjRelation("GRAPHICS", aGraphic); 128 129 130 //Adding ObjRelation for XControl 131 tEnv.addObjRelation("CONTEXT", xTextDoc); 132 tEnv.addObjRelation("WINPEER", the_win); 133 tEnv.addObjRelation("TOOLKIT", the_kit); 134 tEnv.addObjRelation("MODEL", the_Model); 135 136 System.out.println("ImplementationName: " + utils.getImplName(oObj)); 137 138 try { 139 XController aController = xTD2.getCurrentController(); 140 XFrame aFrame = aController.getFrame(); 141 anotherWindow = aFrame.getComponentWindow(); 142 } catch (Exception e) { 143 e.printStackTrace(log); 144 throw new StatusException("Couldn't create XWindow", e); 145 } 146 147 148 // Object Relation for XWindow 149 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow); 150 tEnv.addObjRelation("XWindow.ControlShape", aShape); 151 152 // Adding relation for XTextListener 153 ifc.awt._XTextListener.TestTextListener listener = 154 new ifc.awt._XTextListener.TestTextListener(); 155 XTextComponent textComp = (XTextComponent) UnoRuntime.queryInterface( 156 XTextComponent.class, oObj); 157 textComp.addTextListener(listener); 158 tEnv.addObjRelation("TestTextListener", listener); 159 160 return tEnv; 161 } // finish method getTestEnvironment 162 } // finish class UnoControlDateField 163