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
|
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: adtabdlg.cxx,v $
*
* $Revision: 1.22 $
*
* last change: $Author: obo $ $Date: 2006-01-16 15:28:10 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
#ifndef DBAUI_QYDLGTAB_HXX
#include "adtabdlg.hxx"
#endif
#ifndef DBAUI_ADTABDLG_HRC
#include "adtabdlg.hrc"
#endif
#ifndef _DBAUI_SQLMESSAGE_HXX_
#include "sqlmessage.hxx"
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#include "dbaccess_helpid.hrc"
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef _SFXSIDS_HRC
#include <sfx2/sfxsids.hrc>
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
#ifndef DBAUI_QUERYTABLEVIEW_HXX
#include "QueryTableView.hxx"
#endif
#ifndef DBAUI_QUERYDESIGNVIEW_HXX
#include "QueryDesignView.hxx"
#endif
#ifndef DBAUI_QUERYCONTROLLER_HXX
#include "querycontroller.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef DBACCESS_UI_BROWSER_ID_HXX
#include "browserids.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
#include <algorithm>
// slot ids
using namespace dbaui;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace dbtools;
DBG_NAME(OAddTableDlg)
//------------------------------------------------------------------------------
OAddTableDlg::OAddTableDlg( Window* pParent,OJoinTableView* _pTableView)
:ModelessDialog( pParent, ModuleRes(DLG_JOIN_TABADD) )
,aFTTable( this, ResId( FT_TABLE ) )
,aTableList( this,NULL, ResId( LB_TABLE ),sal_False,sal_False )
,aAddButton( this, ResId( PB_ADDTABLE ) )
,aCloseButton( this, ResId( PB_CLOSE ) )
,aHelpButton( this, ResId( PB_HELP ) )
,aFixedLineTable( this, ResId( FL_TABLE ) )
,aDefaultString( ResId( STR_DEFAULT ) )
,m_pTableView(_pTableView)
,m_bInitialized(sal_False)
{
DBG_CTOR(OAddTableDlg,NULL);
OSL_ENSURE(_pTableView,"Must be a valid pointer!");
// der Close-Button hat schon einen Standard-Help-Text, den ich aber hier nicht haben moechte, also den Text ruecksetzen
// und eine neue ID verteilen
aCloseButton.SetHelpText(String());
aCloseButton.SetHelpId(HID_JOINSH_ADDTAB_CLOSE);
aTableList.SetHelpId(HID_JOINSH_ADDTAB_TABLELIST);
//////////////////////////////////////////////////////////////////////
// Handler setzen
aAddButton.SetClickHdl( LINK(this,OAddTableDlg, AddClickHdl) );
aCloseButton.SetClickHdl( LINK(this,OAddTableDlg, CloseClickHdl) );
aTableList.SetDoubleClickHdl( LINK(this,OAddTableDlg, TableListDoubleClickHdl) );
aTableList.SetSelectHdl( LINK(this,OAddTableDlg, TableListSelectHdl) );
aTableList.EnableInplaceEditing( FALSE );
aTableList.SetWindowBits(WB_BORDER | WB_HASLINES |WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HASLINESATROOT | WB_SORT | WB_HSCROLL );
aTableList.EnableCheckButton( NULL ); // do not show any buttons
aTableList.SetSelectionMode( SINGLE_SELECTION );
aTableList.notifyHiContrastChanged();
FreeResource();
}
//------------------------------------------------------------------------------
OAddTableDlg::~OAddTableDlg()
{
DBG_DTOR(OAddTableDlg,NULL);
::dbaui::notifySystemWindow(m_pTableView->getDesignView(),this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
}
//------------------------------------------------------------------------------
void OAddTableDlg::Update()
{
if(!m_bInitialized)
{
UpdateTableList(m_pTableView->getDesignView()->getController()->isViewAllowed());
m_bInitialized = sal_True;
}
}
//------------------------------------------------------------------------------
void OAddTableDlg::AddTable()
{
//////////////////////////////////////////////////////////////////
// Tabelle hinzufuegen
SvLBoxEntry* pEntry = aTableList.FirstSelected();
if( pEntry && !aTableList.GetModel()->HasChilds(pEntry))
{
::rtl::OUString aCatalog,aSchema,aTableName;
SvLBoxEntry* pSchema = aTableList.GetParent(pEntry);
if(pSchema && pSchema != aTableList.getAllObjectsEntry())
{
SvLBoxEntry* pCatalog = aTableList.GetParent(pSchema);
if(pCatalog && pCatalog != aTableList.getAllObjectsEntry())
aCatalog = aTableList.GetEntryText(pCatalog);
aSchema = aTableList.GetEntryText(pSchema);
}
aTableName = aTableList.GetEntryText(pEntry);
::rtl::OUString aComposedName;
try
{
Reference<XDatabaseMetaData> xMeta = m_pTableView->getDesignView()->getController()->getConnection()->getMetaData();
// den Datenbank-Namen besorgen
if ( !aCatalog.getLength()
&& aSchema.getLength()
&& xMeta->supportsCatalogsInDataManipulation()
&& !xMeta->supportsSchemasInDataManipulation() )
{
aCatalog = aSchema;
aSchema = ::rtl::OUString();
}
::dbtools::composeTableName(xMeta,
aCatalog,
aSchema,
aTableName,
aComposedName,
sal_False,
::dbtools::eInDataManipulation);
}
catch(const Exception&)
{
OSL_ENSURE(0,"Exception catched!");
}
// aOrigTableName is used because AddTabWin would like to have this
// und das Ganze dem Container uebergeben
m_pTableView->AddTabWin( aComposedName,aTableName, TRUE );
}
}
//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, AddClickHdl, Button*, pButton )
{
TableListDoubleClickHdl(NULL);
return 0;
}
//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, TableListDoubleClickHdl, ListBox *, EMPTY_ARG )
{
if (IsAddAllowed())
AddTable();
if (!IsAddAllowed())
Close();
return 0;
}
//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, TableListSelectHdl, ListBox *, EMPTY_ARG )
{
SvLBoxEntry* pEntry = aTableList.FirstSelected();
aAddButton.Enable( pEntry && !aTableList.GetModel()->HasChilds(pEntry) );
return 0;
}
//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, CloseClickHdl, Button*, pButton )
{
return Close();
}
//------------------------------------------------------------------------------
BOOL OAddTableDlg::Close()
{
::dbaui::notifySystemWindow(m_pTableView->getDesignView(),this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
m_pTableView->getDesignView()->getController()->InvalidateFeature(ID_BROWSER_ADDTABLE);
m_pTableView->getDesignView()->getController()->getView()->GrabFocus();
return ModelessDialog::Close();
}
//------------------------------------------------------------------------------
BOOL OAddTableDlg::IsAddAllowed()
{
return m_pTableView && m_pTableView->IsAddAllowed();
}
//------------------------------------------------------------------------------
void OAddTableDlg::UpdateTableList(BOOL bViewsAllowed)
{
//////////////////////////////////////////////////////////////////////
// Datenbank- und Tabellennamen setzen
Reference< XTablesSupplier > xTableSupp(m_pTableView->getDesignView()->getController()->getConnection(),UNO_QUERY);
Reference< XViewsSupplier > xViewSupp;
Reference< XNameAccess > xTables, xViews;
xTables = xTableSupp->getTables();
// get the views supplier and the views
Sequence< ::rtl::OUString> sTables,sViews;
if (xTables.is())
sTables = xTables->getElementNames();
xViewSupp.set(xTableSupp,UNO_QUERY);
if (xViewSupp.is())
{
xViews = xViewSupp->getViews();
if (xViews.is())
sViews = xViews->getElementNames();
}
// if no views are allowed remove the views also out the table name filter
if ( !bViewsAllowed )
{
const ::rtl::OUString* pTableBegin = sTables.getConstArray();
const ::rtl::OUString* pTableEnd = pTableBegin + sTables.getLength();
::std::vector< ::rtl::OUString > aTables(pTableBegin,pTableEnd);
const ::rtl::OUString* pViewBegin = sViews.getConstArray();
const ::rtl::OUString* pViewEnd = pViewBegin + sViews.getLength();
::comphelper::TStringMixEqualFunctor aEqualFunctor;
for(;pViewBegin != pViewEnd;++pViewBegin)
aTables.erase(::std::remove_if(aTables.begin(),aTables.end(),::std::bind2nd(aEqualFunctor,*pViewBegin)),aTables.end());
::rtl::OUString* pTables = aTables.empty() ? 0 : &aTables[0];
sTables = Sequence< ::rtl::OUString>(pTables, aTables.size());
sViews = Sequence< ::rtl::OUString>();
}
aTableList.UpdateTableList(Reference< XConnection>(xTableSupp,UNO_QUERY)->getMetaData(),sTables,sViews);
SvLBoxEntry* pEntry = aTableList.First();
while( pEntry && aTableList.GetModel()->HasChilds(pEntry))
{
aTableList.Expand(pEntry);
pEntry = aTableList.Next(pEntry);
}
if ( pEntry )
aTableList.Select(pEntry);
}
// -----------------------------------------------------------------------------
|