bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / MutableTreeNode.java
blob6a9cf937639875ff8350f152894323e94021c49f
1 /*
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 .
18 package mod._toolkit;
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;
31 import lib.Status;
32 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 import util.utils;
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;
46 /**
47 * Creates StarOffice Writer document.
49 protected void initialize(TestParameters tParam, PrintWriter log) {
50 mxMSF = (XMultiServiceFactory) tParam.getMSF();
51 // log.println("creating a textdocument");
52 // xTextDoc = WriterTools.createTextDoc(mxMSF);
55 /**
56 * Disposes StarOffice Writer document.
58 protected void cleanup(TestParameters tParam, PrintWriter log) {
59 log.println(" disposing xTextDoc ");
61 util.DesktopTools.closeDoc(xTextDoc);
64 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param,
65 PrintWriter log) {
66 XMutableTreeNode xNode;
68 try {
69 mXTreeDataModel = UnoRuntime.queryInterface(XMutableTreeDataModel.class,
70 mxMSF.createInstance("com.sun.star.awt.tree.MutableTreeDataModel"));
71 } catch (com.sun.star.uno.Exception ex) {
72 throw new StatusException(Status.failed("ERROR: could not create instance of" +
73 " 'com.sun.star.awt.tree.MutableTreeDataModel'"));
76 xNode = mXTreeDataModel.createNode("UnoTreeControl", false);
78 String sDisplayValue = "UnoTreeControl";
79 String sExpandedGraphicURL = "private:graphicrepository/sd/res/triangle_down.png";
80 String sCollapsedGraphicURL = "private:graphicrepository/sd/res/triangle_right.png";
81 String sNodeGraphicURL = "private:graphicrepository/sw/imglst/nc20010.png";
83 xNode.setDisplayValue( sDisplayValue);
84 xNode.setDataValue(sDisplayValue);
85 xNode.setExpandedGraphicURL(sExpandedGraphicURL);
86 xNode.setCollapsedGraphicURL(sCollapsedGraphicURL);
87 xNode.setNodeGraphicURL(sNodeGraphicURL);
88 xNode.setHasChildrenOnDemand(true);
90 fillNode(xNode);
92 TestEnvironment tEnv = new TestEnvironment(xNode);
94 tEnv.addObjRelation("OBJNAME", "toolkit.MutableTreeDataModel");
95 log.println("ImplementationName: " + utils.getImplName(oObj));
97 tEnv.addObjRelation("XTreeNode_DisplayValue", sDisplayValue);
98 tEnv.addObjRelation("XTreeNode_ExpandedGraphicURL", sExpandedGraphicURL);
99 tEnv.addObjRelation("XTreeNode_CollapsedGraphicURL", sCollapsedGraphicURL);
100 tEnv.addObjRelation("XTreeNode_NodeGraphicURL", sNodeGraphicURL);
102 tEnv.addObjRelation("XMutableTreeNode_NodeToAppend",
103 mXTreeDataModel.createNode("XMutableTreeNode_NodeToAppend", true));
105 tEnv.addObjRelation("XMutableTreeNodeCreator", new XMutableTreeNodeCreator(){
106 public XMutableTreeNode createNode(String name){
107 return mXTreeDataModel.createNode(name, true);
111 return tEnv;
112 } // finish method getTestEnvironment
114 private void fillNode( XMutableTreeNode xNode ){
116 if( xNode.getChildCount() == 0 )
118 xNode.getDataValue();
120 String officeUserPath = utils.getOfficeUserPath(mxMSF);
121 Object fileacc = null;
122 try {
123 fileacc = mxMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
124 } catch (com.sun.star.uno.Exception ex) {
125 ex.printStackTrace();
127 UnoRuntime.queryInterface(XSimpleFileAccess.class,fileacc);
130 dirlist(officeUserPath, xNode);
134 private void dirlist(String dir, XMutableTreeNode xNode){
136 Object fileacc = null;
137 try {
138 fileacc = mxMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess");
139 } catch (com.sun.star.uno.Exception ex) {
140 ex.printStackTrace();
142 XSimpleFileAccess sfa = UnoRuntime.queryInterface(XSimpleFileAccess.class,fileacc);
143 XMutableTreeNode xChildNode = null;
144 try {
145 xChildNode = mXTreeDataModel.createNode(dir.substring(dir.lastIndexOf("/")+1, dir.length()), sfa.isFolder(dir));
146 xChildNode.setDataValue(dir);
147 sfa.isFolder(dir);
148 if (sfa.isFolder(dir)){
149 xChildNode.setExpandedGraphicURL( "private:graphicrepository/sd/res/triangle_down.png");
150 xChildNode.setCollapsedGraphicURL("private:graphicrepository/sd/res/triangle_right.png");
151 String[] children = sfa.getFolderContents(dir, true);
152 if (children != null){
153 for (int i=0; i<children.length; i++) {
154 // Get filename of file or directory
155 String filename = children[i];
156 dirlist( filename , xChildNode);
160 else{
161 xChildNode.setNodeGraphicURL( "private:graphicrepository/sw/imglst/nc20010.png");
163 } catch (CommandAbortedException ex) {
164 ex.printStackTrace();
165 } catch (com.sun.star.uno.Exception ex) {
166 ex.printStackTrace();
169 try {
170 xNode.appendChild( xChildNode );
171 } catch (com.sun.star.lang.IllegalArgumentException ex) {
172 ex.printStackTrace();
175 } // finish class UnoControlListBoxModel