xref: /trunk/main/dbaccess/source/ui/dlg/dlgsave.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef DBAUI_DLGSAVE_HXX
32*cdf0e10cSrcweir #include "dlgsave.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #ifndef DBAUI_DLGSAVE_HRC
35*cdf0e10cSrcweir #include "dlgsave.hrc"
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX //autogen
38*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_
41*cdf0e10cSrcweir #include "dbu_dlg.hrc"
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
44*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
47*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #ifndef _DBAUI_SQLMESSAGE_HXX_
50*cdf0e10cSrcweir #include "sqlmessage.hxx"
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
53*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
56*cdf0e10cSrcweir #include "UITools.hxx"
57*cdf0e10cSrcweir #endif
58*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
59*cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
60*cdf0e10cSrcweir #endif
61*cdf0e10cSrcweir #ifndef DBAUI_SQLNAMEEDIT_HXX
62*cdf0e10cSrcweir #include "SqlNameEdit.hxx"
63*cdf0e10cSrcweir #endif
64*cdf0e10cSrcweir #ifndef _BUTTON_HXX //autogen
65*cdf0e10cSrcweir #include <vcl/button.hxx>
66*cdf0e10cSrcweir #endif
67*cdf0e10cSrcweir #ifndef _FIXED_HXX //autogen
68*cdf0e10cSrcweir #include <vcl/fixed.hxx>
69*cdf0e10cSrcweir #endif
70*cdf0e10cSrcweir #ifndef _EDIT_HXX //autogen
71*cdf0e10cSrcweir #include <vcl/edit.hxx>
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
74*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
77*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
78*cdf0e10cSrcweir #endif
79*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
80*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
81*cdf0e10cSrcweir #endif
82*cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_
83*cdf0e10cSrcweir #include "moduledbu.hxx"
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_UI_INC_OBJECTNAMECHECK_HXX
86*cdf0e10cSrcweir #include "objectnamecheck.hxx"
87*cdf0e10cSrcweir #endif
88*cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
89*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
90*cdf0e10cSrcweir #endif
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir using namespace dbaui;
94*cdf0e10cSrcweir using namespace dbtools;
95*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
96*cdf0e10cSrcweir using namespace ::com::sun::star::container;
97*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
98*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
99*cdf0e10cSrcweir namespace dbaui
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir class OSaveAsDlgImpl
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir public:
104*cdf0e10cSrcweir     FixedText           m_aDescription;
105*cdf0e10cSrcweir     FixedText           m_aCatalogLbl;
106*cdf0e10cSrcweir     OSQLNameComboBox    m_aCatalog;
107*cdf0e10cSrcweir     FixedText           m_aSchemaLbl;
108*cdf0e10cSrcweir     OSQLNameComboBox    m_aSchema;
109*cdf0e10cSrcweir     FixedText           m_aLabel;
110*cdf0e10cSrcweir     OSQLNameEdit        m_aTitle;
111*cdf0e10cSrcweir     OKButton            m_aPB_OK;
112*cdf0e10cSrcweir     CancelButton        m_aPB_CANCEL;
113*cdf0e10cSrcweir     HelpButton          m_aPB_HELP;
114*cdf0e10cSrcweir     String              m_aQryLabel;
115*cdf0e10cSrcweir     String              m_sTblLabel;
116*cdf0e10cSrcweir     rtl::OUString       m_sCatalog;
117*cdf0e10cSrcweir     rtl::OUString       m_sSchema;
118*cdf0e10cSrcweir     String              m_aName;
119*cdf0e10cSrcweir     const IObjectNameCheck&
120*cdf0e10cSrcweir                         m_rObjectNameCheck;
121*cdf0e10cSrcweir     String              m_sParentURL;
122*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>            m_xMetaData;
123*cdf0e10cSrcweir     sal_Int32           m_nType;
124*cdf0e10cSrcweir     sal_Int32           m_nFlags;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     OSaveAsDlgImpl( Window * pParent,const sal_Int32& _rType,
127*cdf0e10cSrcweir                     const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,
128*cdf0e10cSrcweir                     const String& rDefault,
129*cdf0e10cSrcweir                     const IObjectNameCheck& _rObjectNameCheck,
130*cdf0e10cSrcweir                     sal_Int32 _nFlags);
131*cdf0e10cSrcweir     OSaveAsDlgImpl( Window * pParent,
132*cdf0e10cSrcweir                     const String& rDefault,
133*cdf0e10cSrcweir                     const IObjectNameCheck& _rObjectNameCheck,
134*cdf0e10cSrcweir                     sal_Int32 _nFlags);
135*cdf0e10cSrcweir };
136*cdf0e10cSrcweir // -----------------------------------------------------------------------------
137*cdf0e10cSrcweir } // dbaui
138*cdf0e10cSrcweir // -----------------------------------------------------------------------------
139*cdf0e10cSrcweir OSaveAsDlgImpl::OSaveAsDlgImpl( Window * _pParent,
140*cdf0e10cSrcweir                         const sal_Int32& _rType,
141*cdf0e10cSrcweir                         const Reference< XConnection>& _xConnection,
142*cdf0e10cSrcweir                         const String& rDefault,
143*cdf0e10cSrcweir                         const IObjectNameCheck& _rObjectNameCheck,
144*cdf0e10cSrcweir                         sal_Int32 _nFlags)
145*cdf0e10cSrcweir     :m_aDescription(_pParent, ModuleRes (FT_DESCRIPTION))
146*cdf0e10cSrcweir     ,m_aCatalogLbl(_pParent, ModuleRes (FT_CATALOG))
147*cdf0e10cSrcweir     ,m_aCatalog(_pParent, ModuleRes (ET_CATALOG), ::rtl::OUString())
148*cdf0e10cSrcweir     ,m_aSchemaLbl(_pParent, ModuleRes (FT_SCHEMA))
149*cdf0e10cSrcweir     ,m_aSchema(_pParent, ModuleRes (ET_SCHEMA), ::rtl::OUString())
150*cdf0e10cSrcweir     ,m_aLabel(_pParent, ModuleRes (FT_TITLE))
151*cdf0e10cSrcweir     ,m_aTitle(_pParent, ModuleRes (ET_TITLE), ::rtl::OUString())
152*cdf0e10cSrcweir     ,m_aPB_OK(_pParent, ModuleRes( PB_OK ) )
153*cdf0e10cSrcweir     ,m_aPB_CANCEL(_pParent, ModuleRes( PB_CANCEL ))
154*cdf0e10cSrcweir     ,m_aPB_HELP(_pParent, ModuleRes( PB_HELP))
155*cdf0e10cSrcweir     ,m_aQryLabel(ModuleRes(STR_QRY_LABEL))
156*cdf0e10cSrcweir     ,m_sTblLabel(ModuleRes(STR_TBL_LABEL))
157*cdf0e10cSrcweir     ,m_aName(rDefault)
158*cdf0e10cSrcweir     ,m_rObjectNameCheck( _rObjectNameCheck )
159*cdf0e10cSrcweir              ,m_nType(_rType)
160*cdf0e10cSrcweir              ,m_nFlags(_nFlags)
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     if ( _xConnection.is() )
163*cdf0e10cSrcweir         m_xMetaData = _xConnection->getMetaData();
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     if ( m_xMetaData.is() )
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         ::rtl::OUString sExtraNameChars( m_xMetaData->getExtraNameCharacters() );
168*cdf0e10cSrcweir         m_aCatalog.setAllowedChars( sExtraNameChars );
169*cdf0e10cSrcweir         m_aSchema.setAllowedChars( sExtraNameChars );
170*cdf0e10cSrcweir         m_aTitle.setAllowedChars( sExtraNameChars );
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir     m_aCatalog.SetDropDownLineCount( 10 );
174*cdf0e10cSrcweir     m_aSchema.SetDropDownLineCount( 10 );
175*cdf0e10cSrcweir }
176*cdf0e10cSrcweir // -----------------------------------------------------------------------------
177*cdf0e10cSrcweir OSaveAsDlgImpl::OSaveAsDlgImpl( Window * _pParent,
178*cdf0e10cSrcweir                         const String& rDefault,
179*cdf0e10cSrcweir                         const IObjectNameCheck& _rObjectNameCheck,
180*cdf0e10cSrcweir                         sal_Int32 _nFlags)
181*cdf0e10cSrcweir              :m_aDescription(_pParent, ModuleRes (FT_DESCRIPTION))
182*cdf0e10cSrcweir              ,m_aCatalogLbl(_pParent, ModuleRes (FT_CATALOG))
183*cdf0e10cSrcweir              ,m_aCatalog(_pParent, ModuleRes (ET_CATALOG))
184*cdf0e10cSrcweir              ,m_aSchemaLbl(_pParent, ModuleRes (FT_SCHEMA))
185*cdf0e10cSrcweir              ,m_aSchema(_pParent, ModuleRes (ET_SCHEMA))
186*cdf0e10cSrcweir              ,m_aLabel(_pParent, ModuleRes (FT_TITLE))
187*cdf0e10cSrcweir              ,m_aTitle(_pParent, ModuleRes (ET_TITLE))
188*cdf0e10cSrcweir              ,m_aPB_OK(_pParent, ModuleRes( PB_OK ) )
189*cdf0e10cSrcweir              ,m_aPB_CANCEL(_pParent, ModuleRes( PB_CANCEL ))
190*cdf0e10cSrcweir              ,m_aPB_HELP(_pParent, ModuleRes( PB_HELP))
191*cdf0e10cSrcweir              ,m_aQryLabel(ModuleRes(STR_QRY_LABEL))
192*cdf0e10cSrcweir              ,m_sTblLabel(ModuleRes(STR_TBL_LABEL))
193*cdf0e10cSrcweir              ,m_aName(rDefault)
194*cdf0e10cSrcweir              ,m_rObjectNameCheck( _rObjectNameCheck )
195*cdf0e10cSrcweir              ,m_nType(CommandType::COMMAND)
196*cdf0e10cSrcweir              ,m_nFlags(_nFlags)
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     m_aCatalog.SetDropDownLineCount( 10 );
199*cdf0e10cSrcweir     m_aSchema.SetDropDownLineCount( 10 );
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir // -----------------------------------------------------------------------------
203*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir //==================================================================
206*cdf0e10cSrcweir namespace
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir     typedef Reference< XResultSet > (SAL_CALL XDatabaseMetaData::*FGetMetaStrings)();
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     void lcl_fillComboList( ComboBox& _rList, const Reference< XConnection >& _rxConnection,
211*cdf0e10cSrcweir         FGetMetaStrings _GetAll, const ::rtl::OUString& _rCurrent )
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir         try
214*cdf0e10cSrcweir         {
215*cdf0e10cSrcweir             Reference< XDatabaseMetaData > xMetaData( _rxConnection->getMetaData(), UNO_QUERY_THROW );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir             Reference< XResultSet > xRes = (xMetaData.get()->*_GetAll)();
218*cdf0e10cSrcweir             Reference< XRow > xRow( xRes, UNO_QUERY_THROW );
219*cdf0e10cSrcweir             ::rtl::OUString sValue;
220*cdf0e10cSrcweir             while ( xRes->next() )
221*cdf0e10cSrcweir             {
222*cdf0e10cSrcweir                 sValue = xRow->getString( 1 );
223*cdf0e10cSrcweir                 if ( !xRow->wasNull() )
224*cdf0e10cSrcweir                     _rList.InsertEntry( sValue );
225*cdf0e10cSrcweir             }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir             sal_uInt16 nPos = _rList.GetEntryPos( String( _rCurrent ) );
228*cdf0e10cSrcweir             if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
229*cdf0e10cSrcweir                 _rList.SelectEntryPos( nPos );
230*cdf0e10cSrcweir             else
231*cdf0e10cSrcweir                 _rList.SelectEntryPos( 0 );
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir         catch( const Exception& )
234*cdf0e10cSrcweir         {
235*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir //==================================================================
241*cdf0e10cSrcweir OSaveAsDlg::OSaveAsDlg( Window * pParent,
242*cdf0e10cSrcweir                         const sal_Int32& _rType,
243*cdf0e10cSrcweir                         const Reference< XMultiServiceFactory >& _rxORB,
244*cdf0e10cSrcweir                         const Reference< XConnection>& _xConnection,
245*cdf0e10cSrcweir                         const String& rDefault,
246*cdf0e10cSrcweir                         const IObjectNameCheck& _rObjectNameCheck,
247*cdf0e10cSrcweir                         sal_Int32 _nFlags)
248*cdf0e10cSrcweir     :ModalDialog( pParent, ModuleRes(DLG_SAVE_AS))
249*cdf0e10cSrcweir     ,m_xORB( _rxORB )
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir     m_pImpl = new OSaveAsDlgImpl(this,_rType,_xConnection,rDefault,_rObjectNameCheck,_nFlags);
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     switch (_rType)
254*cdf0e10cSrcweir     {
255*cdf0e10cSrcweir         case CommandType::QUERY:
256*cdf0e10cSrcweir             implInitOnlyTitle(m_pImpl->m_aQryLabel);
257*cdf0e10cSrcweir             break;
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir         case CommandType::TABLE:
260*cdf0e10cSrcweir             OSL_ENSURE( m_pImpl->m_xMetaData.is(), "OSaveAsDlg::OSaveAsDlg: no meta data for entering table names: this will crash!" );
261*cdf0e10cSrcweir             {
262*cdf0e10cSrcweir                 m_pImpl->m_aLabel.SetText(m_pImpl->m_sTblLabel);
263*cdf0e10cSrcweir                 Point aPos(m_pImpl->m_aPB_OK.GetPosPixel());
264*cdf0e10cSrcweir                 if(m_pImpl->m_xMetaData.is() && !m_pImpl->m_xMetaData->supportsCatalogsInTableDefinitions())
265*cdf0e10cSrcweir                 {
266*cdf0e10cSrcweir                     m_pImpl->m_aCatalogLbl.Hide();
267*cdf0e10cSrcweir                     m_pImpl->m_aCatalog.Hide();
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir                     aPos = m_pImpl->m_aLabel.GetPosPixel();
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir                     m_pImpl->m_aLabel.SetPosPixel(m_pImpl->m_aSchemaLbl.GetPosPixel());
272*cdf0e10cSrcweir                     m_pImpl->m_aTitle.SetPosPixel(m_pImpl->m_aSchema.GetPosPixel());
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir                     m_pImpl->m_aSchemaLbl.SetPosPixel(m_pImpl->m_aCatalogLbl.GetPosPixel());
275*cdf0e10cSrcweir                     m_pImpl->m_aSchema.SetPosPixel(m_pImpl->m_aCatalog.GetPosPixel());
276*cdf0e10cSrcweir                 }
277*cdf0e10cSrcweir                 else
278*cdf0e10cSrcweir                 {
279*cdf0e10cSrcweir                     // now fill the catalogs
280*cdf0e10cSrcweir                     lcl_fillComboList( m_pImpl->m_aCatalog, _xConnection,
281*cdf0e10cSrcweir                         &XDatabaseMetaData::getCatalogs, _xConnection->getCatalog() );
282*cdf0e10cSrcweir                 }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir                 if ( !m_pImpl->m_xMetaData->supportsSchemasInTableDefinitions())
285*cdf0e10cSrcweir                 {
286*cdf0e10cSrcweir                     m_pImpl->m_aSchemaLbl.Hide();
287*cdf0e10cSrcweir                     m_pImpl->m_aSchema.Hide();
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir                     aPos = m_pImpl->m_aLabel.GetPosPixel();
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir                     m_pImpl->m_aLabel.SetPosPixel(m_pImpl->m_aSchemaLbl.GetPosPixel());
292*cdf0e10cSrcweir                     m_pImpl->m_aTitle.SetPosPixel(m_pImpl->m_aSchema.GetPosPixel());
293*cdf0e10cSrcweir                 }
294*cdf0e10cSrcweir                 else
295*cdf0e10cSrcweir                 {
296*cdf0e10cSrcweir                     lcl_fillComboList( m_pImpl->m_aSchema, _xConnection,
297*cdf0e10cSrcweir                         &XDatabaseMetaData::getSchemas, m_pImpl->m_xMetaData->getUserName() );
298*cdf0e10cSrcweir                 }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir                 OSL_ENSURE(m_pImpl->m_xMetaData.is(),"The metadata can not be null!");
301*cdf0e10cSrcweir                 if(m_pImpl->m_aName.Search('.') != STRING_NOTFOUND)
302*cdf0e10cSrcweir                 {
303*cdf0e10cSrcweir                     ::rtl::OUString sCatalog,sSchema,sTable;
304*cdf0e10cSrcweir                     ::dbtools::qualifiedNameComponents(m_pImpl->m_xMetaData,
305*cdf0e10cSrcweir                                                         m_pImpl->m_aName,
306*cdf0e10cSrcweir                                                         sCatalog,
307*cdf0e10cSrcweir                                                         sSchema,
308*cdf0e10cSrcweir                                                         sTable,
309*cdf0e10cSrcweir                                                         ::dbtools::eInDataManipulation);
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir                     sal_uInt16 nPos = m_pImpl->m_aCatalog.GetEntryPos(String(sCatalog));
312*cdf0e10cSrcweir                     if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
313*cdf0e10cSrcweir                         m_pImpl->m_aCatalog.SelectEntryPos(nPos);
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir                     if ( sSchema.getLength() )
316*cdf0e10cSrcweir                     {
317*cdf0e10cSrcweir                         nPos = m_pImpl->m_aSchema.GetEntryPos(String(sSchema));
318*cdf0e10cSrcweir                         if ( nPos != COMBOBOX_ENTRY_NOTFOUND )
319*cdf0e10cSrcweir                             m_pImpl->m_aSchema.SelectEntryPos(nPos);
320*cdf0e10cSrcweir                     }
321*cdf0e10cSrcweir                     m_pImpl->m_aTitle.SetText(sTable);
322*cdf0e10cSrcweir                 }
323*cdf0e10cSrcweir                 else
324*cdf0e10cSrcweir                     m_pImpl->m_aTitle.SetText(m_pImpl->m_aName);
325*cdf0e10cSrcweir                 m_pImpl->m_aTitle.SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir                 m_pImpl->m_aPB_OK.SetPosPixel(Point(m_pImpl->m_aPB_OK.GetPosPixel().X(),aPos.Y()));
328*cdf0e10cSrcweir                 m_pImpl->m_aPB_CANCEL.SetPosPixel(Point(m_pImpl->m_aPB_CANCEL.GetPosPixel().X(),aPos.Y()));
329*cdf0e10cSrcweir                 m_pImpl->m_aPB_HELP.SetPosPixel(Point(m_pImpl->m_aPB_HELP.GetPosPixel().X(),aPos.Y()));
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir                 sal_uInt16 nLength =  m_pImpl->m_xMetaData.is() ? static_cast<sal_uInt16>(m_pImpl->m_xMetaData->getMaxTableNameLength()) : 0;
332*cdf0e10cSrcweir                 nLength = nLength ? nLength : EDIT_NOLIMIT;
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir                 m_pImpl->m_aTitle.SetMaxTextLen(nLength);
335*cdf0e10cSrcweir                 m_pImpl->m_aSchema.SetMaxTextLen(nLength);
336*cdf0e10cSrcweir                 m_pImpl->m_aCatalog.SetMaxTextLen(nLength);
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir                 sal_Bool bCheck = _xConnection.is() && isSQL92CheckEnabled(_xConnection);
339*cdf0e10cSrcweir                 m_pImpl->m_aTitle.setCheck(bCheck); // enable non valid sql chars as well
340*cdf0e10cSrcweir                 m_pImpl->m_aSchema.setCheck(bCheck); // enable non valid sql chars as well
341*cdf0e10cSrcweir                 m_pImpl->m_aCatalog.setCheck(bCheck); // enable non valid sql chars as well
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir                 Size aSize = GetSizePixel();
344*cdf0e10cSrcweir                 aSize.Height() =
345*cdf0e10cSrcweir                     aPos.Y() + m_pImpl->m_aPB_OK.GetSizePixel().Height() + m_pImpl->m_aTitle.GetSizePixel().Height() / 2;
346*cdf0e10cSrcweir                 SetSizePixel(aSize);
347*cdf0e10cSrcweir             }
348*cdf0e10cSrcweir             break;
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir         default:
351*cdf0e10cSrcweir             OSL_ENSURE( false, "OSaveAsDlg::OSaveAsDlg: Type not supported yet!" );
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     implInit();
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir // -----------------------------------------------------------------------------
357*cdf0e10cSrcweir OSaveAsDlg::OSaveAsDlg( Window * pParent,
358*cdf0e10cSrcweir                         const Reference< XMultiServiceFactory >& _rxORB,
359*cdf0e10cSrcweir                         const String& rDefault,
360*cdf0e10cSrcweir                         const String& _sLabel,
361*cdf0e10cSrcweir                         const IObjectNameCheck& _rObjectNameCheck,
362*cdf0e10cSrcweir                         sal_Int32 _nFlags)
363*cdf0e10cSrcweir              :ModalDialog( pParent, ModuleRes(DLG_SAVE_AS))
364*cdf0e10cSrcweir              ,m_xORB( _rxORB )
365*cdf0e10cSrcweir {
366*cdf0e10cSrcweir     m_pImpl = new OSaveAsDlgImpl(this,rDefault,_rObjectNameCheck,_nFlags);
367*cdf0e10cSrcweir     implInitOnlyTitle(_sLabel);
368*cdf0e10cSrcweir     implInit();
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir // -----------------------------------------------------------------------------
371*cdf0e10cSrcweir OSaveAsDlg::~OSaveAsDlg()
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir     DELETEZ(m_pImpl);
374*cdf0e10cSrcweir }
375*cdf0e10cSrcweir // -----------------------------------------------------------------------------
376*cdf0e10cSrcweir IMPL_LINK(OSaveAsDlg, ButtonClickHdl, Button *, pButton)
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir     if (pButton == &m_pImpl->m_aPB_OK)
379*cdf0e10cSrcweir     {
380*cdf0e10cSrcweir         m_pImpl->m_aName = m_pImpl->m_aTitle.GetText();
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir         ::rtl::OUString sNameToCheck( m_pImpl->m_aName );
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir         if ( m_pImpl->m_nType == CommandType::TABLE )
385*cdf0e10cSrcweir         {
386*cdf0e10cSrcweir             sNameToCheck = ::dbtools::composeTableName(
387*cdf0e10cSrcweir                 m_pImpl->m_xMetaData,
388*cdf0e10cSrcweir                 getCatalog(),
389*cdf0e10cSrcweir                 getSchema(),
390*cdf0e10cSrcweir                 sNameToCheck,
391*cdf0e10cSrcweir                 sal_False,  // no quoting
392*cdf0e10cSrcweir                 ::dbtools::eInDataManipulation
393*cdf0e10cSrcweir             );
394*cdf0e10cSrcweir         }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir         SQLExceptionInfo aNameError;
397*cdf0e10cSrcweir         if ( m_pImpl->m_rObjectNameCheck.isNameValid( sNameToCheck, aNameError ) )
398*cdf0e10cSrcweir             EndDialog( RET_OK );
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir         showError( aNameError, this, m_xORB );
401*cdf0e10cSrcweir         m_pImpl->m_aTitle.GrabFocus();
402*cdf0e10cSrcweir     }
403*cdf0e10cSrcweir     return 0;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir // -----------------------------------------------------------------------------
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir IMPL_LINK(OSaveAsDlg, EditModifyHdl, Edit *, pEdit )
408*cdf0e10cSrcweir {
409*cdf0e10cSrcweir     if (pEdit == &m_pImpl->m_aTitle)
410*cdf0e10cSrcweir         m_pImpl->m_aPB_OK.Enable(0 != m_pImpl->m_aTitle.GetText().Len());
411*cdf0e10cSrcweir     return 0;
412*cdf0e10cSrcweir }
413*cdf0e10cSrcweir // -----------------------------------------------------------------------------
414*cdf0e10cSrcweir void OSaveAsDlg::implInitOnlyTitle(const String& _rLabel)
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir     m_pImpl->m_aLabel.SetText(_rLabel);
417*cdf0e10cSrcweir     m_pImpl->m_aCatalogLbl.Hide();
418*cdf0e10cSrcweir     m_pImpl->m_aCatalog.Hide();
419*cdf0e10cSrcweir     m_pImpl->m_aSchemaLbl.Hide();
420*cdf0e10cSrcweir     m_pImpl->m_aSchema.Hide();
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir     Point aPos(m_pImpl->m_aSchemaLbl.GetPosPixel());
423*cdf0e10cSrcweir     m_pImpl->m_aLabel.SetPosPixel(m_pImpl->m_aCatalogLbl.GetPosPixel());
424*cdf0e10cSrcweir     m_pImpl->m_aTitle.SetPosPixel(m_pImpl->m_aCatalog.GetPosPixel());
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir     m_pImpl->m_aPB_OK.SetPosPixel(Point(m_pImpl->m_aPB_OK.GetPosPixel().X(),aPos.Y()));
427*cdf0e10cSrcweir     m_pImpl->m_aPB_CANCEL.SetPosPixel(Point(m_pImpl->m_aPB_CANCEL.GetPosPixel().X(),aPos.Y()));
428*cdf0e10cSrcweir     m_pImpl->m_aPB_HELP.SetPosPixel(Point(m_pImpl->m_aPB_HELP.GetPosPixel().X(),aPos.Y()));
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir     sal_Int32 nNewHeight =
431*cdf0e10cSrcweir         aPos.Y() + m_pImpl->m_aPB_OK.GetSizePixel().Height() + m_pImpl->m_aTitle.GetSizePixel().Height() / 2;
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir     SetSizePixel(Size(GetSizePixel().Width(), nNewHeight));
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     m_pImpl->m_aTitle.SetText(m_pImpl->m_aName);
436*cdf0e10cSrcweir     m_pImpl->m_aTitle.setCheck(sal_False); // enable non valid sql chars as well
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir // -----------------------------------------------------------------------------
439*cdf0e10cSrcweir void OSaveAsDlg::implInit()
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir     if ( 0 == ( m_pImpl->m_nFlags & SAD_ADDITIONAL_DESCRIPTION ) )
442*cdf0e10cSrcweir     {
443*cdf0e10cSrcweir         // hide the description window
444*cdf0e10cSrcweir         m_pImpl->m_aDescription.Hide();
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir         // the number of pixels we have to move the other controls
447*cdf0e10cSrcweir         sal_Int32 nMoveUp = m_pImpl->m_aCatalog.GetPosPixel().Y() - m_pImpl->m_aDescription.GetPosPixel().Y();
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir         // loop to all controls and move them ...
450*cdf0e10cSrcweir         for (   Window* pChildControl = GetWindow( WINDOW_FIRSTCHILD );
451*cdf0e10cSrcweir                 pChildControl;
452*cdf0e10cSrcweir                 pChildControl= pChildControl->GetWindow( WINDOW_NEXT )
453*cdf0e10cSrcweir             )
454*cdf0e10cSrcweir         {
455*cdf0e10cSrcweir             if ( &m_pImpl->m_aDescription != pChildControl )
456*cdf0e10cSrcweir             {
457*cdf0e10cSrcweir                 Point aPos = pChildControl->GetPosPixel();
458*cdf0e10cSrcweir                 aPos.Y() -= nMoveUp;
459*cdf0e10cSrcweir                 pChildControl->SetPosPixel(aPos);
460*cdf0e10cSrcweir             }
461*cdf0e10cSrcweir         }
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir         // change our own size accordingly
464*cdf0e10cSrcweir         Size aSize = GetSizePixel();
465*cdf0e10cSrcweir         aSize.Height() -= nMoveUp;
466*cdf0e10cSrcweir         SetSizePixel(aSize);
467*cdf0e10cSrcweir     }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir     if ( SAD_TITLE_PASTE_AS == ( m_pImpl->m_nFlags & SAD_TITLE_PASTE_AS ) )
470*cdf0e10cSrcweir         SetText( String( ModuleRes( STR_TITLE_PASTE_AS ) ) );
471*cdf0e10cSrcweir     else if ( SAD_TITLE_RENAME == ( m_pImpl->m_nFlags & SAD_TITLE_RENAME ) )
472*cdf0e10cSrcweir     {
473*cdf0e10cSrcweir         SetText( String( ModuleRes( STR_TITLE_RENAME ) ) );
474*cdf0e10cSrcweir         m_pImpl->m_aTitle.SetHelpId(HID_DLG_RENAME);
475*cdf0e10cSrcweir     }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir     m_pImpl->m_aPB_OK.SetClickHdl(LINK(this,OSaveAsDlg,ButtonClickHdl));
478*cdf0e10cSrcweir     m_pImpl->m_aTitle.SetModifyHdl(LINK(this,OSaveAsDlg,EditModifyHdl));
479*cdf0e10cSrcweir     m_pImpl->m_aTitle.GrabFocus();
480*cdf0e10cSrcweir     FreeResource();
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir // -----------------------------------------------------------------------------
483*cdf0e10cSrcweir String OSaveAsDlg::getName() const      { return m_pImpl->m_aName; }
484*cdf0e10cSrcweir String OSaveAsDlg::getCatalog() const   { return m_pImpl->m_aCatalog.IsVisible() ? m_pImpl->m_aCatalog.GetText() : String(); }
485*cdf0e10cSrcweir String OSaveAsDlg::getSchema() const    { return m_pImpl->m_aSchema.IsVisible() ? m_pImpl->m_aSchema.GetText() : String(); }
486*cdf0e10cSrcweir 
487