2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-09-27 13:52:10 +01: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 .
|
|
|
|
*/
|
2006-09-17 06:21:44 +00:00
|
|
|
|
2001-02-05 08:26:47 +00:00
|
|
|
#include "QTableWindow.hxx"
|
|
|
|
#include "QueryTableView.hxx"
|
|
|
|
#include "dbustrings.hrc"
|
2011-02-03 00:33:36 +01:00
|
|
|
#include <osl/diagnose.h>
|
2001-02-05 08:26:47 +00:00
|
|
|
#include "dbaccess_helpid.hrc"
|
|
|
|
#include "QueryDesignView.hxx"
|
|
|
|
#include "browserids.hxx"
|
|
|
|
#include "querycontroller.hxx"
|
|
|
|
#include <vcl/image.hxx>
|
|
|
|
#include "TableWindowListBox.hxx"
|
2002-08-19 07:01:32 +00:00
|
|
|
#include "dbu_qry.hrc"
|
2001-02-05 08:26:47 +00:00
|
|
|
#include "Query.hrc"
|
|
|
|
#include <com/sun/star/sdbcx/XKeysSupplier.hpp>
|
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
|
|
|
#include <com/sun/star/container/XIndexAccess.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/sdbcx/KeyType.hpp>
|
|
|
|
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
|
|
|
|
#include "TableFieldInfo.hxx"
|
2001-03-15 07:29:16 +00:00
|
|
|
#include <comphelper/extract.hxx>
|
2011-11-18 21:03:31 +00:00
|
|
|
#include <comphelper/string.hxx>
|
|
|
|
#include <comphelper/uno3.hxx>
|
2002-05-02 06:54:11 +00:00
|
|
|
#include "UITools.hxx"
|
2001-02-14 13:54:12 +00:00
|
|
|
|
2001-02-05 08:26:47 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::sdbcx;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace dbaui;
|
|
|
|
//========================================================================
|
|
|
|
// class OQueryTableWindow
|
|
|
|
//========================================================================
|
2007-11-05 08:06:13 +00:00
|
|
|
DBG_NAME(OQueryTableWindow)
|
2001-02-05 08:26:47 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2007-11-01 14:30:28 +00:00
|
|
|
OQueryTableWindow::OQueryTableWindow( Window* pParent, const TTableWindowData::value_type& pTabWinData, sal_Unicode* pszInitialAlias)
|
2001-02-05 08:26:47 +00:00
|
|
|
:OTableWindow( pParent, pTabWinData )
|
|
|
|
,m_nAliasNum(0)
|
|
|
|
{
|
|
|
|
DBG_CTOR(OQueryTableWindow,NULL);
|
|
|
|
if (pszInitialAlias != NULL)
|
|
|
|
m_strInitialAlias = ::rtl::OUString(pszInitialAlias);
|
|
|
|
else
|
2007-11-01 14:30:28 +00:00
|
|
|
m_strInitialAlias = GetAliasName();
|
2001-02-05 08:26:47 +00:00
|
|
|
|
|
|
|
// wenn der Tabellen- gleich dem Aliasnamen ist, dann darf ich das nicht an InitialAlias weiterreichen, denn das Anhaengen
|
|
|
|
// eines eventuelle Tokens nicht klappen ...
|
|
|
|
if (m_strInitialAlias == pTabWinData->GetTableName())
|
|
|
|
m_strInitialAlias = ::rtl::OUString();
|
|
|
|
|
2010-07-10 18:21:24 +02:00
|
|
|
SetHelpId(HID_CTL_QRYDGNTAB);
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
OQueryTableWindow::~OQueryTableWindow()
|
|
|
|
{
|
|
|
|
DBG_DTOR(OQueryTableWindow,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
sal_Bool OQueryTableWindow::Init()
|
|
|
|
{
|
|
|
|
sal_Bool bSuccess = OTableWindow::Init();
|
2001-02-23 14:04:37 +00:00
|
|
|
if(!bSuccess)
|
|
|
|
return bSuccess;
|
2001-02-05 08:26:47 +00:00
|
|
|
|
|
|
|
OQueryTableView* pContainer = static_cast<OQueryTableView*>(getTableView());
|
|
|
|
|
|
|
|
// zuerst Alias bestimmen
|
2006-07-10 14:40:46 +00:00
|
|
|
::rtl::OUString sAliasName;
|
2001-02-05 08:26:47 +00:00
|
|
|
|
2007-11-01 14:30:28 +00:00
|
|
|
TTableWindowData::value_type pWinData = GetData();
|
2001-02-05 08:26:47 +00:00
|
|
|
|
2011-12-19 18:10:37 -02:00
|
|
|
if (!m_strInitialAlias.isEmpty() )
|
2001-02-05 08:26:47 +00:00
|
|
|
// Der Alias wurde explizit mit angegeben
|
2006-07-10 14:40:46 +00:00
|
|
|
sAliasName = m_strInitialAlias;
|
2008-12-09 07:25:38 +00:00
|
|
|
else if ( GetTable().is() )
|
2007-11-01 14:30:28 +00:00
|
|
|
GetTable()->getPropertyValue( PROPERTY_NAME ) >>= sAliasName;
|
2008-12-09 07:25:38 +00:00
|
|
|
else
|
|
|
|
return sal_False;
|
2001-02-05 08:26:47 +00:00
|
|
|
|
|
|
|
// Alias mit fortlaufender Nummer versehen
|
2006-07-10 14:40:46 +00:00
|
|
|
if (pContainer->CountTableAlias(sAliasName, m_nAliasNum))
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2006-07-10 14:40:46 +00:00
|
|
|
sAliasName += ::rtl::OUString('_');
|
|
|
|
sAliasName += ::rtl::OUString::valueOf(m_nAliasNum);
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-18 21:03:31 +00:00
|
|
|
sAliasName = comphelper::string::remove(sAliasName, '"');
|
2006-07-10 14:40:46 +00:00
|
|
|
SetAliasName(sAliasName);
|
2001-02-05 08:26:47 +00:00
|
|
|
// SetAliasName reicht das als WinName weiter, dadurch benutzt es die Basisklasse
|
2010-11-25 01:16:20 +00:00
|
|
|
// reset the title
|
2001-02-05 08:26:47 +00:00
|
|
|
m_aTitle.SetText( pWinData->GetWinName() );
|
|
|
|
m_aTitle.Show();
|
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{ // es soll nur ein Dummy-Window aufgemacht werden ...
|
2011-12-19 18:10:37 -02:00
|
|
|
OSL_ENSURE(!GetAliasName().isEmpty(), "OQueryTableWindow::Init : kein Alias- UND kein Tabellenname geht nicht !");
|
2001-02-05 08:26:47 +00:00
|
|
|
// .. aber das braucht wenigstens einen Alias
|
|
|
|
|
|
|
|
// ::com::sun::star::form::ListBox anlegen
|
|
|
|
if (!m_pListBox)
|
|
|
|
m_pListBox = CreateListBox();
|
|
|
|
|
|
|
|
// Titel setzen
|
|
|
|
m_aTitle.SetText(GetAliasName());
|
|
|
|
m_aTitle.Show();
|
|
|
|
|
2002-06-27 07:23:50 +00:00
|
|
|
clearListBox();
|
2001-02-05 08:26:47 +00:00
|
|
|
// neu zu fuellen brauche ich die nicht, da ich ja keine Tabelle habe
|
|
|
|
m_pListBox->Show();
|
|
|
|
}
|
|
|
|
|
2008-06-25 11:53:28 +00:00
|
|
|
getTableView()->getDesignView()->getController().InvalidateFeature(ID_BROWSER_QUERY_EXECUTE);
|
2001-02-05 08:26:47 +00:00
|
|
|
return bSuccess;
|
|
|
|
}
|
2002-06-27 07:23:50 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey)
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2002-06-27 07:23:50 +00:00
|
|
|
OTableFieldInfo* pInfo = new OTableFieldInfo();
|
|
|
|
pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD);
|
|
|
|
if ( _xColumn.is() )
|
|
|
|
pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE)));
|
|
|
|
return pInfo;
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
2002-06-27 07:23:50 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryTableWindow::deleteUserData(void*& _pUserData)
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2002-06-27 07:23:50 +00:00
|
|
|
delete static_cast<OTableFieldInfo*>(_pUserData);
|
|
|
|
_pUserData = NULL;
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2012-10-18 16:28:20 +02:00
|
|
|
void OQueryTableWindow::OnEntryDoubleClicked(SvTreeListEntry* pEntry)
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2011-02-03 00:33:36 +01:00
|
|
|
OSL_ENSURE(pEntry != NULL, "OQueryTableWindow::OnEntryDoubleClicked : pEntry darf nicht NULL sein !");
|
2001-02-05 08:26:47 +00:00
|
|
|
// man koennte das auch abfragen und dann ein return hinsetzen, aber so weist es vielleicht auf Fehler bei Aufrufer hin
|
|
|
|
|
2008-06-25 11:53:28 +00:00
|
|
|
if (getTableView()->getDesignView()->getController().isReadOnly())
|
2001-02-05 08:26:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
|
2011-02-03 00:33:36 +01:00
|
|
|
OSL_ENSURE(pInf != NULL, "OQueryTableWindow::OnEntryDoubleClicked : Feld hat keine FieldInfo !");
|
2001-02-05 08:26:47 +00:00
|
|
|
|
|
|
|
// eine DragInfo aufbauen
|
2001-10-05 05:49:21 +00:00
|
|
|
OTableFieldDescRef aInfo = new OTableFieldDesc(GetTableName(),m_pListBox->GetEntryText(pEntry));
|
|
|
|
aInfo->SetTabWindow(this);
|
|
|
|
aInfo->SetAlias(GetAliasName());
|
|
|
|
aInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
|
|
|
|
aInfo->SetDataType(pInf->GetDataType());
|
2001-02-05 08:26:47 +00:00
|
|
|
|
|
|
|
// und das entsprechende Feld einfuegen
|
|
|
|
static_cast<OQueryTableView*>(getTableView())->InsertField(aInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2001-10-05 05:49:21 +00:00
|
|
|
sal_Bool OQueryTableWindow::ExistsField(const ::rtl::OUString& strFieldName, OTableFieldDescRef& rInfo)
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2011-02-03 00:33:36 +01:00
|
|
|
OSL_ENSURE(m_pListBox != NULL, "OQueryTableWindow::ExistsField : habe keine ::com::sun::star::form::ListBox !");
|
2010-11-06 20:03:40 +02:00
|
|
|
OSL_ENSURE(rInfo.is(),"OQueryTableWindow::ExistsField: invlid argument for OTableFieldDescRef!");
|
2008-06-25 11:53:28 +00:00
|
|
|
Reference< XConnection> xConnection = getTableView()->getDesignView()->getController().getConnection();
|
2001-06-28 13:22:47 +00:00
|
|
|
sal_Bool bExists = sal_False;
|
|
|
|
if(xConnection.is())
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2012-10-18 16:28:20 +02:00
|
|
|
SvTreeListEntry* pEntry = m_pListBox->First();
|
2001-10-11 07:38:14 +00:00
|
|
|
try
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2003-12-01 09:38:18 +00:00
|
|
|
Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
|
2006-08-15 09:55:53 +00:00
|
|
|
::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
|
|
while (pEntry)
|
2001-06-28 13:22:47 +00:00
|
|
|
{
|
2001-10-11 07:38:14 +00:00
|
|
|
if (bCase(strFieldName,::rtl::OUString(m_pListBox->GetEntryText(pEntry))))
|
|
|
|
{
|
|
|
|
OTableFieldInfo* pInf = static_cast<OTableFieldInfo*>(pEntry->GetUserData());
|
2011-02-03 00:33:36 +01:00
|
|
|
OSL_ENSURE(pInf != NULL, "OQueryTableWindow::ExistsField : Feld hat keine FieldInfo !");
|
2001-10-11 07:38:14 +00:00
|
|
|
|
|
|
|
rInfo->SetTabWindow(this);
|
|
|
|
rInfo->SetField(strFieldName);
|
|
|
|
rInfo->SetTable(GetTableName());
|
|
|
|
rInfo->SetAlias(GetAliasName());
|
|
|
|
rInfo->SetFieldIndex(m_pListBox->GetModel()->GetAbsPos(pEntry));
|
|
|
|
rInfo->SetDataType(pInf->GetDataType());
|
|
|
|
bExists = sal_True;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pEntry = m_pListBox->Next(pEntry);
|
2001-06-28 13:22:47 +00:00
|
|
|
}
|
2001-10-11 07:38:14 +00:00
|
|
|
}
|
|
|
|
catch(SQLException&)
|
|
|
|
{
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-28 13:22:47 +00:00
|
|
|
return bExists;
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
sal_Bool OQueryTableWindow::ExistsAVisitedConn() const
|
|
|
|
{
|
|
|
|
return static_cast<const OQueryTableView*>(getTableView())->ExistsAVisitedConn(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void OQueryTableWindow::KeyInput( const KeyEvent& rEvt )
|
|
|
|
{
|
|
|
|
OTableWindow::KeyInput( rEvt );
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|