1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <stdio.h>
29*cdf0e10cSrcweir #include <wchar.h>
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <osl/file.hxx>
34*cdf0e10cSrcweir #include <osl/process.h>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/awt/tree/XMutableTreeDataModel.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/awt/tree/XTreeControl.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/awt/tree/XTreeExpansionListener.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/awt/tree/XTreeEditListener.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/awt/XDialog.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/awt/XControlContainer.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/view/SelectionType.hpp>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <tools/urlobj.hxx>
51*cdf0e10cSrcweir #include <vcl/image.hxx>
52*cdf0e10cSrcweir #include <vcl/graph.hxx>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir #include <string.h>
57*cdf0e10cSrcweir #include <rtl/ref.hxx>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include "imagemgr.hxx"
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir using rtl::OUString;
62*cdf0e10cSrcweir using namespace com::sun::star::uno;
63*cdf0e10cSrcweir using namespace com::sun::star::lang;
64*cdf0e10cSrcweir using namespace com::sun::star::beans;
65*cdf0e10cSrcweir using namespace com::sun::star::bridge;
66*cdf0e10cSrcweir using namespace com::sun::star::frame;
67*cdf0e10cSrcweir using namespace com::sun::star::registry;
68*cdf0e10cSrcweir using namespace com::sun::star::awt;
69*cdf0e10cSrcweir using namespace com::sun::star::awt::tree;
70*cdf0e10cSrcweir using namespace com::sun::star::container;
71*cdf0e10cSrcweir using namespace com::sun::star::view;
72*cdf0e10cSrcweir using namespace com::sun::star::util;
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir class DirectoryTree : public ::cppu::WeakImplHelper2< XTreeExpansionListener, XTreeEditListener >
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir public:
77*cdf0e10cSrcweir 	DirectoryTree( const Reference< XComponentContext >& xComponentContext );
78*cdf0e10cSrcweir 	virtual ~DirectoryTree();
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	void fillNode( const Reference< XMutableTreeNode >& xNode );
81*cdf0e10cSrcweir 	void display( const OUString& rURL );
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	// XTreeExpansionListener
84*cdf0e10cSrcweir     virtual void SAL_CALL requestChildNodes( const TreeExpansionEvent& Event ) throw (RuntimeException);
85*cdf0e10cSrcweir     virtual void SAL_CALL treeExpanding( const TreeExpansionEvent& Event ) throw (ExpandVetoException, RuntimeException);
86*cdf0e10cSrcweir     virtual void SAL_CALL treeCollapsing( const TreeExpansionEvent& Event ) throw (ExpandVetoException, RuntimeException);
87*cdf0e10cSrcweir     virtual void SAL_CALL treeExpanded( const TreeExpansionEvent& Event ) throw (RuntimeException);
88*cdf0e10cSrcweir     virtual void SAL_CALL treeCollapsed( const TreeExpansionEvent& Event ) throw (RuntimeException);
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	// XTreeEditListener
91*cdf0e10cSrcweir     virtual void SAL_CALL nodeEditing( const Reference< XTreeNode >& Node ) throw (VetoException, RuntimeException);
92*cdf0e10cSrcweir     virtual void SAL_CALL nodeEdited( const Reference< XTreeNode >& Node, const OUString& NewText ) throw (RuntimeException);
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	// XEventListener
95*cdf0e10cSrcweir     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (RuntimeException);
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	Reference< XMultiComponentFactory > mxMultiComponentFactoryServer;
98*cdf0e10cSrcweir 	Reference< XComponentContext > mxComponentContext;
99*cdf0e10cSrcweir 	Reference< XTreeControl > mxTreeControl;
100*cdf0e10cSrcweir 	Reference< XMutableTreeDataModel > mxTreeDataModel;
101*cdf0e10cSrcweir };
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir DirectoryTree::DirectoryTree( const Reference< XComponentContext >& xComponentContext )
104*cdf0e10cSrcweir : mxComponentContext( xComponentContext )
105*cdf0e10cSrcweir , mxMultiComponentFactoryServer( xComponentContext->getServiceManager() )
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir DirectoryTree::~DirectoryTree()
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir void DirectoryTree::display( const OUString& rURL )
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	// some property names for later use
116*cdf0e10cSrcweir 	const OUString sPositionX( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) );
117*cdf0e10cSrcweir 	const OUString sPositionY( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) );
118*cdf0e10cSrcweir 	const OUString sWidth( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
119*cdf0e10cSrcweir 	const OUString sHeight( RTL_CONSTASCII_USTRINGPARAM( "Height" ) );
120*cdf0e10cSrcweir 	const OUString sDataModel( RTL_CONSTASCII_USTRINGPARAM( "DataModel" ) );
121*cdf0e10cSrcweir 	const OUString sSelectionType( RTL_CONSTASCII_USTRINGPARAM( "SelectionType" ) );
122*cdf0e10cSrcweir 	const OUString sShowsRootHandles( RTL_CONSTASCII_USTRINGPARAM( "ShowsRootHandles" ) );
123*cdf0e10cSrcweir 	const OUString sShowsHandles( RTL_CONSTASCII_USTRINGPARAM( "ShowsHandles" ) );
124*cdf0e10cSrcweir 	const OUString sRootDisplayed( RTL_CONSTASCII_USTRINGPARAM( "RootDisplayed" ) );
125*cdf0e10cSrcweir 	const OUString sEditable( RTL_CONSTASCII_USTRINGPARAM( "Editable" ) );
126*cdf0e10cSrcweir 	const OUString sTitle( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
127*cdf0e10cSrcweir 	const OUString sRowHeight( RTL_CONSTASCII_USTRINGPARAM( "RowHeight" ) );
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	// first create a data model for our tree control
130*cdf0e10cSrcweir 	mxTreeDataModel = Reference< XMutableTreeDataModel >(
131*cdf0e10cSrcweir 		mxMultiComponentFactoryServer->createInstanceWithContext(
132*cdf0e10cSrcweir 	        OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.tree.MutableTreeDataModel" ) ),
133*cdf0e10cSrcweir 		    mxComponentContext ), UNO_QUERY_THROW );
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	// now fill it with some sample data
136*cdf0e10cSrcweir 	Reference< XMutableTreeNode > xNode( mxTreeDataModel->createNode( Any( rURL ), false ), UNO_QUERY_THROW );
137*cdf0e10cSrcweir 	xNode->setDataValue( Any( rURL ) );
138*cdf0e10cSrcweir 	xNode->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
139*cdf0e10cSrcweir 	xNode->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	fillNode( xNode );
142*cdf0e10cSrcweir 	mxTreeDataModel->setRoot( xNode );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	// now create the dialog
145*cdf0e10cSrcweir 	Reference< XControlModel > xDialogModel(
146*cdf0e10cSrcweir 		mxMultiComponentFactoryServer->createInstanceWithContext(
147*cdf0e10cSrcweir 	        OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlDialogModel" ) ),
148*cdf0e10cSrcweir 		    mxComponentContext ), UNO_QUERY_THROW );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	Reference< XPropertySet > xDialogPropertySet( xDialogModel, UNO_QUERY_THROW );
151*cdf0e10cSrcweir 	xDialogPropertySet->setPropertyValue( sPositionX,	Any( sal_Int32(50) ) );
152*cdf0e10cSrcweir 	xDialogPropertySet->setPropertyValue( sPositionY,	Any( sal_Int32(50) ) );
153*cdf0e10cSrcweir 	xDialogPropertySet->setPropertyValue( sWidth,		Any( sal_Int32(256) ) );
154*cdf0e10cSrcweir 	xDialogPropertySet->setPropertyValue( sHeight,		Any( sal_Int32(256) ) );
155*cdf0e10cSrcweir 	xDialogPropertySet->setPropertyValue( sTitle,		Any( OUString( RTL_CONSTASCII_USTRINGPARAM( "Tree Control Test" ) ) ) );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xDialogMSF( xDialogModel, UNO_QUERY_THROW );
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	// now create our tree control
160*cdf0e10cSrcweir 	Reference< XControlModel > xTreeControlModel(
161*cdf0e10cSrcweir 		xDialogMSF->createInstance(
162*cdf0e10cSrcweir 	        OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.tree.TreeControlModel" ) ) ),
163*cdf0e10cSrcweir 		    UNO_QUERY_THROW );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 	Reference< XPropertySet > XTreeControlModelSet( xTreeControlModel, UNO_QUERY_THROW );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sSelectionType,	Any( SelectionType_NONE ) );
168*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sPositionX,		Any( sal_Int32(3) ) );
169*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sPositionY,		Any( sal_Int32(3) ) );
170*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sWidth,			Any( sal_Int32(253) ) );
171*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sHeight,		Any( sal_Int32(253) ) );
172*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sDataModel,		Any( mxTreeDataModel ) );
173*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sShowsRootHandles,Any( sal_False ) );
174*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sShowsHandles,	Any( sal_False ) );
175*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sRootDisplayed,	Any( sal_True ) );
176*cdf0e10cSrcweir 	XTreeControlModelSet->setPropertyValue( sEditable,		Any( sal_True ) );
177*cdf0e10cSrcweir //	XTreeControlModelSet->setPropertyValue( sRowHeight,		Any( sal_Int32( 12 ) ) );
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	Reference< XNameContainer > xDialogModelContainer( xDialogModel, UNO_QUERY_THROW );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	const OUString sTreeControlName( RTL_CONSTASCII_USTRINGPARAM( "tree" ) );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	xDialogModelContainer->insertByName( sTreeControlName, Any( xTreeControlModel ) );
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	// now create the peers
186*cdf0e10cSrcweir 	Reference< XControl > xDialogControl(
187*cdf0e10cSrcweir 		mxMultiComponentFactoryServer->createInstanceWithContext(
188*cdf0e10cSrcweir 	        OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlDialog" ) ),
189*cdf0e10cSrcweir 		    mxComponentContext ), UNO_QUERY_THROW );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir 	xDialogControl->setModel( xDialogModel );
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 	Reference< XToolkit > xToolkit(
194*cdf0e10cSrcweir 		mxMultiComponentFactoryServer->createInstanceWithContext(
195*cdf0e10cSrcweir 	        OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.Toolkit" ) ),
196*cdf0e10cSrcweir 		    mxComponentContext ), UNO_QUERY_THROW );
197*cdf0e10cSrcweir 	xDialogControl->createPeer( xToolkit, 0 );
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	// get the peers of the sub controls from the dialog peer container
200*cdf0e10cSrcweir 	Reference< XControlContainer > xDialogContainer( xDialogControl, UNO_QUERY_THROW );
201*cdf0e10cSrcweir 	mxTreeControl = Reference< XTreeControl >( xDialogContainer->getControl( sTreeControlName ), UNO_QUERY_THROW );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	Reference< XTreeExpansionListener > xListener( static_cast<XWeak*>(this), UNO_QUERY_THROW );
204*cdf0e10cSrcweir 	mxTreeControl->addTreeExpansionListener( xListener );
205*cdf0e10cSrcweir 	Reference< XDialog > xDialog( xDialogControl, UNO_QUERY_THROW );
206*cdf0e10cSrcweir 	xDialog->execute();
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir void DirectoryTree::fillNode( const Reference< XMutableTreeNode >& xNode )
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir 	if( xNode->getChildCount() == 0 )
212*cdf0e10cSrcweir 	{
213*cdf0e10cSrcweir 		OUString sParentPath;
214*cdf0e10cSrcweir 		xNode->getDataValue() >>= sParentPath;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 		osl::Directory aDirectory( sParentPath );
217*cdf0e10cSrcweir 		if( aDirectory.open() == osl::Directory::E_None )
218*cdf0e10cSrcweir 		{
219*cdf0e10cSrcweir 			osl::DirectoryItem aItem;
220*cdf0e10cSrcweir 			osl::FileStatus fs( FileStatusMask_Type | FileStatusMask_FileURL);
221*cdf0e10cSrcweir 			while( aDirectory.getNextItem( aItem, 0xffffffff ) == osl::Directory::E_None )
222*cdf0e10cSrcweir 			{
223*cdf0e10cSrcweir 				if (aItem.getFileStatus(fs) == osl::FileBase::E_None)
224*cdf0e10cSrcweir 				{
225*cdf0e10cSrcweir 					bool bDirectory = fs.getFileType() == osl::FileStatus::Directory;
226*cdf0e10cSrcweir 					Reference< XMutableTreeNode > xChildNode( mxTreeDataModel->createNode( Any( fs.getFileName() ), bDirectory ), UNO_QUERY_THROW );
227*cdf0e10cSrcweir 					xChildNode->setDataValue( Any( fs.getFileURL() ) );
228*cdf0e10cSrcweir 					if( bDirectory )
229*cdf0e10cSrcweir 					{
230*cdf0e10cSrcweir 						xChildNode->setExpandedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_down.png" ) ) );
231*cdf0e10cSrcweir 						xChildNode->setCollapsedGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:graphicrepository/sd/res/triangle_right.png" ) ) );
232*cdf0e10cSrcweir 					}
233*cdf0e10cSrcweir 					else
234*cdf0e10cSrcweir 					{
235*cdf0e10cSrcweir 						xChildNode->setNodeGraphicURL( OUString( RTL_CONSTASCII_USTRINGPARAM("private:graphicrepository/sw/imglst/nc20010.png") ) );
236*cdf0e10cSrcweir 					}
237*cdf0e10cSrcweir 					xNode->appendChild( xChildNode );
238*cdf0e10cSrcweir 				}
239*cdf0e10cSrcweir 			}
240*cdf0e10cSrcweir 		}
241*cdf0e10cSrcweir 	}
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir // XTreeExpansionListener
245*cdf0e10cSrcweir void SAL_CALL DirectoryTree::requestChildNodes( const TreeExpansionEvent& rEvent ) throw (RuntimeException)
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	if( rEvent.Node.is() && rEvent.Node->hasChildsOnDemand() )
248*cdf0e10cSrcweir 	{
249*cdf0e10cSrcweir 		Reference< XMutableTreeNode > xNode( rEvent.Node, UNO_QUERY );
250*cdf0e10cSrcweir 		if( xNode.is() )
251*cdf0e10cSrcweir 		{
252*cdf0e10cSrcweir 			fillNode( xNode );
253*cdf0e10cSrcweir 			xNode->setHasChildsOnDemand( sal_False );
254*cdf0e10cSrcweir 		}
255*cdf0e10cSrcweir 	}
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir void SAL_CALL DirectoryTree::treeExpanding( const TreeExpansionEvent& /*rEvent*/ ) throw (ExpandVetoException, RuntimeException)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir void SAL_CALL DirectoryTree::treeCollapsing( const TreeExpansionEvent&  ) throw (ExpandVetoException, RuntimeException)
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir void SAL_CALL DirectoryTree::treeExpanded( const TreeExpansionEvent&  ) throw (RuntimeException)
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir void SAL_CALL DirectoryTree::treeCollapsed( const TreeExpansionEvent& /*rEvent*/ ) throw (RuntimeException)
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir /*
273*cdf0e10cSrcweir 	if( rEvent.Node != mxTreeDataModel->getRoot() )
274*cdf0e10cSrcweir 	{
275*cdf0e10cSrcweir 		Reference< XMutableTreeNode > xNode( rEvent.Node, UNO_QUERY );
276*cdf0e10cSrcweir 		if( xNode.is() )
277*cdf0e10cSrcweir 		{
278*cdf0e10cSrcweir 			while( xNode->getChildCount() )
279*cdf0e10cSrcweir 				xNode->removeChildByIndex(0);
280*cdf0e10cSrcweir 			xNode->setHasChildsOnDemand( sal_True );
281*cdf0e10cSrcweir 		}
282*cdf0e10cSrcweir 	}
283*cdf0e10cSrcweir */
284*cdf0e10cSrcweir }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir // XTreeEditListener
287*cdf0e10cSrcweir void SAL_CALL DirectoryTree::nodeEditing( const Reference< XTreeNode >&  ) throw (VetoException, RuntimeException)
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir void SAL_CALL DirectoryTree::nodeEdited( const Reference< XTreeNode >& , const OUString&  ) throw (RuntimeException)
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir // XEventListener
296*cdf0e10cSrcweir void SAL_CALL DirectoryTree::disposing( const ::com::sun::star::lang::EventObject&  ) throw (RuntimeException)
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir //============================================================================
301*cdf0e10cSrcweir int SAL_CALL main( int argc, char **argv )
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir     OUString sConnectionString(RTL_CONSTASCII_USTRINGPARAM("uno:socket,host=localhost,port=5678;urp;StarOffice.ServiceManager"));
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	if (argc < 2)
306*cdf0e10cSrcweir 	{
307*cdf0e10cSrcweir 		printf("using: treetest <directory> [<uno_connection_url>]\n\n"
308*cdf0e10cSrcweir #ifdef WNT
309*cdf0e10cSrcweir 				"example: treetest  \"c:\" \"uno:socket,host=localhost,port=5678;urp;StarOffice.ServiceManager\"\n");
310*cdf0e10cSrcweir #else
311*cdf0e10cSrcweir 				"example: treetest  \"/etc\" \"uno:socket,host=localhost,port=5678;urp;StarOffice.ServiceManager\"\n");
312*cdf0e10cSrcweir #endif
313*cdf0e10cSrcweir 		exit(1);
314*cdf0e10cSrcweir 	}
315*cdf0e10cSrcweir  	if (argc == 3)
316*cdf0e10cSrcweir 	{
317*cdf0e10cSrcweir 		sConnectionString = OUString::createFromAscii(argv[2]);
318*cdf0e10cSrcweir 	}
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 	// Creates a simple registry service instance.
321*cdf0e10cSrcweir     Reference< XSimpleRegistry > xSimpleRegistry(::cppu::createSimpleRegistry() );
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir     // Connects the registry to a persistent data source represented by an URL.
324*cdf0e10cSrcweir     xSimpleRegistry->open(
325*cdf0e10cSrcweir 		OUString( RTL_CONSTASCII_USTRINGPARAM("treetest.rdb") ), sal_True, sal_False );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     /* Bootstraps an initial component context with service manager upon a given
328*cdf0e10cSrcweir        registry. This includes insertion of initial services:
329*cdf0e10cSrcweir        - (registry) service manager, shared lib loader,
330*cdf0e10cSrcweir        - simple registry, nested registry,
331*cdf0e10cSrcweir        - implementation registration
332*cdf0e10cSrcweir        - registry typedescription provider, typedescription manager (also
333*cdf0e10cSrcweir          installs it into cppu core)
334*cdf0e10cSrcweir     */
335*cdf0e10cSrcweir     Reference< XComponentContext > xComponentContext(
336*cdf0e10cSrcweir         ::cppu::bootstrap_InitialComponentContext( xSimpleRegistry ) );
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir     /* Gets the service manager instance to be used (or null). This method has
339*cdf0e10cSrcweir        been added for convenience, because the service manager is a often used
340*cdf0e10cSrcweir        object.
341*cdf0e10cSrcweir     */
342*cdf0e10cSrcweir 	Reference< XMultiComponentFactory > xMultiComponentFactoryClient(
343*cdf0e10cSrcweir 		xComponentContext->getServiceManager() );
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     /* Creates an instance of a component which supports the services specified
346*cdf0e10cSrcweir        by the factory.
347*cdf0e10cSrcweir     */
348*cdf0e10cSrcweir     Reference< XInterface > xInterface =
349*cdf0e10cSrcweir         xMultiComponentFactoryClient->createInstanceWithContext(
350*cdf0e10cSrcweir             OUString::createFromAscii( "com.sun.star.bridge.UnoUrlResolver" ),
351*cdf0e10cSrcweir             xComponentContext );
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir     Reference< XUnoUrlResolver > resolver( xInterface, UNO_QUERY );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir     // Resolves the component context from the office, on the uno URL given by argv[1].
356*cdf0e10cSrcweir     try
357*cdf0e10cSrcweir     {
358*cdf0e10cSrcweir         xInterface = Reference< XInterface >(
359*cdf0e10cSrcweir             resolver->resolve( sConnectionString ), UNO_QUERY );
360*cdf0e10cSrcweir     }
361*cdf0e10cSrcweir     catch ( Exception& e )
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir 		printf("Error: cannot establish a connection using '%s':\n       %s\n",
364*cdf0e10cSrcweir                OUStringToOString(sConnectionString, RTL_TEXTENCODING_ASCII_US).getStr(),
365*cdf0e10cSrcweir                OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
366*cdf0e10cSrcweir 		exit(1);
367*cdf0e10cSrcweir     }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir     // gets the server component context as property of the office component factory
370*cdf0e10cSrcweir     Reference< XPropertySet > xPropSet( xInterface, UNO_QUERY );
371*cdf0e10cSrcweir     xPropSet->getPropertyValue( OUString::createFromAscii("DefaultContext") ) >>= xComponentContext;
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     // gets the service manager from the office
374*cdf0e10cSrcweir     Reference< XMultiComponentFactory > xMultiComponentFactoryServer(
375*cdf0e10cSrcweir         xComponentContext->getServiceManager() );
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 	try
378*cdf0e10cSrcweir 	{
379*cdf0e10cSrcweir 		OUString ustrFileURL;
380*cdf0e10cSrcweir 		osl::FileBase::getFileURLFromSystemPath( OUString::createFromAscii(argv[1]), ustrFileURL );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 		rtl::Reference< DirectoryTree >(
383*cdf0e10cSrcweir 			new DirectoryTree( xComponentContext ) )->display(ustrFileURL);
384*cdf0e10cSrcweir 	}
385*cdf0e10cSrcweir 	catch( Exception& e )
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir 		printf("Error: exception caught during test:\n       %s\n",
388*cdf0e10cSrcweir                OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
389*cdf0e10cSrcweir 		exit(1);
390*cdf0e10cSrcweir 	}
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 	// dispose the local service manager
393*cdf0e10cSrcweir     Reference< XComponent >::query( xMultiComponentFactoryClient )->dispose();
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir     return 0;
396*cdf0e10cSrcweir }
397