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