Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "UITools.hxx"
22 : #include <sfx2/docfilt.hxx>
23 : #include "callbacks.hxx"
24 : #include "dbustrings.hrc"
25 : #include "dbu_resource.hrc"
26 : #include "dlgsave.hxx"
27 : #include "dbtreelistbox.hxx"
28 : #include "defaultobjectnamecheck.hxx"
29 : #include <comphelper/extract.hxx>
30 : #include <com/sun/star/sdb/DatabaseContext.hpp>
31 : #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
32 : #include <com/sun/star/sdb/XCompletedConnection.hpp>
33 : #include <com/sun/star/sdbc/XDataSource.hpp>
34 : #include <com/sun/star/sdb/SQLContext.hpp>
35 : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
36 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
37 : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
38 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
39 : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
40 : #include <com/sun/star/sdbcx/XAppend.hpp>
41 : #include <com/sun/star/sdbc/XRow.hpp>
42 : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
43 : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
44 : #include <com/sun/star/sdbc/ColumnValue.hpp>
45 : #include <com/sun/star/task/InteractionHandler.hpp>
46 : #include <com/sun/star/ucb/XContent.hpp>
47 : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
48 : #include <com/sun/star/beans/PropertyValue.hpp>
49 : #include <com/sun/star/container/XIndexAccess.hpp>
50 : #include <com/sun/star/container/XNameContainer.hpp>
51 : #include <com/sun/star/ucb/InteractiveIOException.hpp>
52 : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
53 : #include <com/sun/star/ucb/IOErrorCode.hpp>
54 : #include <toolkit/helper/vclunohelper.hxx>
55 : #include <toolkit/awt/vclxwindow.hxx>
56 : #include <vcl/stdtext.hxx>
57 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
58 : #include <com/sun/star/beans/XPropertySet.hpp>
59 : #include <com/sun/star/container/XNameAccess.hpp>
60 : #include <com/sun/star/container/XContainer.hpp>
61 : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
62 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
63 : #include <com/sun/star/awt/TextAlign.hpp>
64 : #include <com/sun/star/awt/FontDescriptor.hpp>
65 : #include <com/sun/star/awt/FontWeight.hpp>
66 : #include <com/sun/star/awt/FontRelief.hpp>
67 : #include <com/sun/star/awt/FontWidth.hpp>
68 : #include <com/sun/star/frame/XModel.hpp>
69 : #include "dlgattr.hrc"
70 : #include "TypeInfo.hxx"
71 : #include "FieldDescriptions.hxx"
72 : #include <comphelper/processfactory.hxx>
73 : #include <comphelper/stl_types.hxx>
74 :
75 : #include <svx/svxids.hrc>
76 :
77 : #include <svl/itempool.hxx>
78 : #include <tools/string.hxx>
79 : #include "dbaccess_helpid.hrc"
80 : #include <svl/itemset.hxx>
81 : #include "sbagrid.hrc"
82 : #include <svl/rngitem.hxx>
83 : #include <svl/intitem.hxx>
84 : #include <svx/algitem.hxx>
85 : #include <svx/numinf.hxx>
86 : #include <svl/zforlist.hxx>
87 : #include "dlgattr.hxx"
88 : #include <vcl/msgbox.hxx>
89 : #include <com/sun/star/container/XChild.hpp>
90 : #include <com/sun/star/util/NumberFormatter.hpp>
91 : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
92 : #include <com/sun/star/util/XNumberFormatter.hpp>
93 : #include "dbu_misc.hrc"
94 : #include "sqlmessage.hxx"
95 : #include <com/sun/star/util/NumberFormat.hpp>
96 : #include <com/sun/star/util/URL.hpp>
97 : #include <vcl/toolbox.hxx>
98 : #include "dlgsize.hxx"
99 : #include <svtools/editbrowsebox.hxx>
100 : #include <unotools/configmgr.hxx>
101 : #include <svtools/helpopt.hxx>
102 : #include <ucbhelper/content.hxx>
103 : #include <tools/urlobj.hxx>
104 : #include <tools/diagnose_ex.h>
105 : #include <svl/numuno.hxx>
106 : #include <unotools/pathoptions.hxx>
107 : #include <svl/filenotation.hxx>
108 : #include <svtools/fileview.hxx>
109 : #include <connectivity/FValue.hxx>
110 :
111 : #include <editeng/justifyitem.hxx>
112 :
113 : // .........................................................................
114 : namespace dbaui
115 : {
116 : // .........................................................................
117 : using namespace ::dbtools;
118 : using namespace ::comphelper;
119 : using namespace ::com::sun::star;
120 : using namespace ::com::sun::star::uno;
121 : using namespace ::com::sun::star::task;
122 : using namespace ::com::sun::star::sdbcx;
123 : using namespace ::com::sun::star::sdbc;
124 : using namespace ::com::sun::star::sdb;
125 : using namespace ::com::sun::star::util;
126 : using namespace ::com::sun::star::ucb;
127 : using namespace ::com::sun::star::beans;
128 : using namespace ::com::sun::star::container;
129 : using namespace ::com::sun::star::lang;
130 : using namespace ::com::sun::star::ui::dialogs;
131 : using namespace ::svt;
132 : using ::com::sun::star::ucb::InteractiveIOException;
133 : using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
134 : using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
135 : using ::com::sun::star::frame::XModel;
136 :
137 : // -----------------------------------------------------------------------------
138 0 : SQLExceptionInfo createConnection( const OUString& _rsDataSourceName,
139 : const Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext,
140 : const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
141 : Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
142 : Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
143 : {
144 0 : Reference<XPropertySet> xProp;
145 : try
146 : {
147 0 : xProp.set(_xDatabaseContext->getByName(_rsDataSourceName),UNO_QUERY);
148 : }
149 0 : catch(const Exception&)
150 : {
151 : }
152 0 : SQLExceptionInfo aInfo;
153 :
154 0 : return createConnection(xProp,_rxContext,_rEvtLst,_rOUTConnection);
155 : }
156 : // -----------------------------------------------------------------------------
157 0 : SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource,
158 : const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
159 : Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
160 : Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
161 : {
162 0 : SQLExceptionInfo aInfo;
163 0 : if ( !_xDataSource.is() )
164 : {
165 : SAL_WARN("dbaccess.ui", "createConnection: coult not retrieve the data source!");
166 0 : return aInfo;
167 : }
168 :
169 0 : OUString sPwd, sUser;
170 0 : sal_Bool bPwdReq = sal_False;
171 : try
172 : {
173 0 : _xDataSource->getPropertyValue(PROPERTY_PASSWORD) >>= sPwd;
174 0 : bPwdReq = ::cppu::any2bool(_xDataSource->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED));
175 0 : _xDataSource->getPropertyValue(PROPERTY_USER) >>= sUser;
176 : }
177 0 : catch(const Exception&)
178 : {
179 : SAL_WARN("dbaccess.ui", "createConnection: error while retrieving data source properties!");
180 : }
181 :
182 :
183 : try
184 : {
185 0 : if(bPwdReq && sPwd.isEmpty())
186 : { // password required, but empty -> connect using an interaction handler
187 0 : Reference<XCompletedConnection> xConnectionCompletion(_xDataSource, UNO_QUERY);
188 0 : if (!xConnectionCompletion.is())
189 : {
190 : SAL_WARN("dbaccess.ui", "createConnection: missing an interface ... need an error message here!");
191 : }
192 : else
193 : { // instantiate the default SDB interaction handler
194 0 : Reference< XInteractionHandler > xHandler( InteractionHandler::createWithParent(_rxContext, 0), UNO_QUERY);
195 0 : _rOUTConnection = xConnectionCompletion->connectWithCompletion(xHandler);
196 0 : }
197 : }
198 : else
199 : {
200 0 : Reference<XDataSource> xDataSource(_xDataSource,UNO_QUERY);
201 0 : _rOUTConnection = xDataSource->getConnection(sUser, sPwd);
202 : }
203 : // be notified when connection is in disposing
204 0 : Reference< XComponent > xComponent(_rOUTConnection, UNO_QUERY);
205 0 : if (xComponent.is() && _rEvtLst.is())
206 0 : xComponent->addEventListener(_rEvtLst);
207 : }
208 0 : catch(const SQLContext& e) { aInfo = SQLExceptionInfo(e); }
209 0 : catch(const SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
210 0 : catch(const SQLException& e) { aInfo = SQLExceptionInfo(e); }
211 0 : catch(const Exception&) { SAL_WARN("dbaccess.ui", "SbaTableQueryBrowser::OnExpandEntry: could not connect - unknown exception!"); }
212 :
213 0 : return aInfo;
214 : }
215 : // -----------------------------------------------------------------------------
216 1 : Reference< XDataSource > getDataSourceByName( const OUString& _rDataSourceName,
217 : Window* _pErrorMessageParent, Reference< XComponentContext > _rxContext, ::dbtools::SQLExceptionInfo* _pErrorInfo )
218 : {
219 1 : Reference< XDatabaseContext > xDatabaseContext = DatabaseContext::create(_rxContext);
220 :
221 2 : Reference< XDataSource > xDatasource;
222 2 : Any aError;
223 2 : SQLExceptionInfo aSQLError;
224 : try
225 : {
226 1 : xDatabaseContext->getByName( _rDataSourceName ) >>= xDatasource;
227 : }
228 0 : catch(const WrappedTargetException& e)
229 : {
230 0 : InteractiveIOException aIOException;
231 0 : if ( ( e.TargetException >>= aIOException )
232 0 : && ( ( aIOException.Code == IOErrorCode_NO_FILE )
233 0 : || ( aIOException.Code == IOErrorCode_NOT_EXISTING )
234 : )
235 : )
236 : {
237 0 : String sErrorMessage = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
238 0 : OFileNotation aTransformer( e.Message );
239 0 : sErrorMessage.SearchAndReplaceAscii( "$file$", aTransformer.get( OFileNotation::N_SYSTEM ) );
240 0 : aSQLError = SQLExceptionInfo( sErrorMessage ).get();
241 : }
242 : else
243 : {
244 0 : aSQLError = SQLExceptionInfo( e.TargetException );
245 0 : if ( !aSQLError.isValid() )
246 0 : aError = e.TargetException;
247 0 : }
248 : }
249 0 : catch( const Exception& )
250 : {
251 : DBG_UNHANDLED_EXCEPTION();
252 : }
253 :
254 1 : if ( xDatasource.is() )
255 1 : return xDatasource;
256 :
257 0 : if ( aSQLError.isValid() )
258 : {
259 0 : if ( _pErrorInfo )
260 : {
261 0 : *_pErrorInfo = aSQLError;
262 : }
263 : else
264 : {
265 0 : showError( aSQLError, _pErrorMessageParent, _rxContext );
266 : }
267 : }
268 :
269 1 : return Reference<XDataSource>();
270 : }
271 : // -----------------------------------------------------------------------------
272 0 : Reference< XInterface > getDataSourceOrModel(const Reference< XInterface >& _xObject)
273 : {
274 0 : Reference< XInterface > xRet;
275 0 : Reference<XDocumentDataSource> xDocumentDataSource(_xObject,UNO_QUERY);
276 0 : if ( xDocumentDataSource.is() )
277 0 : xRet = xDocumentDataSource->getDatabaseDocument();
278 :
279 0 : if ( !xRet.is() )
280 : {
281 0 : Reference<XOfficeDatabaseDocument> xOfficeDoc(_xObject,UNO_QUERY);
282 0 : if ( xOfficeDoc.is() )
283 0 : xRet = xOfficeDoc->getDataSource();
284 : }
285 :
286 0 : return xRet;
287 : }
288 : // -----------------------------------------------------------------------------
289 0 : void showError(const SQLExceptionInfo& _rInfo,Window* _pParent,const Reference< XComponentContext >& _rxContext)
290 : {
291 : OSL_ENSURE(_pParent,"showError: Parent window must be NOT NULL!");
292 0 : ::dbtools::showError(_rInfo,VCLUnoHelper::GetInterface(_pParent), _rxContext);
293 0 : }
294 :
295 : // -----------------------------------------------------------------------------
296 :
297 0 : TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
298 : sal_Int32 _nType,
299 : const OUString& _sTypeName,
300 : const OUString& _sCreateParams,
301 : sal_Int32 _nPrecision,
302 : sal_Int32 _nScale,
303 : sal_Bool _bAutoIncrement,
304 : sal_Bool& _brForceToType)
305 : {
306 0 : TOTypeInfoSP pTypeInfo;
307 0 : _brForceToType = sal_False;
308 : // search for type
309 0 : ::std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
310 0 : OTypeInfoMap::const_iterator aIter = aPair.first;
311 0 : if(aIter != _rTypeInfo.end()) // compare with end is correct here
312 : {
313 0 : for(;aIter != aPair.second;++aIter)
314 : {
315 : // search the best matching type
316 : #ifdef DBG_UTIL
317 : OUString sDBTypeName = aIter->second->aTypeName; (void)sDBTypeName;
318 : sal_Int32 nDBTypePrecision = aIter->second->nPrecision; (void)nDBTypePrecision;
319 : sal_Int32 nDBTypeScale = aIter->second->nMaximumScale; (void)nDBTypeScale;
320 : sal_Bool bDBAutoIncrement = aIter->second->bAutoIncrement; (void)bDBAutoIncrement;
321 : #endif
322 0 : if ( (
323 0 : _sTypeName.isEmpty()
324 0 : || (aIter->second->aTypeName.equalsIgnoreAsciiCase(_sTypeName))
325 : )
326 0 : && (
327 : (
328 0 : !aIter->second->aCreateParams.getLength()
329 0 : && _sCreateParams.isEmpty()
330 : )
331 0 : || (
332 0 : (aIter->second->nPrecision >= _nPrecision)
333 0 : && (aIter->second->nMaximumScale >= _nScale)
334 0 : && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
335 : )
336 : )
337 : )
338 0 : break;
339 : }
340 :
341 0 : if (aIter == aPair.second)
342 : {
343 0 : for(aIter = aPair.first; aIter != aPair.second; ++aIter)
344 : {
345 0 : sal_Int32 nPrec = aIter->second->nPrecision;
346 0 : sal_Int32 nScale = aIter->second->nMaximumScale;
347 : // search the best matching type (now comparing the local names)
348 0 : if ( (aIter->second->aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
349 0 : && (nPrec >= _nPrecision)
350 0 : && (nScale >= _nScale)
351 0 : && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
352 : )
353 : {
354 : SAL_WARN("dbaccess.ui", "getTypeInfoFromType: assuming column type " <<
355 : aIter->second->aTypeName << "\" (expected type name " <<
356 : _sTypeName << " matches the type's local name).");
357 0 : break;
358 : }
359 : }
360 : }
361 :
362 0 : if (aIter == aPair.second)
363 : { // no match for the names, no match for the local names
364 : // -> drop the precision and the scale restriction, accept any type with the property
365 : // type id (nType)
366 :
367 0 : for(aIter = aPair.first; aIter != aPair.second; ++aIter)
368 : {
369 : // search the best matching type (now comparing the local names)
370 0 : sal_Int32 nPrec = aIter->second->nPrecision;
371 0 : sal_Int32 nScale = aIter->second->nMaximumScale;
372 0 : if ( (nPrec >= _nPrecision)
373 0 : && (nScale >= _nScale)
374 0 : && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
375 : )
376 0 : break;
377 : }
378 : }
379 0 : if (aIter == aPair.second)
380 : {
381 0 : if ( _bAutoIncrement )
382 : {
383 0 : for(aIter = aPair.first; aIter != aPair.second; ++aIter)
384 : {
385 : // search the best matching type (now comparing the local names)
386 0 : sal_Int32 nScale = aIter->second->nMaximumScale;
387 0 : if ( (nScale >= _nScale)
388 0 : && (aIter->second->bAutoIncrement == _bAutoIncrement)
389 : )
390 0 : break;
391 : }
392 0 : if ( aIter == aPair.second )
393 : {
394 : // try it without the auto increment flag
395 0 : pTypeInfo = getTypeInfoFromType(_rTypeInfo,
396 : _nType,
397 : _sTypeName,
398 : _sCreateParams,
399 : _nPrecision,
400 : _nScale,
401 : sal_False,
402 0 : _brForceToType);
403 : }
404 : else
405 0 : pTypeInfo = aIter->second;
406 : }
407 : else
408 : {
409 0 : pTypeInfo = aPair.first->second;
410 0 : _brForceToType = sal_True;
411 : }
412 : }
413 : else
414 0 : pTypeInfo = aIter->second;
415 : }
416 : else
417 : {
418 0 : ::comphelper::TStringMixEqualFunctor aCase(sal_False);
419 : // search for typeinfo where the typename is equal _sTypeName
420 0 : OTypeInfoMap::const_iterator typeInfoLoop = _rTypeInfo.begin();
421 0 : OTypeInfoMap::const_iterator typeInfoEnd = _rTypeInfo.end();
422 0 : for (; typeInfoLoop != typeInfoEnd; ++typeInfoLoop)
423 : {
424 0 : if ( aCase( typeInfoLoop->second->getDBName() , _sTypeName ) )
425 : {
426 0 : pTypeInfo = typeInfoLoop->second;
427 0 : break;
428 : }
429 : }
430 : }
431 :
432 : OSL_ENSURE(pTypeInfo, "getTypeInfoFromType: no type info found for this type!");
433 0 : return pTypeInfo;
434 : }
435 : // -----------------------------------------------------------------------------
436 0 : void fillTypeInfo( const Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection,
437 : const String& _rsTypeNames,
438 : OTypeInfoMap& _rTypeInfoMap,
439 : ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters)
440 : {
441 0 : if(!_rxConnection.is())
442 0 : return;
443 0 : Reference< XResultSet> xRs = _rxConnection->getMetaData ()->getTypeInfo ();
444 0 : Reference< XRow> xRow(xRs,UNO_QUERY);
445 : // Information for a single SQL type
446 0 : if(xRs.is())
447 : {
448 0 : static const OUString aB1(" [ ");
449 0 : static const OUString aB2(" ]");
450 0 : Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
451 0 : ::connectivity::ORowSetValue aValue;
452 0 : ::std::vector<sal_Int32> aTypes;
453 0 : ::std::vector<sal_Bool> aNullable;
454 : // Loop on the result set until we reach end of file
455 0 : while (xRs->next())
456 : {
457 0 : TOTypeInfoSP pInfo(new OTypeInfo());
458 0 : sal_Int32 nPos = 1;
459 0 : if ( aTypes.empty() )
460 : {
461 0 : sal_Int32 nCount = xResultSetMetaData->getColumnCount();
462 0 : if ( nCount < 1 )
463 0 : nCount = 18;
464 0 : aTypes.reserve(nCount+1);
465 0 : aTypes.push_back(-1);
466 0 : aNullable.push_back(sal_False);
467 0 : for (sal_Int32 j = 1; j <= nCount ; ++j)
468 : {
469 0 : aTypes.push_back(xResultSetMetaData->getColumnType(j));
470 0 : aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS);
471 : }
472 : }
473 :
474 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
475 0 : pInfo->aTypeName = aValue;
476 0 : ++nPos;
477 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
478 0 : pInfo->nType = aValue;
479 0 : ++nPos;
480 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
481 0 : pInfo->nPrecision = aValue;
482 0 : ++nPos;
483 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
484 0 : pInfo->aLiteralPrefix = aValue;
485 0 : ++nPos;
486 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
487 0 : pInfo->aLiteralSuffix = aValue;
488 0 : ++nPos;
489 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
490 0 : pInfo->aCreateParams = aValue;
491 0 : ++nPos;
492 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
493 0 : pInfo->bNullable = (sal_Int32)aValue == ColumnValue::NULLABLE;
494 0 : ++nPos;
495 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
496 0 : pInfo->bCaseSensitive = (sal_Bool)aValue;
497 0 : ++nPos;
498 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
499 0 : pInfo->nSearchType = aValue;
500 0 : ++nPos;
501 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
502 0 : pInfo->bUnsigned = (sal_Bool)aValue;
503 0 : ++nPos;
504 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
505 0 : pInfo->bCurrency = (sal_Bool)aValue;
506 0 : ++nPos;
507 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
508 0 : pInfo->bAutoIncrement = (sal_Bool)aValue;
509 0 : ++nPos;
510 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
511 0 : pInfo->aLocalTypeName = aValue;
512 0 : ++nPos;
513 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
514 0 : pInfo->nMinimumScale = aValue;
515 0 : ++nPos;
516 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
517 0 : pInfo->nMaximumScale = aValue;
518 0 : nPos = 18;
519 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
520 :
521 : // check if values are less than zero like it happens in a oracle jdbc driver
522 0 : if( pInfo->nPrecision < 0)
523 0 : pInfo->nPrecision = 0;
524 0 : if( pInfo->nMinimumScale < 0)
525 0 : pInfo->nMinimumScale = 0;
526 0 : if( pInfo->nMaximumScale < 0)
527 0 : pInfo->nMaximumScale = 0;
528 :
529 0 : String aName;
530 0 : switch(pInfo->nType)
531 : {
532 : case DataType::CHAR:
533 0 : aName = _rsTypeNames.GetToken(TYPE_CHAR);
534 0 : break;
535 : case DataType::VARCHAR:
536 0 : aName = _rsTypeNames.GetToken(TYPE_TEXT);
537 0 : break;
538 : case DataType::DECIMAL:
539 0 : aName = _rsTypeNames.GetToken(TYPE_DECIMAL);
540 0 : break;
541 : case DataType::NUMERIC:
542 0 : aName = _rsTypeNames.GetToken(TYPE_NUMERIC);
543 0 : break;
544 : case DataType::BIGINT:
545 0 : aName = _rsTypeNames.GetToken(TYPE_BIGINT);
546 0 : break;
547 : case DataType::FLOAT:
548 0 : aName = _rsTypeNames.GetToken(TYPE_FLOAT);
549 0 : break;
550 : case DataType::DOUBLE:
551 0 : aName = _rsTypeNames.GetToken(TYPE_DOUBLE);
552 0 : break;
553 : case DataType::LONGVARCHAR:
554 0 : aName = _rsTypeNames.GetToken(TYPE_MEMO);
555 0 : break;
556 : case DataType::LONGVARBINARY:
557 0 : aName = _rsTypeNames.GetToken(TYPE_IMAGE);
558 0 : break;
559 : case DataType::DATE:
560 0 : aName = _rsTypeNames.GetToken(TYPE_DATE);
561 0 : break;
562 : case DataType::TIME:
563 0 : aName = _rsTypeNames.GetToken(TYPE_TIME);
564 0 : break;
565 : case DataType::TIMESTAMP:
566 0 : aName = _rsTypeNames.GetToken(TYPE_DATETIME);
567 0 : break;
568 : case DataType::BIT:
569 0 : if ( !pInfo->aCreateParams.isEmpty() )
570 : {
571 0 : aName = _rsTypeNames.GetToken(TYPE_BIT);
572 0 : break;
573 : }
574 : // run through
575 : case DataType::BOOLEAN:
576 0 : aName = _rsTypeNames.GetToken(TYPE_BOOL);
577 0 : break;
578 : case DataType::TINYINT:
579 0 : aName = _rsTypeNames.GetToken(TYPE_TINYINT);
580 0 : break;
581 : case DataType::SMALLINT:
582 0 : aName = _rsTypeNames.GetToken(TYPE_SMALLINT);
583 0 : break;
584 : case DataType::INTEGER:
585 0 : aName = _rsTypeNames.GetToken(TYPE_INTEGER);
586 0 : break;
587 : case DataType::REAL:
588 0 : aName = _rsTypeNames.GetToken(TYPE_REAL);
589 0 : break;
590 : case DataType::BINARY:
591 0 : aName = _rsTypeNames.GetToken(TYPE_BINARY);
592 0 : break;
593 : case DataType::VARBINARY:
594 0 : aName = _rsTypeNames.GetToken(TYPE_VARBINARY);
595 0 : break;
596 : case DataType::SQLNULL:
597 0 : aName = _rsTypeNames.GetToken(TYPE_SQLNULL);
598 0 : break;
599 : case DataType::OBJECT:
600 0 : aName = _rsTypeNames.GetToken(TYPE_OBJECT);
601 0 : break;
602 : case DataType::DISTINCT:
603 0 : aName = _rsTypeNames.GetToken(TYPE_DISTINCT);
604 0 : break;
605 : case DataType::STRUCT:
606 0 : aName = _rsTypeNames.GetToken(TYPE_STRUCT);
607 0 : break;
608 : case DataType::ARRAY:
609 0 : aName = _rsTypeNames.GetToken(TYPE_ARRAY);
610 0 : break;
611 : case DataType::BLOB:
612 0 : aName = _rsTypeNames.GetToken(TYPE_BLOB);
613 0 : break;
614 : case DataType::CLOB:
615 0 : aName = _rsTypeNames.GetToken(TYPE_CLOB);
616 0 : break;
617 : case DataType::REF:
618 0 : aName = _rsTypeNames.GetToken(TYPE_REF);
619 0 : break;
620 : case DataType::OTHER:
621 0 : aName = _rsTypeNames.GetToken(TYPE_OTHER);
622 0 : break;
623 : }
624 0 : if ( aName.Len() )
625 : {
626 0 : pInfo->aUIName = aName.GetBuffer();
627 0 : pInfo->aUIName += aB1;
628 : }
629 0 : pInfo->aUIName += pInfo->aTypeName;
630 0 : if ( aName.Len() )
631 0 : pInfo->aUIName += aB2;
632 : // Now that we have the type info, save it in the multimap
633 0 : _rTypeInfoMap.insert(OTypeInfoMap::value_type(pInfo->nType,pInfo));
634 0 : }
635 : // for a faster index access
636 0 : _rTypeInfoIters.reserve(_rTypeInfoMap.size());
637 :
638 0 : OTypeInfoMap::iterator aIter = _rTypeInfoMap.begin();
639 0 : OTypeInfoMap::iterator aEnd = _rTypeInfoMap.end();
640 0 : for(;aIter != aEnd;++aIter)
641 0 : _rTypeInfoIters.push_back(aIter);
642 :
643 : // Close the result set/statement.
644 :
645 0 : ::comphelper::disposeComponent(xRs);
646 0 : }
647 : }
648 : // -----------------------------------------------------------------------------
649 0 : void setColumnProperties(const Reference<XPropertySet>& _rxColumn,const OFieldDescription* _pFieldDesc)
650 : {
651 0 : _rxColumn->setPropertyValue(PROPERTY_NAME,makeAny(_pFieldDesc->GetName()));
652 0 : _rxColumn->setPropertyValue(PROPERTY_TYPENAME,makeAny(_pFieldDesc->getTypeInfo()->aTypeName));
653 0 : _rxColumn->setPropertyValue(PROPERTY_TYPE,makeAny(_pFieldDesc->GetType()));
654 0 : _rxColumn->setPropertyValue(PROPERTY_PRECISION,makeAny(_pFieldDesc->GetPrecision()));
655 0 : _rxColumn->setPropertyValue(PROPERTY_SCALE,makeAny(_pFieldDesc->GetScale()));
656 0 : _rxColumn->setPropertyValue(PROPERTY_ISNULLABLE, makeAny(_pFieldDesc->GetIsNullable()));
657 0 : _rxColumn->setPropertyValue(PROPERTY_ISAUTOINCREMENT,::cppu::bool2any(_pFieldDesc->IsAutoIncrement()));
658 0 : _rxColumn->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_pFieldDesc->GetDescription()));
659 0 : if ( _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ISCURRENCY) && _pFieldDesc->IsCurrency() )
660 0 : _rxColumn->setPropertyValue(PROPERTY_ISCURRENCY,::cppu::bool2any(_pFieldDesc->IsCurrency()));
661 : // set autoincrement value when available
662 : // and only set when the entry is not empty, that lets the value in the column untouched
663 0 : if ( _pFieldDesc->IsAutoIncrement() && !_pFieldDesc->GetAutoIncrementValue().isEmpty() && _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
664 0 : _rxColumn->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_pFieldDesc->GetAutoIncrementValue()));
665 0 : }
666 : // -----------------------------------------------------------------------------
667 0 : OUString createDefaultName(const Reference< XDatabaseMetaData>& _xMetaData,const Reference<XNameAccess>& _xTables,const OUString& _sName)
668 : {
669 : OSL_ENSURE(_xMetaData.is(),"No MetaData!");
670 0 : OUString sDefaultName = _sName;
671 : try
672 : {
673 0 : OUString sCatalog,sSchema,sCompsedName;
674 0 : if(_xMetaData->supportsCatalogsInTableDefinitions())
675 : {
676 : try
677 : {
678 0 : Reference< XConnection> xCon = _xMetaData->getConnection();
679 0 : if ( xCon.is() )
680 0 : sCatalog = xCon->getCatalog();
681 0 : if ( sCatalog.isEmpty() )
682 : {
683 0 : Reference<XResultSet> xRes = _xMetaData->getCatalogs();
684 0 : Reference<XRow> xRow(xRes,UNO_QUERY);
685 0 : while(xRes.is() && xRes->next())
686 : {
687 0 : sCatalog = xRow->getString(1);
688 0 : if(!xRow->wasNull())
689 0 : break;
690 0 : }
691 0 : }
692 : }
693 0 : catch(const SQLException&)
694 : {
695 : }
696 : }
697 0 : if(_xMetaData->supportsSchemasInTableDefinitions())
698 : {
699 0 : sSchema = _xMetaData->getUserName();
700 : }
701 0 : sCompsedName = ::dbtools::composeTableName( _xMetaData, sCatalog, sSchema, _sName, sal_False, ::dbtools::eInDataManipulation );
702 0 : sDefaultName = ::dbtools::createUniqueName(_xTables,sCompsedName);
703 : }
704 0 : catch(const SQLException&)
705 : {
706 : }
707 0 : return sDefaultName;
708 : }
709 : // -----------------------------------------------------------------------------
710 0 : sal_Bool checkDataSourceAvailable(const OUString& _sDataSourceName,const Reference< ::com::sun::star::uno::XComponentContext >& _xContext)
711 : {
712 0 : Reference< XDatabaseContext > xDataBaseContext = DatabaseContext::create(_xContext);
713 0 : sal_Bool bRet = xDataBaseContext->hasByName(_sDataSourceName);
714 0 : if ( !bRet )
715 : { // try if this one is a URL
716 : try
717 : {
718 0 : bRet = xDataBaseContext->getByName(_sDataSourceName).hasValue();
719 : }
720 0 : catch(const Exception&)
721 : {
722 : }
723 : }
724 0 : return bRet;
725 : }
726 : // -----------------------------------------------------------------------------
727 0 : sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment)
728 : {
729 0 : sal_Int32 nAlignment = com::sun::star::awt::TextAlign::LEFT;
730 0 : switch (_eAlignment)
731 : {
732 : case SVX_HOR_JUSTIFY_STANDARD:
733 0 : case SVX_HOR_JUSTIFY_LEFT: nAlignment = ::com::sun::star::awt::TextAlign::LEFT; break;
734 0 : case SVX_HOR_JUSTIFY_CENTER: nAlignment = ::com::sun::star::awt::TextAlign::CENTER; break;
735 0 : case SVX_HOR_JUSTIFY_RIGHT: nAlignment = ::com::sun::star::awt::TextAlign::RIGHT; break;
736 : default:
737 : SAL_WARN("dbaccess.ui", "Invalid TextAlign!");
738 : }
739 0 : return nAlignment;
740 : }
741 : // -----------------------------------------------------------------------------
742 0 : SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment)
743 : {
744 0 : SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_LEFT;
745 0 : switch (_nAlignment)
746 : {
747 0 : case ::com::sun::star::awt::TextAlign::LEFT : eJustify = SVX_HOR_JUSTIFY_LEFT; break;
748 0 : case ::com::sun::star::awt::TextAlign::CENTER : eJustify = SVX_HOR_JUSTIFY_CENTER; break;
749 0 : case ::com::sun::star::awt::TextAlign::RIGHT : eJustify = SVX_HOR_JUSTIFY_RIGHT; break;
750 : default:
751 : SAL_WARN("dbaccess.ui", "Invalid TextAlign!");
752 : }
753 0 : return eJustify;
754 : }
755 : // -----------------------------------------------------------------------------
756 0 : void callColumnFormatDialog(const Reference<XPropertySet>& xAffectedCol,
757 : const Reference<XPropertySet>& xField,
758 : SvNumberFormatter* _pFormatter,
759 : Window* _pParent)
760 : {
761 0 : if (xAffectedCol.is() && xField.is())
762 : {
763 : try
764 : {
765 0 : Reference< XPropertySetInfo > xInfo = xAffectedCol->getPropertySetInfo();
766 0 : sal_Bool bHasFormat = xInfo->hasPropertyByName(PROPERTY_FORMATKEY);
767 0 : sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE));
768 :
769 0 : SvxCellHorJustify eJustify(SVX_HOR_JUSTIFY_STANDARD);
770 0 : Any aAlignment = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
771 0 : if (aAlignment.hasValue())
772 0 : eJustify = dbaui::mapTextJustify(::comphelper::getINT16(aAlignment));
773 0 : sal_Int32 nFormatKey = 0;
774 0 : if ( bHasFormat )
775 0 : nFormatKey = ::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY));
776 :
777 0 : sal_uInt16 nFlags = 0;
778 0 : if(callColumnFormatDialog(_pParent,_pFormatter,nDataType,nFormatKey,eJustify,nFlags,bHasFormat))
779 : {
780 0 : xAffectedCol->setPropertyValue(PROPERTY_ALIGN, makeAny((sal_Int16)dbaui::mapTextAllign(eJustify)));
781 0 : if (nFlags & TP_ATTR_NUMBER)
782 0 : xAffectedCol->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
783 :
784 0 : }
785 : }
786 0 : catch( const Exception& )
787 : {
788 : DBG_UNHANDLED_EXCEPTION();
789 : }
790 : }
791 0 : }
792 : // -----------------------------------------------------------------------------
793 0 : sal_Bool callColumnFormatDialog(Window* _pParent,
794 : SvNumberFormatter* _pFormatter,
795 : sal_Int32 _nDataType,
796 : sal_Int32& _nFormatKey,
797 : SvxCellHorJustify& _eJustify,
798 : sal_uInt16& _nFlags,
799 : sal_Bool _bHasFormat)
800 : {
801 0 : sal_Bool bRet = sal_False;
802 : // the allowed format changes depending on the type of the field ...
803 0 : _nFlags = TP_ATTR_ALIGN;
804 :
805 0 : if (_bHasFormat)
806 0 : _nFlags |= TP_ATTR_NUMBER;
807 :
808 : // ------------
809 : // UNO->ItemSet
810 : static SfxItemInfo aItemInfos[] =
811 : {
812 : { 0, 0 },
813 : { SID_ATTR_NUMBERFORMAT_VALUE, SFX_ITEM_POOLABLE },
814 : { SID_ATTR_ALIGN_HOR_JUSTIFY, SFX_ITEM_POOLABLE },
815 : { SID_ATTR_NUMBERFORMAT_ONE_AREA, SFX_ITEM_POOLABLE },
816 : { SID_ATTR_NUMBERFORMAT_INFO, SFX_ITEM_POOLABLE }
817 : };
818 : static sal_uInt16 aAttrMap[] =
819 : {
820 : SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY,
821 : SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
822 : SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
823 : 0
824 : };
825 :
826 : SfxPoolItem* pDefaults[] =
827 : {
828 0 : new SfxRangeItem(SBA_DEF_RANGEFORMAT, SBA_DEF_FMTVALUE, SBA_ATTR_ALIGN_HOR_JUSTIFY),
829 0 : new SfxUInt32Item(SBA_DEF_FMTVALUE),
830 0 : new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, SBA_ATTR_ALIGN_HOR_JUSTIFY),
831 0 : new SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_False),
832 0 : new SvxNumberInfoItem(SID_ATTR_NUMBERFORMAT_INFO)
833 0 : };
834 :
835 0 : SfxItemPool* pPool = new SfxItemPool(OUString("GridBrowserProperties"), SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, pDefaults);
836 0 : pPool->SetDefaultMetric( SFX_MAPUNIT_TWIP ); // ripped, don't understand why
837 0 : pPool->FreezeIdRanges(); // the same
838 :
839 0 : SfxItemSet* pFormatDescriptor = new SfxItemSet(*pPool, aAttrMap);
840 : // fill it
841 0 : pFormatDescriptor->Put(SvxHorJustifyItem(_eJustify, SBA_ATTR_ALIGN_HOR_JUSTIFY));
842 0 : sal_Bool bText = sal_False;
843 0 : if (_bHasFormat)
844 : {
845 : // if the col is bound to a text field we have to disallow all non-text formats
846 0 : if ((DataType::CHAR == _nDataType) || (DataType::VARCHAR == _nDataType) || (DataType::LONGVARCHAR == _nDataType) || (DataType::CLOB == _nDataType))
847 : {
848 0 : bText = sal_True;
849 0 : pFormatDescriptor->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_True));
850 0 : if (!_pFormatter->IsTextFormat(_nFormatKey))
851 : // text fields can only have text formats
852 0 : _nFormatKey = _pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT,_pParent->GetSettings().GetLanguageTag().getLanguageType());
853 : }
854 :
855 0 : pFormatDescriptor->Put(SfxUInt32Item(SBA_DEF_FMTVALUE, _nFormatKey));
856 : }
857 :
858 0 : if (!bText)
859 : {
860 0 : double dPreviewVal = 1234.56789;
861 0 : SvxNumberInfoItem aFormatter(_pFormatter, dPreviewVal, SID_ATTR_NUMBERFORMAT_INFO);
862 0 : pFormatDescriptor->Put(aFormatter);
863 : }
864 :
865 : { // want the dialog to be destroyed before our set
866 0 : SbaSbAttrDlg aDlg(_pParent, pFormatDescriptor, _pFormatter, _nFlags);
867 0 : if (RET_OK == aDlg.Execute())
868 : {
869 : // ------------
870 : // ItemSet->UNO
871 : // UNO-properties
872 0 : const SfxItemSet* pSet = aDlg.GetExampleSet();
873 : // (of course we could put the modified items directly into the column, but then the UNO-model
874 : // won't reflect these changes, and why do we have a model, then ?)
875 :
876 : // horizontal justify
877 0 : SFX_ITEMSET_GET(*pSet, pHorJustify, SvxHorJustifyItem, SBA_ATTR_ALIGN_HOR_JUSTIFY, sal_True);
878 :
879 0 : _eJustify = (SvxCellHorJustify)pHorJustify->GetValue();
880 :
881 : // format key
882 0 : if (_nFlags & TP_ATTR_NUMBER)
883 : {
884 0 : SFX_ITEMSET_GET(*pSet, pFormat, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
885 0 : _nFormatKey = (sal_Int32)pFormat->GetValue();
886 : }
887 0 : bRet = sal_True;
888 : }
889 : // deleted formats
890 0 : const SfxItemSet* pResult = aDlg.GetOutputItemSet();
891 0 : if (pResult)
892 : {
893 0 : const SfxPoolItem* pItem = pResult->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
894 0 : const SvxNumberInfoItem* pInfoItem = static_cast<const SvxNumberInfoItem*>(pItem);
895 0 : if (pInfoItem && pInfoItem->GetDelCount())
896 : {
897 0 : const sal_uInt32* pDeletedKeys = pInfoItem->GetDelArray();
898 :
899 0 : for (sal_uInt16 i=0; i< pInfoItem->GetDelCount(); ++i, ++pDeletedKeys)
900 0 : _pFormatter->DeleteEntry(*pDeletedKeys);
901 : }
902 0 : }
903 : }
904 :
905 0 : delete pFormatDescriptor;
906 0 : SfxItemPool::Free(pPool);
907 0 : for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
908 0 : delete pDefaults[i];
909 :
910 0 : return bRet;
911 : }
912 :
913 : //------------------------------------------------------------------------------
914 0 : const SfxFilter* getStandardDatabaseFilter()
915 : {
916 0 : const SfxFilter* pFilter = SfxFilter::GetFilterByName(OUString("StarOffice XML (Base)"));
917 : OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
918 0 : return pFilter;
919 : }
920 :
921 :
922 : // -----------------------------------------------------------------------------
923 0 : sal_Bool appendToFilter(const Reference<XConnection>& _xConnection,
924 : const OUString& _sName,
925 : const Reference< XComponentContext >& _rxContext,
926 : Window* _pParent)
927 : {
928 0 : sal_Bool bRet = sal_False;
929 0 : Reference< XChild> xChild(_xConnection,UNO_QUERY);
930 0 : if(xChild.is())
931 : {
932 0 : Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
933 0 : if(xProp.is())
934 : {
935 0 : Sequence< OUString > aFilter;
936 0 : xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aFilter;
937 : // first check if we have something like SCHEMA.%
938 0 : sal_Bool bHasToInsert = sal_True;
939 0 : const OUString* pBegin = aFilter.getConstArray();
940 0 : const OUString* pEnd = pBegin + aFilter.getLength();
941 0 : for (;pBegin != pEnd; ++pBegin)
942 : {
943 0 : if(pBegin->indexOf('%') != -1)
944 : {
945 : sal_Int32 nLen;
946 0 : if((nLen = pBegin->lastIndexOf('.')) != -1 && !pBegin->compareTo(_sName,nLen))
947 0 : bHasToInsert = sal_False;
948 0 : else if(pBegin->getLength() == 1)
949 0 : bHasToInsert = sal_False;
950 : }
951 : }
952 :
953 0 : bRet = sal_True;
954 0 : if(bHasToInsert)
955 : {
956 0 : if(! ::dbaui::checkDataSourceAvailable(::comphelper::getString(xProp->getPropertyValue(PROPERTY_NAME)),_rxContext))
957 : {
958 0 : String aMessage(ModuleRes(STR_TABLEDESIGN_DATASOURCE_DELETED));
959 0 : OSQLWarningBox( _pParent, aMessage ).Execute();
960 0 : bRet = sal_False;
961 : }
962 : else
963 : {
964 0 : aFilter.realloc(aFilter.getLength()+1);
965 0 : aFilter.getArray()[aFilter.getLength()-1] = _sName;
966 0 : xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
967 : }
968 0 : }
969 0 : }
970 : }
971 0 : return bRet;
972 : }
973 : // -----------------------------------------------------------------------------
974 0 : void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc)
975 : {
976 : OSL_ENSURE(_pWindow,"Window can not be null!");
977 0 : SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : NULL;
978 0 : if ( pSystemWindow )
979 : {
980 0 : _rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
981 : }
982 0 : }
983 : // -----------------------------------------------------------------------------
984 0 : void adjustToolBoxSize(ToolBox* _pToolBox)
985 : {
986 : // adjust the toolbox size, otherwise large bitmaps don't fit into
987 0 : Size aOldSize = _pToolBox->GetSizePixel();
988 0 : Size aSize = _pToolBox->CalcWindowSizePixel();
989 0 : if ( !aSize.Width() )
990 0 : aSize.Width() = aOldSize.Width();
991 0 : else if ( !aSize.Height() )
992 0 : aSize.Height() = aOldSize.Height();
993 :
994 0 : Size aTbSize = _pToolBox->GetSizePixel();
995 0 : if ( (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
996 0 : (aSize.Height() && aSize.Height() != aTbSize.Height()) )
997 : {
998 0 : _pToolBox->SetPosSizePixel( _pToolBox->GetPosPixel(), aSize );
999 0 : _pToolBox->Invalidate();
1000 : }
1001 0 : }
1002 : // -----------------------------------------------------------------------------
1003 0 : void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId )
1004 : {
1005 0 : sal_Int32 nColSize = -1;
1006 0 : sal_uInt32 nDefaultWidth = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1007 0 : if ( nDefaultWidth != _pBox->GetColumnWidth( _nColId ) )
1008 : {
1009 0 : Size aSizeMM = _pBox->PixelToLogic( Size( _pBox->GetColumnWidth( _nColId ), 0 ), MapMode( MAP_MM ) );
1010 0 : nColSize = aSizeMM.Width() * 10;
1011 : }
1012 :
1013 0 : Size aDefaultMM = _pBox->PixelToLogic( Size( nDefaultWidth, 0 ), MapMode( MAP_MM ) );
1014 :
1015 0 : DlgSize aColumnSizeDlg( _pBox, nColSize, sal_False, aDefaultMM.Width() * 10 );
1016 0 : if ( aColumnSizeDlg.Execute() )
1017 : {
1018 0 : sal_Int32 nValue = aColumnSizeDlg.GetValue();
1019 0 : if ( -1 == nValue )
1020 : { // default width
1021 0 : nValue = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
1022 : }
1023 : else
1024 : {
1025 0 : Size aSizeMM( nValue / 10, 0 );
1026 0 : nValue = _pBox->LogicToPixel( aSizeMM, MapMode( MAP_MM ) ).Width();
1027 : }
1028 0 : _pBox->SetColumnWidth( _nColId, nValue );
1029 0 : }
1030 0 : }
1031 : // -----------------------------------------------------------------------------
1032 : // check if SQL92 name checking is enabled
1033 0 : sal_Bool isSQL92CheckEnabled(const Reference<XConnection>& _xConnection)
1034 : {
1035 0 : return ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_ENABLESQL92CHECK );
1036 : }
1037 : // -----------------------------------------------------------------------------
1038 0 : sal_Bool isAppendTableAliasEnabled(const Reference<XConnection>& _xConnection)
1039 : {
1040 0 : return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_APPEND_TABLE_ALIAS );
1041 : }
1042 :
1043 : // -----------------------------------------------------------------------------
1044 0 : sal_Bool generateAsBeforeTableAlias(const Reference<XConnection>& _xConnection)
1045 : {
1046 0 : return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_AS_BEFORE_CORRELATION_NAME );
1047 : }
1048 :
1049 : // -----------------------------------------------------------------------------
1050 0 : void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
1051 : sal_Bool& _rAutoIncrementValueEnabled,
1052 : OUString& _rsAutoIncrementValue)
1053 : {
1054 0 : if ( _xDatasource.is() )
1055 : {
1056 : OSL_ENSURE(_xDatasource->getPropertySetInfo()->hasPropertyByName(PROPERTY_INFO),"NO datasource supplied!");
1057 0 : Sequence<PropertyValue> aInfo;
1058 0 : _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
1059 :
1060 : // search the right propertyvalue
1061 : const PropertyValue* pValue =::std::find_if(aInfo.getConstArray(),
1062 0 : aInfo.getConstArray() + aInfo.getLength(),
1063 0 : ::std::bind2nd(TPropertyValueEqualFunctor(),PROPERTY_AUTOINCREMENTCREATION));
1064 0 : if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1065 0 : pValue->Value >>= _rsAutoIncrementValue;
1066 : pValue =::std::find_if(aInfo.getConstArray(),
1067 0 : aInfo.getConstArray() + aInfo.getLength(),
1068 0 : ::std::bind2nd(TPropertyValueEqualFunctor(),OUString("IsAutoRetrievingEnabled") ));
1069 0 : if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
1070 0 : pValue->Value >>= _rAutoIncrementValueEnabled;
1071 : }
1072 0 : }
1073 : // -----------------------------------------------------------------------------
1074 0 : void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
1075 : sal_Bool& _rAutoIncrementValueEnabled,
1076 : OUString& _rsAutoIncrementValue)
1077 : {
1078 0 : Reference< XChild> xChild(_xConnection,UNO_QUERY);
1079 0 : if(xChild.is())
1080 : {
1081 0 : Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
1082 0 : fillAutoIncrementValue(xProp,_rAutoIncrementValueEnabled,_rsAutoIncrementValue);
1083 0 : }
1084 0 : }
1085 : // -----------------------------------------------------------------------------
1086 0 : OUString getStrippedDatabaseName(const Reference<XPropertySet>& _xDataSource,OUString& _rsDatabaseName)
1087 : {
1088 0 : if ( _rsDatabaseName.isEmpty() && _xDataSource.is() )
1089 : {
1090 : try
1091 : {
1092 0 : _xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
1093 : }
1094 0 : catch(const Exception& )
1095 : {
1096 : DBG_UNHANDLED_EXCEPTION();
1097 : }
1098 : }
1099 0 : OUString sName = _rsDatabaseName;
1100 0 : INetURLObject aURL(sName);
1101 0 : if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1102 0 : sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
1103 0 : return sName;
1104 : }
1105 : // -----------------------------------------------------------------------------
1106 0 : void AppendConfigToken( OUString& _rURL, sal_Bool _bQuestionMark )
1107 : {
1108 : // query part exists?
1109 0 : if ( _bQuestionMark )
1110 : // no, so start with '?'
1111 0 : _rURL += OUString("?");
1112 : else
1113 : // yes, so only append with '&'
1114 0 : _rURL += OUString("&");
1115 :
1116 : // set parameters
1117 0 : _rURL += OUString("Language=");
1118 0 : _rURL += utl::ConfigManager::getLocale();
1119 0 : _rURL += OUString("&System=");
1120 0 : _rURL += SvtHelpOptions().GetSystem();
1121 0 : }
1122 :
1123 : namespace
1124 : {
1125 : // -----------------------------------------------------------------------
1126 :
1127 0 : sal_Bool GetHelpAnchor_Impl( const OUString& _rURL, OUString& _rAnchor )
1128 : {
1129 0 : sal_Bool bRet = sal_False;
1130 0 : OUString sAnchor;
1131 :
1132 : try
1133 : {
1134 : ::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
1135 : Reference< ::com::sun::star::ucb::XCommandEnvironment >(),
1136 0 : comphelper::getProcessComponentContext() );
1137 0 : if ( ( aCnt.getPropertyValue("AnchorName") >>= sAnchor ) )
1138 : {
1139 :
1140 0 : if ( !sAnchor.isEmpty() )
1141 : {
1142 0 : _rAnchor = sAnchor;
1143 0 : bRet = sal_True;
1144 : }
1145 : }
1146 : else
1147 : {
1148 : SAL_WARN( "dbaccess.ui", "Property 'AnchorName' is missing" );
1149 0 : }
1150 : }
1151 0 : catch( Exception& )
1152 : {
1153 : }
1154 :
1155 0 : return bRet;
1156 : }
1157 : // .........................................................................
1158 : } // annonymous
1159 : // .........................................................................
1160 : // -----------------------------------------------------------------------------
1161 0 : ::com::sun::star::util::URL createHelpAgentURL(const OUString& _sModuleName, const OString& sHelpId)
1162 : {
1163 0 : ::com::sun::star::util::URL aURL;
1164 0 : aURL.Complete = OUString( "vnd.sun.star.help://" );
1165 0 : aURL.Complete += _sModuleName;
1166 0 : aURL.Complete += OUString( "/" );
1167 0 : aURL.Complete += OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8);
1168 :
1169 0 : OUString sAnchor;
1170 0 : OUString sTempURL = aURL.Complete;
1171 0 : AppendConfigToken( sTempURL, sal_True );
1172 0 : sal_Bool bHasAnchor = GetHelpAnchor_Impl( sTempURL, sAnchor );
1173 0 : AppendConfigToken(aURL.Complete,sal_True);
1174 0 : if ( bHasAnchor )
1175 : {
1176 0 : aURL.Complete += OUString("#");
1177 0 : aURL.Complete += sAnchor;
1178 : }
1179 0 : return aURL;
1180 : }
1181 : // -----------------------------------------------------------------------------
1182 0 : void setEvalDateFormatForFormatter(Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
1183 : {
1184 : OSL_ENSURE( _rxFormatter.is(),"setEvalDateFormatForFormatter: Formatter is NULL!");
1185 0 : if ( _rxFormatter.is() )
1186 : {
1187 0 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = _rxFormatter->getNumberFormatsSupplier();
1188 :
1189 0 : Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
1190 0 : SvNumberFormatsSupplierObj* pSupplierImpl = reinterpret_cast<SvNumberFormatsSupplierObj*>(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1191 : OSL_ENSURE(pSupplierImpl,"No Supplier!");
1192 :
1193 0 : if ( pSupplierImpl )
1194 : {
1195 0 : SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
1196 0 : pFormatter->SetEvalDateFormat(NF_EVALDATEFORMAT_FORMAT);
1197 0 : }
1198 : }
1199 0 : }
1200 : // -----------------------------------------------------------------------------
1201 0 : TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo)
1202 : {
1203 0 : TOTypeInfoSP pTypeInfo;
1204 : // first we search for a type which supports autoIncrement
1205 0 : OTypeInfoMap::const_iterator aIter = _rTypeInfo.begin();
1206 0 : OTypeInfoMap::const_iterator aEnd = _rTypeInfo.end();
1207 0 : for(;aIter != aEnd;++aIter)
1208 : {
1209 : // OJ: we don't want to set an autoincrement column to be key
1210 : // because we don't have the possiblity to know how to create
1211 : // such auto increment column later on
1212 : // so until we know how to do it, we create a column without autoincrement
1213 : // if ( !aIter->second->bAutoIncrement )
1214 : { // therefor we have searched
1215 0 : if ( aIter->second->nType == DataType::INTEGER )
1216 : {
1217 0 : pTypeInfo = aIter->second; // alternative
1218 0 : break;
1219 : }
1220 0 : else if ( !pTypeInfo.get() && aIter->second->nType == DataType::DOUBLE )
1221 0 : pTypeInfo = aIter->second; // alternative
1222 0 : else if ( !pTypeInfo.get() && aIter->second->nType == DataType::REAL )
1223 0 : pTypeInfo = aIter->second; // alternative
1224 : }
1225 : }
1226 0 : if ( !pTypeInfo.get() ) // just a fallback
1227 0 : pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo);
1228 :
1229 : OSL_ENSURE(pTypeInfo.get(),"checkColumns: cann't find a type which is useable as a key!");
1230 0 : return pTypeInfo;
1231 : }
1232 : // -----------------------------------------------------------------------------
1233 0 : TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo)
1234 : {
1235 0 : OTypeInfoMap::const_iterator aIter = _rTypeInfo.find(_nDataType);
1236 0 : if(aIter != _rTypeInfo.end())
1237 0 : return aIter->second;
1238 : // fall back if the type is unknown
1239 0 : TOTypeInfoSP pTypeInfo;
1240 0 : switch(_nDataType)
1241 : {
1242 : case DataType::TINYINT:
1243 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::SMALLINT,_rTypeInfo) ) )
1244 0 : break;
1245 : // run through
1246 : case DataType::SMALLINT:
1247 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::INTEGER,_rTypeInfo) ) )
1248 0 : break;
1249 : // run through
1250 : case DataType::INTEGER:
1251 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::FLOAT,_rTypeInfo) ) )
1252 0 : break;
1253 : // run through
1254 : case DataType::FLOAT:
1255 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::REAL,_rTypeInfo) ) )
1256 0 : break;
1257 : // run through
1258 : case DataType::DATE:
1259 : case DataType::TIME:
1260 0 : if( DataType::DATE == _nDataType || DataType::TIME == _nDataType )
1261 : {
1262 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::TIMESTAMP,_rTypeInfo) ) )
1263 0 : break;
1264 : }
1265 : // run through
1266 : case DataType::TIMESTAMP:
1267 : case DataType::REAL:
1268 : case DataType::BIGINT:
1269 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
1270 0 : break;
1271 : // run through
1272 : case DataType::DOUBLE:
1273 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
1274 0 : break;
1275 : // run through
1276 : case DataType::NUMERIC:
1277 0 : pTypeInfo = queryTypeInfoByType(DataType::DECIMAL,_rTypeInfo);
1278 0 : break;
1279 : case DataType::DECIMAL:
1280 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
1281 0 : break;
1282 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
1283 0 : break;
1284 0 : break;
1285 : case DataType::VARCHAR:
1286 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::LONGVARCHAR,_rTypeInfo) ) )
1287 0 : break;
1288 0 : break;
1289 : case DataType::LONGVARCHAR:
1290 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::CLOB,_rTypeInfo) ) )
1291 0 : break;
1292 0 : break;
1293 : default:
1294 : ;
1295 : }
1296 0 : if ( !pTypeInfo )
1297 : {
1298 0 : OUString sCreate("x"),sTypeName;
1299 0 : sal_Bool bForce = sal_True;
1300 0 : pTypeInfo = ::dbaui::getTypeInfoFromType(_rTypeInfo,DataType::VARCHAR,sTypeName,sCreate,50,0,sal_False,bForce);
1301 : }
1302 : OSL_ENSURE(pTypeInfo,"Wrong DataType supplied!");
1303 0 : return pTypeInfo;
1304 : }
1305 : // -----------------------------------------------------------------------------
1306 0 : sal_Int32 askForUserAction(Window* _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const OUString& _sName)
1307 : {
1308 0 : SolarMutexGuard aGuard;
1309 0 : String aMsg = String(ModuleRes(_nText));
1310 0 : aMsg.SearchAndReplace(OUString("%1"),String(_sName));
1311 0 : OSQLMessageBox aAsk(_pParent,String(ModuleRes(_nTitle )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
1312 0 : if ( _bAll )
1313 : {
1314 0 : aAsk.AddButton(String(ModuleRes(STR_BUTTON_TEXT_ALL)), RET_ALL, 0);
1315 0 : aAsk.GetPushButton(RET_ALL)->SetHelpId(HID_CONFIRM_DROP_BUTTON_ALL);
1316 : }
1317 0 : return aAsk.Execute();
1318 : }
1319 :
1320 : // -----------------------------------------------------------------------------
1321 : namespace
1322 : {
1323 0 : static OUString lcl_createSDBCLevelStatement( const OUString& _rStatement, const Reference< XConnection >& _rxConnection )
1324 : {
1325 0 : OUString sSDBCLevelStatement( _rStatement );
1326 : try
1327 : {
1328 0 : Reference< XMultiServiceFactory > xAnalyzerFactory( _rxConnection, UNO_QUERY_THROW );
1329 0 : Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xAnalyzerFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
1330 0 : xAnalyzer->setQuery( _rStatement );
1331 0 : sSDBCLevelStatement = xAnalyzer->getQueryWithSubstitution();
1332 : }
1333 0 : catch( const Exception& )
1334 : {
1335 : DBG_UNHANDLED_EXCEPTION();
1336 : }
1337 0 : return sSDBCLevelStatement;
1338 : }
1339 : }
1340 :
1341 : // -----------------------------------------------------------------------------
1342 0 : Reference< XPropertySet > createView( const OUString& _rName, const Reference< XConnection >& _rxConnection,
1343 : const OUString& _rCommand )
1344 : {
1345 0 : Reference<XViewsSupplier> xSup(_rxConnection,UNO_QUERY);
1346 0 : Reference< XNameAccess > xViews;
1347 0 : if(xSup.is())
1348 0 : xViews = xSup->getViews();
1349 0 : Reference<XDataDescriptorFactory> xFact(xViews,UNO_QUERY);
1350 : OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
1351 0 : if(!xFact.is())
1352 0 : return NULL;
1353 :
1354 0 : Reference<XPropertySet> xView = xFact->createDataDescriptor();
1355 0 : if ( !xView.is() )
1356 0 : return NULL;
1357 :
1358 0 : OUString sCatalog,sSchema,sTable;
1359 0 : ::dbtools::qualifiedNameComponents(_rxConnection->getMetaData(),
1360 : _rName,
1361 : sCatalog,
1362 : sSchema,
1363 : sTable,
1364 0 : ::dbtools::eInDataManipulation);
1365 :
1366 0 : xView->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
1367 0 : xView->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
1368 0 : xView->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
1369 :
1370 0 : xView->setPropertyValue( PROPERTY_COMMAND, makeAny( _rCommand ) );
1371 :
1372 0 : Reference<XAppend> xAppend(xViews,UNO_QUERY);
1373 0 : if(xAppend.is())
1374 0 : xAppend->appendByDescriptor(xView);
1375 :
1376 0 : xView = NULL;
1377 : // we need to reget the view because after appending it it is no longer valid
1378 : // but this time it isn't a view object it is a table object with type "VIEW"
1379 0 : Reference<XTablesSupplier> xTabSup(_rxConnection,UNO_QUERY);
1380 0 : Reference< XNameAccess > xTables;
1381 0 : if ( xTabSup.is() )
1382 : {
1383 0 : xTables = xTabSup->getTables();
1384 0 : if ( xTables.is() && xTables->hasByName( _rName ) )
1385 0 : xTables->getByName( _rName ) >>= xView;
1386 : }
1387 :
1388 0 : return xView;
1389 : }
1390 :
1391 : // -----------------------------------------------------------------------------
1392 0 : Reference<XPropertySet> createView( const OUString& _rName, const Reference< XConnection >& _rxConnection
1393 : ,const Reference<XPropertySet>& _rxSourceObject)
1394 : {
1395 0 : OUString sCommand;
1396 0 : Reference< XPropertySetInfo > xPSI( _rxSourceObject->getPropertySetInfo(), UNO_SET_THROW );
1397 0 : if ( xPSI->hasPropertyByName( PROPERTY_COMMAND ) )
1398 : {
1399 0 : _rxSourceObject->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand;
1400 :
1401 0 : sal_Bool bEscapeProcessing( sal_False );
1402 0 : OSL_VERIFY( _rxSourceObject->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
1403 0 : if ( bEscapeProcessing )
1404 0 : sCommand = lcl_createSDBCLevelStatement( sCommand, _rxConnection );
1405 : }
1406 : else
1407 : {
1408 0 : sCommand = OUString( "SELECT * FROM " );
1409 0 : sCommand += composeTableNameForSelect( _rxConnection, _rxSourceObject );
1410 : }
1411 0 : return createView( _rName, _rxConnection, sCommand );
1412 : }
1413 :
1414 : // -----------------------------------------------------------------------------
1415 0 : sal_Bool insertHierachyElement( Window* _pParent, const Reference< XComponentContext >& _rxContext,
1416 : const Reference<XHierarchicalNameContainer>& _xNames,
1417 : const String& _sParentFolder,
1418 : sal_Bool _bForm,
1419 : sal_Bool _bCollection,
1420 : const Reference<XContent>& _xContent,
1421 : sal_Bool _bMove)
1422 : {
1423 : OSL_ENSURE( _xNames.is(), "insertHierachyElement: illegal name container!" );
1424 0 : if ( !_xNames.is() )
1425 0 : return sal_False;
1426 :
1427 0 : Reference<XNameAccess> xNameAccess( _xNames, UNO_QUERY );
1428 0 : OUString sName = _sParentFolder;
1429 0 : if ( _xNames->hasByHierarchicalName(sName) )
1430 : {
1431 0 : Reference<XChild> xChild(_xNames->getByHierarchicalName(sName),UNO_QUERY);
1432 0 : xNameAccess.set(xChild,UNO_QUERY);
1433 0 : if ( !xNameAccess.is() && xChild.is() )
1434 0 : xNameAccess.set(xChild->getParent(),UNO_QUERY);
1435 : }
1436 :
1437 : OSL_ENSURE( xNameAccess.is(), "insertHierachyElement: could not find the proper name container!" );
1438 0 : if ( !xNameAccess.is() )
1439 0 : return sal_False;
1440 :
1441 0 : OUString sNewName;
1442 0 : Reference<XPropertySet> xProp(_xContent,UNO_QUERY);
1443 0 : if ( xProp.is() )
1444 0 : xProp->getPropertyValue(PROPERTY_NAME) >>= sNewName;
1445 :
1446 0 : if ( !_bMove || sNewName.isEmpty() )
1447 : {
1448 0 : String sTargetName,sLabel;
1449 0 : if ( sNewName.isEmpty() || xNameAccess->hasByName(sNewName) )
1450 : {
1451 0 : if ( !sNewName.isEmpty() )
1452 0 : sTargetName = sNewName;
1453 : else
1454 0 : sTargetName = String(ModuleRes( _bCollection ? STR_NEW_FOLDER : ((_bForm) ? RID_STR_FORM : RID_STR_REPORT)));
1455 0 : sLabel = String(ModuleRes( _bCollection ? STR_FOLDER_LABEL : ((_bForm) ? STR_FRM_LABEL : STR_RPT_LABEL)));
1456 0 : sTargetName = ::dbtools::createUniqueName(xNameAccess,sTargetName);
1457 :
1458 :
1459 : // here we have everything needed to create a new query object ...
1460 0 : HierarchicalNameCheck aNameChecker( _xNames.get(), sName );
1461 : // ... ehm, except a new name
1462 : OSaveAsDlg aAskForName( _pParent,
1463 : _rxContext,
1464 : sTargetName,
1465 : sLabel,
1466 : aNameChecker,
1467 0 : SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
1468 0 : if ( RET_OK != aAskForName.Execute() )
1469 : // cancelled by the user
1470 0 : return sal_False;
1471 :
1472 0 : sNewName = aAskForName.getName();
1473 0 : }
1474 : }
1475 0 : else if ( xNameAccess->hasByName(sNewName) )
1476 : {
1477 0 : String sError(ModuleRes(STR_NAME_ALREADY_EXISTS));
1478 0 : sError.SearchAndReplaceAscii("#",sNewName);
1479 0 : throw SQLException(sError,NULL,OUString("S1000") ,0,Any());
1480 : }
1481 :
1482 : try
1483 : {
1484 0 : Reference<XMultiServiceFactory> xORB( xNameAccess, UNO_QUERY_THROW );
1485 0 : Sequence< Any > aArguments(3);
1486 0 : PropertyValue aValue;
1487 : // set as folder
1488 0 : aValue.Name = OUString("Name");
1489 0 : aValue.Value <<= sNewName;
1490 0 : aArguments[0] <<= aValue;
1491 : //parent
1492 0 : aValue.Name = OUString("Parent");
1493 0 : aValue.Value <<= xNameAccess;
1494 0 : aArguments[1] <<= aValue;
1495 :
1496 0 : aValue.Name = PROPERTY_EMBEDDEDOBJECT;
1497 0 : aValue.Value <<= _xContent;
1498 0 : aArguments[2] <<= aValue;
1499 :
1500 0 : OUString sServiceName(_bCollection ? ((_bForm) ? OUString(SERVICE_NAME_FORM_COLLECTION) : OUString(SERVICE_NAME_REPORT_COLLECTION)) : OUString(SERVICE_SDB_DOCUMENTDEFINITION));
1501 :
1502 0 : Reference<XContent > xNew( xORB->createInstanceWithArguments( sServiceName, aArguments ), UNO_QUERY_THROW );
1503 0 : Reference< XNameContainer > xNameContainer( xNameAccess, UNO_QUERY_THROW );
1504 0 : xNameContainer->insertByName( sNewName, makeAny( xNew ) );
1505 : }
1506 0 : catch( const IllegalArgumentException& e )
1507 : {
1508 0 : ::dbtools::throwGenericSQLException( e.Message, e.Context );
1509 : }
1510 0 : catch( const Exception& )
1511 : {
1512 : DBG_UNHANDLED_EXCEPTION();
1513 0 : return sal_False;
1514 : }
1515 :
1516 0 : return sal_True;
1517 : }
1518 : // -----------------------------------------------------------------------------
1519 0 : Reference< XNumberFormatter > getNumberFormatter(const Reference< XConnection >& _rxConnection, const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext )
1520 : {
1521 : // ---------------------------------------------------------------
1522 : // create a formatter working with the connections format supplier
1523 0 : Reference< XNumberFormatter > xFormatter;
1524 :
1525 : try
1526 : {
1527 0 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(_rxConnection, sal_True, _rxContext));
1528 :
1529 0 : if ( xSupplier.is() )
1530 : {
1531 : // create a new formatter
1532 0 : xFormatter = Reference< util::XNumberFormatter > (
1533 0 : util::NumberFormatter::create( _rxContext ), UNO_QUERY_THROW);
1534 0 : xFormatter->attachNumberFormatsSupplier(xSupplier);
1535 0 : }
1536 : }
1537 0 : catch(const Exception&)
1538 : {
1539 : DBG_UNHANDLED_EXCEPTION();
1540 : }
1541 0 : return xFormatter;
1542 : }
1543 :
1544 :
1545 : // .........................................................................
1546 12 : } // dbaui
1547 : // .........................................................................
1548 :
1549 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|