1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #ifndef DBAUI_UNODIRECTSQL_HXX
32 #include "unoDirectSql.hxx"
33 #endif
34 #ifndef _DBU_REGHELPER_HXX_
35 #include "dbu_reghelper.hxx"
36 #endif
37 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
38 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
39 #endif
40 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
41 #include <com/sun/star/container/XNameAccess.hpp>
42 #endif
43 #ifndef _COM_SUN_STAR_CONNECTION_XCONNECTION_HPP_
44 #include <com/sun/star/connection/XConnection.hpp>
45 #endif
46 #ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_
47 #include <com/sun/star/container/XNamed.hpp>
48 #endif
49 #ifndef _DBACCESS_UI_DIRECTSQL_HXX_
50 #include "directsql.hxx"
51 #endif
52 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
53 #include "dbustrings.hrc"
54 #endif
55 #ifndef _DBAUI_DATASOURCECONNECTOR_HXX_
56 #include "datasourceconnector.hxx"
57 #endif
58 #ifndef TOOLS_DIAGNOSE_EX_H
59 #include <tools/diagnose_ex.h>
60 #endif
61 
62 
63 extern "C" void SAL_CALL createRegistryInfo_ODirectSQLDialog()
64 {
65 	static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::ODirectSQLDialog > aAutoRegistration;
66 }
67 
68 //.........................................................................
69 namespace dbaui
70 {
71 //.........................................................................
72 
73 	using namespace ::com::sun::star::uno;
74 	using namespace ::com::sun::star::lang;
75 	using namespace ::com::sun::star::beans;
76 	using namespace ::com::sun::star::container;
77 	using namespace ::com::sun::star::sdbcx;
78 	using namespace ::com::sun::star::sdbc;
79 	using namespace ::com::sun::star::sdb;
80 
81 	//=====================================================================
82 	//= ODirectSQLDialog
83 	//=====================================================================
84 DBG_NAME(ODirectSQLDialog)
85 //---------------------------------------------------------------------
86 	ODirectSQLDialog::ODirectSQLDialog(const Reference< XMultiServiceFactory >& _rxORB)
87 		:ODirectSQLDialog_BASE( _rxORB )
88 	{
89         DBG_CTOR(ODirectSQLDialog,NULL);
90 
91 	}
92 
93 	//---------------------------------------------------------------------
94 	ODirectSQLDialog::~ODirectSQLDialog()
95 	{
96 
97         DBG_DTOR(ODirectSQLDialog,NULL);
98     }
99 
100 	//---------------------------------------------------------------------
101 	IMPLEMENT_IMPLEMENTATION_ID( ODirectSQLDialog )
102 
103 	//---------------------------------------------------------------------
104 	IMPLEMENT_SERVICE_INFO1_STATIC( ODirectSQLDialog, "com.sun.star.comp.sdb.DirectSQLDialog", SERVICE_SDB_DIRECTSQLDIALOG )
105 
106 	//---------------------------------------------------------------------
107 	IMPLEMENT_PROPERTYCONTAINER_DEFAULTS( ODirectSQLDialog )
108 
109 	//---------------------------------------------------------------------
110 	Dialog*	ODirectSQLDialog::createDialog(Window* _pParent)
111 	{
112 		// obtain all the objects needed for the dialog
113 		Reference< XConnection > xConnection = m_xActiveConnection;
114 		if ( !xConnection.is() )
115 		{
116 			try
117 			{
118 				// the connection the row set is working with
119 				ODatasourceConnector aDSConnector(m_aContext.getLegacyServiceFactory(),_pParent);
120 				xConnection = aDSConnector.connect( m_sInitialSelection, NULL );
121 			}
122             catch( const Exception& )
123             {
124                 DBG_UNHANDLED_EXCEPTION();
125             }
126 		}
127 		if ( !xConnection.is() )
128 			// can't create the dialog if I have improper settings
129 			return NULL;
130 
131 		return new DirectSQLDialog( _pParent, xConnection);
132 	}
133 	//---------------------------------------------------------------------
134 	void ODirectSQLDialog::implInitialize(const Any& _rValue)
135 	{
136 		PropertyValue aProperty;
137 		if (_rValue >>= aProperty)
138 		{
139 			if (0 == aProperty.Name.compareToAscii("InitialSelection"))
140 			{
141 				OSL_VERIFY( aProperty.Value >>= m_sInitialSelection );
142                 return;
143 			}
144 			else if (0 == aProperty.Name.compareToAscii("ActiveConnection"))
145 			{
146 				m_xActiveConnection.set( aProperty.Value, UNO_QUERY );
147                 OSL_ENSURE( m_xActiveConnection.is(), "ODirectSQLDialog::implInitialize: invalid connection!" );
148                 return;
149 			}
150 		}
151 		ODirectSQLDialog_BASE::implInitialize(_rValue);
152 	}
153 //.........................................................................
154 }	// namespace dbaui
155 //.........................................................................
156 
157