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.ucb.CommandAbortedException; 30 import com.sun.star.ucb.XSimpleFileAccess; 31 import com.sun.star.uno.UnoRuntime; 32 import com.sun.star.uno.XInterface; 33 import ifc.awt.tree._XMutableTreeNode.XMutableTreeNodeCreator; 34 35 import java.io.PrintWriter; 36 import lib.Status; 37 import lib.StatusException; 38 39 import lib.TestCase; 40 import lib.TestEnvironment; 41 import lib.TestParameters; 42 import util.PropertyName; 43 import util.utils; 44 45 46 public class MutableTreeNode extends TestCase { 47 private static XTextDocument xTextDoc; 48 private static XInterface oObj = null; 49 private static XMutableTreeDataModel mXTreeDataModel; 50 private static XMultiServiceFactory mxMSF; 51 private static PrintWriter log; 52 private static boolean debug = false; 53 54 /** 55 * Creates StarOffice Writer document. 56 */ initialize(TestParameters tParam, PrintWriter log)57 protected void initialize(TestParameters tParam, PrintWriter log) { 58 this.log = log; 59 debug = tParam.getBool(PropertyName.DEBUG_IS_ACTIVE); 60 mxMSF = (XMultiServiceFactory) tParam.getMSF(); 61 // log.println("creating a textdocument"); 62 // xTextDoc = WriterTools.createTextDoc(mxMSF); 63 } 64 65 /** 66 * Disposes StarOffice Writer document. 67 */ cleanup(TestParameters tParam, PrintWriter log)68 protected void cleanup(TestParameters tParam, PrintWriter log) { 69 log.println(" disposing xTextDoc "); 70 71 util.DesktopTools.closeDoc(xTextDoc); 72 } 73 createTestEnvironment(TestParameters Param, PrintWriter log)74 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 75 PrintWriter log) { 76 XMutableTreeNode xNode; 77 78 try { 79 mXTreeDataModel = (XMutableTreeDataModel) UnoRuntime.queryInterface(XMutableTreeDataModel.class, 80 mxMSF.createInstance("com.sun.star.awt.tree.MutableTreeDataModel")); 81 } catch (com.sun.star.uno.Exception ex) { 82 throw new StatusException(Status.failed("ERROR: could not create instance of" + 83 " 'com.sun.star.awt.tree.MutableTreeDataModel'")); 84 } 85 86 xNode = mXTreeDataModel.createNode("UnoTreeControl", false); 87 88 String sDisplayValue = "UnoTreeControl"; 89 String sExpandedGraphicURL = "private:graphicrepository/sd/res/triangle_down.png"; 90 String sCollapsedGraphicURL = "private:graphicrepository/sd/res/triangle_right.png"; 91 String sNodeGraphicURL = "private:graphicrepository/sw/imglst/nc20010.png"; 92 93 xNode.setDisplayValue( sDisplayValue); 94 xNode.setDataValue(sDisplayValue); 95 xNode.setExpandedGraphicURL(sExpandedGraphicURL); 96 xNode.setCollapsedGraphicURL(sCollapsedGraphicURL); 97 xNode.setNodeGraphicURL(sNodeGraphicURL); 98 xNode.setHasChildrenOnDemand(true); 99 100 fillNode(xNode); 101 102 TestEnvironment tEnv = new TestEnvironment(xNode); 103 104 tEnv.addObjRelation("OBJNAME", "toolkit.MutableTreeDataModel"); 105 log.println("ImplementationName: " + utils.getImplName(oObj)); 106 107 tEnv.addObjRelation("XTreeNode_DisplayValue", sDisplayValue); 108 tEnv.addObjRelation("XTreeNode_ExpandedGraphicURL", sExpandedGraphicURL); 109 tEnv.addObjRelation("XTreeNode_CollapsedGraphicURL", sCollapsedGraphicURL); 110 tEnv.addObjRelation("XTreeNode_NodeGraphicURL", sNodeGraphicURL); 111 112 tEnv.addObjRelation("XMutableTreeNode_NodeToAppend", 113 mXTreeDataModel.createNode("XMutableTreeNode_NodeToAppend", true)); 114 115 tEnv.addObjRelation("XMutableTreeNodeCreator", new XMutableTreeNodeCreator(){ 116 public XMutableTreeNode createNode(String name){ 117 return mXTreeDataModel.createNode(name, true); 118 } 119 }); 120 121 return tEnv; 122 } // finish method getTestEnvironment 123 fillNode( XMutableTreeNode xNode )124 private void fillNode( XMutableTreeNode xNode ){ 125 126 if( xNode.getChildCount() == 0 ) 127 { 128 String sParentPath = (String) xNode.getDataValue(); 129 130 String officeUserPath = utils.getOfficeUserPath(mxMSF); 131 Object fileacc = null; 132 try { 133 fileacc = mxMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess"); 134 } catch (com.sun.star.uno.Exception ex) { 135 ex.printStackTrace(); 136 } 137 XSimpleFileAccess sA = (XSimpleFileAccess) 138 UnoRuntime.queryInterface(XSimpleFileAccess.class,fileacc); 139 140 141 dirlist(officeUserPath, xNode); 142 } 143 } 144 dirlist(String dir, XMutableTreeNode xNode)145 private void dirlist(String dir, XMutableTreeNode xNode){ 146 147 Object fileacc = null; 148 try { 149 fileacc = mxMSF.createInstance("com.sun.star.comp.ucb.SimpleFileAccess"); 150 } catch (com.sun.star.uno.Exception ex) { 151 ex.printStackTrace(); 152 } 153 XSimpleFileAccess sfa = (XSimpleFileAccess) 154 UnoRuntime.queryInterface(XSimpleFileAccess.class,fileacc); 155 XMutableTreeNode xChildNode = null; 156 try { 157 xChildNode = mXTreeDataModel.createNode(dir.substring(dir.lastIndexOf("/")+1, dir.length()), sfa.isFolder(dir)); 158 xChildNode.setDataValue(dir); 159 boolean test = sfa.isFolder(dir); 160 if (sfa.isFolder(dir)){ 161 xChildNode.setExpandedGraphicURL( "private:graphicrepository/sd/res/triangle_down.png"); 162 xChildNode.setCollapsedGraphicURL("private:graphicrepository/sd/res/triangle_right.png"); 163 String[] children = sfa.getFolderContents(dir, true); 164 if (children != null){ 165 for (int i=0; i<children.length; i++) { 166 // Get filename of file or directory 167 String filename = children[i]; 168 dirlist( filename , xChildNode); 169 } 170 } 171 } 172 else{ 173 xChildNode.setNodeGraphicURL( "private:graphicrepository/sw/imglst/nc20010.png"); 174 } 175 } catch (CommandAbortedException ex) { 176 ex.printStackTrace(); 177 } catch (com.sun.star.uno.Exception ex) { 178 ex.printStackTrace(); 179 } 180 181 try { 182 xNode.appendChild( xChildNode ); 183 } catch (com.sun.star.lang.IllegalArgumentException ex) { 184 ex.printStackTrace(); 185 } 186 } 187 } // finish class UnoControlListBoxModel 188