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