1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "AppController.hxx"
#include "AppDetailView.hxx"
#include "AppView.hxx"
#include "dbaccess_slotid.hrc"
#include "dbu_app.hrc"
#include "dbustrings.hrc"
#include "defaultobjectnamecheck.hxx"
#include "dlgsave.hxx"
#include "UITools.hxx"
#include "subcomponentmanager.hxx"
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/container/XContainer.hpp>
#include <com/sun/star/container/XHierarchicalNameContainer.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/lang/XEventListener.hpp>
#include <com/sun/star/sdb/CommandType.hpp>
#include <com/sun/star/sdb/SQLContext.hpp>
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
#include <com/sun/star/sdbcx/XRename.hpp>
#include <com/sun/star/sdb/ErrorCondition.hpp>
#include <com/sun/star/sdb/application/DatabaseObject.hpp>
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
#include <com/sun/star/ucb/Command.hpp>
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#include <com/sun/star/ucb/XCommandProcessor.hpp>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <com/sun/star/uno/XNamingService.hpp>
#include <com/sun/star/util/XRefreshable.hpp>
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/processfactory.hxx>
#include <connectivity/dbexception.hxx>
#include <connectivity/dbtools.hxx>
#include <connectivity/sqlerror.hxx>
#include <sfx2/mailmodelapi.hxx>
#include <svx/dbaexchange.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <tools/diagnose_ex.h>
#include <osl/diagnose.h>
#include <unotools/bootstrap.hxx>
#include <vcl/layout.hxx>
#include <vcl/mnemonic.hxx>
#include <vcl/svapp.hxx>
#include <vcl/waitobj.hxx>
#include <osl/mutex.hxx>
namespace dbaui
{
using namespace ::dbtools;
using namespace ::connectivity;
using namespace ::svx;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::ucb;
using ::com::sun::star::ui::XContextMenuInterceptor;
namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition;
void OApplicationController::convertToView(const OUString& _sName)
{
try
{
SharedConnection xConnection( getConnection() );
Reference< XQueriesSupplier > xSup( xConnection, UNO_QUERY_THROW );
Reference< XNameAccess > xQueries( xSup->getQueries(), UNO_QUERY_THROW );
Reference< XPropertySet > xSourceObject( xQueries->getByName( _sName ), UNO_QUERY_THROW );
Reference< XTablesSupplier > xTablesSup( xConnection, UNO_QUERY_THROW );
Reference< XNameAccess > xTables( xTablesSup->getTables(), UNO_QUERY_THROW );
Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
OUString aName = OUString(ModuleRes(STR_TBL_TITLE));
aName = aName.getToken(0,' ');
OUString aDefaultName = ::dbaui::createDefaultName(xMeta,xTables,aName);
DynamicTableOrQueryNameCheck aNameChecker( xConnection, CommandType::TABLE );
ScopedVclPtrInstance< OSaveAsDlg > aDlg( getView(), CommandType::TABLE, getORB(), xConnection, aDefaultName, aNameChecker );
if ( aDlg->Execute() == RET_OK )
{
OUString sName = aDlg->getName();
OUString sCatalog = aDlg->getCatalog();
OUString sSchema = aDlg->getSchema();
OUString sNewName(
::dbtools::composeTableName( xMeta, sCatalog, sSchema, sName, false, ::dbtools::EComposeRule::InTableDefinitions ) );
Reference<XPropertySet> xView = ::dbaui::createView(sNewName,xConnection,xSourceObject);
if ( !xView.is() )
throw SQLException(ModuleRes(STR_NO_TABLE_FORMAT_INSIDE),*this,OUString( "S1000" ) ,0,Any());
getContainer()->elementAdded(E_TABLE,sNewName,makeAny(xView));
}
}
catch(const SQLException& )
{
showError( SQLExceptionInfo( ::cppu::getCaughtException() ) );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
void OApplicationController::pasteFormat(SotClipboardFormatId _nFormatId)
{
if ( _nFormatId != SotClipboardFormatId::NONE )
{
try
{
const TransferableDataHelper& rClipboard = getViewClipboard();
ElementType eType = getContainer()->getElementType();
if ( eType == E_TABLE )
{
m_aTableCopyHelper.pasteTable( _nFormatId, rClipboard, getDatabaseName(), ensureConnection() );
}
else
paste( eType, ODataAccessObjectTransferable::extractObjectDescriptor( rClipboard ) );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
}
void OApplicationController::openDialog( const OUString& _sServiceName )
{
try
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( getMutex() );
WaitObject aWO(getView());
Sequence< Any > aArgs(3);
sal_Int32 nArgPos = 0;
Reference< css::awt::XWindow> xWindow = getTopMostContainerWindow();
if ( !xWindow.is() )
{
OSL_ENSURE( getContainer(), "OApplicationController::Construct: have no view!" );
if ( getContainer() )
xWindow = VCLUnoHelper::GetInterface(getView()->Window::GetParent());
}
// the parent window
aArgs[nArgPos++] <<= PropertyValue( OUString("ParentWindow"),
0,
makeAny(xWindow),
PropertyState_DIRECT_VALUE);
// the initial selection
OUString sInitialSelection;
if ( getContainer() )
sInitialSelection = getDatabaseName();
if ( !sInitialSelection.isEmpty() )
{
aArgs[ nArgPos++ ] <<= PropertyValue(
OUString( "InitialSelection" ), 0,
makeAny( sInitialSelection ), PropertyState_DIRECT_VALUE );
}
SharedConnection xConnection( getConnection() );
if ( xConnection.is() )
{
aArgs[ nArgPos++ ] <<= PropertyValue(
PROPERTY_ACTIVE_CONNECTION, 0,
makeAny( xConnection ), PropertyState_DIRECT_VALUE );
}
aArgs.realloc( nArgPos );
// create the dialog
Reference< XExecutableDialog > xAdminDialog;
xAdminDialog.set(
getORB()->getServiceManager()->createInstanceWithArgumentsAndContext(_sServiceName, aArgs, getORB()),
UNO_QUERY);
// execute it
if (xAdminDialog.is())
xAdminDialog->execute();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
void OApplicationController::refreshTables()
{
if ( getContainer() && getContainer()->getDetailView() )
{
WaitObject aWO(getView());
OSL_ENSURE(getContainer()->getElementType() == E_TABLE,"Only allowed when the tables container is selected!");
try
{
Reference<XRefreshable> xRefresh(getElements(E_TABLE),UNO_QUERY);
if ( xRefresh.is() )
xRefresh->refresh();
}
catch(const Exception&)
{
OSL_FAIL("Could not refresh tables!");
}
getContainer()->getDetailView()->clearPages(false);
getContainer()->getDetailView()->createTablesPage( ensureConnection() );
}
}
void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& evt )
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( getMutex() );
if ( evt.PropertyName == PROPERTY_USER )
{
m_bNeedToReconnect = true;
InvalidateFeature(SID_DB_APP_STATUS_USERNAME);
}
else if ( evt.PropertyName == PROPERTY_URL )
{
m_bNeedToReconnect = true;
InvalidateFeature(SID_DB_APP_STATUS_DBNAME);
InvalidateFeature(SID_DB_APP_STATUS_TYPE);
InvalidateFeature(SID_DB_APP_STATUS_HOSTNAME);
}
else if ( PROPERTY_NAME == evt.PropertyName )
{
const ElementType eType = getContainer()->getElementType();
if ( eType == E_FORM || eType == E_REPORT )
{
OUString sOldName,sNewName;
evt.OldValue >>= sOldName;
evt.NewValue >>= sNewName;
// if the old name is empty, then this is a newly inserted content. We're notified of it via the
// elementInserted method, so there's no need to handle it here.
if ( !sOldName.isEmpty() )
{
Reference<XChild> xChild(evt.Source,UNO_QUERY);
if ( xChild.is() )
{
Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
if ( xContent.is() )
sOldName = xContent->getIdentifier()->getContentIdentifier() + "/" + sOldName;
}
getContainer()->elementReplaced( eType , sOldName, sNewName );
}
}
}
EventObject aEvt;
aEvt.Source = m_xModel;
modified(aEvt);
}
Reference< XDataSource > SAL_CALL OApplicationController::getDataSource()
{
::osl::MutexGuard aGuard( getMutex() );
Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
return xDataSource;
}
Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow()
{
::osl::MutexGuard aGuard( getMutex() );
Reference< XFrame > xFrame( getFrame(), UNO_QUERY_THROW );
Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
return xWindow;
}
Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents()
{
::osl::MutexGuard aGuard( getMutex() );
return m_pSubComponentManager->getSubComponents();
}
Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection()
{
::osl::MutexGuard aGuard( getMutex() );
return m_xDataSourceConnection.getTyped();
}
sal_Bool SAL_CALL OApplicationController::isConnected( )
{
::osl::MutexGuard aGuard( getMutex() );
return m_xDataSourceConnection.is();
}
void SAL_CALL OApplicationController::connect( )
{
SQLExceptionInfo aError;
SharedConnection xConnection = ensureConnection( &aError );
if ( !xConnection.is() )
{
if ( aError.isValid() )
aError.doThrow();
// no particular error, but nonetheless could not connect -> throw a generic exception
OUString sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
::dbtools::throwGenericSQLException( sConnectingContext.replaceFirst( "$name$", getStrippedDatabaseName() ), *this );
}
}
beans::Pair< ::sal_Int32, OUString > SAL_CALL OApplicationController::identifySubComponent( const Reference< XComponent >& i_rSubComponent )
{
::osl::MutexGuard aGuard( getMutex() );
sal_Int32 nType = -1;
OUString sName;
if ( !m_pSubComponentManager->lookupSubComponent( i_rSubComponent, sName, nType ) )
throw IllegalArgumentException( OUString(), *this, 1 );
if ( nType == SID_DB_APP_DSRELDESIGN )
// this is somewhat hacky ... we're expected to return a DatabaseObject value. However, there is no such
// value for the relation design. /me thinks we should change the API definition here ...
nType = -1;
return beans::Pair< ::sal_Int32, OUString >( nType, sName );
}
sal_Bool SAL_CALL OApplicationController::closeSubComponents( )
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( getMutex() );
return m_pSubComponentManager->closeSubComponents();
}
namespace
{
ElementType lcl_objectType2ElementType( const sal_Int32 _nObjectType )
{
ElementType eType( E_NONE );
switch ( _nObjectType )
{
case DatabaseObject::TABLE: eType = E_TABLE; break;
case DatabaseObject::QUERY: eType = E_QUERY; break;
case DatabaseObject::FORM: eType = E_FORM; break;
case DatabaseObject::REPORT: eType = E_REPORT; break;
default:
OSL_FAIL( "lcl_objectType2ElementType: unsupported object type!" );
// this should have been caught earlier
}
return eType;
}
}
void OApplicationController::impl_validateObjectTypeAndName_throw( const sal_Int32 _nObjectType, const ::boost::optional< OUString >& i_rObjectName )
{
// ensure we're connected
if ( !isConnected() )
{
SQLError aError( getORB() );
aError.raiseException( ErrorCondition::DB_NOT_CONNECTED, *this );
}
// ensure a proper object type
if ( ( _nObjectType != DatabaseObject::TABLE )
&& ( _nObjectType != DatabaseObject::QUERY )
&& ( _nObjectType != DatabaseObject::FORM )
&& ( _nObjectType != DatabaseObject::REPORT )
)
throw IllegalArgumentException( OUString(), *this, 1 );
if ( !i_rObjectName )
return;
// ensure an existing object
Reference< XNameAccess > xContainer( getElements( lcl_objectType2ElementType( _nObjectType ) ) );
if ( !xContainer.is() )
// all possible reasons for this (e.g. not being connected currently) should
// have been handled before
throw RuntimeException( OUString(), *this );
bool bExistentObject = false;
switch ( _nObjectType )
{
case DatabaseObject::TABLE:
case DatabaseObject::QUERY:
bExistentObject = xContainer->hasByName( *i_rObjectName );
break;
case DatabaseObject::FORM:
case DatabaseObject::REPORT:
{
Reference< XHierarchicalNameAccess > xHierarchy( xContainer, UNO_QUERY_THROW );
bExistentObject = xHierarchy->hasByHierarchicalName( *i_rObjectName );
}
break;
}
if ( !bExistentObject )
throw NoSuchElementException( *i_rObjectName, *this );
}
Reference< XComponent > SAL_CALL OApplicationController::loadComponent( ::sal_Int32 ObjectType,
const OUString& ObjectName, sal_Bool ForEditing )
{
return loadComponentWithArguments( ObjectType, ObjectName, ForEditing, Sequence< PropertyValue >() );
}
Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArguments( ::sal_Int32 ObjectType,
const OUString& ObjectName, sal_Bool ForEditing, const Sequence< PropertyValue >& Arguments )
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( getMutex() );
impl_validateObjectTypeAndName_throw( ObjectType, ObjectName );
Reference< XComponent > xComponent( openElementWithArguments(
ObjectName,
lcl_objectType2ElementType( ObjectType ),
ForEditing ? E_OPEN_DESIGN : E_OPEN_NORMAL,
ForEditing ? SID_DB_APP_EDIT : SID_DB_APP_OPEN,
::comphelper::NamedValueCollection( Arguments )
) );
return xComponent;
}
Reference< XComponent > SAL_CALL OApplicationController::createComponent( ::sal_Int32 i_nObjectType, Reference< XComponent >& o_DocumentDefinition )
{
return createComponentWithArguments( i_nObjectType, Sequence< PropertyValue >(), o_DocumentDefinition );
}
Reference< XComponent > SAL_CALL OApplicationController::createComponentWithArguments( ::sal_Int32 i_nObjectType, const Sequence< PropertyValue >& i_rArguments, Reference< XComponent >& o_DocumentDefinition )
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( getMutex() );
impl_validateObjectTypeAndName_throw( i_nObjectType, ::boost::optional< OUString >() );
Reference< XComponent > xComponent( newElement(
lcl_objectType2ElementType( i_nObjectType ),
::comphelper::NamedValueCollection( i_rArguments ),
o_DocumentDefinition
) );
return xComponent;
}
void SAL_CALL OApplicationController::registerContextMenuInterceptor( const Reference< XContextMenuInterceptor >& Interceptor )
{
if ( Interceptor.is() )
m_aContextMenuInterceptors.addInterface( Interceptor );
}
void SAL_CALL OApplicationController::releaseContextMenuInterceptor( const Reference< XContextMenuInterceptor >& Interceptor )
{
m_aContextMenuInterceptors.removeInterface( Interceptor );
}
void OApplicationController::previewChanged( sal_Int32 _nMode )
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( getMutex() );
if ( m_xDataSource.is() && !isDataSourceReadOnly() )
{
try
{
::comphelper::NamedValueCollection aLayoutInfo( m_xDataSource->getPropertyValue( PROPERTY_LAYOUTINFORMATION ) );
sal_Int32 nOldMode = aLayoutInfo.getOrDefault( "Preview", _nMode );
if ( nOldMode != _nMode )
{
aLayoutInfo.put( "Preview", _nMode );
m_xDataSource->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aLayoutInfo.getPropertyValues() ) );
}
}
catch ( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
InvalidateFeature(SID_DB_APP_DISABLE_PREVIEW);
InvalidateFeature(SID_DB_APP_VIEW_DOCINFO_PREVIEW);
InvalidateFeature(SID_DB_APP_VIEW_DOC_PREVIEW);
}
void OApplicationController::askToReconnect()
{
if ( m_bNeedToReconnect )
{
m_bNeedToReconnect = false;
bool bClear = true;
if ( !m_pSubComponentManager->empty() )
{
ScopedVclPtrInstance< MessageDialog > aQry(getView(), ModuleRes(STR_QUERY_CLOSEDOCUMENTS), VclMessageType::Question, VclButtonsType::YesNo);
switch (aQry->Execute())
{
case RET_YES:
closeSubComponents();
break;
default:
bClear = false;
break;
}
}
if ( bClear )
{
ElementType eType = getContainer()->getElementType();
disconnect();
getContainer()->getDetailView()->clearPages(false);
getContainer()->selectContainer(E_NONE); // invalidate the old selection
m_eCurrentType = E_NONE;
getContainer()->selectContainer(eType); // reselect the current one again
}
}
}
OUString OApplicationController::getDatabaseName() const
{
OUString sDatabaseName;
try
{
if ( m_xDataSource.is() )
{
OSL_VERIFY( m_xDataSource->getPropertyValue( PROPERTY_NAME ) >>= sDatabaseName );
}
}
catch ( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
return sDatabaseName;
}
OUString OApplicationController::getStrippedDatabaseName() const
{
OUString sDatabaseName;
return ::dbaui::getStrippedDatabaseName( m_xDataSource, sDatabaseName );
}
void OApplicationController::onDocumentOpened( const OUString& _rName, const sal_Int32 _nType,
const ElementOpenMode _eMode, const Reference< XComponent >& _xDocument, const Reference< XComponent >& _rxDefinition )
{
if ( !_xDocument.is() )
return;
try
{
OSL_ENSURE( _xDocument.is(), "OApplicationController::onDocumentOpened: is there any *valid* scenario where this fails?" );
m_pSubComponentManager->onSubComponentOpened( _rName, _nType, _eMode, _xDocument.is() ? _xDocument : _rxDefinition );
if ( _rxDefinition.is() )
{
Reference< XPropertySet > xProp( _rxDefinition, UNO_QUERY_THROW );
Reference< XPropertySetInfo > xPSI( xProp->getPropertySetInfo(), UNO_SET_THROW );
xProp->addPropertyChangeListener( PROPERTY_NAME, static_cast< XPropertyChangeListener* >( this ) );
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
bool OApplicationController::insertHierachyElement(ElementType _eType, const OUString& _sParentFolder, bool _bCollection, const Reference<XContent>& _xContent, bool _bMove)
{
Reference<XHierarchicalNameContainer> xNames(getElements(_eType), UNO_QUERY);
return dbaui::insertHierachyElement(getView()
,getORB()
,xNames
,_sParentFolder
,_eType == E_FORM
,_bCollection
,_xContent
,_bMove);
}
bool OApplicationController::isRenameDeleteAllowed(ElementType _eType, bool _bDelete) const
{
ElementType eType = getContainer()->getElementType();
bool bEnabled = !isDataSourceReadOnly() && eType == _eType;
if ( bEnabled )
{
if ( E_TABLE == eType )
bEnabled = !isConnectionReadOnly() && getContainer()->isALeafSelected();
bool bCompareRes = false;
if ( _bDelete )
bCompareRes = getContainer()->getSelectionCount() > 0;
else
{
bCompareRes = getContainer()->getSelectionCount() == 1;
if ( bEnabled && bCompareRes && E_TABLE == eType )
{
::std::vector< OUString> aList;
getSelectionElementNames(aList);
try
{
Reference< XNameAccess > xContainer = const_cast<OApplicationController*>(this)->getElements(eType);
bEnabled = (xContainer.is() && xContainer->hasByName(*aList.begin()));
if ( bEnabled )
bEnabled = Reference<XRename>(xContainer->getByName(*aList.begin()),UNO_QUERY).is();
}
catch(Exception&)
{
bEnabled = false;
}
}
}
bEnabled = bEnabled && bCompareRes;
}
return bEnabled;
}
void OApplicationController::onLoadedMenu(const Reference< css::frame::XLayoutManager >& _xLayoutManager)
{
if ( _xLayoutManager.is() )
{
static const char s_sStatusbar[] = "private:resource/statusbar/statusbar";
_xLayoutManager->createElement( s_sStatusbar );
_xLayoutManager->requestElement( s_sStatusbar );
if ( getContainer() )
{
// we need to share the "mnemonic space":
MnemonicGenerator aMnemonicGenerator;
// - the menu already has mnemonics
SystemWindow* pSystemWindow = getContainer()->GetSystemWindow();
MenuBar* pMenu = pSystemWindow ? pSystemWindow->GetMenuBar() : nullptr;
if ( pMenu )
{
sal_uInt16 nMenuItems = pMenu->GetItemCount();
for ( sal_uInt16 i = 0; i < nMenuItems; ++i )
aMnemonicGenerator.RegisterMnemonic( pMenu->GetItemText( pMenu->GetItemId( i ) ) );
}
// - the icons should use automatic ones
getContainer()->createIconAutoMnemonics( aMnemonicGenerator );
// - as well as the entries in the task pane
getContainer()->setTaskExternalMnemonics( aMnemonicGenerator );
}
Execute( SID_DB_APP_VIEW_FORMS, Sequence< PropertyValue >() );
InvalidateAll();
}
}
void OApplicationController::doAction(sal_uInt16 _nId, const ElementOpenMode _eOpenMode)
{
::std::vector< OUString> aList;
getSelectionElementNames(aList);
ElementType eType = getContainer()->getElementType();
::comphelper::NamedValueCollection aArguments;
ElementOpenMode eOpenMode = _eOpenMode;
if ( eType == E_REPORT && E_OPEN_FOR_MAIL == _eOpenMode )
{
aArguments.put("Hidden",true);
eOpenMode = E_OPEN_NORMAL;
}
::std::vector< ::std::pair< OUString ,Reference< XModel > > > aComponents;
::std::vector< OUString>::const_iterator aEnd = aList.end();
for (::std::vector< OUString>::const_iterator aIter = aList.begin(); aIter != aEnd; ++aIter)
{
if ( SID_DB_APP_CONVERTTOVIEW == _nId )
convertToView(*aIter);
else
{
Reference< XModel > xModel( openElementWithArguments( *aIter, eType, eOpenMode, _nId,aArguments ), UNO_QUERY );
aComponents.push_back( ::std::pair< OUString, Reference< XModel > >( *aIter, xModel ) );
}
}
// special handling for mail, if more than one document is selected attach them all
if ( _eOpenMode == E_OPEN_FOR_MAIL )
{
::std::vector< ::std::pair< OUString ,Reference< XModel > > >::const_iterator componentIter = aComponents.begin();
::std::vector< ::std::pair< OUString ,Reference< XModel > > >::const_iterator componentEnd = aComponents.end();
OUString aDocTypeString;
SfxMailModel aSendMail;
SfxMailModel::SendMailResult eResult = SfxMailModel::SEND_MAIL_OK;
for (; componentIter != componentEnd && SfxMailModel::SEND_MAIL_OK == eResult; ++componentIter)
{
try
{
Reference< XModel > xModel(componentIter->second,UNO_QUERY);
// Send document as e-Mail using stored/default type
eResult = aSendMail.AttachDocument(aDocTypeString,xModel,componentIter->first);
::comphelper::disposeComponent(xModel);
}
catch(const Exception&)
{
DBG_UNHANDLED_EXCEPTION();
}
}
if ( !aSendMail.IsEmpty() )
aSendMail.Send( getFrame() );
}
}
ElementType OApplicationController::getElementType(const Reference< XContainer >& _xContainer)
{
ElementType eRet = E_NONE;
Reference<XServiceInfo> xServiceInfo(_xContainer,UNO_QUERY);
if ( xServiceInfo.is() )
{
if ( xServiceInfo->supportsService(SERVICE_SDBCX_TABLES) )
eRet = E_TABLE;
else if ( xServiceInfo->supportsService(SERVICE_NAME_FORM_COLLECTION) )
eRet = E_FORM;
else if ( xServiceInfo->supportsService(SERVICE_NAME_REPORT_COLLECTION) )
eRet = E_REPORT;
else
eRet = E_QUERY;
}
return eRet;
}
} // namespace dbaui
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|