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.tree.XMutableTreeDataModel;
26 import com.sun.star.awt.tree.XMutableTreeNode;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.text.XTextDocument;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
31 
32 import java.io.PrintWriter;
33 
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 
38 import util.WriterTools;
39 import util.utils;
40 
41 
42 public class MutableTreeDataModel extends TestCase {
43     private static XTextDocument xTextDoc;
44     private static XInterface oObj = null;
45 
46     /**
47      * Creates StarOffice Writer document.
48      */
initialize(TestParameters tParam, PrintWriter log)49     protected void initialize(TestParameters tParam, PrintWriter log) {
50         log.println("creating a textdocument");
51         xTextDoc = WriterTools.createTextDoc(
52             (XMultiServiceFactory) tParam.getMSF());
53     }
54 
55     /**
56      * Disposes StarOffice Writer document.
57      */
cleanup(TestParameters tParam, PrintWriter log)58     protected void cleanup(TestParameters tParam, PrintWriter log) {
59         log.println("    disposing xTextDoc ");
60 
61         util.DesktopTools.closeDoc(xTextDoc);
62     }
63 
createTestEnvironment(TestParameters Param, PrintWriter log)64     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
65         PrintWriter log) {
66 
67         try {
68             oObj = (XInterface) ((XMultiServiceFactory) Param.getMSF()).createInstance(
69                 "com.sun.star.awt.tree.MutableTreeDataModel");
70         } catch (Exception e) {
71         }
72 
73         log.println(
74             "creating a new environment for MutableTreeDataModel object");
75 
76         TestEnvironment tEnv = new TestEnvironment(oObj);
77 
78         tEnv.addObjRelation("OBJNAME", "toolkit.MutableTreeDataModel");
79         log.println("ImplementationName: " + utils.getImplName(oObj));
80 
81         tEnv.addObjRelation("XTreeDataModelListenerEvent", new XTreeDataModelListenerEvent());
82 
83         return tEnv;
84     } // finish method getTestEnvironment
85 
86     public class XTreeDataModelListenerEvent implements ifc.awt.tree._XTreeDataModel.XTreeDataModelListenerEvent{
87 
fireEvent()88         public void fireEvent(){
89 
90             XMutableTreeDataModel xModel = (XMutableTreeDataModel) UnoRuntime.queryInterface(XMutableTreeDataModel.class, oObj);
91             XMutableTreeNode node = xModel.createNode("EventNode", true);
92             try {
93                 xModel.setRoot(node);
94             } catch (com.sun.star.lang.IllegalArgumentException ex) {
95                 log.println("ERROR: could not perform event: " + ex.toString());
96                 ex.printStackTrace();
97             }
98 
99         }
100     }
101 } // finish class UnoControlListBoxModel
102