Branch data Line data Source code
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 : :
21 : : #include "tablespage.hxx"
22 : : #include "dbu_dlg.hrc"
23 : : #include "dbadmin.hrc"
24 : : #include "dsitems.hxx"
25 : : #include "browserids.hxx"
26 : : #include "datasourceconnector.hxx"
27 : : #include <comphelper/types.hxx>
28 : : #include <connectivity/dbtools.hxx>
29 : : #include <connectivity/dbexception.hxx>
30 : : #include "stringlistitem.hxx"
31 : : #include <svl/eitem.hxx>
32 : : #include <svl/stritem.hxx>
33 : : #include "dbustrings.hrc"
34 : : #include <vcl/svapp.hxx>
35 : : #include <vcl/waitobj.hxx>
36 : : #include <com/sun/star/sdb/SQLContext.hpp>
37 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
38 : : #include <com/sun/star/sdbcx/XAppend.hpp>
39 : : #include <com/sun/star/util/XModifiable.hpp>
40 : : #include <com/sun/star/sdbcx/XDrop.hpp>
41 : : #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
42 : : #include "sqlmessage.hxx"
43 : : #include <vcl/msgbox.hxx>
44 : : #include "dbaccess_helpid.hrc"
45 : : #include "UITools.hxx"
46 : : #include <osl/mutex.hxx>
47 : : #include <osl/diagnose.h>
48 : : #include <svtools/imgdef.hxx>
49 : : #include "TablesSingleDlg.hxx"
50 : : #include <tools/diagnose_ex.h>
51 : : #include <cppuhelper/exc_hlp.hxx>
52 : : #include "AutoControls.hrc"
53 : :
54 : : //.........................................................................
55 : : namespace dbaui
56 : : {
57 : : //.........................................................................
58 : :
59 : : using namespace ::com::sun::star::uno;
60 : : using namespace ::com::sun::star::sdbc;
61 : : using namespace ::com::sun::star::sdbcx;
62 : : using namespace ::com::sun::star::sdb;
63 : : using namespace ::com::sun::star::beans;
64 : : using namespace ::com::sun::star::lang;
65 : : using namespace ::com::sun::star::i18n;
66 : : using namespace ::com::sun::star::container;
67 : : using namespace ::com::sun::star::frame;
68 : : using namespace ::com::sun::star::util;
69 : : using namespace ::dbtools;
70 : : using namespace ::comphelper;
71 : :
72 : : //========================================================================
73 : : //= OTableSubscriptionPage
74 : : //========================================================================
75 : : DBG_NAME(OTableSubscriptionPage)
76 : : //------------------------------------------------------------------------
77 : 0 : OTableSubscriptionPage::OTableSubscriptionPage( Window* pParent, const SfxItemSet& _rCoreAttrs,OTableSubscriptionDialog* _pTablesDlg )
78 : : :OGenericAdministrationPage( pParent, ModuleRes(PAGE_TABLESUBSCRIPTION), _rCoreAttrs )
79 : : ,m_aTables (this, ModuleRes(FL_SEPARATOR1))
80 : : ,m_aTablesList (this, NULL,ModuleRes(CTL_TABLESUBSCRIPTION),sal_True)
81 : : ,m_aExplanation (this, ModuleRes(FT_FILTER_EXPLANATION))
82 : : ,m_bCheckedAll ( sal_False )
83 : : ,m_bCatalogAtStart ( sal_True )
84 [ # # ][ # # ]: 0 : ,m_pTablesDlg(_pTablesDlg)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
85 : : {
86 : : DBG_CTOR(OTableSubscriptionPage,NULL);
87 : :
88 [ # # ]: 0 : m_aTablesList.SetCheckHandler(getControlModifiedLink());
89 : :
90 : : // initialize the TabListBox
91 [ # # ]: 0 : m_aTablesList.SetSelectionMode( MULTIPLE_SELECTION );
92 [ # # ]: 0 : m_aTablesList.SetDragDropMode( 0 );
93 [ # # ]: 0 : m_aTablesList.EnableInplaceEditing( sal_False );
94 [ # # ][ # # ]: 0 : m_aTablesList.SetStyle(m_aTablesList.GetStyle() | WB_BORDER | WB_HASLINES | WB_HASLINESATROOT | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT);
95 : :
96 [ # # ]: 0 : m_aTablesList.Clear();
97 : :
98 [ # # ]: 0 : FreeResource();
99 : :
100 [ # # ]: 0 : m_aTablesList.SetCheckButtonHdl(LINK(this, OTableSubscriptionPage, OnTreeEntryChecked));
101 [ # # ]: 0 : m_aTablesList.SetCheckHandler(LINK(this, OTableSubscriptionPage, OnTreeEntryChecked));
102 : 0 : }
103 : :
104 : : //------------------------------------------------------------------------
105 [ # # ][ # # ]: 0 : OTableSubscriptionPage::~OTableSubscriptionPage()
[ # # ][ # # ]
106 : : {
107 : : // just to make sure that our connection will be removed
108 : : try
109 : : {
110 [ # # ]: 0 : ::comphelper::disposeComponent(m_xCurrentConnection);
111 : : }
112 [ # # ]: 0 : catch (RuntimeException&) { }
113 : :
114 : : DBG_DTOR(OTableSubscriptionPage,NULL);
115 [ # # ][ # # ]: 0 : }
116 : :
117 : : // -----------------------------------------------------------------------------
118 : 0 : void OTableSubscriptionPage::StateChanged( StateChangedType nType )
119 : : {
120 : 0 : OGenericAdministrationPage::StateChanged( nType );
121 : :
122 [ # # ]: 0 : if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
123 : : {
124 : : // Check if we need to get new images for normal/high contrast mode
125 : 0 : m_aTablesList.notifyHiContrastChanged();
126 : : }
127 : 0 : }
128 : : // -----------------------------------------------------------------------------
129 : 0 : void OTableSubscriptionPage::DataChanged( const DataChangedEvent& rDCEvt )
130 : : {
131 : 0 : OGenericAdministrationPage::DataChanged( rDCEvt );
132 : :
133 [ # # ][ # # : 0 : if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
# # # # ]
134 : 0 : ( rDCEvt.GetType() == DATACHANGED_DISPLAY )) &&
135 : 0 : ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
136 : : {
137 : : // Check if we need to get new images for normal/high contrast mode
138 : 0 : m_aTablesList.notifyHiContrastChanged();
139 : : }
140 : 0 : }
141 : : //------------------------------------------------------------------
142 : 0 : void OTableSubscriptionPage::resizeControls(const Size& _rDiff)
143 : : {
144 [ # # ]: 0 : if ( _rDiff.Height() )
145 : : {
146 [ # # ]: 0 : Size aOldSize = m_aTablesList.GetSizePixel();
147 : 0 : aOldSize.Height() -= _rDiff.Height();
148 : : m_aTablesList.SetPosSizePixel(
149 [ # # ]: 0 : m_aTablesList.GetPosPixel()+Point(0,_rDiff.Height()),
150 : : aOldSize
151 [ # # ]: 0 : );
152 : : }
153 : 0 : }
154 : : //------------------------------------------------------------------------
155 : 0 : void OTableSubscriptionPage::implCheckTables(const Sequence< ::rtl::OUString >& _rTables)
156 : : {
157 : : // the meta data for the current connection, used for splitting up table names
158 : 0 : Reference< XDatabaseMetaData > xMeta;
159 : : try
160 : : {
161 [ # # ]: 0 : if (m_xCurrentConnection.is())
162 [ # # ][ # # ]: 0 : xMeta = m_xCurrentConnection->getMetaData();
[ # # ][ # # ]
163 : : }
164 [ # # ]: 0 : catch(SQLException&)
165 : : {
166 : : OSL_FAIL("OTableSubscriptionPage::implCheckTables : could not retrieve the current connection's meta data!");
167 : : }
168 : :
169 : : // uncheck all
170 [ # # ]: 0 : CheckAll(sal_False);
171 : :
172 : : // check the ones which are in the list
173 [ # # ]: 0 : String aListBoxTable;
174 : 0 : ::rtl::OUString sCatalog, sSchema, sName;
175 : :
176 [ # # ]: 0 : SvLBoxEntry* pRootEntry = m_aTablesList.getAllObjectsEntry();
177 : 0 : sal_Bool bAllTables = sal_False;
178 : 0 : sal_Bool bAllSchemas = sal_False;
179 : :
180 : 0 : const ::rtl::OUString* pIncludeTable = _rTables.getConstArray();
181 [ # # ]: 0 : for (sal_Int32 i=0; i<_rTables.getLength(); ++i, ++pIncludeTable)
182 : : {
183 [ # # ]: 0 : if (xMeta.is())
184 [ # # ]: 0 : qualifiedNameComponents(xMeta, pIncludeTable->getStr(), sCatalog, sSchema, sName,::dbtools::eInDataManipulation);
185 : : else
186 : 0 : sName = pIncludeTable->getStr();
187 : :
188 [ # # ][ # # ]: 0 : bAllTables = (1 == sName.getLength()) && ('%' == sName[0]);
189 [ # # ][ # # ]: 0 : bAllSchemas = (1 == sSchema.getLength()) && ('%' == sSchema[0]);
190 : :
191 : : // the catalog entry
192 [ # # ][ # # ]: 0 : SvLBoxEntry* pCatalog = m_aTablesList.GetEntryPosByName(sCatalog, pRootEntry);
[ # # ]
193 [ # # ][ # # ]: 0 : if (!(pCatalog || sCatalog.isEmpty()))
[ # # ]
194 : : // the table (resp. its catalog) refered in this filter entry does not exist anymore
195 : 0 : continue;
196 : :
197 [ # # ][ # # ]: 0 : if (bAllSchemas && pCatalog)
198 : : {
199 [ # # ]: 0 : m_aTablesList.checkWildcard(pCatalog);
200 : 0 : continue;
201 : : }
202 : :
203 : : // the schema entry
204 [ # # ][ # # ]: 0 : SvLBoxEntry* pSchema = m_aTablesList.GetEntryPosByName(sSchema, (pCatalog ? pCatalog : pRootEntry));
[ # # ][ # # ]
205 [ # # ][ # # ]: 0 : if (!(pSchema || sSchema.isEmpty()))
[ # # ]
206 : : // the table (resp. its schema) refered in this filter entry does not exist anymore
207 : 0 : continue;
208 : :
209 [ # # ][ # # ]: 0 : if (bAllTables && pSchema)
210 : : {
211 [ # # ]: 0 : m_aTablesList.checkWildcard(pSchema);
212 : 0 : continue;
213 : : }
214 : :
215 [ # # ][ # # ]: 0 : SvLBoxEntry* pEntry = m_aTablesList.GetEntryPosByName(sName, pSchema ? pSchema : (pCatalog ? pCatalog : pRootEntry) );
[ # # ][ # # ]
[ # # ]
216 [ # # ]: 0 : if (pEntry)
217 [ # # ]: 0 : m_aTablesList.SetCheckButtonState(pEntry, SV_BUTTON_CHECKED);
218 : : }
219 [ # # ][ # # ]: 0 : m_aTablesList.CheckButtons();
220 : 0 : }
221 : :
222 : : //------------------------------------------------------------------------
223 : 0 : void OTableSubscriptionPage::implCompleteTablesCheck( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rTableFilter )
224 : : {
225 [ # # ]: 0 : if (!_rTableFilter.getLength())
226 : : { // no tables visible
227 : 0 : CheckAll(sal_False);
228 : : }
229 : : else
230 : : {
231 [ # # ][ # # ]: 0 : if ((1 == _rTableFilter.getLength()) && _rTableFilter[0].equalsAsciiL("%", 1))
[ # # ]
232 : : { // all tables visible
233 : 0 : CheckAll(sal_True);
234 : : }
235 : : else
236 : 0 : implCheckTables( _rTableFilter );
237 : : }
238 : 0 : }
239 : :
240 : : //-------------------------------------------------------------------------
241 : 0 : void OTableSubscriptionPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
242 : : {
243 : : // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
244 : : sal_Bool bValid, bReadonly;
245 [ # # ]: 0 : getFlags(_rSet, bValid, bReadonly);
246 : :
247 : : // get the name of the data source we're working for
248 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(_rSet, pNameItem, SfxStringItem, DSID_NAME, sal_True);
249 : : OSL_ENSURE(pNameItem, "OTableSubscriptionPage::implInitControls: missing the name attribute!");
250 [ # # ]: 0 : String sDSName = pNameItem->GetValue();
251 : :
252 [ # # ][ # # ]: 0 : if (bValid && sDSName.Len() && !m_xCurrentConnection.is() )
[ # # ][ # # ]
253 : : { // get the current table list from the connection for the current settings
254 : :
255 : : // the PropertyValues for the current dialog settings
256 [ # # ]: 0 : Sequence< PropertyValue > aConnectionParams;
257 : : OSL_ENSURE(m_pTablesDlg, "OTableSubscriptionPage::implInitControls: need a parent dialog doing the translation!");
258 [ # # ]: 0 : if ( m_pTablesDlg )
259 : : {
260 [ # # ][ # # ]: 0 : if (!m_pTablesDlg->getCurrentSettings(aConnectionParams))
261 : : {
262 [ # # ]: 0 : m_aTablesList.Clear();
263 : 0 : m_pTablesDlg->endExecution();
264 : 0 : return;
265 : : }
266 : : }
267 : :
268 [ # # ]: 0 : if (!m_xCollator.is())
269 : : {
270 : : // the collator for the string compares
271 : : try
272 : : {
273 [ # # ][ # # ]: 0 : m_xCollator = Reference< XCollator >(m_xORB->createInstance(SERVICE_I18N_COLLATOR), UNO_QUERY);
[ # # ][ # # ]
[ # # ][ # # ]
274 [ # # ]: 0 : if (m_xCollator.is())
275 [ # # ][ # # ]: 0 : m_xCollator->loadDefaultCollator(Application::GetSettings().GetLocale(), 0);
[ # # ][ # # ]
276 : : }
277 [ # # ]: 0 : catch(const Exception&)
278 : : {
279 : : DBG_UNHANDLED_EXCEPTION();
280 : : }
281 : : }
282 : :
283 : : // fill the table list with this connection information
284 [ # # ]: 0 : SQLExceptionInfo aErrorInfo;
285 : : // the current DSN
286 [ # # ]: 0 : String sURL;
287 [ # # ]: 0 : if ( m_pTablesDlg )
288 [ # # ][ # # ]: 0 : sURL = m_pTablesDlg->getConnectionURL();
[ # # ]
289 : :
290 : : try
291 : : {
292 [ # # ]: 0 : WaitObject aWaitCursor(this);
293 : 0 : m_aTablesList.GetModel()->SetSortMode(SortAscending);
294 [ # # ]: 0 : m_aTablesList.GetModel()->SetCompareHdl(LINK(this, OTableSubscriptionPage, OnTreeEntryCompare));
295 : :
296 : 0 : Reference< XDriver > xDriver;
297 [ # # ]: 0 : m_aTablesList.setORB(m_xORB);
298 [ # # ]: 0 : Reference<XPropertySet> xProp = m_pTablesDlg->getCurrentDataSource();
299 : : OSL_ENSURE(xProp.is(),"No data source set!");
300 [ # # ]: 0 : if ( xProp.is() )
301 : : {
302 [ # # ][ # # ]: 0 : Any aTableFilter = xProp->getPropertyValue(PROPERTY_TABLEFILTER);
[ # # ]
303 [ # # ][ # # ]: 0 : Any aTableTypeFilter = xProp->getPropertyValue(PROPERTY_TABLETYPEFILTER);
[ # # ]
304 : :
305 [ # # ][ # # ]: 0 : Reference<XModifiable> xModi(getDataSourceOrModel(xProp),UNO_QUERY);
306 [ # # ][ # # ]: 0 : sal_Bool bModified = ( xModi.is() && xModi->isModified() );
[ # # ][ # # ]
307 : :
308 [ # # ]: 0 : Sequence< ::rtl::OUString > aNewTableFilter(1);
309 [ # # ][ # # ]: 0 : aNewTableFilter[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"));
310 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aNewTableFilter));
[ # # ][ # # ]
311 : :
312 [ # # ][ # # ]: 0 : xProp->setPropertyValue( PROPERTY_TABLETYPEFILTER, makeAny( Sequence< ::rtl::OUString >() ) );
[ # # ][ # # ]
[ # # ][ # # ]
313 : 0 : Reference< ::com::sun::star::lang::XEventListener> xEvt;
314 [ # # ][ # # ]: 0 : aErrorInfo = ::dbaui::createConnection(xProp,m_xORB,xEvt,m_xCurrentConnection);
[ # # ]
315 : :
316 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_TABLEFILTER,aTableFilter);
[ # # ]
317 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_TABLETYPEFILTER,aTableTypeFilter);
[ # # ]
318 : :
319 [ # # ][ # # ]: 0 : if ( xModi.is() && !bModified )
[ # # ]
320 [ # # ][ # # ]: 0 : xModi->setModified(sal_False);
[ # # ]
321 : :
322 : : }
323 : :
324 [ # # ]: 0 : if ( m_xCurrentConnection.is() )
325 : : {
326 [ # # ]: 0 : m_aTablesList.UpdateTableList( m_xCurrentConnection );
327 [ # # ]: 0 : if (m_pTablesDlg)
328 [ # # ]: 0 : m_pTablesDlg->successfullyConnected();
329 [ # # ]: 0 : }
330 : : }
331 [ # # # # ]: 0 : catch (const SQLException&)
332 : : {
333 [ # # # # ]: 0 : aErrorInfo = ::cppu::getCaughtException();
334 : : }
335 : :
336 [ # # ]: 0 : if (aErrorInfo.isValid())
337 : : {
338 : : // establishing the connection failed. Show an error window and exit.
339 [ # # ][ # # ]: 0 : OSQLMessageBox aMessageBox( GetParent()->GetParent(), aErrorInfo );
[ # # ]
340 [ # # ]: 0 : aMessageBox.Execute();
341 [ # # ]: 0 : m_aTables.Enable(sal_False);
342 [ # # ]: 0 : m_aTablesList.Enable(sal_False);
343 [ # # ]: 0 : m_aExplanation.Enable(sal_False);
344 [ # # ]: 0 : m_aTablesList.Clear();
345 : :
346 [ # # ]: 0 : if ( m_pTablesDlg )
347 : : {
348 [ # # ]: 0 : m_pTablesDlg->clearPassword();
349 : 0 : m_pTablesDlg->endExecution();
350 [ # # ]: 0 : }
351 : : }
352 : : else
353 : : {
354 : : // in addition, we need some infos about the connection used
355 [ # # ]: 0 : m_sCatalogSeparator = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")); // (default)
356 : 0 : m_bCatalogAtStart = sal_True; // (default)
357 : : try
358 : : {
359 : 0 : Reference< XDatabaseMetaData > xMeta;
360 [ # # ]: 0 : if (m_xCurrentConnection.is())
361 [ # # ][ # # ]: 0 : xMeta = m_xCurrentConnection->getMetaData();
[ # # ]
362 [ # # ][ # # ]: 0 : if (xMeta.is() && xMeta->supportsCatalogsInDataManipulation())
[ # # ][ # # ]
[ # # ]
363 : : {
364 [ # # ][ # # ]: 0 : m_sCatalogSeparator = xMeta->getCatalogSeparator();
365 [ # # ][ # # ]: 0 : m_bCatalogAtStart = xMeta->isCatalogAtStart();
366 [ # # ]: 0 : }
367 : : }
368 [ # # ]: 0 : catch(Exception&)
369 : : {
370 : : DBG_UNHANDLED_EXCEPTION();
371 : : }
372 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
373 : : }
374 : :
375 [ # # ][ # # ]: 0 : bValid = bValid && m_xCurrentConnection.is();
376 [ # # ][ # # ]: 0 : bReadonly = bReadonly || !bValid;
377 : :
378 : : // get the current table filter
379 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(_rSet, pTableFilter, OStringListItem, DSID_TABLEFILTER, sal_True);
380 [ # # ]: 0 : Sequence< ::rtl::OUString > aTableFilter;
381 [ # # ]: 0 : if (pTableFilter)
382 [ # # ][ # # ]: 0 : aTableFilter = pTableFilter->getList();
[ # # ]
383 : :
384 [ # # ]: 0 : implCompleteTablesCheck( aTableFilter );
385 : :
386 : : // expand the first entry by default
387 [ # # ]: 0 : SvLBoxEntry* pExpand = m_aTablesList.getAllObjectsEntry();
388 [ # # ]: 0 : while (pExpand)
389 : : {
390 [ # # ]: 0 : m_aTablesList.Expand(pExpand);
391 [ # # ]: 0 : pExpand = m_aTablesList.FirstChild(pExpand);
392 [ # # ][ # # ]: 0 : if (pExpand && m_aTablesList.NextSibling(pExpand))
[ # # ][ # # ]
393 : 0 : pExpand = NULL;
394 : : }
395 : :
396 : : // update the toolbox according the the current selection and check state
397 [ # # ][ # # ]: 0 : OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
[ # # ][ # # ]
398 : : }
399 : :
400 : : //------------------------------------------------------------------------
401 : 0 : void OTableSubscriptionPage::CheckAll( sal_Bool _bCheck )
402 : : {
403 [ # # ]: 0 : SvButtonState eState = _bCheck ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED;
404 : 0 : SvLBoxEntry* pEntry = m_aTablesList.First();
405 [ # # ]: 0 : while (pEntry)
406 : : {
407 : 0 : m_aTablesList.SetCheckButtonState( pEntry, eState);
408 : 0 : pEntry = m_aTablesList.Next(pEntry);
409 : : }
410 : :
411 [ # # ][ # # ]: 0 : if (_bCheck && m_aTablesList.getAllObjectsEntry())
[ # # ]
412 : 0 : m_aTablesList.checkWildcard(m_aTablesList.getAllObjectsEntry());
413 : 0 : }
414 : :
415 : : //------------------------------------------------------------------------
416 : 0 : int OTableSubscriptionPage::DeactivatePage(SfxItemSet* _pSet)
417 : : {
418 : 0 : int nResult = OGenericAdministrationPage::DeactivatePage(_pSet);
419 : :
420 : : // dispose the connection, we don't need it anymore, so we're not wasting resources
421 : : try
422 : : {
423 [ # # ]: 0 : ::comphelper::disposeComponent(m_xCurrentConnection);
424 : : }
425 : 0 : catch (RuntimeException&) { }
426 : :
427 [ # # ]: 0 : return nResult;
428 : : }
429 : : //------------------------------------------------------------------------
430 : 0 : IMPL_LINK( OTableSubscriptionPage, OnTreeEntryChecked, Control*, _pControl )
431 : : {
432 : 0 : return OnControlModified(_pControl);
433 : : }
434 : : //------------------------------------------------------------------------
435 : 0 : IMPL_LINK( OTableSubscriptionPage, OnTreeEntryCompare, const SvSortData*, _pSortData )
436 : : {
437 : 0 : SvLBoxEntry* pLHS = static_cast<SvLBoxEntry*>(_pSortData->pLeft);
438 : 0 : SvLBoxEntry* pRHS = static_cast<SvLBoxEntry*>(_pSortData->pRight);
439 : : OSL_ENSURE(pLHS && pRHS, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid tree entries!");
440 : :
441 [ # # ]: 0 : SvLBoxString* pLeftTextItem = static_cast<SvLBoxString*>(pLHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
442 [ # # ]: 0 : SvLBoxString* pRightTextItem = static_cast<SvLBoxString*>(pRHS->GetFirstItem(SV_ITEM_ID_LBOXSTRING));
443 : : OSL_ENSURE(pLeftTextItem && pRightTextItem, "SbaTableQueryBrowser::OnTreeEntryCompare: invalid text items!");
444 : :
445 [ # # ]: 0 : String sLeftText = pLeftTextItem->GetText();
446 [ # # ]: 0 : String sRightText = pRightTextItem->GetText();
447 : :
448 : 0 : sal_Int32 nCompareResult = 0; // equal by default
449 : :
450 [ # # ]: 0 : if (m_xCollator.is())
451 : : {
452 : : try
453 : : {
454 [ # # ][ # # ]: 0 : nCompareResult = m_xCollator->compareString(sLeftText, sRightText);
[ # # ][ # # ]
[ # # ]
455 : : }
456 [ # # ]: 0 : catch(Exception&)
457 : : {
458 : : }
459 : : }
460 : : else
461 : : // default behaviour if we do not have a collator -> do the simple string compare
462 [ # # ]: 0 : nCompareResult = sLeftText.CompareTo(sRightText);
463 : :
464 [ # # ][ # # ]: 0 : return nCompareResult;
465 : : }
466 : :
467 : : //------------------------------------------------------------------------
468 : 0 : Sequence< ::rtl::OUString > OTableSubscriptionPage::collectDetailedSelection() const
469 : : {
470 [ # # ]: 0 : Sequence< ::rtl::OUString > aTableFilter;
471 [ # # ][ # # ]: 0 : static const ::rtl::OUString sDot(RTL_CONSTASCII_USTRINGPARAM("."));
[ # # ][ # # ]
472 [ # # ][ # # ]: 0 : static const ::rtl::OUString sWildcard(RTL_CONSTASCII_USTRINGPARAM("%"));
[ # # ][ # # ]
473 : :
474 : 0 : ::rtl::OUString sComposedName;
475 [ # # ]: 0 : const SvLBoxEntry* pAllObjectsEntry = m_aTablesList.getAllObjectsEntry();
476 [ # # ]: 0 : if (!pAllObjectsEntry)
477 : : return aTableFilter;
478 [ # # ]: 0 : SvLBoxEntry* pEntry = m_aTablesList.GetModel()->Next(const_cast<SvLBoxEntry*>(pAllObjectsEntry));
479 [ # # ]: 0 : while(pEntry)
480 : : {
481 : 0 : sal_Bool bCatalogWildcard = sal_False;
482 : 0 : sal_Bool bSchemaWildcard = sal_False;
483 : 0 : SvLBoxEntry* pSchema = NULL;
484 : 0 : SvLBoxEntry* pCatalog = NULL;
485 : :
486 [ # # ][ # # ]: 0 : if (m_aTablesList.GetCheckButtonState(pEntry) == SV_BUTTON_CHECKED && !m_aTablesList.GetModel()->HasChildren(pEntry))
[ # # ][ # # ]
[ # # ]
487 : : { // checked and a leaf, which means it's no catalog, no schema, but a real table
488 : 0 : ::rtl::OUString sCatalog;
489 [ # # ]: 0 : if(m_aTablesList.GetModel()->HasParent(pEntry))
490 : : {
491 [ # # ]: 0 : pSchema = m_aTablesList.GetModel()->GetParent(pEntry);
492 [ # # ]: 0 : if (pAllObjectsEntry == pSchema)
493 : : // do not want to have the root entry
494 : 0 : pSchema = NULL;
495 : :
496 [ # # ]: 0 : if (pSchema)
497 : : { // it's a real schema entry, not the "all objects" root
498 [ # # ]: 0 : if(m_aTablesList.GetModel()->HasParent(pSchema))
499 : : {
500 [ # # ]: 0 : pCatalog = m_aTablesList.GetModel()->GetParent(pSchema);
501 [ # # ]: 0 : if (pAllObjectsEntry == pCatalog)
502 : : // do not want to have the root entry
503 : 0 : pCatalog = NULL;
504 : :
505 [ # # ]: 0 : if (pCatalog)
506 : : { // it's a real catalog entry, not the "all objects" root
507 [ # # ]: 0 : bCatalogWildcard = m_aTablesList.isWildcardChecked(pCatalog);
508 [ # # ]: 0 : if (m_bCatalogAtStart)
509 : : {
510 [ # # ][ # # ]: 0 : sComposedName += m_aTablesList.GetEntryText( pCatalog );
[ # # ]
511 : 0 : sComposedName += m_sCatalogSeparator;
512 [ # # ]: 0 : if (bCatalogWildcard)
513 : 0 : sComposedName += sWildcard;
514 : : }
515 : : else
516 : : {
517 [ # # ]: 0 : if (bCatalogWildcard)
518 : 0 : sCatalog = sWildcard;
519 : : else
520 : 0 : sCatalog = ::rtl::OUString();
521 : 0 : sCatalog += m_sCatalogSeparator;
522 [ # # ][ # # ]: 0 : sCatalog += m_aTablesList.GetEntryText( pCatalog );
[ # # ]
523 : : }
524 : : }
525 : : }
526 [ # # ]: 0 : bSchemaWildcard = m_aTablesList.isWildcardChecked(pSchema);
527 [ # # ][ # # ]: 0 : sComposedName += m_aTablesList.GetEntryText( pSchema );
[ # # ]
528 : 0 : sComposedName += sDot;
529 : : }
530 : :
531 [ # # ]: 0 : if (bSchemaWildcard)
532 : 0 : sComposedName += sWildcard;
533 : : }
534 [ # # ][ # # ]: 0 : if (!bSchemaWildcard && !bCatalogWildcard)
535 [ # # ][ # # ]: 0 : sComposedName += m_aTablesList.GetEntryText( pEntry );
[ # # ]
536 : :
537 [ # # ][ # # ]: 0 : if (!m_bCatalogAtStart && !bCatalogWildcard)
538 : 0 : sComposedName += sCatalog;
539 : :
540 : : // need some space
541 : 0 : sal_Int32 nOldLen = aTableFilter.getLength();
542 [ # # ]: 0 : aTableFilter.realloc(nOldLen + 1);
543 : : // add the new name
544 [ # # ]: 0 : aTableFilter[nOldLen] = sComposedName;
545 : :
546 : : // reset the composed name
547 : 0 : sComposedName = ::rtl::OUString();
548 : : }
549 : :
550 [ # # ]: 0 : if (bCatalogWildcard)
551 [ # # ]: 0 : pEntry = implNextSibling(pCatalog);
552 [ # # ]: 0 : else if (bSchemaWildcard)
553 [ # # ]: 0 : pEntry = implNextSibling(pSchema);
554 : : else
555 [ # # ]: 0 : pEntry = m_aTablesList.GetModel()->Next(pEntry);
556 : : }
557 : :
558 : 0 : return aTableFilter;
559 : : }
560 : :
561 : : //------------------------------------------------------------------------
562 : 0 : SvLBoxEntry* OTableSubscriptionPage::implNextSibling(SvLBoxEntry* _pEntry) const
563 : : {
564 : 0 : SvLBoxEntry* pReturn = NULL;
565 [ # # ]: 0 : if (_pEntry)
566 : : {
567 : 0 : pReturn = m_aTablesList.NextSibling(_pEntry);
568 [ # # ]: 0 : if (!pReturn)
569 : 0 : pReturn = implNextSibling(m_aTablesList.GetParent(_pEntry));
570 : : }
571 : 0 : return pReturn;
572 : : }
573 : :
574 : : //------------------------------------------------------------------------
575 : 0 : sal_Bool OTableSubscriptionPage::FillItemSet( SfxItemSet& _rCoreAttrs )
576 : : {
577 : : sal_Bool bValid, bReadonly;
578 [ # # ]: 0 : getFlags(_rCoreAttrs, bValid, bReadonly);
579 : :
580 [ # # ][ # # ]: 0 : if (!bValid || bReadonly)
581 : : // don't store anything if the data we're working with is invalid or readonly
582 : 0 : return sal_True;
583 : :
584 : : /////////////////////////////////////////////////////////////////////////
585 : : // create the output string which contains all the table names
586 [ # # ]: 0 : if ( m_xCurrentConnection.is() )
587 : : { // collect the table filter data only if we have a connection - else no tables are displayed at all
588 [ # # ]: 0 : Sequence< ::rtl::OUString > aTableFilter;
589 [ # # ][ # # ]: 0 : if (m_aTablesList.isWildcardChecked(m_aTablesList.getAllObjectsEntry()))
[ # # ]
590 : : {
591 [ # # ]: 0 : aTableFilter.realloc(1);
592 [ # # ][ # # ]: 0 : aTableFilter[0] = ::rtl::OUString("%", 1, RTL_TEXTENCODING_ASCII_US);
593 : : }
594 : : else
595 : : {
596 [ # # ][ # # ]: 0 : aTableFilter = collectDetailedSelection();
[ # # ]
597 : : }
598 [ # # ][ # # ]: 0 : _rCoreAttrs.Put( OStringListItem(DSID_TABLEFILTER, aTableFilter) );
[ # # ][ # # ]
599 : : }
600 : :
601 : 0 : return sal_True;
602 : : }
603 : :
604 : : // -----------------------------------------------------------------------
605 : 0 : void OTableSubscriptionPage::fillControls(::std::vector< ISaveValueWrapper* >& /*_rControlList*/)
606 : : {
607 : 0 : }
608 : : // -----------------------------------------------------------------------
609 : 0 : void OTableSubscriptionPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
610 : : {
611 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<OTableTreeListBox>(&m_aTablesList));
612 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aTables));
613 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aExplanation));
614 : 0 : }
615 : : // -----------------------------------------------------------------------
616 : : //.........................................................................
617 : : } // namespace dbaui
618 : : //.........................................................................
619 : :
620 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|