Files
libreoffice/sc/source/ui/dbgui/dapidata.cxx

210 lines
6.6 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Herbert Duerr i#118735 prevent endless loop if vlookup/hlookup doesn't find anything http://svn.apache.org/viewvc?view=revision&revision=1239673 Patches contributed by Andre Fischer remove lp_solver http://svn.apache.org/viewvc?view=revision&revision=1199180 i#118160: Added external CoinMP library. http://svn.apache.org/viewvc?view=revision&revision=1233909 Patches contributed by Armin Le-Grand i#118485 - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 i#118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 Patches contributed by lihuiibm i#108860 - Fix range validation. http://svn.apache.org/viewvc?view=revision&revision=1242846 i#118954 Chart data will lost after copy to different file http://svn.apache.org/viewvc?view=revision&revision=1301345 Patches contributed by Ariel Constenla-Haile Fix Linux build breaker: extra qualification on member http://svn.apache.org/viewvc?view=revision&revision=1301591 i#118696 - i#118697 - Fix some Sheet Tab Color API issues http://svn.apache.org/viewvc?view=revision&revision=1225428 i#118697 - Fix uninitialized variable http://svn.apache.org/viewvc?view=revision&revision=1225859 i#118771 - ScUndoImportTab should preserve tab background color http://svn.apache.org/viewvc?view=revision&revision=1230356 i#118921 - Repaint linked sheet tab background color after updating link http://svn.apache.org/viewvc?view=revision&revision=1245177 i#118927 - Undo/Redo "Update Link" does not reset sheet tab color http://svn.apache.org/viewvc?view=revision&revision=1245241 i#118747 - Copy tab color when transferring sheets across documents http://svn.apache.org/viewvc?view=revision&revision=1230355 Patch contributed by Oliver Rainer-Wittman i#118012 - methods <ScBroadcastAreaSlot::AreaBroadcast(..)> and <ScBroadcastAreaSlot::AreaBroadcastInRange(..)> adapt stl-container iteration in order to avoid destroyed iterators during iteration. http://svn.apache.org/viewvc?view=revision&revision=1297916 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 Patch contributed by Daniel Rentz calc69: #i116936# fix VBA symbol Cells http://svn.apache.org/viewvc?view=revision&revision=1172135 Patches contributed by leiw: i#118546 CPU 100% on switched off AutoCalculate with Conditional Formatting on date values http://svn.apache.org/viewvc?view=revision&revision=1301380 Re-add new function documentation. Many various cleanups. Add missing calc66: #o11817313# also look at formula result number format, remove redundant binaries.
2012-11-30 12:23:25 +00:00
/*
* 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 .
*/
2000-09-18 16:07:07 +00:00
#undef SC_DLLIMPLEMENTATION
2000-09-18 16:07:07 +00:00
//------------------------------------------------------------------
#include <vcl/waitobj.hxx>
2000-10-20 08:15:16 +00:00
#include <comphelper/processfactory.hxx>
2000-09-18 16:07:07 +00:00
#include <com/sun/star/sheet/DataImportMode.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#include <com/sun/star/sdb/DatabaseContext.hpp>
2001-02-21 15:28:49 +00:00
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
#include <com/sun/star/sdb/XCompletedConnection.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
2000-09-18 16:07:07 +00:00
using namespace com::sun::star;
#include "dapidata.hxx"
#include "scresid.hxx"
#include "sc.hrc"
#include "dapitype.hrc"
#include "miscuno.hxx"
2000-09-18 16:07:07 +00:00
#include "dpsdbtab.hxx" // ScImportSourceDesc
//-------------------------------------------------------------------------
// entries in the "type" ListBox
2001-02-21 15:28:49 +00:00
#define DP_TYPELIST_TABLE 0
#define DP_TYPELIST_QUERY 1
#define DP_TYPELIST_SQLNAT 3
2000-09-18 16:07:07 +00:00
//-------------------------------------------------------------------------
ScDataPilotDatabaseDlg::ScDataPilotDatabaseDlg( Window* pParent ) :
ModalDialog ( pParent, ScResId( RID_SCDLG_DAPIDATA ) ),
//
aFlFrame ( this, ScResId( FL_FRAME ) ),
2000-09-18 16:07:07 +00:00
aFtDatabase ( this, ScResId( FT_DATABASE ) ),
aLbDatabase ( this, ScResId( LB_DATABASE ) ),
aFtObject ( this, ScResId( FT_OBJECT ) ),
aCbObject ( this, ScResId( CB_OBJECT ) ),
aFtType ( this, ScResId( FT_OBJTYPE ) ),
aLbType ( this, ScResId( LB_OBJTYPE ) ),
aBtnOk ( this, ScResId( BTN_OK ) ),
aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
aBtnHelp ( this, ScResId( BTN_HELP ) )
2000-09-18 16:07:07 +00:00
{
FreeResource();
WaitObject aWait( this ); // initializing the database service the first time takes a while
try
2000-09-18 16:07:07 +00:00
{
// get database names
uno::Reference<sdb::XDatabaseContext> xContext = sdb::DatabaseContext::create(
comphelper::getProcessComponentContext() );
uno::Sequence<rtl::OUString> aNames = xContext->getElementNames();
long nCount = aNames.getLength();
const rtl::OUString* pArray = aNames.getConstArray();
for (long nPos = 0; nPos < nCount; nPos++)
2000-09-18 16:07:07 +00:00
{
String aName = pArray[nPos];
aLbDatabase.InsertEntry( aName );
2000-09-18 16:07:07 +00:00
}
}
catch(uno::Exception&)
2000-09-18 16:07:07 +00:00
{
2011-03-01 19:05:02 +01:00
OSL_FAIL("exception in database");
2000-09-18 16:07:07 +00:00
}
aLbDatabase.SelectEntryPos( 0 );
aLbType.SelectEntryPos( 0 );
FillObjects();
aLbDatabase.SetSelectHdl( LINK( this, ScDataPilotDatabaseDlg, SelectHdl ) );
aLbType.SetSelectHdl( LINK( this, ScDataPilotDatabaseDlg, SelectHdl ) );
}
ScDataPilotDatabaseDlg::~ScDataPilotDatabaseDlg()
{
}
void ScDataPilotDatabaseDlg::GetValues( ScImportSourceDesc& rDesc )
{
sal_uInt16 nSelect = aLbType.GetSelectEntryPos();
2000-09-18 16:07:07 +00:00
rDesc.aDBName = aLbDatabase.GetSelectEntry();
rDesc.aObject = aCbObject.GetText();
if (rDesc.aDBName.isEmpty() || rDesc.aObject.isEmpty())
2000-09-18 16:07:07 +00:00
rDesc.nType = sheet::DataImportMode_NONE;
else if ( nSelect == DP_TYPELIST_TABLE )
rDesc.nType = sheet::DataImportMode_TABLE;
2001-02-21 15:28:49 +00:00
else if ( nSelect == DP_TYPELIST_QUERY )
rDesc.nType = sheet::DataImportMode_QUERY;
2000-09-18 16:07:07 +00:00
else
rDesc.nType = sheet::DataImportMode_SQL;
rDesc.bNative = ( nSelect == DP_TYPELIST_SQLNAT );
}
IMPL_LINK_NOARG(ScDataPilotDatabaseDlg, SelectHdl)
2000-09-18 16:07:07 +00:00
{
FillObjects();
return 0;
}
void ScDataPilotDatabaseDlg::FillObjects()
{
aCbObject.Clear();
String aDatabaseName = aLbDatabase.GetSelectEntry();
if (!aDatabaseName.Len())
return;
sal_uInt16 nSelect = aLbType.GetSelectEntryPos();
2001-02-21 15:28:49 +00:00
if ( nSelect > DP_TYPELIST_QUERY )
2000-09-18 16:07:07 +00:00
return; // only tables and queries
try
2000-09-18 16:07:07 +00:00
{
2001-02-21 15:28:49 +00:00
// open connection (for tables or queries)
uno::Reference<sdb::XDatabaseContext> xContext = sdb::DatabaseContext::create(
comphelper::getProcessComponentContext() );
2000-09-18 16:07:07 +00:00
2001-02-21 15:28:49 +00:00
uno::Any aSourceAny = xContext->getByName( aDatabaseName );
uno::Reference<sdb::XCompletedConnection> xSource(
ScUnoHelpFunctions::AnyToInterface( aSourceAny ), uno::UNO_QUERY );
if ( !xSource.is() ) return;
uno::Reference<task::XInteractionHandler> xHandler(
task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(), 0),
uno::UNO_QUERY_THROW);
2001-02-21 15:28:49 +00:00
uno::Reference<sdbc::XConnection> xConnection = xSource->connectWithCompletion( xHandler );
uno::Sequence<rtl::OUString> aNames;
2000-09-18 16:07:07 +00:00
if ( nSelect == DP_TYPELIST_TABLE )
{
// get all tables
uno::Reference<sdbcx::XTablesSupplier> xTablesSupp( xConnection, uno::UNO_QUERY );
if ( !xTablesSupp.is() ) return;
uno::Reference<container::XNameAccess> xTables = xTablesSupp->getTables();
if ( !xTables.is() ) return;
aNames = xTables->getElementNames();
2000-09-18 16:07:07 +00:00
}
else
{
// get all queries
2001-02-21 15:28:49 +00:00
uno::Reference<sdb::XQueriesSupplier> xQueriesSupp( xConnection, uno::UNO_QUERY );
if ( !xQueriesSupp.is() ) return;
uno::Reference<container::XNameAccess> xQueries = xQueriesSupp->getQueries();
if ( !xQueries.is() ) return;
aNames = xQueries->getElementNames();
2000-09-18 16:07:07 +00:00
}
// fill list
long nCount = aNames.getLength();
const rtl::OUString* pArray = aNames.getConstArray();
2000-09-18 16:07:07 +00:00
for( long nPos=0; nPos<nCount; nPos++ )
{
String aName = pArray[nPos];
aCbObject.InsertEntry( aName );
}
}
catch(uno::Exception&)
2000-09-18 16:07:07 +00:00
{
2011-03-01 14:29:24 +01:00
// this may happen if an invalid database is selected -> no DBG_ERROR
OSL_FAIL("exception in database");
2000-09-18 16:07:07 +00:00
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */