1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlgsave.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBAUI_DLGSAVE_HXX
35 #include "dlgsave.hxx"
37 #ifndef DBAUI_DLGSAVE_HRC
38 #include "dlgsave.hrc"
40 #ifndef _SV_MSGBOX_HXX //autogen
41 #include <vcl/msgbox.hxx>
44 #include "dbu_dlg.hrc"
46 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
47 #include <com/sun/star/sdb/CommandType.hpp>
49 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
50 #include <com/sun/star/sdbc/XRow.hpp>
52 #ifndef _DBAUI_SQLMESSAGE_HXX_
53 #include "sqlmessage.hxx"
55 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
56 #include <connectivity/dbtools.hxx>
58 #ifndef DBAUI_TOOLS_HXX
59 #include "UITools.hxx"
61 #ifndef _DBA_DBACCESS_HELPID_HRC_
62 #include "dbaccess_helpid.hrc"
64 #ifndef DBAUI_SQLNAMEEDIT_HXX
65 #include "SqlNameEdit.hxx"
67 #ifndef _BUTTON_HXX //autogen
68 #include <vcl/button.hxx>
70 #ifndef _FIXED_HXX //autogen
71 #include <vcl/fixed.hxx>
73 #ifndef _EDIT_HXX //autogen
74 #include <vcl/edit.hxx>
76 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
77 #include <com/sun/star/container/XNameAccess.hpp>
79 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
80 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
82 #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
83 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
85 #ifndef _DBAUI_MODULE_DBU_HXX_
86 #include "moduledbu.hxx"
88 #ifndef DBACCESS_SOURCE_UI_INC_OBJECTNAMECHECK_HXX
89 #include "objectnamecheck.hxx"
91 #ifndef TOOLS_DIAGNOSE_EX_H
92 #include <tools/diagnose_ex.h>
96 using namespace dbaui
;
97 using namespace dbtools
;
98 using namespace ::com::sun::star::uno
;
99 using namespace ::com::sun::star::container
;
100 using namespace ::com::sun::star::sdb
;
101 using namespace ::com::sun::star::sdbc
;
107 FixedText m_aDescription
;
108 FixedText m_aCatalogLbl
;
109 OSQLNameComboBox m_aCatalog
;
110 FixedText m_aSchemaLbl
;
111 OSQLNameComboBox m_aSchema
;
113 OSQLNameEdit m_aTitle
;
115 CancelButton m_aPB_CANCEL
;
116 HelpButton m_aPB_HELP
;
119 rtl::OUString m_sCatalog
;
120 rtl::OUString m_sSchema
;
122 const IObjectNameCheck
&
125 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
> m_xMetaData
;
129 OSaveAsDlgImpl( Window
* pParent
,const sal_Int32
& _rType
,
130 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
>& _xConnection
,
131 const String
& rDefault
,
132 const IObjectNameCheck
& _rObjectNameCheck
,
134 OSaveAsDlgImpl( Window
* pParent
,
135 const String
& rDefault
,
136 const IObjectNameCheck
& _rObjectNameCheck
,
139 // -----------------------------------------------------------------------------
141 // -----------------------------------------------------------------------------
142 OSaveAsDlgImpl::OSaveAsDlgImpl( Window
* _pParent
,
143 const sal_Int32
& _rType
,
144 const Reference
< XConnection
>& _xConnection
,
145 const String
& rDefault
,
146 const IObjectNameCheck
& _rObjectNameCheck
,
148 :m_aDescription(_pParent
, ModuleRes (FT_DESCRIPTION
))
149 ,m_aCatalogLbl(_pParent
, ModuleRes (FT_CATALOG
))
150 ,m_aCatalog(_pParent
, ModuleRes (ET_CATALOG
), ::rtl::OUString())
151 ,m_aSchemaLbl(_pParent
, ModuleRes (FT_SCHEMA
))
152 ,m_aSchema(_pParent
, ModuleRes (ET_SCHEMA
), ::rtl::OUString())
153 ,m_aLabel(_pParent
, ModuleRes (FT_TITLE
))
154 ,m_aTitle(_pParent
, ModuleRes (ET_TITLE
), ::rtl::OUString())
155 ,m_aPB_OK(_pParent
, ModuleRes( PB_OK
) )
156 ,m_aPB_CANCEL(_pParent
, ModuleRes( PB_CANCEL
))
157 ,m_aPB_HELP(_pParent
, ModuleRes( PB_HELP
))
158 ,m_aQryLabel(ModuleRes(STR_QRY_LABEL
))
159 ,m_sTblLabel(ModuleRes(STR_TBL_LABEL
))
161 ,m_rObjectNameCheck( _rObjectNameCheck
)
165 if ( _xConnection
.is() )
166 m_xMetaData
= _xConnection
->getMetaData();
168 if ( m_xMetaData
.is() )
170 ::rtl::OUString
sExtraNameChars( m_xMetaData
->getExtraNameCharacters() );
171 m_aCatalog
.setAllowedChars( sExtraNameChars
);
172 m_aSchema
.setAllowedChars( sExtraNameChars
);
173 m_aTitle
.setAllowedChars( sExtraNameChars
);
176 m_aCatalog
.SetDropDownLineCount( 10 );
177 m_aSchema
.SetDropDownLineCount( 10 );
179 // -----------------------------------------------------------------------------
180 OSaveAsDlgImpl::OSaveAsDlgImpl( Window
* _pParent
,
181 const String
& rDefault
,
182 const IObjectNameCheck
& _rObjectNameCheck
,
184 :m_aDescription(_pParent
, ModuleRes (FT_DESCRIPTION
))
185 ,m_aCatalogLbl(_pParent
, ModuleRes (FT_CATALOG
))
186 ,m_aCatalog(_pParent
, ModuleRes (ET_CATALOG
))
187 ,m_aSchemaLbl(_pParent
, ModuleRes (FT_SCHEMA
))
188 ,m_aSchema(_pParent
, ModuleRes (ET_SCHEMA
))
189 ,m_aLabel(_pParent
, ModuleRes (FT_TITLE
))
190 ,m_aTitle(_pParent
, ModuleRes (ET_TITLE
))
191 ,m_aPB_OK(_pParent
, ModuleRes( PB_OK
) )
192 ,m_aPB_CANCEL(_pParent
, ModuleRes( PB_CANCEL
))
193 ,m_aPB_HELP(_pParent
, ModuleRes( PB_HELP
))
194 ,m_aQryLabel(ModuleRes(STR_QRY_LABEL
))
195 ,m_sTblLabel(ModuleRes(STR_TBL_LABEL
))
197 ,m_rObjectNameCheck( _rObjectNameCheck
)
198 ,m_nType(CommandType::COMMAND
)
201 m_aCatalog
.SetDropDownLineCount( 10 );
202 m_aSchema
.SetDropDownLineCount( 10 );
205 // -----------------------------------------------------------------------------
206 using namespace ::com::sun::star::lang
;
208 //==================================================================
211 typedef Reference
< XResultSet
> (SAL_CALL
XDatabaseMetaData::*FGetMetaStrings
)();
213 void lcl_fillComboList( ComboBox
& _rList
, const Reference
< XConnection
>& _rxConnection
,
214 FGetMetaStrings _GetAll
, const ::rtl::OUString
& _rCurrent
)
218 Reference
< XDatabaseMetaData
> xMetaData( _rxConnection
->getMetaData(), UNO_QUERY_THROW
);
220 Reference
< XResultSet
> xRes
= (xMetaData
.get()->*_GetAll
)();
221 Reference
< XRow
> xRow( xRes
, UNO_QUERY_THROW
);
222 ::rtl::OUString sValue
;
223 while ( xRes
->next() )
225 sValue
= xRow
->getString( 1 );
226 if ( !xRow
->wasNull() )
227 _rList
.InsertEntry( sValue
);
230 USHORT nPos
= _rList
.GetEntryPos( String( _rCurrent
) );
231 if ( nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
232 _rList
.SelectEntryPos( nPos
);
234 _rList
.SelectEntryPos( 0 );
236 catch( const Exception
& )
238 DBG_UNHANDLED_EXCEPTION();
243 //==================================================================
244 OSaveAsDlg::OSaveAsDlg( Window
* pParent
,
245 const sal_Int32
& _rType
,
246 const Reference
< XMultiServiceFactory
>& _rxORB
,
247 const Reference
< XConnection
>& _xConnection
,
248 const String
& rDefault
,
249 const IObjectNameCheck
& _rObjectNameCheck
,
251 :ModalDialog( pParent
, ModuleRes(DLG_SAVE_AS
))
254 m_pImpl
= new OSaveAsDlgImpl(this,_rType
,_xConnection
,rDefault
,_rObjectNameCheck
,_nFlags
);
258 case CommandType::QUERY
:
259 implInitOnlyTitle(m_pImpl
->m_aQryLabel
);
262 case CommandType::TABLE
:
263 OSL_ENSURE( m_pImpl
->m_xMetaData
.is(), "OSaveAsDlg::OSaveAsDlg: no meta data for entering table names: this will crash!" );
265 m_pImpl
->m_aLabel
.SetText(m_pImpl
->m_sTblLabel
);
266 Point
aPos(m_pImpl
->m_aPB_OK
.GetPosPixel());
267 if(m_pImpl
->m_xMetaData
.is() && !m_pImpl
->m_xMetaData
->supportsCatalogsInTableDefinitions())
269 m_pImpl
->m_aCatalogLbl
.Hide();
270 m_pImpl
->m_aCatalog
.Hide();
272 aPos
= m_pImpl
->m_aLabel
.GetPosPixel();
274 m_pImpl
->m_aLabel
.SetPosPixel(m_pImpl
->m_aSchemaLbl
.GetPosPixel());
275 m_pImpl
->m_aTitle
.SetPosPixel(m_pImpl
->m_aSchema
.GetPosPixel());
277 m_pImpl
->m_aSchemaLbl
.SetPosPixel(m_pImpl
->m_aCatalogLbl
.GetPosPixel());
278 m_pImpl
->m_aSchema
.SetPosPixel(m_pImpl
->m_aCatalog
.GetPosPixel());
282 // now fill the catalogs
283 lcl_fillComboList( m_pImpl
->m_aCatalog
, _xConnection
,
284 &XDatabaseMetaData::getCatalogs
, _xConnection
->getCatalog() );
287 if ( !m_pImpl
->m_xMetaData
->supportsSchemasInTableDefinitions())
289 m_pImpl
->m_aSchemaLbl
.Hide();
290 m_pImpl
->m_aSchema
.Hide();
292 aPos
= m_pImpl
->m_aLabel
.GetPosPixel();
294 m_pImpl
->m_aLabel
.SetPosPixel(m_pImpl
->m_aSchemaLbl
.GetPosPixel());
295 m_pImpl
->m_aTitle
.SetPosPixel(m_pImpl
->m_aSchema
.GetPosPixel());
299 lcl_fillComboList( m_pImpl
->m_aSchema
, _xConnection
,
300 &XDatabaseMetaData::getSchemas
, m_pImpl
->m_xMetaData
->getUserName() );
303 OSL_ENSURE(m_pImpl
->m_xMetaData
.is(),"The metadata can not be null!");
304 if(m_pImpl
->m_aName
.Search('.') != STRING_NOTFOUND
)
306 ::rtl::OUString sCatalog
,sSchema
,sTable
;
307 ::dbtools::qualifiedNameComponents(m_pImpl
->m_xMetaData
,
312 ::dbtools::eInDataManipulation
);
314 USHORT nPos
= m_pImpl
->m_aCatalog
.GetEntryPos(String(sCatalog
));
315 if ( nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
316 m_pImpl
->m_aCatalog
.SelectEntryPos(nPos
);
318 if ( sSchema
.getLength() )
320 nPos
= m_pImpl
->m_aSchema
.GetEntryPos(String(sSchema
));
321 if ( nPos
!= COMBOBOX_ENTRY_NOTFOUND
)
322 m_pImpl
->m_aSchema
.SelectEntryPos(nPos
);
324 m_pImpl
->m_aTitle
.SetText(sTable
);
327 m_pImpl
->m_aTitle
.SetText(m_pImpl
->m_aName
);
329 m_pImpl
->m_aPB_OK
.SetPosPixel(Point(m_pImpl
->m_aPB_OK
.GetPosPixel().X(),aPos
.Y()));
330 m_pImpl
->m_aPB_CANCEL
.SetPosPixel(Point(m_pImpl
->m_aPB_CANCEL
.GetPosPixel().X(),aPos
.Y()));
331 m_pImpl
->m_aPB_HELP
.SetPosPixel(Point(m_pImpl
->m_aPB_HELP
.GetPosPixel().X(),aPos
.Y()));
333 USHORT nLength
= m_pImpl
->m_xMetaData
.is() ? static_cast<USHORT
>(m_pImpl
->m_xMetaData
->getMaxTableNameLength()) : 0;
334 nLength
= nLength
? nLength
: EDIT_NOLIMIT
;
336 m_pImpl
->m_aTitle
.SetMaxTextLen(nLength
);
337 m_pImpl
->m_aSchema
.SetMaxTextLen(nLength
);
338 m_pImpl
->m_aCatalog
.SetMaxTextLen(nLength
);
340 sal_Bool bCheck
= _xConnection
.is() && isSQL92CheckEnabled(_xConnection
);
341 m_pImpl
->m_aTitle
.setCheck(bCheck
); // enable non valid sql chars as well
342 m_pImpl
->m_aSchema
.setCheck(bCheck
); // enable non valid sql chars as well
343 m_pImpl
->m_aCatalog
.setCheck(bCheck
); // enable non valid sql chars as well
345 Size aSize
= GetSizePixel();
347 aPos
.Y() + m_pImpl
->m_aPB_OK
.GetSizePixel().Height() + m_pImpl
->m_aTitle
.GetSizePixel().Height() / 2;
353 OSL_ENSURE( false, "OSaveAsDlg::OSaveAsDlg: Type not supported yet!" );
358 // -----------------------------------------------------------------------------
359 OSaveAsDlg::OSaveAsDlg( Window
* pParent
,
360 const Reference
< XMultiServiceFactory
>& _rxORB
,
361 const String
& rDefault
,
362 const String
& _sLabel
,
363 const IObjectNameCheck
& _rObjectNameCheck
,
365 :ModalDialog( pParent
, ModuleRes(DLG_SAVE_AS
))
368 m_pImpl
= new OSaveAsDlgImpl(this,rDefault
,_rObjectNameCheck
,_nFlags
);
369 implInitOnlyTitle(_sLabel
);
372 // -----------------------------------------------------------------------------
373 OSaveAsDlg::~OSaveAsDlg()
377 // -----------------------------------------------------------------------------
378 IMPL_LINK(OSaveAsDlg
, ButtonClickHdl
, Button
*, pButton
)
380 if (pButton
== &m_pImpl
->m_aPB_OK
)
382 m_pImpl
->m_aName
= m_pImpl
->m_aTitle
.GetText();
384 ::rtl::OUString
sNameToCheck( m_pImpl
->m_aName
);
386 if ( m_pImpl
->m_nType
== CommandType::TABLE
)
388 sNameToCheck
= ::dbtools::composeTableName(
389 m_pImpl
->m_xMetaData
,
393 sal_False
, // no quoting
394 ::dbtools::eInDataManipulation
398 SQLExceptionInfo aNameError
;
399 if ( m_pImpl
->m_rObjectNameCheck
.isNameValid( sNameToCheck
, aNameError
) )
402 showError( aNameError
, this, m_xORB
);
403 m_pImpl
->m_aTitle
.GrabFocus();
407 // -----------------------------------------------------------------------------
409 IMPL_LINK(OSaveAsDlg
, EditModifyHdl
, Edit
*, pEdit
)
411 if (pEdit
== &m_pImpl
->m_aTitle
)
412 m_pImpl
->m_aPB_OK
.Enable(0 != m_pImpl
->m_aTitle
.GetText().Len());
415 // -----------------------------------------------------------------------------
416 void OSaveAsDlg::implInitOnlyTitle(const String
& _rLabel
)
418 m_pImpl
->m_aLabel
.SetText(_rLabel
);
419 m_pImpl
->m_aCatalogLbl
.Hide();
420 m_pImpl
->m_aCatalog
.Hide();
421 m_pImpl
->m_aSchemaLbl
.Hide();
422 m_pImpl
->m_aSchema
.Hide();
424 Point
aPos(m_pImpl
->m_aSchemaLbl
.GetPosPixel());
425 m_pImpl
->m_aLabel
.SetPosPixel(m_pImpl
->m_aCatalogLbl
.GetPosPixel());
426 m_pImpl
->m_aTitle
.SetPosPixel(m_pImpl
->m_aCatalog
.GetPosPixel());
428 m_pImpl
->m_aPB_OK
.SetPosPixel(Point(m_pImpl
->m_aPB_OK
.GetPosPixel().X(),aPos
.Y()));
429 m_pImpl
->m_aPB_CANCEL
.SetPosPixel(Point(m_pImpl
->m_aPB_CANCEL
.GetPosPixel().X(),aPos
.Y()));
430 m_pImpl
->m_aPB_HELP
.SetPosPixel(Point(m_pImpl
->m_aPB_HELP
.GetPosPixel().X(),aPos
.Y()));
432 sal_Int32 nNewHeight
=
433 aPos
.Y() + m_pImpl
->m_aPB_OK
.GetSizePixel().Height() + m_pImpl
->m_aTitle
.GetSizePixel().Height() / 2;
435 SetSizePixel(Size(GetSizePixel().Width(), nNewHeight
));
437 m_pImpl
->m_aTitle
.SetText(m_pImpl
->m_aName
);
438 m_pImpl
->m_aTitle
.setCheck(sal_False
); // enable non valid sql chars as well
440 // -----------------------------------------------------------------------------
441 void OSaveAsDlg::implInit()
443 if ( 0 == ( m_pImpl
->m_nFlags
& SAD_ADDITIONAL_DESCRIPTION
) )
445 // hide the description window
446 m_pImpl
->m_aDescription
.Hide();
448 // the number of pixels we have to move the other controls
449 sal_Int32 nMoveUp
= m_pImpl
->m_aCatalog
.GetPosPixel().Y() - m_pImpl
->m_aDescription
.GetPosPixel().Y();
451 // loop to all controls and move them ...
452 for ( Window
* pChildControl
= GetWindow( WINDOW_FIRSTCHILD
);
454 pChildControl
= pChildControl
->GetWindow( WINDOW_NEXT
)
457 if ( &m_pImpl
->m_aDescription
!= pChildControl
)
459 Point aPos
= pChildControl
->GetPosPixel();
461 pChildControl
->SetPosPixel(aPos
);
465 // change our own size accordingly
466 Size aSize
= GetSizePixel();
467 aSize
.Height() -= nMoveUp
;
471 if ( SAD_TITLE_PASTE_AS
== ( m_pImpl
->m_nFlags
& SAD_TITLE_PASTE_AS
) )
472 SetText( String( ModuleRes( STR_TITLE_PASTE_AS
) ) );
473 else if ( SAD_TITLE_RENAME
== ( m_pImpl
->m_nFlags
& SAD_TITLE_RENAME
) )
475 SetText( String( ModuleRes( STR_TITLE_RENAME
) ) );
476 m_pImpl
->m_aTitle
.SetHelpId(HID_DLG_RENAME
);
479 m_pImpl
->m_aPB_OK
.SetClickHdl(LINK(this,OSaveAsDlg
,ButtonClickHdl
));
480 m_pImpl
->m_aTitle
.SetModifyHdl(LINK(this,OSaveAsDlg
,EditModifyHdl
));
481 m_pImpl
->m_aTitle
.GrabFocus();
484 // -----------------------------------------------------------------------------
485 String
OSaveAsDlg::getName() const { return m_pImpl
->m_aName
; }
486 String
OSaveAsDlg::getCatalog() const { return m_pImpl
->m_aCatalog
.IsVisible() ? m_pImpl
->m_aCatalog
.GetText() : String(); }
487 String
OSaveAsDlg::getSchema() const { return m_pImpl
->m_aSchema
.IsVisible() ? m_pImpl
->m_aSchema
.GetText() : String(); }