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 
24 package ifc.awt.tree;
25 
26 import com.sun.star.awt.tree.TreeDataModelEvent;
27 import com.sun.star.awt.tree.XMutableTreeNode;
28 import com.sun.star.awt.tree.XTreeDataModel;
29 import com.sun.star.awt.tree.XTreeDataModelListener;
30 import com.sun.star.awt.tree.XTreeNode;
31 import com.sun.star.lang.EventObject;
32 import lib.MultiMethodTest;
33 import lib.Status;
34 import lib.StatusException;
35 
36 /**
37  * Testing <code>com.sun.star.awt.tree.XTreeDataModel</code>
38  * interface methods :
39  * <ul>
40  *  <li><code> createNode()</code></li>
41  *  <li><code> setRoot()</code></li>
42  * </ul> <p>
43  * Test is <b> NOT </b> multithread compilant. <p>
44  *
45  * @see com.sun.star.awt.tree.XTreeDataModel
46  */
47 public class _XTreeDataModel extends MultiMethodTest {
48 
49     public XTreeDataModel oObj = null;
50 
51     private XMutableTreeNode mNewNode = null;
52 
53     XTreeDataModelListener mListener1 = new myEventListener1();
54 
55     XTreeDataModelListener mListener2 = new myEventListener2();
56 
57     XTreeDataModelListenerEvent mListenerEvent = null;
58 
59     boolean mTreeStructureChanged1 = false;
60 
61     boolean mTreeStructureChanged2 = false;
62 
63     public static interface XTreeDataModelListenerEvent{
fireEvent()64         public void fireEvent();
65     }
66 
67     public class myEventListener1 implements XTreeDataModelListener{
treeNodesChanged(TreeDataModelEvent treeDataModelEvent)68         public void treeNodesChanged(TreeDataModelEvent treeDataModelEvent) {
69             log.println("Listener 1: treeNodesChanged");
70         }
71 
treeNodesInserted(TreeDataModelEvent treeDataModelEvent)72         public void treeNodesInserted(TreeDataModelEvent treeDataModelEvent) {
73             log.println("Listener 1: treeNodesInserted");
74         }
75 
treeNodesRemoved(TreeDataModelEvent treeDataModelEvent)76         public void treeNodesRemoved(TreeDataModelEvent treeDataModelEvent) {
77             log.println("Listener 1: treeNodesRemoved");
78         }
79 
treeStructureChanged(TreeDataModelEvent treeDataModelEvent)80         public void treeStructureChanged(TreeDataModelEvent treeDataModelEvent) {
81             log.println("Listener 1: treeStructureChanged");
82             mTreeStructureChanged1 = true;
83         }
84 
disposing(EventObject eventObject)85         public void disposing(EventObject eventObject) {
86             log.println("Listener 1: disposing");
87         }
88     }
89 
90     public class myEventListener2 implements XTreeDataModelListener{
treeNodesChanged(TreeDataModelEvent treeDataModelEvent)91         public void treeNodesChanged(TreeDataModelEvent treeDataModelEvent) {
92             log.println("Listener 2: treeNodesChanged");
93         }
94 
treeNodesInserted(TreeDataModelEvent treeDataModelEvent)95         public void treeNodesInserted(TreeDataModelEvent treeDataModelEvent) {
96             log.println("Listener 2: treeNodesInserted");
97         }
98 
treeNodesRemoved(TreeDataModelEvent treeDataModelEvent)99         public void treeNodesRemoved(TreeDataModelEvent treeDataModelEvent) {
100             log.println("Listener 2: treeNodesRemoved");
101         }
102 
treeStructureChanged(TreeDataModelEvent treeDataModelEvent)103         public void treeStructureChanged(TreeDataModelEvent treeDataModelEvent) {
104             log.println("Listener 2: treeStructureChanged");
105             mTreeStructureChanged2 = true;
106         }
107 
disposing(EventObject eventObject)108         public void disposing(EventObject eventObject) {
109             log.println("Listener 2: disposing");
110         }
111 
112     }
113 
before()114     public void before(){
115         mListenerEvent = (XTreeDataModelListenerEvent) tEnv.getObjRelation("XTreeDataModelListenerEvent");
116         if (mListenerEvent == null) {
117             throw new StatusException(Status.failed("ERROR: could not get object relation 'XTreeDataModelListenerEvent'\n" +
118                 "This object relation must be kind of 'ifc.awt.tree._XTreeDataModel.XTreeDataModelListenerEvent'"));
119         }
120     }
121 
122     /**
123      * Gets the title and compares it to the value set in
124      * <code>setTitle</code> method test. <p>
125      * Has <b>OK</b> status is set/get values are equal.
126      * The following method tests are to be completed successfully before :
127      * <ul>
128      *  <li> <code> setTitle </code>  </li>
129      * </ul>
130      */
_getRoot()131     public void _getRoot() {
132 
133         boolean bOK = true;
134         XTreeNode root = oObj.getRoot();
135 
136         tRes.tested("getRoot()", bOK);
137 
138     }
139 
_addTreeDataModelListener()140     public void _addTreeDataModelListener(){
141 
142         boolean bOK = true;
143 
144         log.println("add listener 1 to object...");
145         oObj.addTreeDataModelListener(mListener1);
146 
147         log.println("add listener 2 to object...");
148         oObj.addTreeDataModelListener(mListener2);
149 
150         mTreeStructureChanged1 = false;
151         mTreeStructureChanged2 = false;
152 
153         mListenerEvent.fireEvent();
154 
155         bOK = mTreeStructureChanged1 & mTreeStructureChanged2;
156 
157         tRes.tested("addTreeDataModelListener()", bOK);
158     }
159 
_removeTreeDataModelListener()160     public void _removeTreeDataModelListener(){
161 
162         boolean bOK = true;
163 
164         log.println("remove listener 2 from object...");
165         oObj.removeTreeDataModelListener(mListener2);
166 
167         mTreeStructureChanged1 = false;
168         mTreeStructureChanged2 = false;
169 
170         mListenerEvent.fireEvent();
171 
172         bOK = mTreeStructureChanged1 & ! mTreeStructureChanged2;
173 
174         tRes.tested("removeTreeDataModelListener()", bOK);
175 
176     }
177 }
178 
179 
180