2010-10-12 15:59:00 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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
|
|
|
|
2006-07-21 12:20:53 +00:00
|
|
|
|
2004-08-23 08:29:44 +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>
|
2000-12-12 14:08:44 +00:00
|
|
|
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
|
2012-09-18 09:46:34 +02:00
|
|
|
#include <com/sun/star/sdb/DatabaseContext.hpp>
|
2001-02-21 15:28:49 +00:00
|
|
|
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
|
2000-12-12 14:08:44 +00:00
|
|
|
#include <com/sun/star/sdb/XCompletedConnection.hpp>
|
2012-10-02 15:03:12 +02:00
|
|
|
#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"
|
2000-12-12 14:08:44 +00:00
|
|
|
#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 ) ),
|
|
|
|
//
|
2007-02-27 12:01:41 +00:00
|
|
|
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 ) ),
|
2007-02-27 12:01:41 +00:00
|
|
|
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
|
|
|
|
|
2000-10-09 16:39:56 +00:00
|
|
|
try
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// get database names
|
|
|
|
|
2012-09-18 09:46:34 +02:00
|
|
|
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
|
|
|
{
|
2012-09-18 09:46:34 +02:00
|
|
|
String aName = pArray[nPos];
|
|
|
|
aLbDatabase.InsertEntry( aName );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-09 16:39:56 +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 )
|
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nSelect = aLbType.GetSelectEntryPos();
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
rDesc.aDBName = aLbDatabase.GetSelectEntry();
|
|
|
|
rDesc.aObject = aCbObject.GetText();
|
|
|
|
|
2011-04-27 17:21:25 -04:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
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;
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
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
|
|
|
|
|
2000-10-09 16:39:56 +00:00
|
|
|
try
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-02-21 15:28:49 +00:00
|
|
|
// open connection (for tables or queries)
|
|
|
|
|
2012-09-18 09:46:34 +02:00
|
|
|
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(
|
2012-10-04 14:36:34 +02:00
|
|
|
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 );
|
|
|
|
|
2000-12-12 14:08:44 +00:00
|
|
|
uno::Sequence<rtl::OUString> aNames;
|
2000-09-18 16:07:07 +00:00
|
|
|
if ( nSelect == DP_TYPELIST_TABLE )
|
|
|
|
{
|
|
|
|
// get all tables
|
2000-12-12 14:08:44 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2000-12-12 14:08:44 +00:00
|
|
|
// 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
|
|
|
|
|
2000-12-12 14:08:44 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2000-10-09 16:39:56 +00:00
|
|
|
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
|
2011-05-21 15:04:26 +02:00
|
|
|
OSL_FAIL("exception in database");
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-12 15:59:00 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|