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
.tree
.XMutableTreeDataModel
;
21 import com
.sun
.star
.awt
.tree
.XMutableTreeNode
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.text
.XTextDocument
;
24 import com
.sun
.star
.ucb
.CommandAbortedException
;
25 import com
.sun
.star
.ucb
.XSimpleFileAccess
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
27 import com
.sun
.star
.uno
.XInterface
;
28 import ifc
.awt
.tree
._XMutableTreeNode
.XMutableTreeNodeCreator
;
30 import java
.io
.PrintWriter
;
32 import lib
.StatusException
;
35 import lib
.TestEnvironment
;
36 import lib
.TestParameters
;
40 public class MutableTreeNode
extends TestCase
{
41 private static XTextDocument xTextDoc
;
42 private static XInterface oObj
= null;
43 private static XMutableTreeDataModel mXTreeDataModel
;
44 private static XMultiServiceFactory mxMSF
;
47 * Creates StarOffice Writer document.
50 protected void initialize(TestParameters tParam
, PrintWriter log
) {
51 mxMSF
= tParam
.getMSF();
55 * Disposes StarOffice Writer document.
58 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
59 log
.println(" disposing xTextDoc ");
61 util
.DesktopTools
.closeDoc(xTextDoc
);
65 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
,
67 XMutableTreeNode xNode
;
70 mXTreeDataModel
= UnoRuntime
.queryInterface(XMutableTreeDataModel
.class,
71 mxMSF
.createInstance("com.sun.star.awt.tree.MutableTreeDataModel"));
72 } catch (com
.sun
.star
.uno
.Exception ex
) {
73 throw new StatusException(ex
, Status
.failed("ERROR: could not create instance of" +
74 " 'com.sun.star.awt.tree.MutableTreeDataModel'"));
77 xNode
= mXTreeDataModel
.createNode("UnoTreeControl", false);
79 String sDisplayValue
= "UnoTreeControl";
80 String sExpandedGraphicURL
= "private:graphicrepository/sd/res/triangle_down.png";
81 String sCollapsedGraphicURL
= "private:graphicrepository/sd/res/triangle_right.png";
82 String sNodeGraphicURL
= "private:graphicrepository/sw/imglst/nc20010.png";
84 xNode
.setDisplayValue( sDisplayValue
);
85 xNode
.setDataValue(sDisplayValue
);
86 xNode
.setExpandedGraphicURL(sExpandedGraphicURL
);
87 xNode
.setCollapsedGraphicURL(sCollapsedGraphicURL
);
88 xNode
.setNodeGraphicURL(sNodeGraphicURL
);
89 xNode
.setHasChildrenOnDemand(true);
93 TestEnvironment tEnv
= new TestEnvironment(xNode
);
95 tEnv
.addObjRelation("OBJNAME", "toolkit.MutableTreeDataModel");
96 log
.println("ImplementationName: " + utils
.getImplName(oObj
));
98 tEnv
.addObjRelation("XTreeNode_DisplayValue", sDisplayValue
);
99 tEnv
.addObjRelation("XTreeNode_ExpandedGraphicURL", sExpandedGraphicURL
);
100 tEnv
.addObjRelation("XTreeNode_CollapsedGraphicURL", sCollapsedGraphicURL
);
101 tEnv
.addObjRelation("XTreeNode_NodeGraphicURL", sNodeGraphicURL
);
103 tEnv
.addObjRelation("XMutableTreeNode_NodeToAppend",
104 mXTreeDataModel
.createNode("XMutableTreeNode_NodeToAppend", true));
106 tEnv
.addObjRelation("XMutableTreeNodeCreator", new XMutableTreeNodeCreator(){
107 public XMutableTreeNode
createNode(String name
){
108 return mXTreeDataModel
.createNode(name
, true);
113 } // finish method getTestEnvironment
115 private void fillNode( XMutableTreeNode xNode
){
117 if( xNode
.getChildCount() == 0 )
119 xNode
.getDataValue();
121 String officeUserPath
= utils
.getOfficeUserPath(mxMSF
);
122 Object fileacc
= null;
124 fileacc
= mxMSF
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
125 } catch (com
.sun
.star
.uno
.Exception ex
) {
126 ex
.printStackTrace();
128 UnoRuntime
.queryInterface(XSimpleFileAccess
.class,fileacc
);
131 dirlist(officeUserPath
, xNode
);
135 private void dirlist(String dir
, XMutableTreeNode xNode
){
137 Object fileacc
= null;
139 fileacc
= mxMSF
.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
140 } catch (com
.sun
.star
.uno
.Exception ex
) {
141 ex
.printStackTrace();
143 XSimpleFileAccess sfa
= UnoRuntime
.queryInterface(XSimpleFileAccess
.class,fileacc
);
144 XMutableTreeNode xChildNode
= null;
146 xChildNode
= mXTreeDataModel
.createNode(dir
.substring(dir
.lastIndexOf("/")+1, dir
.length()), sfa
.isFolder(dir
));
147 xChildNode
.setDataValue(dir
);
149 if (sfa
.isFolder(dir
)){
150 xChildNode
.setExpandedGraphicURL( "private:graphicrepository/sd/res/triangle_down.png");
151 xChildNode
.setCollapsedGraphicURL("private:graphicrepository/sd/res/triangle_right.png");
152 String
[] children
= sfa
.getFolderContents(dir
, true);
153 if (children
!= null){
154 for (int i
=0; i
<children
.length
; i
++) {
155 // Get filename of file or directory
156 String filename
= children
[i
];
157 dirlist( filename
, xChildNode
);
162 xChildNode
.setNodeGraphicURL( "private:graphicrepository/sw/imglst/nc20010.png");
164 } catch (CommandAbortedException ex
) {
165 ex
.printStackTrace();
166 } catch (com
.sun
.star
.uno
.Exception ex
) {
167 ex
.printStackTrace();
171 xNode
.appendChild( xChildNode
);
172 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
173 ex
.printStackTrace();
176 } // finish class UnoControlListBoxModel