LibreOffice Module dbaccess (master) 1
QTableWindow.cxx
Go to the documentation of this file.
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#include "QTableWindow.hxx"
21#include <QueryTableView.hxx>
22#include <JoinController.hxx>
23#include <JoinDesignView.hxx>
24#include <osl/diagnose.h>
25#include <helpids.h>
26#include <browserids.hxx>
28#include <strings.hxx>
29#include <com/sun/star/beans/XPropertySet.hpp>
30#include <com/sun/star/sdbc/SQLException.hpp>
31#include "TableFieldInfo.hxx"
33#include <comphelper/types.hxx>
34
35using namespace ::com::sun::star::sdbc;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::container;
38using namespace ::com::sun::star::beans;
39using namespace dbaui;
40OQueryTableWindow::OQueryTableWindow( vcl::Window* pParent, const TTableWindowData::value_type& pTabWinData)
41 :OTableWindow( pParent, pTabWinData )
42 ,m_nAliasNum(0)
43{
45
46 // if table name matches alias, do not pass to InitialAlias,
47 // as the appending of a possible token could not succeed...
48 if (m_strInitialAlias == pTabWinData->GetTableName())
49 m_strInitialAlias.clear();
50
52}
53
55{
56 bool bSuccess = OTableWindow::Init();
57 if (!bSuccess)
58 return bSuccess;
59
60 OQueryTableView* pContainer = static_cast<OQueryTableView*>(getTableView());
61
62 // first determine Alias
63 OUString sAliasName;
64
65 TTableWindowData::value_type pWinData = GetData();
66
67 if (!m_strInitialAlias.isEmpty() )
68 // Alias was explicitly given
69 sAliasName = m_strInitialAlias;
70 else if ( GetTable().is() )
71 GetTable()->getPropertyValue( PROPERTY_NAME ) >>= sAliasName;
72 else
73 return false;
74
75 // Alias with successive number
76 if (pContainer->CountTableAlias(sAliasName, m_nAliasNum))
77 {
78 sAliasName += "_" + OUString::number(m_nAliasNum);
79 }
80
81 sAliasName = sAliasName.replaceAll("\"", "");
82 SetAliasName(sAliasName);
83 // SetAliasName passes it as WinName, hence it uses the base class
84 // reset the title
85 m_xTitle->SetText( pWinData->GetWinName() );
86 m_xTitle->Show();
87
89 return bSuccess;
90}
91
92void* OQueryTableWindow::createUserData(const Reference< XPropertySet>& _xColumn,bool _bPrimaryKey)
93{
94 OTableFieldInfo* pInfo = new OTableFieldInfo();
95 pInfo->SetKey(_bPrimaryKey ? TAB_PRIMARY_FIELD : TAB_NORMAL_FIELD);
96 if ( _xColumn.is() )
97 pInfo->SetDataType(::comphelper::getINT32(_xColumn->getPropertyValue(PROPERTY_TYPE)));
98 return pInfo;
99}
100
102{
103 delete static_cast<OTableFieldInfo*>(_pUserData);
104 _pUserData = nullptr;
105}
106
108{
109 if (getTableView()->getDesignView()->getController().isReadOnly())
110 return;
111
112 weld::TreeView& rTreeView = m_xListBox->get_widget();
113 OTableFieldInfo* pInf = weld::fromId<OTableFieldInfo*>(rTreeView.get_id(rEntry));
114 OSL_ENSURE(pInf != nullptr, "OQueryTableWindow::OnEntryDoubleClicked : field doesn't have FieldInfo !");
115
116 // build up DragInfo
117 OTableFieldDescRef aInfo = new OTableFieldDesc(GetTableName(), rTreeView.get_text(rEntry));
118 aInfo->SetTabWindow(this);
119 aInfo->SetAlias(GetAliasName());
120 aInfo->SetFieldIndex(rTreeView.get_iter_index_in_parent(rEntry));
121 aInfo->SetDataType(pInf->GetDataType());
122
123 // and insert corresponding field
124 static_cast<OQueryTableView*>(getTableView())->InsertField(aInfo);
125}
126
127bool OQueryTableWindow::ExistsField(const OUString& strFieldName, OTableFieldDescRef const & rInfo)
128{
129 OSL_ENSURE(m_xListBox != nullptr, "OQueryTableWindow::ExistsField : doesn't have css::form::ListBox !");
130 OSL_ENSURE(rInfo.is(),"OQueryTableWindow::ExistsField: invalid argument for OTableFieldDescRef!");
131 Reference< XConnection> xConnection = getTableView()->getDesignView()->getController().getConnection();
132 bool bExists = false;
133 if(xConnection.is())
134 {
135 weld::TreeView& rTreeView = m_xListBox->get_widget();
136 std::unique_ptr<weld::TreeIter> xEntry(rTreeView.make_iterator());
137 bool bEntry = rTreeView.get_iter_first(*xEntry);
138 try
139 {
140 Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
141 ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
142
143 while (bEntry)
144 {
145 if (bCase(strFieldName, rTreeView.get_text(*xEntry)))
146 {
147 OTableFieldInfo* pInf = weld::fromId<OTableFieldInfo*>(rTreeView.get_id(*xEntry));
148 assert(pInf && "OQueryTableWindow::ExistsField : field doesn't have FieldInfo !");
149
150 rInfo->SetTabWindow(this);
151 rInfo->SetField(strFieldName);
152 rInfo->SetTable(GetTableName());
153 rInfo->SetAlias(GetAliasName());
154 rInfo->SetFieldIndex(rTreeView.get_iter_index_in_parent(*xEntry));
155 rInfo->SetDataType(pInf->GetDataType());
156 bExists = true;
157 break;
158 }
159 bEntry = rTreeView.iter_next(*xEntry);
160 }
161 }
162 catch(SQLException&)
163 {
164 }
165 }
166
167 return bExists;
168}
169
171{
172 return static_cast<const OQueryTableView*>(getTableView())->ExistsAVisitedConn(this);
173}
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define ID_BROWSER_QUERY_EXECUTE
Definition: browserids.hxx:90
OJoinController & getController() const
OJoinDesignView * getDesignView() const
sal_Int32 CountTableAlias(const OUString &rName, sal_Int32 &rMax)
how many tables with a certain alias do I already have?
virtual bool Init() override
bool ExistsField(const OUString &strFieldName, OTableFieldDescRef const &rInfo)
virtual void OnEntryDoubleClicked(weld::TreeIter &rEntry) override
bool ExistsAVisitedConn() const
virtual void * createUserData(const css::uno::Reference< css::beans::XPropertySet > &_xColumn, bool _bPrimaryKey) override
creates user information that will be append at the ListBoxentry
virtual void deleteUserData(void *&_pUserData) override
delete the user data with the equal type as created within createUserData
OUString const & GetAliasName() const
void SetAliasName(const OUString &strNewAlias)
sal_Int32 GetDataType() const
void SetKey(ETableFieldType bKey)
void SetDataType(sal_Int32 eTyp)
OJoinDesignView * getDesignView()
OJoinTableView * getTableView()
const TTableWindowData::value_type & GetData() const
virtual bool Init()
VclPtr< OTableWindowListBox > m_xListBox
Definition: TableWindow.hxx:62
css::uno::Reference< css::beans::XPropertySet > GetTable() const
OUString const & GetTableName() const
VclPtr< OTableWindowTitle > m_xTitle
Definition: TableWindow.hxx:61
void SetHelpId(const OUString &)
virtual std::unique_ptr< TreeIter > make_iterator(const TreeIter *pOrig=nullptr) const=0
virtual int get_iter_index_in_parent(const TreeIter &rIter) const=0
virtual OUString get_text(int row, int col=-1) const=0
virtual bool get_iter_first(TreeIter &rIter) const=0
virtual bool iter_next(TreeIter &rIter) const=0
virtual OUString get_id(int pos) const=0
constexpr OUStringLiteral HID_CTL_QRYDGNTAB
Definition: helpids.h:33
@ TAB_NORMAL_FIELD
Definition: QEnumTypes.hxx:49
@ TAB_PRIMARY_FIELD
Definition: QEnumTypes.hxx:50
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")