Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / misc / UITools.cxx
blobcc5409441d9183853971cef4a48e03f20b0a55f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "UITools.hxx"
31 #include <sfx2/docfilt.hxx>
32 #include "callbacks.hxx"
33 #include "dbustrings.hrc"
34 #include "dbu_resource.hrc"
35 #include "dlgsave.hxx"
36 #include "dbtreelistbox.hxx"
37 #include "defaultobjectnamecheck.hxx"
38 #include <comphelper/extract.hxx>
39 #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
40 #include <com/sun/star/sdb/XCompletedConnection.hpp>
41 #include <com/sun/star/sdbc/XDataSource.hpp>
42 #include <com/sun/star/sdb/SQLContext.hpp>
43 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
44 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
45 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
46 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
47 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
48 #include <com/sun/star/sdbcx/XAppend.hpp>
49 #include <com/sun/star/sdbc/XRow.hpp>
50 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
51 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
52 #include <com/sun/star/sdbc/ColumnValue.hpp>
53 #include <com/sun/star/task/XInteractionHandler.hpp>
54 #include <com/sun/star/ucb/XContent.hpp>
55 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
56 #include <com/sun/star/beans/PropertyValue.hpp>
57 #include <com/sun/star/container/XIndexAccess.hpp>
58 #include <com/sun/star/container/XNameContainer.hpp>
59 #include <com/sun/star/ucb/InteractiveIOException.hpp>
60 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
61 #include <com/sun/star/ucb/IOErrorCode.hpp>
62 #include <toolkit/helper/vclunohelper.hxx>
63 #include <toolkit/awt/vclxwindow.hxx>
64 #include <vcl/stdtext.hxx>
65 #include <com/sun/star/beans/XPropertySetInfo.hpp>
66 #include <com/sun/star/beans/XPropertySet.hpp>
67 #include <com/sun/star/container/XNameAccess.hpp>
68 #include <com/sun/star/container/XContainer.hpp>
69 #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
70 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
71 #include <com/sun/star/awt/TextAlign.hpp>
72 #include <com/sun/star/awt/FontDescriptor.hpp>
73 #include <com/sun/star/awt/FontWeight.hpp>
74 #include <com/sun/star/awt/FontRelief.hpp>
75 #include <com/sun/star/awt/FontWidth.hpp>
76 #include <com/sun/star/frame/XModel.hpp>
77 #include "dlgattr.hrc"
78 #include "TypeInfo.hxx"
79 #include "FieldDescriptions.hxx"
80 #include <comphelper/stl_types.hxx>
81 #include <comphelper/componentcontext.hxx>
83 #include <svx/svxids.hrc>
85 #include <svl/itempool.hxx>
86 #include <tools/string.hxx>
87 #include "dbaccess_helpid.hrc"
88 #include <svl/itemset.hxx>
89 #include "sbagrid.hrc"
90 #include <svl/rngitem.hxx>
91 #include <svl/intitem.hxx>
92 #include <svx/algitem.hxx>
93 #include <svx/numinf.hxx>
94 #include <svl/zforlist.hxx>
95 #include "dlgattr.hxx"
96 #include <vcl/msgbox.hxx>
97 #include <com/sun/star/container/XChild.hpp>
98 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
99 #include <com/sun/star/util/XNumberFormatter.hpp>
100 #include "dbu_misc.hrc"
101 #include "sqlmessage.hxx"
102 #include <com/sun/star/util/NumberFormat.hpp>
103 #include <com/sun/star/util/URL.hpp>
104 #include <vcl/toolbox.hxx>
105 #include "dlgsize.hxx"
106 #include <svtools/editbrowsebox.hxx>
107 #include <unotools/configmgr.hxx>
108 #include <svtools/helpopt.hxx>
109 #include <ucbhelper/content.hxx>
110 #include <tools/urlobj.hxx>
111 #include <tools/diagnose_ex.h>
112 #include <svl/numuno.hxx>
113 #include <unotools/pathoptions.hxx>
114 #include <svl/filenotation.hxx>
115 #include <svtools/fileview.hxx>
116 #include <connectivity/FValue.hxx>
118 #include <editeng/justifyitem.hxx>
120 // .........................................................................
121 namespace dbaui
123 // .........................................................................
124 using namespace ::dbtools;
125 using namespace ::comphelper;
126 using namespace ::com::sun::star::uno;
127 using namespace ::com::sun::star::task;
128 using namespace ::com::sun::star::sdbcx;
129 using namespace ::com::sun::star::sdbc;
130 using namespace ::com::sun::star::sdb;
131 using namespace ::com::sun::star::util;
132 using namespace ::com::sun::star::ucb;
133 using namespace ::com::sun::star::beans;
134 using namespace ::com::sun::star::container;
135 using namespace ::com::sun::star::lang;
136 using namespace ::com::sun::star::ui::dialogs;
137 using namespace ::svt;
138 using ::com::sun::star::ucb::InteractiveIOException;
139 using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
140 using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
141 using ::com::sun::star::frame::XModel;
143 // -----------------------------------------------------------------------------
144 SQLExceptionInfo createConnection( const ::rtl::OUString& _rsDataSourceName,
145 const Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext,
146 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
147 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
148 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
150 Reference<XPropertySet> xProp;
153 xProp.set(_xDatabaseContext->getByName(_rsDataSourceName),UNO_QUERY);
155 catch(const Exception&)
158 SQLExceptionInfo aInfo;
160 return createConnection(xProp,_rMF,_rEvtLst,_rOUTConnection);
162 // -----------------------------------------------------------------------------
163 SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource,
164 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
165 Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
166 Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
168 SQLExceptionInfo aInfo;
169 if ( !_xDataSource.is() )
171 OSL_FAIL("createConnection: coult not retrieve the data source!");
172 return aInfo;
175 ::rtl::OUString sPwd, sUser;
176 sal_Bool bPwdReq = sal_False;
179 _xDataSource->getPropertyValue(PROPERTY_PASSWORD) >>= sPwd;
180 bPwdReq = ::cppu::any2bool(_xDataSource->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED));
181 _xDataSource->getPropertyValue(PROPERTY_USER) >>= sUser;
183 catch(const Exception&)
185 OSL_FAIL("createConnection: error while retrieving data source properties!");
191 if(bPwdReq && sPwd.isEmpty())
192 { // password required, but empty -> connect using an interaction handler
193 Reference<XCompletedConnection> xConnectionCompletion(_xDataSource, UNO_QUERY);
194 if (!xConnectionCompletion.is())
196 OSL_FAIL("createConnection: missing an interface ... need an error message here!");
198 else
199 { // instantiate the default SDB interaction handler
200 Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY);
201 if (!xHandler.is())
203 OSL_FAIL("createConnection: could not instantiate an interaction handler!");
204 // TODO: a real parent!
206 else
207 _rOUTConnection = xConnectionCompletion->connectWithCompletion(xHandler);
210 else
212 Reference<XDataSource> xDataSource(_xDataSource,UNO_QUERY);
213 _rOUTConnection = xDataSource->getConnection(sUser, sPwd);
215 // be notified when connection is in disposing
216 Reference< XComponent > xComponent(_rOUTConnection, UNO_QUERY);
217 if (xComponent.is() && _rEvtLst.is())
218 xComponent->addEventListener(_rEvtLst);
220 catch(const SQLContext& e) { aInfo = SQLExceptionInfo(e); }
221 catch(const SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
222 catch(const SQLException& e) { aInfo = SQLExceptionInfo(e); }
223 catch(const Exception&) { OSL_FAIL("SbaTableQueryBrowser::OnExpandEntry: could not connect - unknown exception!"); }
225 return aInfo;
227 // -----------------------------------------------------------------------------
228 Reference< XDataSource > getDataSourceByName( const ::rtl::OUString& _rDataSourceName,
229 Window* _pErrorMessageParent, Reference< XMultiServiceFactory > _rxORB, ::dbtools::SQLExceptionInfo* _pErrorInfo )
231 ::comphelper::ComponentContext aContext( _rxORB );
232 Reference< XNameAccess > xDatabaseContext( aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
234 Reference< XDataSource > xDatasource;
235 Any aError;
236 SQLExceptionInfo aSQLError;
239 xDatabaseContext->getByName( _rDataSourceName ) >>= xDatasource;
241 catch(const WrappedTargetException& e)
243 InteractiveIOException aIOException;
244 if ( ( e.TargetException >>= aIOException )
245 && ( ( aIOException.Code == IOErrorCode_NO_FILE )
246 || ( aIOException.Code == IOErrorCode_NOT_EXISTING )
250 String sErrorMessage = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
251 OFileNotation aTransformer( e.Message );
252 sErrorMessage.SearchAndReplaceAscii( "$file$", aTransformer.get( OFileNotation::N_SYSTEM ) );
253 aSQLError = SQLExceptionInfo( sErrorMessage ).get();
255 else
257 aSQLError = SQLExceptionInfo( e.TargetException );
258 if ( !aSQLError.isValid() )
259 aError = e.TargetException;
262 catch( const Exception& )
264 DBG_UNHANDLED_EXCEPTION();
267 if ( xDatasource.is() )
268 return xDatasource;
270 if ( aSQLError.isValid() )
272 if ( _pErrorInfo )
274 *_pErrorInfo = aSQLError;
276 else
278 showError( aSQLError, _pErrorMessageParent, _rxORB );
282 return Reference<XDataSource>();
284 // -----------------------------------------------------------------------------
285 Reference< XInterface > getDataSourceOrModel(const Reference< XInterface >& _xObject)
287 Reference< XInterface > xRet;
288 Reference<XDocumentDataSource> xDocumentDataSource(_xObject,UNO_QUERY);
289 if ( xDocumentDataSource.is() )
290 xRet = xDocumentDataSource->getDatabaseDocument();
292 if ( !xRet.is() )
294 Reference<XOfficeDatabaseDocument> xOfficeDoc(_xObject,UNO_QUERY);
295 if ( xOfficeDoc.is() )
296 xRet = xOfficeDoc->getDataSource();
299 return xRet;
301 // -----------------------------------------------------------------------------
302 void showError(const SQLExceptionInfo& _rInfo,Window* _pParent,const Reference< XMultiServiceFactory >& _xFactory)
304 OSL_ENSURE(_pParent,"showError: Parent window must be NOT NULL!");
305 ::dbtools::showError(_rInfo,VCLUnoHelper::GetInterface(_pParent),_xFactory);
308 // -----------------------------------------------------------------------------
309 ::std::vector< Reference<XNameAccess> > getKeyColumns(const Reference<XIndexAccess >& _rxKeys,
310 sal_Int32 _nKeyType)
312 // use keys and indexes for excat postioning
313 // first the keys
314 ::std::vector< Reference<XNameAccess> > vRet;
315 if(_rxKeys.is())
317 Reference<XPropertySet> xProp;
318 for(sal_Int32 i=0;i< _rxKeys->getCount();++i)
320 _rxKeys->getByIndex(i) >>= xProp;
321 sal_Int32 nKeyType = 0;
322 xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
323 if(_nKeyType == nKeyType)
325 Reference<XColumnsSupplier> xKeyColsSup(xProp,UNO_QUERY);
326 OSL_ENSURE(xKeyColsSup.is(),"Columnsupplier is null!");
327 vRet.push_back(xKeyColsSup->getColumns());
332 return vRet;
334 // -----------------------------------------------------------------------------
336 TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
337 sal_Int32 _nType,
338 const ::rtl::OUString& _sTypeName,
339 const ::rtl::OUString& _sCreateParams,
340 sal_Int32 _nPrecision,
341 sal_Int32 _nScale,
342 sal_Bool _bAutoIncrement,
343 sal_Bool& _brForceToType)
345 TOTypeInfoSP pTypeInfo;
346 _brForceToType = sal_False;
347 // search for type
348 ::std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
349 OTypeInfoMap::const_iterator aIter = aPair.first;
350 if(aIter != _rTypeInfo.end()) // compare with end is correct here
352 for(;aIter != aPair.second;++aIter)
354 // search the best matching type
355 #ifdef DBG_UTIL
356 ::rtl::OUString sDBTypeName = aIter->second->aTypeName; (void)sDBTypeName;
357 sal_Int32 nDBTypePrecision = aIter->second->nPrecision; (void)nDBTypePrecision;
358 sal_Int32 nDBTypeScale = aIter->second->nMaximumScale; (void)nDBTypeScale;
359 sal_Bool bDBAutoIncrement = aIter->second->bAutoIncrement; (void)bDBAutoIncrement;
360 #endif
361 if ( (
362 _sTypeName.isEmpty()
363 || (aIter->second->aTypeName.equalsIgnoreAsciiCase(_sTypeName))
365 && (
367 !aIter->second->aCreateParams.getLength()
368 && _sCreateParams.isEmpty()
370 || (
371 (aIter->second->nPrecision >= _nPrecision)
372 && (aIter->second->nMaximumScale >= _nScale)
373 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
377 break;
380 if (aIter == aPair.second)
382 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
384 sal_Int32 nPrec = aIter->second->nPrecision;
385 sal_Int32 nScale = aIter->second->nMaximumScale;
386 // search the best matching type (now comparing the local names)
387 if ( (aIter->second->aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
388 && (nPrec >= _nPrecision)
389 && (nScale >= _nScale)
390 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
393 OSL_FAIL(( ::rtl::OString("getTypeInfoFromType: assuming column type ")
394 += ::rtl::OString(aIter->second->aTypeName.getStr(), aIter->second->aTypeName.getLength(), osl_getThreadTextEncoding())
395 += ::rtl::OString("\" (expected type name ")
396 += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), osl_getThreadTextEncoding())
397 += ::rtl::OString(" matches the type's local name).")).getStr());
398 break;
403 if (aIter == aPair.second)
404 { // no match for the names, no match for the local names
405 // -> drop the precision and the scale restriction, accept any type with the property
406 // type id (nType)
408 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
410 // search the best matching type (now comparing the local names)
411 #ifdef DBG_UTIL
412 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
413 #endif
414 sal_Int32 nPrec = aIter->second->nPrecision;
415 sal_Int32 nScale = aIter->second->nMaximumScale;
416 if ( (nPrec >= _nPrecision)
417 && (nScale >= _nScale)
418 && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
420 break;
423 if (aIter == aPair.second)
425 if ( _bAutoIncrement )
427 for(aIter = aPair.first; aIter != aPair.second; ++aIter)
429 // search the best matching type (now comparing the local names)
430 #ifdef DBG_UTIL
431 ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
432 #endif
433 sal_Int32 nScale = aIter->second->nMaximumScale;
434 if ( (nScale >= _nScale)
435 && (aIter->second->bAutoIncrement == _bAutoIncrement)
437 break;
439 if ( aIter == aPair.second )
441 // try it without the auto increment flag
442 pTypeInfo = getTypeInfoFromType(_rTypeInfo,
443 _nType,
444 _sTypeName,
445 _sCreateParams,
446 _nPrecision,
447 _nScale,
448 sal_False,
449 _brForceToType);
451 else
452 pTypeInfo = aIter->second;
454 else
456 pTypeInfo = aPair.first->second;
457 _brForceToType = sal_True;
460 else
461 pTypeInfo = aIter->second;
463 else
465 ::comphelper::TStringMixEqualFunctor aCase(sal_False);
466 // search for typeinfo where the typename is equal _sTypeName
467 OTypeInfoMap::const_iterator typeInfoLoop = _rTypeInfo.begin();
468 OTypeInfoMap::const_iterator typeInfoEnd = _rTypeInfo.end();
469 for (; typeInfoLoop != typeInfoEnd; ++typeInfoLoop)
471 if ( aCase( typeInfoLoop->second->getDBName() , _sTypeName ) )
473 pTypeInfo = typeInfoLoop->second;
474 break;
479 OSL_ENSURE(pTypeInfo, "getTypeInfoFromType: no type info found for this type!");
480 return pTypeInfo;
482 // -----------------------------------------------------------------------------
483 void fillTypeInfo( const Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection,
484 const String& _rsTypeNames,
485 OTypeInfoMap& _rTypeInfoMap,
486 ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters)
488 if(!_rxConnection.is())
489 return;
490 Reference< XResultSet> xRs = _rxConnection->getMetaData ()->getTypeInfo ();
491 Reference< XRow> xRow(xRs,UNO_QUERY);
492 // Information for a single SQL type
493 if(xRs.is())
495 static const ::rtl::OUString aB1(RTL_CONSTASCII_USTRINGPARAM(" [ "));
496 static const ::rtl::OUString aB2(RTL_CONSTASCII_USTRINGPARAM(" ]"));
497 Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
498 ::connectivity::ORowSetValue aValue;
499 ::std::vector<sal_Int32> aTypes;
500 ::std::vector<sal_Bool> aNullable;
501 // Loop on the result set until we reach end of file
502 while (xRs->next())
504 TOTypeInfoSP pInfo(new OTypeInfo());
505 sal_Int32 nPos = 1;
506 if ( aTypes.empty() )
508 sal_Int32 nCount = xResultSetMetaData->getColumnCount();
509 if ( nCount < 1 )
510 nCount = 18;
511 aTypes.reserve(nCount+1);
512 aTypes.push_back(-1);
513 aNullable.push_back(sal_False);
514 for (sal_Int32 j = 1; j <= nCount ; ++j)
516 aTypes.push_back(xResultSetMetaData->getColumnType(j));
517 aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS);
521 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
522 pInfo->aTypeName = aValue;
523 ++nPos;
524 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
525 pInfo->nType = aValue;
526 ++nPos;
527 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
528 pInfo->nPrecision = aValue;
529 ++nPos;
530 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
531 pInfo->aLiteralPrefix = aValue;
532 ++nPos;
533 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
534 pInfo->aLiteralSuffix = aValue;
535 ++nPos;
536 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
537 pInfo->aCreateParams = aValue;
538 ++nPos;
539 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
540 pInfo->bNullable = (sal_Int32)aValue == ColumnValue::NULLABLE;
541 ++nPos;
542 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
543 pInfo->bCaseSensitive = (sal_Bool)aValue;
544 ++nPos;
545 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
546 pInfo->nSearchType = aValue;
547 ++nPos;
548 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
549 pInfo->bUnsigned = (sal_Bool)aValue;
550 ++nPos;
551 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
552 pInfo->bCurrency = (sal_Bool)aValue;
553 ++nPos;
554 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
555 pInfo->bAutoIncrement = (sal_Bool)aValue;
556 ++nPos;
557 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
558 pInfo->aLocalTypeName = aValue;
559 ++nPos;
560 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
561 pInfo->nMinimumScale = aValue;
562 ++nPos;
563 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
564 pInfo->nMaximumScale = aValue;
565 nPos = 18;
566 aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
568 // check if values are less than zero like it happens in a oracle jdbc driver
569 if( pInfo->nPrecision < 0)
570 pInfo->nPrecision = 0;
571 if( pInfo->nMinimumScale < 0)
572 pInfo->nMinimumScale = 0;
573 if( pInfo->nMaximumScale < 0)
574 pInfo->nMaximumScale = 0;
576 String aName;
577 switch(pInfo->nType)
579 case DataType::CHAR:
580 aName = _rsTypeNames.GetToken(TYPE_CHAR);
581 break;
582 case DataType::VARCHAR:
583 aName = _rsTypeNames.GetToken(TYPE_TEXT);
584 break;
585 case DataType::DECIMAL:
586 aName = _rsTypeNames.GetToken(TYPE_DECIMAL);
587 break;
588 case DataType::NUMERIC:
589 aName = _rsTypeNames.GetToken(TYPE_NUMERIC);
590 break;
591 case DataType::BIGINT:
592 aName = _rsTypeNames.GetToken(TYPE_BIGINT);
593 break;
594 case DataType::FLOAT:
595 aName = _rsTypeNames.GetToken(TYPE_FLOAT);
596 break;
597 case DataType::DOUBLE:
598 aName = _rsTypeNames.GetToken(TYPE_DOUBLE);
599 break;
600 case DataType::LONGVARCHAR:
601 aName = _rsTypeNames.GetToken(TYPE_MEMO);
602 break;
603 case DataType::LONGVARBINARY:
604 aName = _rsTypeNames.GetToken(TYPE_IMAGE);
605 break;
606 case DataType::DATE:
607 aName = _rsTypeNames.GetToken(TYPE_DATE);
608 break;
609 case DataType::TIME:
610 aName = _rsTypeNames.GetToken(TYPE_TIME);
611 break;
612 case DataType::TIMESTAMP:
613 aName = _rsTypeNames.GetToken(TYPE_DATETIME);
614 break;
615 case DataType::BIT:
616 if ( !pInfo->aCreateParams.isEmpty() )
618 aName = _rsTypeNames.GetToken(TYPE_BIT);
619 break;
621 // run through
622 case DataType::BOOLEAN:
623 aName = _rsTypeNames.GetToken(TYPE_BOOL);
624 break;
625 case DataType::TINYINT:
626 aName = _rsTypeNames.GetToken(TYPE_TINYINT);
627 break;
628 case DataType::SMALLINT:
629 aName = _rsTypeNames.GetToken(TYPE_SMALLINT);
630 break;
631 case DataType::INTEGER:
632 aName = _rsTypeNames.GetToken(TYPE_INTEGER);
633 break;
634 case DataType::REAL:
635 aName = _rsTypeNames.GetToken(TYPE_REAL);
636 break;
637 case DataType::BINARY:
638 aName = _rsTypeNames.GetToken(TYPE_BINARY);
639 break;
640 case DataType::VARBINARY:
641 aName = _rsTypeNames.GetToken(TYPE_VARBINARY);
642 break;
643 case DataType::SQLNULL:
644 aName = _rsTypeNames.GetToken(TYPE_SQLNULL);
645 break;
646 case DataType::OBJECT:
647 aName = _rsTypeNames.GetToken(TYPE_OBJECT);
648 break;
649 case DataType::DISTINCT:
650 aName = _rsTypeNames.GetToken(TYPE_DISTINCT);
651 break;
652 case DataType::STRUCT:
653 aName = _rsTypeNames.GetToken(TYPE_STRUCT);
654 break;
655 case DataType::ARRAY:
656 aName = _rsTypeNames.GetToken(TYPE_ARRAY);
657 break;
658 case DataType::BLOB:
659 aName = _rsTypeNames.GetToken(TYPE_BLOB);
660 break;
661 case DataType::CLOB:
662 aName = _rsTypeNames.GetToken(TYPE_CLOB);
663 break;
664 case DataType::REF:
665 aName = _rsTypeNames.GetToken(TYPE_REF);
666 break;
667 case DataType::OTHER:
668 aName = _rsTypeNames.GetToken(TYPE_OTHER);
669 break;
671 if ( aName.Len() )
673 pInfo->aUIName = aName.GetBuffer();
674 pInfo->aUIName += aB1;
676 pInfo->aUIName += pInfo->aTypeName;
677 if ( aName.Len() )
678 pInfo->aUIName += aB2;
679 // Now that we have the type info, save it in the multimap
680 _rTypeInfoMap.insert(OTypeInfoMap::value_type(pInfo->nType,pInfo));
682 // for a faster index access
683 _rTypeInfoIters.reserve(_rTypeInfoMap.size());
685 OTypeInfoMap::iterator aIter = _rTypeInfoMap.begin();
686 OTypeInfoMap::iterator aEnd = _rTypeInfoMap.end();
687 for(;aIter != aEnd;++aIter)
688 _rTypeInfoIters.push_back(aIter);
690 // Close the result set/statement.
692 ::comphelper::disposeComponent(xRs);
695 // -----------------------------------------------------------------------------
696 void setColumnProperties(const Reference<XPropertySet>& _rxColumn,const OFieldDescription* _pFieldDesc)
698 _rxColumn->setPropertyValue(PROPERTY_NAME,makeAny(_pFieldDesc->GetName()));
699 _rxColumn->setPropertyValue(PROPERTY_TYPENAME,makeAny(_pFieldDesc->getTypeInfo()->aTypeName));
700 _rxColumn->setPropertyValue(PROPERTY_TYPE,makeAny(_pFieldDesc->GetType()));
701 _rxColumn->setPropertyValue(PROPERTY_PRECISION,makeAny(_pFieldDesc->GetPrecision()));
702 _rxColumn->setPropertyValue(PROPERTY_SCALE,makeAny(_pFieldDesc->GetScale()));
703 _rxColumn->setPropertyValue(PROPERTY_ISNULLABLE, makeAny(_pFieldDesc->GetIsNullable()));
704 _rxColumn->setPropertyValue(PROPERTY_ISAUTOINCREMENT,::cppu::bool2any(_pFieldDesc->IsAutoIncrement()));
705 _rxColumn->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_pFieldDesc->GetDescription()));
706 if ( _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ISCURRENCY) && _pFieldDesc->IsCurrency() )
707 _rxColumn->setPropertyValue(PROPERTY_ISCURRENCY,::cppu::bool2any(_pFieldDesc->IsCurrency()));
708 // set autoincrement value when available
709 // and only set when the entry is not empty, that lets the value in the column untouched
710 if ( _pFieldDesc->IsAutoIncrement() && !_pFieldDesc->GetAutoIncrementValue().isEmpty() && _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
711 _rxColumn->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_pFieldDesc->GetAutoIncrementValue()));
713 // -----------------------------------------------------------------------------
714 ::rtl::OUString createDefaultName(const Reference< XDatabaseMetaData>& _xMetaData,const Reference<XNameAccess>& _xTables,const ::rtl::OUString& _sName)
716 OSL_ENSURE(_xMetaData.is(),"No MetaData!");
717 ::rtl::OUString sDefaultName = _sName;
720 ::rtl::OUString sCatalog,sSchema,sCompsedName;
721 if(_xMetaData->supportsCatalogsInTableDefinitions())
725 Reference< XConnection> xCon = _xMetaData->getConnection();
726 if ( xCon.is() )
727 sCatalog = xCon->getCatalog();
728 if ( sCatalog.isEmpty() )
730 Reference<XResultSet> xRes = _xMetaData->getCatalogs();
731 Reference<XRow> xRow(xRes,UNO_QUERY);
732 while(xRes.is() && xRes->next())
734 sCatalog = xRow->getString(1);
735 if(!xRow->wasNull())
736 break;
740 catch(const SQLException&)
744 if(_xMetaData->supportsSchemasInTableDefinitions())
746 sSchema = _xMetaData->getUserName();
748 sCompsedName = ::dbtools::composeTableName( _xMetaData, sCatalog, sSchema, _sName, sal_False, ::dbtools::eInDataManipulation );
749 sDefaultName = ::dbtools::createUniqueName(_xTables,sCompsedName);
751 catch(const SQLException&)
754 return sDefaultName;
756 // -----------------------------------------------------------------------------
757 sal_Bool checkDataSourceAvailable(const ::rtl::OUString& _sDataSourceName,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
759 sal_Bool bRet = sal_False;
760 Reference< XNameAccess > xDataBaseContext(_xORB->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
761 if ( xDataBaseContext.is() )
763 bRet = xDataBaseContext->hasByName(_sDataSourceName);
764 if ( !bRet )
765 { // try if this one is a URL
768 bRet = xDataBaseContext->getByName(_sDataSourceName).hasValue();
770 catch(const Exception&)
775 return bRet;
777 // -----------------------------------------------------------------------------
778 sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment)
780 sal_Int32 nAlignment = com::sun::star::awt::TextAlign::LEFT;
781 switch (_eAlignment)
783 case SVX_HOR_JUSTIFY_STANDARD:
784 case SVX_HOR_JUSTIFY_LEFT: nAlignment = ::com::sun::star::awt::TextAlign::LEFT; break;
785 case SVX_HOR_JUSTIFY_CENTER: nAlignment = ::com::sun::star::awt::TextAlign::CENTER; break;
786 case SVX_HOR_JUSTIFY_RIGHT: nAlignment = ::com::sun::star::awt::TextAlign::RIGHT; break;
787 default:
788 OSL_FAIL("Invalid TextAlign!");
790 return nAlignment;
792 // -----------------------------------------------------------------------------
793 SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment)
795 SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_LEFT;
796 switch (_nAlignment)
798 case ::com::sun::star::awt::TextAlign::LEFT : eJustify = SVX_HOR_JUSTIFY_LEFT; break;
799 case ::com::sun::star::awt::TextAlign::CENTER : eJustify = SVX_HOR_JUSTIFY_CENTER; break;
800 case ::com::sun::star::awt::TextAlign::RIGHT : eJustify = SVX_HOR_JUSTIFY_RIGHT; break;
801 default:
802 OSL_FAIL("Invalid TextAlign!");
804 return eJustify;
806 // -----------------------------------------------------------------------------
807 float ConvertFontWeight( ::FontWeight eWeight )
809 if( eWeight == WEIGHT_DONTKNOW )
810 return ::com::sun::star::awt::FontWeight::DONTKNOW;
811 else if( eWeight == WEIGHT_THIN )
812 return ::com::sun::star::awt::FontWeight::THIN;
813 else if( eWeight == WEIGHT_ULTRALIGHT )
814 return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
815 else if( eWeight == WEIGHT_LIGHT )
816 return ::com::sun::star::awt::FontWeight::LIGHT;
817 else if( eWeight == WEIGHT_SEMILIGHT )
818 return ::com::sun::star::awt::FontWeight::SEMILIGHT;
819 else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
820 return ::com::sun::star::awt::FontWeight::NORMAL;
821 else if( eWeight == WEIGHT_SEMIBOLD )
822 return ::com::sun::star::awt::FontWeight::SEMIBOLD;
823 else if( eWeight == WEIGHT_BOLD )
824 return ::com::sun::star::awt::FontWeight::BOLD;
825 else if( eWeight == WEIGHT_ULTRABOLD )
826 return ::com::sun::star::awt::FontWeight::ULTRABOLD;
827 else if( eWeight == WEIGHT_BLACK )
828 return ::com::sun::star::awt::FontWeight::BLACK;
830 OSL_FAIL("Unknown FontWeigth" );
831 return ::com::sun::star::awt::FontWeight::DONTKNOW;
833 // -----------------------------------------------------------------------------
834 float ConvertFontWidth( ::FontWidth eWidth )
836 if( eWidth == WIDTH_DONTKNOW )
837 return ::com::sun::star::awt::FontWidth::DONTKNOW;
838 else if( eWidth == WIDTH_ULTRA_CONDENSED )
839 return ::com::sun::star::awt::FontWidth::ULTRACONDENSED;
840 else if( eWidth == WIDTH_EXTRA_CONDENSED )
841 return ::com::sun::star::awt::FontWidth::EXTRACONDENSED;
842 else if( eWidth == WIDTH_CONDENSED )
843 return ::com::sun::star::awt::FontWidth::CONDENSED;
844 else if( eWidth == WIDTH_SEMI_CONDENSED )
845 return ::com::sun::star::awt::FontWidth::SEMICONDENSED;
846 else if( eWidth == WIDTH_NORMAL )
847 return ::com::sun::star::awt::FontWidth::NORMAL;
848 else if( eWidth == WIDTH_SEMI_EXPANDED )
849 return ::com::sun::star::awt::FontWidth::SEMIEXPANDED;
850 else if( eWidth == WIDTH_EXPANDED )
851 return ::com::sun::star::awt::FontWidth::EXPANDED;
852 else if( eWidth == WIDTH_EXTRA_EXPANDED )
853 return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED;
854 else if( eWidth == WIDTH_ULTRA_EXPANDED )
855 return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED;
857 OSL_FAIL("Unknown FontWidth" );
858 return ::com::sun::star::awt::FontWidth::DONTKNOW;
860 // -----------------------------------------------------------------------------
861 ::com::sun::star::awt::FontDescriptor CreateFontDescriptor( const Font& rFont )
863 ::com::sun::star::awt::FontDescriptor aFD;
864 aFD.Name = rFont.GetName();
865 aFD.StyleName = rFont.GetStyleName();
866 aFD.Height = (sal_Int16)rFont.GetSize().Height();
867 aFD.Width = (sal_Int16)rFont.GetSize().Width();
868 aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
869 aFD.CharSet = rFont.GetCharSet();
870 aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
871 aFD.CharacterWidth = ConvertFontWidth( rFont.GetWidthType() );
872 aFD.Weight = ConvertFontWeight( rFont.GetWeight() );
873 aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
874 aFD.Underline = sal::static_int_cast< sal_Int16 >(
875 rFont.GetUnderline());
876 aFD.Strikeout = sal::static_int_cast< sal_Int16 >(
877 rFont.GetStrikeout());
878 aFD.Orientation = rFont.GetOrientation();
879 aFD.Kerning = rFont.IsKerning();
880 aFD.WordLineMode = rFont.IsWordLineMode();
881 aFD.Type = 0; // ??? => Nur an Metric...
882 return aFD;
884 // -----------------------------------------------------------------------------
885 void callColumnFormatDialog(const Reference<XPropertySet>& xAffectedCol,
886 const Reference<XPropertySet>& xField,
887 SvNumberFormatter* _pFormatter,
888 Window* _pParent)
890 if (xAffectedCol.is() && xField.is())
894 Reference< XPropertySetInfo > xInfo = xAffectedCol->getPropertySetInfo();
895 sal_Bool bHasFormat = xInfo->hasPropertyByName(PROPERTY_FORMATKEY);
896 sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE));
898 SvxCellHorJustify eJustify(SVX_HOR_JUSTIFY_STANDARD);
899 Any aAlignment = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
900 if (aAlignment.hasValue())
901 eJustify = dbaui::mapTextJustify(::comphelper::getINT16(aAlignment));
902 sal_Int32 nFormatKey = 0;
903 if ( bHasFormat )
904 nFormatKey = ::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY));
906 sal_uInt16 nFlags = 0;
907 if(callColumnFormatDialog(_pParent,_pFormatter,nDataType,nFormatKey,eJustify,nFlags,bHasFormat))
909 xAffectedCol->setPropertyValue(PROPERTY_ALIGN, makeAny((sal_Int16)dbaui::mapTextAllign(eJustify)));
910 if (nFlags & TP_ATTR_NUMBER)
911 xAffectedCol->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
915 catch( const Exception& )
917 DBG_UNHANDLED_EXCEPTION();
921 // -----------------------------------------------------------------------------
922 sal_Bool callColumnFormatDialog(Window* _pParent,
923 SvNumberFormatter* _pFormatter,
924 sal_Int32 _nDataType,
925 sal_Int32& _nFormatKey,
926 SvxCellHorJustify& _eJustify,
927 sal_uInt16& _nFlags,
928 sal_Bool _bHasFormat)
930 sal_Bool bRet = sal_False;
931 // the allowed format changes depending on the type of the field ...
932 _nFlags = TP_ATTR_ALIGN;
934 if (_bHasFormat)
935 _nFlags |= TP_ATTR_NUMBER;
937 // ------------
938 // UNO->ItemSet
939 static SfxItemInfo aItemInfos[] =
941 { 0, 0 },
942 { SID_ATTR_NUMBERFORMAT_VALUE, SFX_ITEM_POOLABLE },
943 { SID_ATTR_ALIGN_HOR_JUSTIFY, SFX_ITEM_POOLABLE },
944 { SID_ATTR_NUMBERFORMAT_ONE_AREA, SFX_ITEM_POOLABLE },
945 { SID_ATTR_NUMBERFORMAT_INFO, SFX_ITEM_POOLABLE }
947 static sal_uInt16 aAttrMap[] =
949 SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY,
950 SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
951 SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
955 SfxPoolItem* pDefaults[] =
957 new SfxRangeItem(SBA_DEF_RANGEFORMAT, SBA_DEF_FMTVALUE, SBA_ATTR_ALIGN_HOR_JUSTIFY),
958 new SfxUInt32Item(SBA_DEF_FMTVALUE),
959 new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, SBA_ATTR_ALIGN_HOR_JUSTIFY),
960 new SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_False),
961 new SvxNumberInfoItem(SID_ATTR_NUMBERFORMAT_INFO)
964 SfxItemPool* pPool = new SfxItemPool(String::CreateFromAscii("GridBrowserProperties"), SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, pDefaults);
965 pPool->SetDefaultMetric( SFX_MAPUNIT_TWIP ); // ripped, don't understand why
966 pPool->FreezeIdRanges(); // the same
968 SfxItemSet* pFormatDescriptor = new SfxItemSet(*pPool, aAttrMap);
969 // fill it
970 pFormatDescriptor->Put(SvxHorJustifyItem(_eJustify, SBA_ATTR_ALIGN_HOR_JUSTIFY));
971 sal_Bool bText = sal_False;
972 if (_bHasFormat)
974 // if the col is bound to a text field we have to disallow all non-text formats
975 if ((DataType::CHAR == _nDataType) || (DataType::VARCHAR == _nDataType) || (DataType::LONGVARCHAR == _nDataType) || (DataType::CLOB == _nDataType))
977 bText = sal_True;
978 pFormatDescriptor->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_True));
979 if (!_pFormatter->IsTextFormat(_nFormatKey))
980 // text fields can only have text formats
981 _nFormatKey = _pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT,_pParent->GetSettings().GetLanguage());
984 pFormatDescriptor->Put(SfxUInt32Item(SBA_DEF_FMTVALUE, _nFormatKey));
987 if (!bText)
989 double dPreviewVal = 1234.56789;
990 SvxNumberInfoItem aFormatter(_pFormatter, dPreviewVal, SID_ATTR_NUMBERFORMAT_INFO);
991 pFormatDescriptor->Put(aFormatter);
994 { // want the dialog to be destroyed before our set
995 SbaSbAttrDlg aDlg(_pParent, pFormatDescriptor, _pFormatter, _nFlags);
996 if (RET_OK == aDlg.Execute())
998 // ------------
999 // ItemSet->UNO
1000 // UNO-properties
1001 const SfxItemSet* pSet = aDlg.GetExampleSet();
1002 // (of course we could put the modified items directly into the column, but then the UNO-model
1003 // won't reflect these changes, and why do we have a model, then ?)
1005 // horizontal justify
1006 SFX_ITEMSET_GET(*pSet, pHorJustify, SvxHorJustifyItem, SBA_ATTR_ALIGN_HOR_JUSTIFY, sal_True);
1008 _eJustify = (SvxCellHorJustify)pHorJustify->GetValue();
1010 // format key
1011 if (_nFlags & TP_ATTR_NUMBER)
1013 SFX_ITEMSET_GET(*pSet, pFormat, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
1014 _nFormatKey = (sal_Int32)pFormat->GetValue();
1016 bRet = sal_True;
1018 // deleted formats
1019 const SfxItemSet* pResult = aDlg.GetOutputItemSet();
1020 if (pResult)
1022 const SfxPoolItem* pItem = pResult->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
1023 const SvxNumberInfoItem* pInfoItem = static_cast<const SvxNumberInfoItem*>(pItem);
1024 if (pInfoItem && pInfoItem->GetDelCount())
1026 const sal_uInt32* pDeletedKeys = pInfoItem->GetDelArray();
1028 for (sal_uInt16 i=0; i< pInfoItem->GetDelCount(); ++i, ++pDeletedKeys)
1029 _pFormatter->DeleteEntry(*pDeletedKeys);
1034 delete pFormatDescriptor;
1035 SfxItemPool::Free(pPool);
1036 for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
1037 delete pDefaults[i];
1039 return bRet;
1042 //------------------------------------------------------------------------------
1043 const SfxFilter* getStandardDatabaseFilter()
1045 static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
1046 const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
1047 OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
1048 return pFilter;
1052 // -----------------------------------------------------------------------------
1053 sal_Bool appendToFilter(const Reference<XConnection>& _xConnection,
1054 const ::rtl::OUString& _sName,
1055 const Reference< XMultiServiceFactory >& _xFactory,
1056 Window* _pParent)
1058 sal_Bool bRet = sal_False;
1059 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1060 if(xChild.is())
1062 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1063 if(xProp.is())
1065 Sequence< ::rtl::OUString > aFilter;
1066 xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aFilter;
1067 // first check if we have something like SCHEMA.%
1068 sal_Bool bHasToInsert = sal_True;
1069 const ::rtl::OUString* pBegin = aFilter.getConstArray();
1070 const ::rtl::OUString* pEnd = pBegin + aFilter.getLength();
1071 for (;pBegin != pEnd; ++pBegin)
1073 if(pBegin->indexOf('%') != -1)
1075 sal_Int32 nLen;
1076 if((nLen = pBegin->lastIndexOf('.')) != -1 && !pBegin->compareTo(_sName,nLen))
1077 bHasToInsert = sal_False;
1078 else if(pBegin->getLength() == 1)
1079 bHasToInsert = sal_False;
1083 bRet = sal_True;
1084 if(bHasToInsert)
1086 if(! ::dbaui::checkDataSourceAvailable(::comphelper::getString(xProp->getPropertyValue(PROPERTY_NAME)),_xFactory))
1088 String aMessage(ModuleRes(STR_TABLEDESIGN_DATASOURCE_DELETED));
1089 OSQLWarningBox( _pParent, aMessage ).Execute();
1090 bRet = sal_False;
1092 else
1094 aFilter.realloc(aFilter.getLength()+1);
1095 aFilter.getArray()[aFilter.getLength()-1] = _sName;
1096 xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
1101 return bRet;
1103 // -----------------------------------------------------------------------------
1104 void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc)
1106 OSL_ENSURE(_pWindow,"Window can not be null!");
1107 SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : NULL;
1108 if ( pSystemWindow )
1110 _rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
1113 // -----------------------------------------------------------------------------
1114 void adjustToolBoxSize(ToolBox* _pToolBox)
1116 // adjust the toolbox size, otherwise large bitmaps don't fit into
1117 Size aOldSize = _pToolBox->GetSizePixel();
1118 Size aSize = _pToolBox->CalcWindowSizePixel();
1119 if ( !aSize.Width() )
1120 aSize.Width() = aOldSize.Width();
1121 else if ( !aSize.Height() )
1122 aSize.Height() = aOldSize.Height();
1124 Size aTbSize = _pToolBox->GetSizePixel();
1125 if ( (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
1126 (aSize.Height() && aSize.Height() != aTbSize.Height()) )
1128 _pToolBox->SetPosSizePixel( _pToolBox->GetPosPixel(), aSize );
1129 _pToolBox->Invalidate();
1132 // -----------------------------------------------------------------------------
1133 void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId )
1135 sal_Int32 nColSize = -1;
1136 sal_uInt32 nDefaultWidth = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1137 if ( nDefaultWidth != _pBox->GetColumnWidth( _nColId ) )
1139 Size aSizeMM = _pBox->PixelToLogic( Size( _pBox->GetColumnWidth( _nColId ), 0 ), MapMode( MAP_MM ) );
1140 nColSize = aSizeMM.Width() * 10;
1143 Size aDefaultMM = _pBox->PixelToLogic( Size( nDefaultWidth, 0 ), MapMode( MAP_MM ) );
1145 DlgSize aColumnSizeDlg( _pBox, nColSize, sal_False, aDefaultMM.Width() * 10 );
1146 if ( aColumnSizeDlg.Execute() )
1148 sal_Int32 nValue = aColumnSizeDlg.GetValue();
1149 if ( -1 == nValue )
1150 { // default width
1151 nValue = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1153 else
1155 Size aSizeMM( nValue / 10, 0 );
1156 nValue = _pBox->LogicToPixel( aSizeMM, MapMode( MAP_MM ) ).Width();
1158 _pBox->SetColumnWidth( _nColId, nValue );
1161 // -----------------------------------------------------------------------------
1162 // check if SQL92 name checking is enabled
1163 sal_Bool isSQL92CheckEnabled(const Reference<XConnection>& _xConnection)
1165 return ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_ENABLESQL92CHECK.ascii );
1167 // -----------------------------------------------------------------------------
1168 sal_Bool isAppendTableAliasEnabled(const Reference<XConnection>& _xConnection)
1170 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_APPEND_TABLE_ALIAS.ascii );
1173 // -----------------------------------------------------------------------------
1174 sal_Bool generateAsBeforeTableAlias(const Reference<XConnection>& _xConnection)
1176 return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_AS_BEFORE_CORRELATION_NAME.ascii );
1179 // -----------------------------------------------------------------------------
1180 void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
1181 sal_Bool& _rAutoIncrementValueEnabled,
1182 ::rtl::OUString& _rsAutoIncrementValue)
1184 if ( _xDatasource.is() )
1186 OSL_ENSURE(_xDatasource->getPropertySetInfo()->hasPropertyByName(PROPERTY_INFO),"NO datasource supplied!");
1187 Sequence<PropertyValue> aInfo;
1188 _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
1190 // search the right propertyvalue
1191 const PropertyValue* pValue =::std::find_if(aInfo.getConstArray(),
1192 aInfo.getConstArray() + aInfo.getLength(),
1193 ::std::bind2nd(TPropertyValueEqualFunctor(),PROPERTY_AUTOINCREMENTCREATION));
1194 if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1195 pValue->Value >>= _rsAutoIncrementValue;
1196 pValue =::std::find_if(aInfo.getConstArray(),
1197 aInfo.getConstArray() + aInfo.getLength(),
1198 ::std::bind2nd(TPropertyValueEqualFunctor(),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled")) ));
1199 if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1200 pValue->Value >>= _rAutoIncrementValueEnabled;
1203 // -----------------------------------------------------------------------------
1204 void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
1205 sal_Bool& _rAutoIncrementValueEnabled,
1206 ::rtl::OUString& _rsAutoIncrementValue)
1208 Reference< XChild> xChild(_xConnection,UNO_QUERY);
1209 if(xChild.is())
1211 Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1212 fillAutoIncrementValue(xProp,_rAutoIncrementValueEnabled,_rsAutoIncrementValue);
1215 // -----------------------------------------------------------------------------
1216 ::rtl::OUString getStrippedDatabaseName(const Reference<XPropertySet>& _xDataSource,::rtl::OUString& _rsDatabaseName)
1218 if ( _rsDatabaseName.isEmpty() && _xDataSource.is() )
1222 _xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
1224 catch(const Exception& )
1226 DBG_UNHANDLED_EXCEPTION();
1229 ::rtl::OUString sName = _rsDatabaseName;
1230 INetURLObject aURL(sName);
1231 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1232 sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
1233 return sName;
1235 // -----------------------------------------------------------------------------
1236 void AppendConfigToken( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark )
1238 // query part exists?
1239 if ( _bQuestionMark )
1240 // no, so start with '?'
1241 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?"));
1242 else
1243 // yes, so only append with '&'
1244 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&"));
1246 // set parameters
1247 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Language="));
1248 _rURL += utl::ConfigManager::getLocale();
1249 _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&System="));
1250 _rURL += SvtHelpOptions().GetSystem();
1253 namespace
1255 // -----------------------------------------------------------------------
1257 sal_Bool GetHelpAnchor_Impl( const ::rtl::OUString& _rURL, ::rtl::OUString& _rAnchor )
1259 sal_Bool bRet = sal_False;
1260 ::rtl::OUString sAnchor;
1264 ::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
1265 Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
1266 if ( ( aCnt.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AnchorName")) ) >>= sAnchor ) )
1269 if ( !sAnchor.isEmpty() )
1271 _rAnchor = sAnchor;
1272 bRet = sal_True;
1275 else
1277 SAL_WARN( "dbaccess.ui", "Property 'AnchorName' is missing" );
1280 catch( Exception& )
1284 return bRet;
1286 // .........................................................................
1287 } // annonymous
1288 // .........................................................................
1289 // -----------------------------------------------------------------------------
1290 ::com::sun::star::util::URL createHelpAgentURL(const ::rtl::OUString& _sModuleName, const rtl::OString& sHelpId)
1292 ::com::sun::star::util::URL aURL;
1293 aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.help://" ) );
1294 aURL.Complete += _sModuleName;
1295 aURL.Complete += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
1296 aURL.Complete += ::rtl::OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8);
1298 ::rtl::OUString sAnchor;
1299 ::rtl::OUString sTempURL = aURL.Complete;
1300 AppendConfigToken( sTempURL, sal_True );
1301 sal_Bool bHasAnchor = GetHelpAnchor_Impl( sTempURL, sAnchor );
1302 AppendConfigToken(aURL.Complete,sal_True);
1303 if ( bHasAnchor )
1305 aURL.Complete += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#"));
1306 aURL.Complete += sAnchor;
1308 return aURL;
1310 // -----------------------------------------------------------------------------
1311 void setEvalDateFormatForFormatter(Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
1313 OSL_ENSURE( _rxFormatter.is(),"setEvalDateFormatForFormatter: Formatter is NULL!");
1314 if ( _rxFormatter.is() )
1316 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = _rxFormatter->getNumberFormatsSupplier();
1318 Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
1319 SvNumberFormatsSupplierObj* pSupplierImpl = reinterpret_cast<SvNumberFormatsSupplierObj*>(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1320 OSL_ENSURE(pSupplierImpl,"No Supplier!");
1322 if ( pSupplierImpl )
1324 SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
1325 pFormatter->SetEvalDateFormat(NF_EVALDATEFORMAT_FORMAT);
1329 // -----------------------------------------------------------------------------
1330 TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo)
1332 TOTypeInfoSP pTypeInfo;
1333 // first we search for a type which supports autoIncrement
1334 OTypeInfoMap::const_iterator aIter = _rTypeInfo.begin();
1335 OTypeInfoMap::const_iterator aEnd = _rTypeInfo.end();
1336 for(;aIter != aEnd;++aIter)
1338 // OJ: we don't want to set an autoincrement column to be key
1339 // because we don't have the possiblity to know how to create
1340 // such auto increment column later on
1341 // so until we know how to do it, we create a column without autoincrement
1342 // if ( !aIter->second->bAutoIncrement )
1343 { // therefor we have searched
1344 if ( aIter->second->nType == DataType::INTEGER )
1346 pTypeInfo = aIter->second; // alternative
1347 break;
1349 else if ( !pTypeInfo.get() && aIter->second->nType == DataType::DOUBLE )
1350 pTypeInfo = aIter->second; // alternative
1351 else if ( !pTypeInfo.get() && aIter->second->nType == DataType::REAL )
1352 pTypeInfo = aIter->second; // alternative
1355 if ( !pTypeInfo.get() ) // just a fallback
1356 pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo);
1358 OSL_ENSURE(pTypeInfo.get(),"checkColumns: cann't find a type which is useable as a key!");
1359 return pTypeInfo;
1361 // -----------------------------------------------------------------------------
1362 TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo)
1364 OTypeInfoMap::const_iterator aIter = _rTypeInfo.find(_nDataType);
1365 if(aIter != _rTypeInfo.end())
1366 return aIter->second;
1367 // fall back if the type is unknown
1368 TOTypeInfoSP pTypeInfo;
1369 switch(_nDataType)
1371 case DataType::TINYINT:
1372 if( (pTypeInfo = queryTypeInfoByType(DataType::SMALLINT,_rTypeInfo) ) )
1373 break;
1374 // run through
1375 case DataType::SMALLINT:
1376 if( (pTypeInfo = queryTypeInfoByType(DataType::INTEGER,_rTypeInfo) ) )
1377 break;
1378 // run through
1379 case DataType::INTEGER:
1380 if( (pTypeInfo = queryTypeInfoByType(DataType::FLOAT,_rTypeInfo) ) )
1381 break;
1382 // run through
1383 case DataType::FLOAT:
1384 if( (pTypeInfo = queryTypeInfoByType(DataType::REAL,_rTypeInfo) ) )
1385 break;
1386 // run through
1387 case DataType::DATE:
1388 case DataType::TIME:
1389 if( DataType::DATE == _nDataType || DataType::TIME == _nDataType )
1391 if( (pTypeInfo = queryTypeInfoByType(DataType::TIMESTAMP,_rTypeInfo) ) )
1392 break;
1394 // run through
1395 case DataType::TIMESTAMP:
1396 case DataType::REAL:
1397 case DataType::BIGINT:
1398 if ( (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
1399 break;
1400 // run through
1401 case DataType::DOUBLE:
1402 if ( (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
1403 break;
1404 // run through
1405 case DataType::NUMERIC:
1406 pTypeInfo = queryTypeInfoByType(DataType::DECIMAL,_rTypeInfo);
1407 break;
1408 case DataType::DECIMAL:
1409 if ( (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
1410 break;
1411 if ( (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
1412 break;
1413 break;
1414 case DataType::VARCHAR:
1415 if ( (pTypeInfo = queryTypeInfoByType(DataType::LONGVARCHAR,_rTypeInfo) ) )
1416 break;
1417 break;
1418 case DataType::LONGVARCHAR:
1419 if ( (pTypeInfo = queryTypeInfoByType(DataType::CLOB,_rTypeInfo) ) )
1420 break;
1421 break;
1422 default:
1425 if ( !pTypeInfo )
1427 ::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x")),sTypeName;
1428 sal_Bool bForce = sal_True;
1429 pTypeInfo = ::dbaui::getTypeInfoFromType(_rTypeInfo,DataType::VARCHAR,sTypeName,sCreate,50,0,sal_False,bForce);
1431 OSL_ENSURE(pTypeInfo,"Wrong DataType supplied!");
1432 return pTypeInfo;
1434 // -----------------------------------------------------------------------------
1435 sal_Int32 askForUserAction(Window* _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const ::rtl::OUString& _sName)
1437 SolarMutexGuard aGuard;
1438 String aMsg = String(ModuleRes(_nText));
1439 aMsg.SearchAndReplace(String::CreateFromAscii("%1"),String(_sName));
1440 OSQLMessageBox aAsk(_pParent,String(ModuleRes(_nTitle )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
1441 if ( _bAll )
1443 aAsk.AddButton(String(ModuleRes(STR_BUTTON_TEXT_ALL)), RET_ALL, 0);
1444 aAsk.GetPushButton(RET_ALL)->SetHelpId(HID_CONFIRM_DROP_BUTTON_ALL);
1446 return aAsk.Execute();
1449 // -----------------------------------------------------------------------------
1450 namespace
1452 static ::rtl::OUString lcl_createSDBCLevelStatement( const ::rtl::OUString& _rStatement, const Reference< XConnection >& _rxConnection )
1454 ::rtl::OUString sSDBCLevelStatement( _rStatement );
1457 Reference< XMultiServiceFactory > xAnalyzerFactory( _rxConnection, UNO_QUERY_THROW );
1458 Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xAnalyzerFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1459 xAnalyzer->setQuery( _rStatement );
1460 sSDBCLevelStatement = xAnalyzer->getQueryWithSubstitution();
1462 catch( const Exception& )
1464 DBG_UNHANDLED_EXCEPTION();
1466 return sSDBCLevelStatement;
1470 // -----------------------------------------------------------------------------
1471 Reference< XPropertySet > createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection,
1472 const ::rtl::OUString& _rCommand )
1474 Reference<XViewsSupplier> xSup(_rxConnection,UNO_QUERY);
1475 Reference< XNameAccess > xViews;
1476 if(xSup.is())
1477 xViews = xSup->getViews();
1478 Reference<XDataDescriptorFactory> xFact(xViews,UNO_QUERY);
1479 OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
1480 if(!xFact.is())
1481 return NULL;
1483 Reference<XPropertySet> xView = xFact->createDataDescriptor();
1484 if ( !xView.is() )
1485 return NULL;
1487 ::rtl::OUString sCatalog,sSchema,sTable;
1488 ::dbtools::qualifiedNameComponents(_rxConnection->getMetaData(),
1489 _rName,
1490 sCatalog,
1491 sSchema,
1492 sTable,
1493 ::dbtools::eInDataManipulation);
1495 xView->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
1496 xView->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
1497 xView->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
1499 xView->setPropertyValue( PROPERTY_COMMAND, makeAny( _rCommand ) );
1501 Reference<XAppend> xAppend(xViews,UNO_QUERY);
1502 if(xAppend.is())
1503 xAppend->appendByDescriptor(xView);
1505 xView = NULL;
1506 // we need to reget the view because after appending it it is no longer valid
1507 // but this time it isn't a view object it is a table object with type "VIEW"
1508 Reference<XTablesSupplier> xTabSup(_rxConnection,UNO_QUERY);
1509 Reference< XNameAccess > xTables;
1510 if ( xTabSup.is() )
1512 xTables = xTabSup->getTables();
1513 if ( xTables.is() && xTables->hasByName( _rName ) )
1514 xTables->getByName( _rName ) >>= xView;
1517 return xView;
1520 // -----------------------------------------------------------------------------
1521 Reference<XPropertySet> createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection
1522 ,const Reference<XPropertySet>& _rxSourceObject)
1524 ::rtl::OUString sCommand;
1525 Reference< XPropertySetInfo > xPSI( _rxSourceObject->getPropertySetInfo(), UNO_SET_THROW );
1526 if ( xPSI->hasPropertyByName( PROPERTY_COMMAND ) )
1528 _rxSourceObject->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand;
1530 sal_Bool bEscapeProcessing( sal_False );
1531 OSL_VERIFY( _rxSourceObject->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
1532 if ( bEscapeProcessing )
1533 sCommand = lcl_createSDBCLevelStatement( sCommand, _rxConnection );
1535 else
1537 sCommand = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SELECT * FROM " ) );
1538 sCommand += composeTableNameForSelect( _rxConnection, _rxSourceObject );
1540 return createView( _rName, _rxConnection, sCommand );
1543 // -----------------------------------------------------------------------------
1544 sal_Bool insertHierachyElement( Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB,
1545 const Reference<XHierarchicalNameContainer>& _xNames,
1546 const String& _sParentFolder,
1547 sal_Bool _bForm,
1548 sal_Bool _bCollection,
1549 const Reference<XContent>& _xContent,
1550 sal_Bool _bMove)
1552 OSL_ENSURE( _xNames.is(), "insertHierachyElement: illegal name container!" );
1553 if ( !_xNames.is() )
1554 return sal_False;
1556 Reference<XNameAccess> xNameAccess( _xNames, UNO_QUERY );
1557 ::rtl::OUString sName = _sParentFolder;
1558 if ( _xNames->hasByHierarchicalName(sName) )
1560 Reference<XChild> xChild(_xNames->getByHierarchicalName(sName),UNO_QUERY);
1561 xNameAccess.set(xChild,UNO_QUERY);
1562 if ( !xNameAccess.is() && xChild.is() )
1563 xNameAccess.set(xChild->getParent(),UNO_QUERY);
1566 OSL_ENSURE( xNameAccess.is(), "insertHierachyElement: could not find the proper name container!" );
1567 if ( !xNameAccess.is() )
1568 return sal_False;
1570 ::rtl::OUString sNewName;
1571 Reference<XPropertySet> xProp(_xContent,UNO_QUERY);
1572 if ( xProp.is() )
1573 xProp->getPropertyValue(PROPERTY_NAME) >>= sNewName;
1575 if ( !_bMove || sNewName.isEmpty() )
1577 String sTargetName,sLabel;
1578 if ( sNewName.isEmpty() || xNameAccess->hasByName(sNewName) )
1580 if ( !sNewName.isEmpty() )
1581 sTargetName = sNewName;
1582 else
1583 sTargetName = String(ModuleRes( _bCollection ? STR_NEW_FOLDER : ((_bForm) ? RID_STR_FORM : RID_STR_REPORT)));
1584 sLabel = String(ModuleRes( _bCollection ? STR_FOLDER_LABEL : ((_bForm) ? STR_FRM_LABEL : STR_RPT_LABEL)));
1585 sTargetName = ::dbtools::createUniqueName(xNameAccess,sTargetName);
1588 // here we have everything needed to create a new query object ...
1589 HierarchicalNameCheck aNameChecker( _xNames.get(), sName );
1590 // ... ehm, except a new name
1591 OSaveAsDlg aAskForName( _pParent,
1592 _rxORB,
1593 sTargetName,
1594 sLabel,
1595 aNameChecker,
1596 SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
1597 if ( RET_OK != aAskForName.Execute() )
1598 // cancelled by the user
1599 return sal_False;
1601 sNewName = aAskForName.getName();
1604 else if ( xNameAccess->hasByName(sNewName) )
1606 String sError(ModuleRes(STR_NAME_ALREADY_EXISTS));
1607 sError.SearchAndReplaceAscii("#",sNewName);
1608 throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
1613 Reference<XMultiServiceFactory> xORB( xNameAccess, UNO_QUERY_THROW );
1614 Sequence< Any > aArguments(3);
1615 PropertyValue aValue;
1616 // set as folder
1617 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
1618 aValue.Value <<= sNewName;
1619 aArguments[0] <<= aValue;
1620 //parent
1621 aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
1622 aValue.Value <<= xNameAccess;
1623 aArguments[1] <<= aValue;
1625 aValue.Name = PROPERTY_EMBEDDEDOBJECT;
1626 aValue.Value <<= _xContent;
1627 aArguments[2] <<= aValue;
1629 ::rtl::OUString sServiceName(_bCollection ? ((_bForm) ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION) : SERVICE_SDB_DOCUMENTDEFINITION);
1631 Reference<XContent > xNew( xORB->createInstanceWithArguments( sServiceName, aArguments ), UNO_QUERY_THROW );
1632 Reference< XNameContainer > xNameContainer( xNameAccess, UNO_QUERY_THROW );
1633 xNameContainer->insertByName( sNewName, makeAny( xNew ) );
1635 catch( const IllegalArgumentException& e )
1637 ::dbtools::throwGenericSQLException( e.Message, e.Context );
1639 catch( const Exception& )
1641 DBG_UNHANDLED_EXCEPTION();
1642 return sal_False;
1645 return sal_True;
1647 // -----------------------------------------------------------------------------
1648 Reference< XNumberFormatter > getNumberFormatter(const Reference< XConnection >& _rxConnection,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF )
1650 // ---------------------------------------------------------------
1651 // create a formatter working with the connections format supplier
1652 Reference< XNumberFormatter > xFormatter;
1656 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(_rxConnection, sal_True,_rMF));
1658 if ( xSupplier.is() )
1660 // create a new formatter
1661 xFormatter = Reference< ::com::sun::star::util::XNumberFormatter > (
1662 _rMF->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
1663 if ( xFormatter.is() )
1664 xFormatter->attachNumberFormatsSupplier(xSupplier);
1667 catch(const Exception&)
1669 DBG_UNHANDLED_EXCEPTION();
1671 return xFormatter;
1675 // .........................................................................
1676 } // dbaui
1677 // .........................................................................
1679 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */