2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.awt
.XControl
;
21 import com
.sun
.star
.awt
.XControlContainer
;
22 import com
.sun
.star
.awt
.XControlModel
;
23 import com
.sun
.star
.awt
.XDialog
;
24 import com
.sun
.star
.awt
.XToolkit
;
25 import com
.sun
.star
.awt
.tree
.XMutableTreeDataModel
;
26 import com
.sun
.star
.awt
.tree
.XMutableTreeNode
;
27 import com
.sun
.star
.awt
.tree
.XTreeControl
;
28 import com
.sun
.star
.awt
.tree
.XTreeNode
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.container
.XNameContainer
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.ucb
.CommandAbortedException
;
33 import com
.sun
.star
.ucb
.XSimpleFileAccess
;
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
;
39 import java
.io
.PrintWriter
;
40 import java
.util
.Comparator
;
43 import lib
.TestEnvironment
;
44 import lib
.TestParameters
;
45 import util
.SOfficeFactory
;
49 public class UnoTreeControl
extends TestCase
{
50 private static XMutableTreeDataModel mXTreeDataModel
;
51 private static XMultiServiceFactory mxMSF
;
54 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
55 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
58 log
.println("creating a textdocument");
59 SOF
.createTextDoc(null);
63 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
67 protected TestEnvironment
createTestEnvironment(TestParameters Param
,
69 String sTreeControlName
= "UnoTreeControl-Test";
70 mxMSF
= Param
.getMSF();
71 XInterface oObj
= null;
72 XMutableTreeNode xNode
= null;
76 mXTreeDataModel
= UnoRuntime
.queryInterface(XMutableTreeDataModel
.class,
77 mxMSF
.createInstance("com.sun.star.awt.tree.MutableTreeDataModel"));
79 xNode
= mXTreeDataModel
.createNode("UnoTreeControl", false);
81 xNode
.setDataValue( "UnoTreeControl");
82 xNode
.setExpandedGraphicURL( "private:graphicrepository/sd/res/triangle_down.png");
83 xNode
.setCollapsedGraphicURL( "private:graphicrepository/sd/res/triangle_right.png");
87 mXTreeDataModel
.setRoot(xNode
);
89 XControlModel xDialogModel
= UnoRuntime
.queryInterface(XControlModel
.class,
90 mxMSF
.createInstance("com.sun.star.awt.UnoControlDialogModel"));
92 XPropertySet xDialogPropertySet
= UnoRuntime
.queryInterface(XPropertySet
.class, xDialogModel
);
93 xDialogPropertySet
.setPropertyValue( "PositionX", Integer
.valueOf(50) );
94 xDialogPropertySet
.setPropertyValue( "PositionY", Integer
.valueOf(50) );
95 xDialogPropertySet
.setPropertyValue( "Width", Integer
.valueOf(256) );
96 xDialogPropertySet
.setPropertyValue( "Height", Integer
.valueOf(256) );
97 xDialogPropertySet
.setPropertyValue( "Title", "Tree Control Test");
99 XMultiServiceFactory xDialogMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xDialogModel
);
101 XControlModel xTreeControlModel
= UnoRuntime
.queryInterface(XControlModel
.class,
102 xDialogMSF
.createInstance("com.sun.star.awt.tree.TreeControlModel"));
104 XPropertySet XTreeControlModelSet
= UnoRuntime
.queryInterface(XPropertySet
.class, xTreeControlModel
);
106 XTreeControlModelSet
.setPropertyValue( "SelectionType",com
.sun
.star
.view
.SelectionType
.NONE
);
107 XTreeControlModelSet
.setPropertyValue( "PositionX", Integer
.valueOf(3 ));
108 XTreeControlModelSet
.setPropertyValue( "PositionY", Integer
.valueOf(3 ));
109 XTreeControlModelSet
.setPropertyValue( "Width", Integer
.valueOf(253));
110 XTreeControlModelSet
.setPropertyValue( "Height", Integer
.valueOf(253) );
111 XTreeControlModelSet
.setPropertyValue( "DataModel", mXTreeDataModel
);
112 XTreeControlModelSet
.setPropertyValue( "ShowsRootHandles", Boolean
.FALSE
);
113 XTreeControlModelSet
.setPropertyValue( "ShowsHandles", Boolean
.FALSE
);
114 XTreeControlModelSet
.setPropertyValue( "RootDisplayed", Boolean
.TRUE
);
115 XTreeControlModelSet
.setPropertyValue( "Editable", Boolean
.TRUE
);
117 XNameContainer xDialogModelContainer
= UnoRuntime
.queryInterface(XNameContainer
.class, xDialogModel
);
119 xDialogModelContainer
.insertByName( sTreeControlName
, xTreeControlModel
);
121 XControl xDialogControl
= UnoRuntime
.queryInterface(XControl
.class,
122 mxMSF
.createInstance("com.sun.star.awt.UnoControlDialog"));
124 xDialogControl
.setModel( xDialogModel
);
126 XToolkit xToolkit
= UnoRuntime
.queryInterface(XToolkit
.class,
127 mxMSF
.createInstance("com.sun.star.awt.Toolkit" ));
129 xDialogControl
.createPeer( xToolkit
, null );
131 // get the peers of the sub controls from the dialog peer container
132 XControlContainer xDialogContainer
= UnoRuntime
.queryInterface(XControlContainer
.class ,xDialogControl
);
134 XTreeControl xTreeControl
= UnoRuntime
.queryInterface(XTreeControl
.class, xDialogContainer
.getControl( sTreeControlName
));
136 xTreeControl
.expandNode(xNode
);
139 XDialog xDialog
= UnoRuntime
.queryInterface(XDialog
.class, xDialogControl
);
141 execurteDialog aDialog
= new execurteDialog(xDialog
);
145 } catch (com
.sun
.star
.uno
.Exception ex
) {
146 ex
.printStackTrace();
148 TestEnvironment tEnv
= new TestEnvironment(oObj
);
150 tEnv
.addObjRelation("XTreeControl_Node", xNode
);
152 //com.sun.star.view.XSelectionSupplier
155 System
.out
.println("count of children: " + xNode
.getChildCount());
156 tEnv
.addObjRelation("Selections", new Object
[]{xNode
.getChildAt(0), xNode
});
157 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException ex
) {
158 log
.println("ERROR: could not add object relation 'Selections' because 'xNode.getChildAt(1) failed: " +
162 tEnv
.addObjRelation("Comparer",
163 new Comparator
<Object
>() {
164 public int compare(Object o1
, Object o2
) {
165 XMutableTreeNode xNode1
= UnoRuntime
.queryInterface(
166 XMutableTreeNode
.class, o1
);
167 XTreeNode xNode2a
= null;
169 xNode2a
= (XTreeNode
) AnyConverter
.toObject(new Type(XTreeNode
.class), o2
);
170 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
171 ex
.printStackTrace();
174 XMutableTreeNode xNode2
= UnoRuntime
.queryInterface(
175 XMutableTreeNode
.class, xNode2a
);
177 if (((String
) xNode1
.getDataValue()).equals(xNode2
.getDataValue())) {
184 System
.out
.println("ImplementationName: " + utils
.getImplName(oObj
));
187 } // finish method getTestEnvironment
189 private void fillNode( XMutableTreeNode xNode
){
191 if( xNode
.getChildCount() == 0 )
193 xNode
.getDataValue();
195 String officeUserPath
= utils
.getOfficeUserPath(mxMSF
);
196 Object fileacc
= null;
198 fileacc
= mxMSF
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
199 } catch (com
.sun
.star
.uno
.Exception ex
) {
200 ex
.printStackTrace();
202 UnoRuntime
.queryInterface(XSimpleFileAccess
.class,fileacc
);
205 dirlist(officeUserPath
, xNode
);
209 private void dirlist(String dir
, XMutableTreeNode xNode
){
211 Object fileacc
= null;
213 fileacc
= mxMSF
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
214 } catch (com
.sun
.star
.uno
.Exception ex
) {
215 ex
.printStackTrace();
217 XSimpleFileAccess sfa
= UnoRuntime
.queryInterface(XSimpleFileAccess
.class,fileacc
);
218 XMutableTreeNode xChildNode
= null;
220 xChildNode
= mXTreeDataModel
.createNode(dir
.substring(dir
.lastIndexOf("/")+1, dir
.length()), sfa
.isFolder(dir
));
221 xChildNode
.setDataValue(dir
);
223 if (sfa
.isFolder(dir
)){
224 xChildNode
.setExpandedGraphicURL( "private:graphicrepository/sd/res/triangle_down.png");
225 xChildNode
.setCollapsedGraphicURL("private:graphicrepository/sd/res/triangle_right.png");
226 String
[] children
= sfa
.getFolderContents(dir
, true);
227 if (children
!= null){
228 for (int i
=0; i
<children
.length
; i
++) {
229 // Get filename of file or directory
230 String filename
= children
[i
];
231 dirlist( filename
, xChildNode
);
236 xChildNode
.setNodeGraphicURL( "private:graphicrepository/sw/res/nc20010.png");
238 } catch (CommandAbortedException ex
) {
239 ex
.printStackTrace();
240 } catch (com
.sun
.star
.uno
.Exception ex
) {
241 ex
.printStackTrace();
245 xNode
.appendChild( xChildNode
);
246 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
247 ex
.printStackTrace();
251 private static class execurteDialog
extends Thread
{
252 private final XDialog mXDialog
;
254 public execurteDialog(XDialog xDialog
){
260 mXDialog
.endExecute();
265 } // finish class UnoControlRadioButton