1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include <osl/mutex.hxx>
31 #include <tools/diagnose_ex.h>
32 #include <tools/urlobj.hxx>
33 #include <comphelper/processfactory.hxx>
34 #include <com/sun/star/io/XPersistObject.hpp>
35 #include <com/sun/star/sdbc/ResultSetType.hpp>
36 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
37 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
38 #include <com/sun/star/sdbcx/XRowLocate.hpp>
39 #include <com/sun/star/sdbc/DataType.hpp>
40 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
41 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
42 #include <com/sun/star/sdb/XDatabaseEnvironment.hpp>
43 #include <com/sun/star/uno/XNamingService.hpp>
44 #include <com/sun/star/sdbc/XDataSource.hpp>
45 #include <com/sun/star/sdb/CommandType.hpp>
46 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
47 #include <com/sun/star/sdbc/XConnection.hpp>
48 #include <com/sun/star/sdb/XCompletedConnection.hpp>
49 #include <com/sun/star/task/XInteractionHandler.hpp>
50 #include <com/sun/star/form/XLoadable.hpp>
51 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
52 #include <com/sun/star/form/XGridColumnFactory.hpp>
53 #include <com/sun/star/io/XDataInputStream.hpp>
54 #include <com/sun/star/container/XNameContainer.hpp>
55 #include <com/sun/star/ucb/XContentProvider.hpp>
56 #include <com/sun/star/ucb/XContentAccess.hpp>
57 #include <ucbhelper/contentbroker.hxx>
58 #include <ucbhelper/content.hxx>
59 #include <ucbhelper/contentidentifier.hxx>
60 #include <comphelper/container.hxx>
61 #include <svl/urihelper.hxx>
62 #include <svtools/svtabbx.hxx>
63 #include <svtools/headbar.hxx>
64 #include <vcl/dialog.hxx>
65 #ifndef _SV_BUTTON_HXX
66 #include <vcl/button.hxx>
67 #endif
68 #include <vcl/lstbox.hxx>
69 #include <vcl/fixed.hxx>
70 #include <vcl/group.hxx>
71 #include <vcl/lstbox.hxx>
72 #include <vcl/edit.hxx>
73 #include <vcl/msgbox.hxx>
74 #include <tools/debug.hxx>
75 #include "datman.hxx"
76 #include "bibresid.hxx"
77 #include "bibmod.hxx"
78 #include "bibview.hxx"
79 // #100312# ---------
80 #include "bibbeam.hxx"
81 #include "bibprop.hrc"
82 #include "toolbar.hxx"
83 #include "toolbar.hrc"
84 #include "bibconfig.hxx"
85 #include "bibbeam.hxx"
86 #include "bib.hrc"
87 #include "datman.hrc"
88 #include "bibliography.hrc"
89 #include <connectivity/dbtools.hxx>
90 
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::beans;
93 using namespace ::com::sun::star::container;
94 using namespace ::com::sun::star::uno;
95 using namespace ::com::sun::star::sdb;
96 using namespace ::com::sun::star::sdbc;
97 using namespace ::com::sun::star::sdbcx;
98 using namespace ::com::sun::star::form;
99 using namespace ::com::sun::star::frame;
100 using namespace ::com::sun::star::ucb;
101 using namespace ::com::sun::star::lang;
102 using namespace ::ucb;
103 
104 #define C2U(cChar) ::rtl::OUString::createFromAscii(cChar)
105 #define C2S(cChar) String::CreateFromAscii(cChar)
106 #define MAP_TOKEN ';'
107 #define PAIR_TOKEN ':'
108 
109 
110 /* -----------------17.01.00 14:38-------------------
111 
112  --------------------------------------------------*/
113 Reference< XConnection > getConnection(const ::rtl::OUString& _rURL)
114 {
115 	// first get the sdb::DataSource corresponding to the url
116 	Reference< XDataSource >	xDataSource;
117 	// is it a favorite title ?
118 	Reference< XMultiServiceFactory >  xMgr = comphelper::getProcessServiceFactory();
119 	Reference<XInterface> xNamingContextIfc = xMgr->createInstance(C2U("com.sun.star.sdb.DatabaseContext"));
120 	Reference< XNameAccess >  xNamingContext(xNamingContextIfc, UNO_QUERY);
121 	if (xNamingContext.is() && xNamingContext->hasByName(_rURL))
122 	{
123 		DBG_ASSERT(Reference< XNamingService > (xNamingContext, UNO_QUERY).is(), "::getDataSource : no NamingService interface on the sdb::DatabaseAccessContext !");
124 		try
125         {
126             xDataSource = Reference< XDataSource > (Reference< XNamingService > (xNamingContext, UNO_QUERY)->getRegisteredObject(_rURL), UNO_QUERY);
127         }
128         catch(Exception eEx)
129         {
130             (void) eEx;	// make compiler happy
131             DBG_ERROR("Exception caught in ODatabaseContext::getRegisteredObject()");
132         }
133 	}
134 	// build the connection from the data source
135 	Reference< XConnection >	xConn;
136 	if (xDataSource.is())
137 	{
138 		// need user/pwd for this
139 		::rtl::OUString sUser, sPwd;
140 		Reference< XPropertySet >  xDataSourceProps(xDataSource, UNO_QUERY);
141 		Reference< XCompletedConnection > xComplConn(xDataSource, UNO_QUERY);
142 /*		Reference< XPropertySetInfo >  xInfo = xDataSourceProps.is() ? xDataSourceProps->getPropertySetInfo() : Reference< XPropertySetInfo > ();
143 		if (xInfo.is() && xInfo->hasPropertyByName(C2U("User")))
144 			xDataSourceProps->getPropertyValue(C2U("User")) >>= sUser;
145 		if (xInfo.is() && xInfo->hasPropertyByName(C2U("Password")))
146 			xDataSourceProps->getPropertyValue(C2U("Password"))>>= sPwd;
147 */
148 		try
149 		{
150 
151 			Reference<XInterface> xHdl = xMgr->createInstance(C2U("com.sun.star.task.InteractionHandler"));
152 			Reference<task::XInteractionHandler> xIHdl(xHdl, UNO_QUERY);
153 			xConn = xComplConn->connectWithCompletion(xIHdl);
154 //			xConn = xDataSource->getConnection(sUser, sPwd);
155 		}
156 		catch(SQLException&)
157 		{
158 			// TODO : a real error handling
159 		}
160 		catch(Exception& e )
161 		{
162             (void) e;	// make compiler happy
163 		}
164 
165 	}
166 	return xConn;
167 }
168 
169 /* -----------------17.01.00 14:46-------------------
170 
171  --------------------------------------------------*/
172 Reference< XConnection >	getConnection(const Reference< XInterface > & xRowSet)
173 {
174 	Reference< XConnection >	xConn;
175 	try
176 	{
177 		Reference< XPropertySet >  xFormProps(xRowSet, UNO_QUERY);
178 		if (!xFormProps.is())
179 			return xConn;
180 
181 		xConn = Reference< XConnection > (*(Reference< XInterface > *)xFormProps->getPropertyValue(C2U("ActiveConnection")).getValue(), UNO_QUERY);
182 		if (!xConn.is())
183 		{
184 			DBG_WARNING("no active connection");
185 		}
186 	}
187 	catch(Exception& e )
188 	{
189         (void) e;	// make compiler happy
190 		DBG_ERROR("exception in getConnection");
191 	}
192 
193 	return xConn;
194 }
195 /* -----------------17.01.00 16:07-------------------
196 
197  --------------------------------------------------*/
198 Reference< XNameAccess >  getColumns(const Reference< XForm > & _rxForm)
199 {
200 	Reference< XNameAccess >  xReturn;
201 	// check if the form is alive
202 	Reference< XColumnsSupplier >  xSupplyCols( _rxForm, UNO_QUERY );
203 	if (xSupplyCols.is())
204 		xReturn = xSupplyCols->getColumns();
205 
206 	if (!xReturn.is() || (xReturn->getElementNames().getLength() == 0))
207 	{	// no ....
208 		xReturn = NULL;
209 		// -> get the table the form is bound to and ask it for their columns
210 		Reference< XTablesSupplier >  xSupplyTables( getConnection( _rxForm ), UNO_QUERY );
211 		Reference< XPropertySet >  xFormProps( _rxForm, UNO_QUERY );
212 		if (xFormProps.is() && xSupplyTables.is())
213 		{
214 			try
215 			{
216 				DBG_ASSERT((*(sal_Int32*)xFormProps->getPropertyValue(C2U("CommandType")).getValue()) == CommandType::TABLE,
217 					"::getColumns : invalid form (has no table as data source) !");
218 				::rtl::OUString sTable;
219 				xFormProps->getPropertyValue(C2U("Command")) >>= sTable;
220 				Reference< XNameAccess >  xTables = xSupplyTables->getTables();
221 				if (xTables.is() && xTables->hasByName(sTable))
222 					xSupplyCols = Reference< XColumnsSupplier > (
223 						*(Reference< XInterface > *)xTables->getByName(sTable).getValue(), UNO_QUERY);
224 				if (xSupplyCols.is())
225 					xReturn = xSupplyCols->getColumns();
226 			}
227 #ifdef DBG_UTIL
228 			catch(Exception& e )
229 #else
230 			catch(Exception&)
231 #endif
232 			{
233 #ifdef DBG_UTIL
234 				String sMsg(String::CreateFromAscii("::getColumns : catched an exception ("));
235 				sMsg += String(e.Message);
236 				sMsg.AppendAscii(") ...");
237 				DBG_ERROR( ByteString(sMsg, RTL_TEXTENCODING_ASCII_US ).GetBuffer());
238 #endif
239 			}
240 
241 		}
242 	}
243 	return xReturn;
244 }
245 
246 /* -----------------11.11.99 15:54-------------------
247 
248  --------------------------------------------------*/
249 class MappingDialog_Impl : public ModalDialog
250 {
251     BibDataManager* pDatMan;
252 	OKButton		aOKBT;
253 	CancelButton	aCancelBT;
254     HelpButton		aHelpBT;
255     FixedLine		aMapGB;
256 	FixedText		aIdentifierFT;
257 	ListBox 		aIdentifierLB;
258 	FixedText		aAuthorityTypeFT;
259 	ListBox 		aAuthorityTypeLB;
260     FixedText       aAuthorFT;
261 	ListBox 		aAuthorLB;
262 	FixedText		aTitleFT;
263 	ListBox 		aTitleLB;
264     FixedText       aMonthFT;
265 	ListBox 		aMonthLB;
266     FixedText       aYearFT;
267 	ListBox 		aYearLB;
268     FixedText       aISBNFT;
269 	ListBox 		aISBNLB;
270     FixedText       aBooktitleFT;
271 	ListBox 		aBooktitleLB;
272     FixedText       aChapterFT;
273 	ListBox 		aChapterLB;
274     FixedText       aEditionFT;
275 	ListBox 		aEditionLB;
276     FixedText       aEditorFT;
277 	ListBox 		aEditorLB;
278     FixedText       aHowpublishedFT;
279 	ListBox 		aHowpublishedLB;
280     FixedText       aInstitutionFT;
281 	ListBox 		aInstitutionLB;
282     FixedText       aJournalFT;
283 	ListBox 		aJournalLB;
284     FixedText       aNoteFT;
285 	ListBox 		aNoteLB;
286     FixedText       aAnnoteFT;
287 	ListBox 		aAnnoteLB;
288     FixedText       aNumberFT;
289 	ListBox 		aNumberLB;
290     FixedText       aOrganizationsFT;
291 	ListBox 		aOrganizationsLB;
292     FixedText       aPagesFT;
293 	ListBox 		aPagesLB;
294     FixedText       aPublisherFT;
295 	ListBox 		aPublisherLB;
296     FixedText       aAddressFT;
297 	ListBox 		aAddressLB;
298     FixedText       aSchoolFT;
299 	ListBox 		aSchoolLB;
300     FixedText       aSeriesFT;
301 	ListBox 		aSeriesLB;
302     FixedText       aReportTypeFT;
303 	ListBox 		aReportTypeLB;
304     FixedText       aVolumeFT;
305 	ListBox 		aVolumeLB;
306     FixedText       aURLFT;
307 	ListBox 		aURLLB;
308     FixedText       aCustom1FT;
309 	ListBox 		aCustom1LB;
310 	FixedText		aCustom2FT;
311 	ListBox 		aCustom2LB;
312 	FixedText		aCustom3FT;
313 	ListBox 		aCustom3LB;
314 	FixedText		aCustom4FT;
315 	ListBox 		aCustom4LB;
316 	FixedText		aCustom5FT;
317 	ListBox 		aCustom5LB;
318 	ListBox*		aListBoxes[COLUMN_COUNT];
319 	String			sNone;
320 
321 	sal_Bool		bModified;
322 
323 
324 
325 	DECL_LINK(OkHdl, OKButton*);
326 	DECL_LINK(ListBoxSelectHdl, ListBox*);
327 
328 public:
329 	MappingDialog_Impl(Window* pParent, BibDataManager* pDatMan);
330 	~MappingDialog_Impl();
331 
332 	void	SetModified() {bModified = sal_True;}
333 
334 };
335 /* -----------------11.11.99 16:42-------------------
336 
337  --------------------------------------------------*/
338 sal_uInt16 lcl_FindLogicalName(BibConfig* pConfig ,
339 									const ::rtl::OUString& rLogicalColumnName)
340 {
341 	for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
342 	{
343 		if(rLogicalColumnName == pConfig->GetDefColumnName(i))
344 			return i;
345 	}
346 	return USHRT_MAX;
347 }
348 //-----------------------------------------------------------------------------
349 MappingDialog_Impl::MappingDialog_Impl(Window* pParent, BibDataManager* pMan) :
350 	ModalDialog(pParent, BibResId(RID_DLG_MAPPING) ),
351 	pDatMan(pMan),
352 	aOKBT(this, 				BibResId( BT_OK			)),
353 	aCancelBT(this, 			BibResId( BT_CANCEL		)),
354 	aHelpBT(this,				BibResId( BT_HELP			)),
355 
356 	aMapGB(this,				BibResId( GB_MAPPING		)),
357 
358 	aIdentifierFT(this, 		BibResId( FT_IDENTIFIER	)),
359 	aIdentifierLB(this, 		BibResId( LB_IDENTIFIER	)),
360 	aAuthorityTypeFT(this,		BibResId( FT_AUTHORITYTYPE )),
361 	aAuthorityTypeLB(this,		BibResId( LB_AUTHORITYTYPE )),
362 	aAuthorFT(this, 			BibResId( FT_AUTHOR		)),
363 	aAuthorLB(this, 			BibResId( LB_AUTHOR		)),
364 	aTitleFT(this,				BibResId( FT_TITLE 		)),
365 	aTitleLB(this,				BibResId( LB_TITLE 		)),
366 	aMonthFT(this,				BibResId( FT_MONTH 		)),
367 	aMonthLB(this,				BibResId( LB_MONTH 		)),
368 	aYearFT(this,				BibResId( FT_YEAR			)),
369 	aYearLB(this,				BibResId( LB_YEAR			)),
370 	aISBNFT(this,				BibResId( FT_ISBN			)),
371 	aISBNLB(this,				BibResId( LB_ISBN			)),
372 	aBooktitleFT(this,			BibResId( FT_BOOKTITLE 	)),
373 	aBooktitleLB(this,			BibResId( LB_BOOKTITLE 	)),
374 	aChapterFT(this,			BibResId( FT_CHAPTER		)),
375 	aChapterLB(this,			BibResId( LB_CHAPTER		)),
376 	aEditionFT(this,			BibResId( FT_EDITION		)),
377 	aEditionLB(this,			BibResId( LB_EDITION		)),
378 	aEditorFT(this, 			BibResId( FT_EDITOR		)),
379 	aEditorLB(this, 			BibResId( LB_EDITOR		)),
380 	aHowpublishedFT(this,		BibResId( FT_HOWPUBLISHED	)),
381 	aHowpublishedLB(this,		BibResId( LB_HOWPUBLISHED	)),
382 	aInstitutionFT(this,		BibResId( FT_INSTITUTION	)),
383 	aInstitutionLB(this,		BibResId( LB_INSTITUTION	)),
384 	aJournalFT(this,			BibResId( FT_JOURNAL		)),
385 	aJournalLB(this,			BibResId( LB_JOURNAL		)),
386 	aNoteFT(this,				BibResId( FT_NOTE			)),
387 	aNoteLB(this,				BibResId( LB_NOTE			)),
388 	aAnnoteFT(this, 			BibResId( FT_ANNOTE		)),
389 	aAnnoteLB(this, 			BibResId( LB_ANNOTE		)),
390 	aNumberFT(this, 			BibResId( FT_NUMBER		)),
391 	aNumberLB(this, 			BibResId( LB_NUMBER		)),
392 	aOrganizationsFT(this,		BibResId( FT_ORGANIZATIONS )),
393 	aOrganizationsLB(this,		BibResId( LB_ORGANIZATIONS )),
394 	aPagesFT(this,				BibResId( FT_PAGES 		)),
395 	aPagesLB(this,				BibResId( LB_PAGES 		)),
396 	aPublisherFT(this,			BibResId( FT_PUBLISHER 	)),
397 	aPublisherLB(this,			BibResId( LB_PUBLISHER 	)),
398 	aAddressFT(this,			BibResId( FT_ADDRESS		)),
399 	aAddressLB(this,			BibResId( LB_ADDRESS		)),
400 	aSchoolFT(this, 			BibResId( FT_SCHOOL		)),
401 	aSchoolLB(this, 			BibResId( LB_SCHOOL		)),
402 	aSeriesFT(this, 			BibResId( FT_SERIES		)),
403 	aSeriesLB(this, 			BibResId( LB_SERIES		)),
404 	aReportTypeFT(this, 		BibResId( FT_REPORTTYPE	)),
405 	aReportTypeLB(this, 		BibResId( LB_REPORTTYPE	)),
406 	aVolumeFT(this, 			BibResId( FT_VOLUME		)),
407 	aVolumeLB(this, 			BibResId( LB_VOLUME		)),
408 	aURLFT(this,				BibResId( FT_URL			)),
409 	aURLLB(this,				BibResId( LB_URL			)),
410 	aCustom1FT(this,			BibResId( FT_CUSTOM1		)),
411 	aCustom1LB(this,			BibResId( LB_CUSTOM1		)),
412 	aCustom2FT(this,			BibResId( FT_CUSTOM2		)),
413 	aCustom2LB(this,			BibResId( LB_CUSTOM2		)),
414 	aCustom3FT(this,			BibResId( FT_CUSTOM3		)),
415 	aCustom3LB(this,			BibResId( LB_CUSTOM3		)),
416 	aCustom4FT(this,			BibResId( FT_CUSTOM4		)),
417 	aCustom4LB(this,			BibResId( LB_CUSTOM4		)),
418 	aCustom5FT(this,			BibResId( FT_CUSTOM5		)),
419 	aCustom5LB(this,			BibResId( LB_CUSTOM5		)),
420 	sNone(BibResId(ST_NONE)),
421 	bModified(sal_False)
422 {
423 	FreeResource();
424 
425 	aIdentifierFT.SetText(String(		  BibResId( ST_IDENTIFIER	 )));
426 	aAuthorityTypeFT.SetText(String(	  BibResId( ST_AUTHTYPE )));
427 	aAuthorFT.SetText(String(			  BibResId( ST_AUTHOR		 )));
428 	aTitleFT.SetText(String(			  BibResId( ST_TITLE		 )));
429 	aMonthFT.SetText(String(			  BibResId( ST_MONTH		 )));
430 	aYearFT.SetText(String( 			  BibResId( ST_YEAR 		 )));
431 	aISBNFT.SetText(String( 			  BibResId( ST_ISBN 		 )));
432 	aBooktitleFT.SetText(String(		  BibResId( ST_BOOKTITLE	 )));
433 	aChapterFT.SetText(String(			  BibResId( ST_CHAPTER		 )));
434 	aEditionFT.SetText(String(			  BibResId( ST_EDITION		 )));
435 	aEditorFT.SetText(String(			  BibResId( ST_EDITOR		 )));
436 	aHowpublishedFT.SetText(String( 	  BibResId( ST_HOWPUBLISHED  )));
437 	aInstitutionFT.SetText(String(		  BibResId( ST_INSTITUTION	 )));
438 	aJournalFT.SetText(String(			  BibResId( ST_JOURNAL		 )));
439 	aNoteFT.SetText(String( 			  BibResId( ST_NOTE 		 )));
440 	aAnnoteFT.SetText(String(			  BibResId( ST_ANNOTE		 )));
441 	aNumberFT.SetText(String(			  BibResId( ST_NUMBER		 )));
442 	aOrganizationsFT.SetText(String(	  BibResId( ST_ORGANIZATION )));
443 	aPagesFT.SetText(String(			  BibResId( ST_PAGE 		)));
444 	aPublisherFT.SetText(String(		  BibResId( ST_PUBLISHER	 )));
445 	aAddressFT.SetText(String(			  BibResId( ST_ADDRESS		 )));
446 	aSchoolFT.SetText(String(			  BibResId( ST_SCHOOL		 )));
447 	aSeriesFT.SetText(String(			  BibResId( ST_SERIES		 )));
448 	aReportTypeFT.SetText(String(		  BibResId( ST_REPORT	 )));
449 	aVolumeFT.SetText(String(			  BibResId( ST_VOLUME		 )));
450 	aURLFT.SetText(String(				  BibResId( ST_URL			 )));
451 	aCustom1FT.SetText(String(			  BibResId( ST_CUSTOM1		 )));
452 	aCustom2FT.SetText(String(			  BibResId( ST_CUSTOM2		 )));
453 	aCustom3FT.SetText(String(			  BibResId( ST_CUSTOM3		 )));
454 	aCustom4FT.SetText(String(			  BibResId( ST_CUSTOM4		 )));
455 	aCustom5FT.SetText(String(			  BibResId( ST_CUSTOM5		 )));
456 
457 	aOKBT.SetClickHdl(LINK(this, MappingDialog_Impl, OkHdl));
458 	String sTitle = GetText();
459 	sTitle.SearchAndReplace(C2S("%1"), pDatMan->getActiveDataTable(), 0);
460 	SetText(sTitle);
461 
462 	aListBoxes[0] = &aIdentifierLB;
463 	aListBoxes[1] = &aAuthorityTypeLB;
464 	aListBoxes[2] = &aAuthorLB;
465 	aListBoxes[3] = &aTitleLB;
466 	aListBoxes[4] = &aYearLB;
467 	aListBoxes[5] = &aISBNLB;
468 	aListBoxes[6] = &aBooktitleLB;
469 	aListBoxes[7] = &aChapterLB;
470 	aListBoxes[8] = &aEditionLB;
471 	aListBoxes[9] = &aEditorLB;
472 	aListBoxes[10] = &aHowpublishedLB;
473 	aListBoxes[11] = &aInstitutionLB;
474 	aListBoxes[12] = &aJournalLB;
475 	aListBoxes[13] = &aMonthLB;
476 	aListBoxes[14] = &aNoteLB;
477 	aListBoxes[15] = &aAnnoteLB;
478 	aListBoxes[16] = &aNumberLB;
479 	aListBoxes[17] = &aOrganizationsLB;
480 	aListBoxes[18] = &aPagesLB;
481 	aListBoxes[19] = &aPublisherLB;
482 	aListBoxes[20] = &aAddressLB;
483 	aListBoxes[21] = &aSchoolLB;
484 	aListBoxes[22] = &aSeriesLB;
485 	aListBoxes[23] = &aReportTypeLB;
486 	aListBoxes[24] = &aVolumeLB;
487 	aListBoxes[25] = &aURLLB;
488 	aListBoxes[26] = &aCustom1LB;
489 	aListBoxes[27] = &aCustom2LB;
490 	aListBoxes[28] = &aCustom3LB;
491 	aListBoxes[29] = &aCustom4LB;
492 	aListBoxes[30] = &aCustom5LB;
493 
494 	aListBoxes[0]->InsertEntry(sNone);
495 	Reference< XNameAccess >  xFields = getColumns( pDatMan->getForm() );
496 	DBG_ASSERT(xFields.is(), "MappingDialog_Impl::MappingDialog_Impl : gave me an invalid form !");
497     if(xFields.is())
498     {
499 	    Sequence< ::rtl::OUString > aNames = xFields->getElementNames();
500 	    sal_Int32 nFieldsCount = aNames.getLength();
501 	    const ::rtl::OUString* pNames = aNames.getConstArray();
502 
503 	    for(sal_Int32 nField = 0; nField < nFieldsCount; nField++)
504 		    aListBoxes[0]->InsertEntry(pNames[nField]);
505     }
506 
507 	Link aLnk = LINK(this, MappingDialog_Impl, ListBoxSelectHdl);
508 
509 	aListBoxes[0]->SelectEntryPos(0);
510 	aListBoxes[0]->SetSelectHdl(aLnk);
511 	for(sal_uInt16 i = 1; i < COLUMN_COUNT; i++)
512 	{
513 		for(sal_uInt16 j = 0; j < aListBoxes[0]->GetEntryCount();j++)
514 			aListBoxes[i]->InsertEntry(aListBoxes[0]->GetEntry(j));
515 		aListBoxes[i]->SelectEntryPos(0);
516 		aListBoxes[i]->SetSelectHdl(aLnk);
517 	}
518 	BibConfig* pConfig = BibModul::GetConfig();
519 	BibDBDescriptor aDesc;
520 	aDesc.sDataSource = pDatMan->getActiveDataSource();
521 	aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
522 	aDesc.nCommandType = CommandType::TABLE;
523 	const Mapping* pMapping = pConfig->GetMapping(aDesc);
524 	if(pMapping)
525 	{
526 		for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
527 		{
528 			sal_uInt16 nListBoxIndex = lcl_FindLogicalName( pConfig, pMapping->aColumnPairs[nEntry].sLogicalColumnName);
529 			if(nListBoxIndex < COLUMN_COUNT)
530 			{
531 				aListBoxes[nListBoxIndex]->SelectEntry(pMapping->aColumnPairs[nEntry].sRealColumnName);
532 			}
533 		}
534 	}
535 }
536 /* -----------------11.11.99 16:44-------------------
537 
538  --------------------------------------------------*/
539 MappingDialog_Impl::~MappingDialog_Impl()
540 {}
541 /* -----------------15.11.99 10:38-------------------
542 
543  --------------------------------------------------*/
544 IMPL_LINK(MappingDialog_Impl, ListBoxSelectHdl, ListBox*, pListBox)
545 {
546 	sal_uInt16 nEntryPos = pListBox->GetSelectEntryPos();
547 	if(0 < nEntryPos)
548 	{
549 		for(sal_uInt16 i = 0; i < COLUMN_COUNT; i++)
550 		{
551 			if(pListBox != aListBoxes[i] && aListBoxes[i]->GetSelectEntryPos() == nEntryPos)
552 				aListBoxes[i]->SelectEntryPos(0);
553 		}
554 	}
555 	SetModified();
556 	return 0;
557 }
558 /* -----------------12.11.99 14:50-------------------
559 
560  --------------------------------------------------*/
561 IMPL_LINK(MappingDialog_Impl, OkHdl, OKButton*, EMPTYARG)
562 {
563 	if(bModified)
564 	{
565 		Mapping aNew;
566 		aNew.sTableName = String(pDatMan->getActiveDataTable());
567 		aNew.sURL = String(pDatMan->getActiveDataSource());
568 
569 		sal_uInt16 nWriteIndex = 0;
570 		BibConfig* pConfig = BibModul::GetConfig();
571 		for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
572 		{
573 			String sSel = aListBoxes[nEntry]->GetSelectEntry();
574 			if(sSel != sNone)
575 			{
576 				aNew.aColumnPairs[nWriteIndex].sRealColumnName = sSel;
577 				aNew.aColumnPairs[nWriteIndex].sLogicalColumnName = pConfig->GetDefColumnName(nEntry);
578 				nWriteIndex++;
579 			}
580 		}
581 		BibDBDescriptor aDesc;
582 		aDesc.sDataSource = pDatMan->getActiveDataSource();
583 		aDesc.sTableOrQuery = pDatMan->getActiveDataTable();
584 		aDesc.nCommandType = CommandType::TABLE;
585 		pDatMan->ResetIdentifierMapping();
586 		pConfig->SetMapping(aDesc, &aNew);
587 	}
588 	EndDialog(bModified ? RET_OK : RET_CANCEL);
589 	return 0;
590 }
591 /* -----------------18.11.99 10:23-------------------
592 
593  --------------------------------------------------*/
594 class DBChangeDialog_Impl : public ModalDialog
595 {
596 	OKButton		aOKBT;
597 	CancelButton	aCancelBT;
598 	HelpButton		aHelpBT;
599 	FixedLine		aSelectionGB;
600 	SvTabListBox	aSelectionLB;
601 	HeaderBar		aSelectionHB;
602 	DBChangeDialogConfig_Impl	aConfig;
603 	String			aEntryST;
604 	String			aURLST;
605 
606 	BibDataManager* pDatMan;
607 
608 //	DECL_LINK(EndDragHdl, HeaderBar*);
609 	DECL_LINK(DoubleClickHdl, SvTabListBox*);
610 public:
611 	DBChangeDialog_Impl(Window* pParent, BibDataManager* pMan );
612 	~DBChangeDialog_Impl();
613 
614 	String		GetCurrentURL()const;
615 };
616 
617 /*-- 18.11.99 10:35:20---------------------------------------------------
618 
619   -----------------------------------------------------------------------*/
620 DBChangeDialog_Impl::DBChangeDialog_Impl(Window* pParent, BibDataManager* pMan ) :
621 	ModalDialog(pParent, BibResId(RID_DLG_DBCHANGE) ),
622 	aOKBT(this, 		BibResId( BT_OK		)),
623 	aCancelBT(this, 	BibResId( BT_CANCEL	)),
624 	aHelpBT(this,		BibResId( BT_HELP		)),
625 	aSelectionGB(this,	BibResId( GB_SELECTION )),
626 	aSelectionLB(this,	BibResId( LB_SELECTION )),
627 	aSelectionHB(this,	BibResId( HB_SELECTION )),
628 	aEntryST(BibResId(ST_ENTRY)),
629 	aURLST( BibResId(ST_URL)),
630 	pDatMan(pMan)
631 {
632 	FreeResource();
633 	aSelectionLB.SetDoubleClickHdl( LINK(this, DBChangeDialog_Impl, DoubleClickHdl));
634 	try
635 	{
636 		Reference< XMultiServiceFactory >  xMgr = comphelper::getProcessServiceFactory();
637 
638 		::Size aSize = aSelectionHB.GetSizePixel();
639 		long nTabs[2];
640 		nTabs[0] = 1;// Number of Tabs
641 		nTabs[1] = aSize.Width() / 4;
642 
643 		aSelectionHB.SetStyle(aSelectionHB.GetStyle()|WB_STDHEADERBAR);
644 		aSelectionHB.InsertItem( 1, aEntryST, aSize.Width());
645 		aSelectionHB.SetSizePixel(aSelectionHB.CalcWindowSizePixel());
646 		aSelectionHB.Show();
647 
648 		aSelectionLB.SetTabs( &nTabs[0], MAP_PIXEL );
649 		aSelectionLB.SetStyle(aSelectionLB.GetStyle()|WB_CLIPCHILDREN|WB_SORT);
650 		aSelectionLB.GetModel()->SetSortMode(SortAscending);
651 
652 		::rtl::OUString sActiveSource = pDatMan->getActiveDataSource();
653 		const Sequence< ::rtl::OUString >& rSources = aConfig.GetDataSourceNames();
654 		const ::rtl::OUString* pSourceNames = rSources.getConstArray();
655 		for(int i = 0; i < rSources.getLength(); i++)
656 		{
657 			SvLBoxEntry* pEntry = aSelectionLB.InsertEntry(pSourceNames[i]);
658 			if(pSourceNames[i] == sActiveSource)
659 			{
660 				aSelectionLB.Select(pEntry);
661 			}
662 		}
663 		aSelectionLB.GetModel()->Resort();
664 	}
665 	catch(Exception& e )
666 	{
667 		(void) e;	// make compiler happy
668         DBG_ERROR("Exception in BibDataManager::DBChangeDialog_Impl::DBChangeDialog_Impl");
669 	}
670 
671 
672 }
673 /* -----------------06.12.99 12:09-------------------
674 
675  --------------------------------------------------*/
676 IMPL_LINK(DBChangeDialog_Impl, DoubleClickHdl, SvTabListBox*, /*pLB*/)
677 {
678 	EndDialog(RET_OK);
679 	return 0;
680 }
681 /* -----------------18.11.99 11:17-------------------
682 
683  --------------------------------------------------*/
684 /*IMPL_LINK(DBChangeDialog_Impl, EndDragHdl, HeaderBar*, pHB)
685 {
686 	long nTabs[3];
687 	nTabs[0] = 2;// Number of Tabs
688 	nTabs[1] = 0;
689 	nTabs[2] = pHB->GetItemSize( 1 );
690 	aSelectionLB.SetTabs( &nTabs[0], MAP_PIXEL );
691 	return 0;
692 };*/
693 
694 /*-- 18.11.99 10:35:20---------------------------------------------------
695 
696   -----------------------------------------------------------------------*/
697 DBChangeDialog_Impl::~DBChangeDialog_Impl()
698 {
699 }
700 /* -----------------18.11.99 12:36-------------------
701 
702  --------------------------------------------------*/
703 String	DBChangeDialog_Impl::GetCurrentURL()const
704 {
705 	String sRet;
706 	SvLBoxEntry* pEntry = aSelectionLB.FirstSelected();
707 	if(pEntry)
708 	{
709 		sRet = aSelectionLB.GetEntryText(pEntry, 0);
710 	}
711 	return sRet;
712 }
713 
714 // #100312# --------------------------------------------------------------------
715 // XDispatchProvider
716 BibInterceptorHelper::BibInterceptorHelper( ::bib::BibBeamer* pBibBeamer, ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch)
717 {
718 	if( pBibBeamer )
719 	{
720 		xInterception = pBibBeamer->getDispatchProviderInterception();
721 		if( xInterception.is() )
722 			xInterception->registerDispatchProviderInterceptor( this );
723 	}
724 	if( xDispatch.is() )
725 		xFormDispatch = xDispatch;
726 }
727 
728 BibInterceptorHelper::~BibInterceptorHelper( )
729 {
730 }
731 
732 void BibInterceptorHelper::ReleaseInterceptor()
733 {
734 	if ( xInterception.is() )
735 		xInterception->releaseDispatchProviderInterceptor( this );
736 	xInterception.clear();
737 }
738 
739 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL
740 	BibInterceptorHelper::queryDispatch( const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags ) throw (::com::sun::star::uno::RuntimeException)
741 {
742 	Reference< XDispatch > xReturn;
743 
744 	String aCommand( aURL.Path );
745 	if ( aCommand.EqualsAscii("FormSlots/ConfirmDeletion") )
746 		xReturn = xFormDispatch;
747 	else
748 		if ( xSlaveDispatchProvider.is() )
749 			xReturn = xSlaveDispatchProvider->queryDispatch( aURL, aTargetFrameName, nSearchFlags);
750 
751 	return xReturn;
752 }
753 
754 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL
755 	BibInterceptorHelper::queryDispatches( const ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchDescriptor >& aDescripts ) throw (::com::sun::star::uno::RuntimeException)
756 {
757 	Sequence< Reference< XDispatch> > aReturn( aDescripts.getLength() );
758 	Reference< XDispatch >* pReturn = aReturn.getArray();
759 	const DispatchDescriptor* pDescripts = aDescripts.getConstArray();
760 	for ( sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts )
761 	{
762 		*pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
763 	}
764 	return aReturn;
765 }
766 
767 // XDispatchProviderInterceptor
768 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
769 	BibInterceptorHelper::getSlaveDispatchProvider(  ) throw (::com::sun::star::uno::RuntimeException)
770 {
771 	return xSlaveDispatchProvider;
772 }
773 
774 void SAL_CALL BibInterceptorHelper::setSlaveDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewSlaveDispatchProvider ) throw (::com::sun::star::uno::RuntimeException)
775 {
776 	xSlaveDispatchProvider = xNewSlaveDispatchProvider;
777 }
778 
779 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > SAL_CALL
780 	BibInterceptorHelper::getMasterDispatchProvider(  ) throw (::com::sun::star::uno::RuntimeException)
781 {
782 	return xMasterDispatchProvider;
783 }
784 
785 void SAL_CALL BibInterceptorHelper::setMasterDispatchProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& xNewMasterDispatchProvider ) throw (::com::sun::star::uno::RuntimeException)
786 {
787 	xMasterDispatchProvider = xNewMasterDispatchProvider;
788 }
789 
790 //-----------------------------------------------------------------------------
791 #define STR_UID "uid"
792 ::rtl::OUString gGridName(C2U("theGrid"));
793 ::rtl::OUString gViewName(C2U("theView"));
794 ::rtl::OUString gGlobalName(C2U("theGlobals"));
795 ::rtl::OUString gBeamerSize(C2U("theBeamerSize"));
796 ::rtl::OUString gViewSize(C2U("theViewSize"));
797 
798 BibDataManager::BibDataManager()
799 	:BibDataManager_Base( GetMutex() )
800 	// #100312# --------------
801 	,m_pInterceptorHelper( NULL )
802     ,m_aLoadListeners(m_aMutex)
803 	,pBibView( NULL )
804 	,pToolbar(0)
805 {
806 }
807 
808 /* --------------------------------------------------
809 
810  --------------------------------------------------*/
811 BibDataManager::~BibDataManager()
812 {
813 	Reference< XLoadable >		xLoad( m_xForm, UNO_QUERY );
814 	Reference< XPropertySet >	xPrSet( m_xForm, UNO_QUERY );
815 	Reference< XComponent > 	xComp( m_xForm, UNO_QUERY );
816 	if ( m_xForm.is() )
817 	{
818 		Reference< XComponent >  xConnection;
819 		xPrSet->getPropertyValue(C2U("ActiveConnection")) >>= xConnection;
820 		RemoveMeAsUidListener();
821 		if (xLoad.is())
822 			xLoad->unload();
823 		if (xComp.is())
824 			xComp->dispose();
825 		if(xConnection.is())
826 			xConnection->dispose();
827 		m_xForm = NULL;
828 	}
829 	// #100312# ----------------
830 	if( m_pInterceptorHelper )
831 	{
832 		m_pInterceptorHelper->ReleaseInterceptor();
833 		m_pInterceptorHelper->release();
834 		m_pInterceptorHelper = NULL;
835 	}
836 }
837 //------------------------------------------------------------------------
838 void BibDataManager::InsertFields(const Reference< XFormComponent > & _rxGrid)
839 {
840 	if ( !_rxGrid.is() )
841 		return;
842 
843 	try
844 	{
845 		Reference< XNameContainer > xColContainer( _rxGrid, UNO_QUERY );
846 		// remove the old fields
847 		if ( xColContainer->hasElements() )
848 		{
849 			Sequence< ::rtl::OUString > aNames = xColContainer->getElementNames();
850 			const ::rtl::OUString* pNames = aNames.getConstArray();
851 			const ::rtl::OUString* pNamesEnd = pNames + aNames.getLength();
852 			for ( ; pNames != pNamesEnd; ++pNames )
853 				xColContainer->removeByName( *pNames );
854 		}
855 
856 		Reference< XNameAccess >  xFields = getColumns( m_xForm );
857 		if (!xFields.is())
858 			return;
859 
860 		Reference< XGridColumnFactory > xColFactory( _rxGrid, UNO_QUERY );
861 
862 		Reference< XPropertySet >  xField;
863 
864 		Sequence< ::rtl::OUString > aFields( xFields->getElementNames() );
865 		const ::rtl::OUString* pFields = aFields.getConstArray();
866 		const ::rtl::OUString* pFieldsEnd = pFields + aFields.getLength();
867 
868 		for ( ; pFields != pFieldsEnd; ++pFields )
869 		{
870 			xFields->getByName( *pFields ) >>= xField;
871 
872 			::rtl::OUString sCurrentModelType;
873 			const ::rtl::OUString sType(C2U("Type"));
874 			sal_Int32 nType = 0;
875 			sal_Bool bIsFormatted			= sal_False;
876 			sal_Bool bFormattedIsNumeric	= sal_True;
877 			xField->getPropertyValue(sType) >>= nType;
878 			switch(nType)
879 			{
880 				case DataType::BIT:
881 				case DataType::BOOLEAN:
882 					sCurrentModelType = C2U("CheckBox");
883 					break;
884 
885 				case DataType::BINARY:
886 				case DataType::VARBINARY:
887 				case DataType::LONGVARBINARY:
888 				case DataType::BLOB:
889 					sCurrentModelType = C2U("TextField");
890 					break;
891 
892 				case DataType::VARCHAR:
893 				case DataType::LONGVARCHAR:
894 				case DataType::CHAR:
895 				case DataType::CLOB:
896 					bFormattedIsNumeric = sal_False;
897 					// _NO_ break !
898 				default:
899 					sCurrentModelType = C2U("FormattedField");
900 					bIsFormatted = sal_True;
901 					break;
902 			}
903 
904 			Reference< XPropertySet >  xCurrentCol = xColFactory->createColumn(sCurrentModelType);
905 			if (bIsFormatted)
906 			{
907 				::rtl::OUString sFormatKey(C2U("FormatKey"));
908 				xCurrentCol->setPropertyValue(sFormatKey, xField->getPropertyValue(sFormatKey));
909 				Any aFormatted(&bFormattedIsNumeric, ::getBooleanCppuType());
910 				xCurrentCol->setPropertyValue(C2U("TreatAsNumber"), aFormatted);
911 			}
912 			Any aColName = makeAny( *pFields );
913 			xCurrentCol->setPropertyValue(FM_PROP_CONTROLSOURCE,	aColName);
914 			xCurrentCol->setPropertyValue(FM_PROP_LABEL, aColName);
915 
916 			xColContainer->insertByName( *pFields, makeAny( xCurrentCol ) );
917 		}
918 	}
919 	catch(Exception& e )
920 	{
921 		(void) e;	// make compiler happy
922         DBG_ERROR("Exception in BibDataManager::InsertFields");
923 	}
924 }
925 /* --------------------------------------------------
926 
927  --------------------------------------------------*/
928 Reference< awt::XControlModel >	BibDataManager::updateGridModel()
929 {
930 	return updateGridModel( m_xForm );
931 }
932 /* --------------------------------------------------
933 
934  --------------------------------------------------*/
935 Reference< awt::XControlModel >	BibDataManager::updateGridModel(const Reference< XForm > & xDbForm)
936 {
937 	try
938 	{
939 		Reference< XPropertySet >  aFormPropSet( xDbForm, UNO_QUERY );
940 		::rtl::OUString sName;
941 		aFormPropSet->getPropertyValue(C2U("Command")) >>= sName;
942 
943 		if ( !m_xGridModel.is() )
944 		{
945 			m_xGridModel = createGridModel( gGridName );
946 
947 			Reference< XNameContainer >  xNameCont(xDbForm, UNO_QUERY);
948 //			if (xNameCont->hasByName(sName))
949 //				xNameCont->removeByName(sName);
950 //
951 			xNameCont->insertByName( sName, makeAny( m_xGridModel ) );
952 		}
953 
954 		// insert the fields
955 		Reference< XFormComponent > xFormComp( m_xGridModel, UNO_QUERY );
956 		InsertFields( xFormComp );
957 	}
958 	catch(Exception& e )
959 	{
960 		(void) e;	// make compiler happy
961         DBG_ERROR("::updateGridModel: something went wrong !");
962 	}
963 
964 
965 	return m_xGridModel;
966 }
967 /* --------------------------------------------------
968 
969  --------------------------------------------------*/
970 Reference< XForm >	BibDataManager::createDatabaseForm(BibDBDescriptor& rDesc)
971 {
972 	Reference< XForm >	xResult;
973 	try
974 	{
975 		Reference< XMultiServiceFactory >  xMgr = comphelper::getProcessServiceFactory();
976 		m_xForm = Reference< XForm > ( xMgr->createInstance( C2U("com.sun.star.form.component.Form") ), UNO_QUERY );
977 
978 		Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
979 
980 		aDataSourceURL = rDesc.sDataSource;
981 		if(aPropertySet.is())
982 		{
983 			Any aVal;
984 			aVal <<= (sal_Int32)ResultSetType::SCROLL_INSENSITIVE;
985 			aPropertySet->setPropertyValue(C2U("ResultSetType"),aVal );
986 			aVal <<= (sal_Int32)ResultSetConcurrency::READ_ONLY;
987 			aPropertySet->setPropertyValue(C2U("ResultSetConcurrency"), aVal);
988 
989 			//Caching for Performance
990 			aVal <<= (sal_Int32)50;
991 			aPropertySet->setPropertyValue(C2U("FetchSize"), aVal);
992 
993 			Reference< XConnection >	xConnection = getConnection(rDesc.sDataSource);
994 			aVal <<= xConnection;
995 			aPropertySet->setPropertyValue(C2U("ActiveConnection"), aVal);
996 
997 			Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
998 			Reference< XNameAccess >  xTables = xSupplyTables.is() ?
999 								xSupplyTables->getTables() : Reference< XNameAccess > ();
1000 
1001 			Sequence< ::rtl::OUString > aTableNameSeq;
1002 			if (xTables.is())
1003 				aTableNameSeq = xTables->getElementNames();
1004 
1005 			if(aTableNameSeq.getLength() > 0)
1006 			{
1007 				const ::rtl::OUString* pTableNames = aTableNameSeq.getConstArray();
1008 				if(rDesc.sTableOrQuery.getLength())
1009 					aActiveDataTable = rDesc.sTableOrQuery;
1010 				else
1011 				{
1012 					rDesc.sTableOrQuery = aActiveDataTable = pTableNames[0];
1013 					rDesc.nCommandType = CommandType::TABLE;
1014 				}
1015 
1016 				aVal <<= aActiveDataTable;
1017 				aPropertySet->setPropertyValue(C2U("Command"), aVal);
1018 				aVal <<= rDesc.nCommandType;
1019 				aPropertySet->setPropertyValue(C2U("CommandType"), aVal);
1020 
1021 
1022 				Reference< XDatabaseMetaData >	xMetaData = xConnection->getMetaData();
1023 				aQuoteChar = xMetaData->getIdentifierQuoteString();
1024 
1025 				Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
1026                 if ( xFactory.is() )
1027 				    m_xParser.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.SingleSelectQueryComposer" ) ) ), UNO_QUERY );
1028 
1029 				::rtl::OUString aString(C2U("SELECT * FROM "));
1030 
1031                 ::rtl::OUString sCatalog, sSchema, sName;
1032                 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
1033                 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
1034 
1035                 m_xParser->setElementaryQuery(aString);
1036 				BibConfig* pConfig = BibModul::GetConfig();
1037 				pConfig->setQueryField(getQueryField());
1038 				startQueryWith(pConfig->getQueryText());
1039 
1040 				xResult = m_xForm;
1041 			}
1042 		}
1043 	}
1044 	catch(Exception& e )
1045 	{
1046 		(void) e;	// make compiler happy
1047         DBG_ERROR("::createDatabaseForm: something went wrong !");
1048 	}
1049 
1050 
1051 	return xResult;
1052 }
1053 //------------------------------------------------------------------------
1054 Sequence< ::rtl::OUString > BibDataManager::getDataSources()
1055 {
1056 	Sequence< ::rtl::OUString > aTableNameSeq;
1057 
1058 	try
1059 	{
1060 		Reference< XTablesSupplier >  xSupplyTables( getConnection( m_xForm ), UNO_QUERY );
1061 		Reference< XNameAccess >  xTables;
1062 		if (xSupplyTables.is())
1063 			xTables = xSupplyTables->getTables();
1064 		if (xTables.is())
1065 			aTableNameSeq = xTables->getElementNames();
1066 	}
1067 	catch(Exception& e )
1068 	{
1069 		(void) e;	// make compiler happy
1070         DBG_ERROR("::getDataSources: something went wrong !");
1071 	}
1072 
1073 
1074 	return aTableNameSeq;
1075 }
1076 //------------------------------------------------------------------------
1077 ::rtl::OUString BibDataManager::getActiveDataTable()
1078 {
1079 	return aActiveDataTable;
1080 }
1081 //------------------------------------------------------------------------
1082 void BibDataManager::setFilter(const ::rtl::OUString& rQuery)
1083 {
1084 	if(!m_xParser.is())
1085         return;
1086     try
1087 	{
1088 		m_xParser->setFilter( rQuery );
1089 		::rtl::OUString aQuery = m_xParser->getFilter();
1090 		Reference< XPropertySet >  xFormProps( m_xForm, UNO_QUERY_THROW );
1091 		xFormProps->setPropertyValue( C2U( "Filter" ), makeAny( aQuery ) );
1092 		xFormProps->setPropertyValue( C2U( "ApplyFilter" ), makeAny( sal_True ) );
1093 		reload();
1094 	}
1095 	catch(Exception& e )
1096 	{
1097         DBG_UNHANDLED_EXCEPTION();
1098 	}
1099 
1100 
1101 }
1102 //------------------------------------------------------------------------
1103 ::rtl::OUString BibDataManager::getFilter()
1104 {
1105 
1106 	::rtl::OUString aQueryString;
1107 	try
1108 	{
1109 		Reference< XPropertySet > xFormProps( m_xForm, UNO_QUERY_THROW );
1110         OSL_VERIFY( xFormProps->getPropertyValue( C2U( "Filter" ) ) >>= aQueryString );
1111 	}
1112 	catch( const Exception& )
1113 	{
1114         DBG_UNHANDLED_EXCEPTION();
1115 	}
1116 
1117 
1118 	return aQueryString;
1119 
1120 }
1121 //------------------------------------------------------------------------
1122 Sequence< ::rtl::OUString > BibDataManager::getQueryFields()
1123 {
1124 	Sequence< ::rtl::OUString > aFieldSeq;
1125 	Reference< XNameAccess >  xFields = getColumns( m_xForm );
1126 	if (xFields.is())
1127 		aFieldSeq = xFields->getElementNames();
1128 	return aFieldSeq;
1129 }
1130 //------------------------------------------------------------------------
1131 ::rtl::OUString BibDataManager::getQueryField()
1132 {
1133 	BibConfig* pConfig = BibModul::GetConfig();
1134 	::rtl::OUString aFieldString = pConfig->getQueryField();
1135 	if(!aFieldString.getLength())
1136 	{
1137 		Sequence< ::rtl::OUString > aSeq = getQueryFields();
1138 		const ::rtl::OUString* pFields = aSeq.getConstArray();
1139 		if(aSeq.getLength()>0)
1140 		{
1141 			aFieldString=pFields[0];
1142 		}
1143 	}
1144 	return aFieldString;
1145 }
1146 //------------------------------------------------------------------------
1147 void BibDataManager::startQueryWith(const ::rtl::OUString& rQuery)
1148 {
1149 	BibConfig* pConfig = BibModul::GetConfig();
1150 	pConfig->setQueryText( rQuery );
1151 
1152 	::rtl::OUString aQueryString;
1153 	if(rQuery.getLength()>0)
1154 	{
1155 		aQueryString=aQuoteChar;
1156 		aQueryString+=getQueryField();
1157 		aQueryString+=aQuoteChar;
1158 		aQueryString+=C2U(" like '");
1159 		String sQuery(rQuery);
1160 		sQuery.SearchAndReplaceAll('?','_');
1161 		sQuery.SearchAndReplaceAll('*','%');
1162 		aQueryString += sQuery;
1163 		aQueryString+=C2U("%'");
1164 	}
1165 	setFilter(aQueryString);
1166 }
1167 /* -----------------03.12.99 15:05-------------------
1168 
1169  --------------------------------------------------*/
1170 void BibDataManager::setActiveDataSource(const ::rtl::OUString& rURL)
1171 {
1172 	::rtl::OUString uTable;
1173 	::rtl::OUString sTmp(aDataSourceURL);
1174 	aDataSourceURL = rURL;
1175 
1176 	Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
1177 	if(aPropertySet.is())
1178 	{
1179 		unload();
1180 
1181 		Reference< XComponent >  xOldConnection;
1182 		aPropertySet->getPropertyValue(C2U("ActiveConnection")) >>= xOldConnection;
1183 
1184 		Reference< XConnection >	xConnection = getConnection(rURL);
1185 		if(!xConnection.is())
1186 		{
1187 			aDataSourceURL = sTmp;
1188 			return;
1189 		}
1190 		Any aVal; aVal <<= xConnection;
1191 		aPropertySet->setPropertyValue(C2U("ActiveConnection"), aVal);
1192 		Reference< XMultiServiceFactory >   xFactory(xConnection, UNO_QUERY);
1193         if ( xFactory.is() )
1194 			m_xParser.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.SingleSelectQueryComposer" ) ) ), UNO_QUERY );
1195 
1196 		if(xOldConnection.is())
1197 			xOldConnection->dispose();
1198 
1199 		Sequence< ::rtl::OUString > aTableNameSeq;
1200 		Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
1201 		if(xSupplyTables.is())
1202 		{
1203 			Reference< XNameAccess >  xAccess = xSupplyTables->getTables();
1204 			aTableNameSeq = xAccess->getElementNames();
1205 		}
1206 		if(aTableNameSeq.getLength() > 0)
1207 		{
1208 			const ::rtl::OUString* pTableNames = aTableNameSeq.getConstArray();
1209 			aActiveDataTable = pTableNames[0];
1210 			aVal <<= aActiveDataTable;
1211 			aPropertySet->setPropertyValue(C2U("Command"), aVal);
1212             aPropertySet->setPropertyValue(C2U("CommandType"), makeAny(CommandType::TABLE));
1213             //Caching for Performance
1214             aVal <<= (sal_Int32)50;
1215             aPropertySet->setPropertyValue(C2U("FetchSize"), aVal);
1216             ::rtl::OUString aString(C2U("SELECT * FROM "));
1217 			// quote the table name which may contain catalog.schema.table
1218 			Reference<XDatabaseMetaData> xMetaData(xConnection->getMetaData(),UNO_QUERY);
1219 			aQuoteChar = xMetaData->getIdentifierQuoteString();
1220 
1221             ::rtl::OUString sCatalog, sSchema, sName;
1222             ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
1223             aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
1224 
1225             m_xParser->setElementaryQuery(aString);
1226 			BibConfig* pConfig = BibModul::GetConfig();
1227 			pConfig->setQueryField(getQueryField());
1228 			startQueryWith(pConfig->getQueryText());
1229 			setActiveDataTable(aActiveDataTable);
1230 		}
1231 		FeatureStateEvent aEvent;
1232 		util::URL aURL;
1233 		aEvent.IsEnabled  = sal_True;
1234 		aEvent.Requery	  = sal_False;
1235 		aEvent.FeatureDescriptor = getActiveDataTable();
1236 
1237 		aEvent.State = makeAny( getDataSources() );
1238 
1239 		if(pToolbar)
1240 		{
1241 			aURL.Complete =C2U(".uno:Bib/source");
1242 			aEvent.FeatureURL = aURL;
1243 			pToolbar->statusChanged( aEvent );
1244 		}
1245 
1246         updateGridModel();
1247         load();
1248     }
1249 }
1250 
1251 /* --------------------------------------------------
1252 
1253  --------------------------------------------------*/
1254 void BibDataManager::setActiveDataTable(const ::rtl::OUString& rTable)
1255 {
1256 	ResetIdentifierMapping();
1257 	try
1258 	{
1259 		Reference< XPropertySet >  aPropertySet( m_xForm, UNO_QUERY );
1260 
1261 		if(aPropertySet.is())
1262 		{
1263 			Reference< XConnection >	xConnection = getConnection( m_xForm );
1264 			Reference< XTablesSupplier >  xSupplyTables(xConnection, UNO_QUERY);
1265 			Reference< XNameAccess > xAccess = xSupplyTables->getTables();
1266 			Sequence< ::rtl::OUString > aTableNameSeq = xAccess->getElementNames();
1267 			sal_uInt32 nCount = aTableNameSeq.getLength();
1268 
1269 			const ::rtl::OUString* pTableNames = aTableNameSeq.getConstArray();
1270 			const ::rtl::OUString* pTableNamesEnd = pTableNames + nCount;
1271 
1272 			for ( ; pTableNames != pTableNamesEnd; ++pTableNames )
1273 			{
1274 				if ( rTable == *pTableNames )
1275 				{
1276 					aActiveDataTable = rTable;
1277 					Any aVal; aVal <<= rTable;
1278 					aPropertySet->setPropertyValue( C2U("Command"), aVal );
1279 					break;
1280 				}
1281 			}
1282 			if (pTableNames != pTableNamesEnd)
1283 			{
1284 				Reference< XDatabaseMetaData >	xMetaData = xConnection->getMetaData();
1285 				aQuoteChar = xMetaData->getIdentifierQuoteString();
1286 
1287 				Reference< XMultiServiceFactory > xFactory(xConnection, UNO_QUERY);
1288                 if ( xFactory.is() )
1289 				    m_xParser.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.SingleSelectQueryComposer" ) ) ), UNO_QUERY );
1290 
1291 				::rtl::OUString aString(C2U("SELECT * FROM "));
1292 
1293                 ::rtl::OUString sCatalog, sSchema, sName;
1294                 ::dbtools::qualifiedNameComponents( xMetaData, aActiveDataTable, sCatalog, sSchema, sName, ::dbtools::eInDataManipulation );
1295                 aString += ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sName );
1296 
1297                 m_xParser->setElementaryQuery(aString);
1298 
1299 				BibConfig* pConfig = BibModul::GetConfig();
1300 				pConfig->setQueryField(getQueryField());
1301 				startQueryWith(pConfig->getQueryText());
1302 
1303 				BibDBDescriptor aDesc;
1304 				aDesc.sDataSource = aDataSourceURL;
1305 				aDesc.sTableOrQuery = aActiveDataTable;
1306 				aDesc.nCommandType = CommandType::TABLE;
1307 				BibModul::GetConfig()->SetBibliographyURL(aDesc);
1308 			}
1309 		}
1310 	}
1311 	catch(Exception& e )
1312 	{
1313 		(void) e;	// make compiler happy
1314         DBG_ERROR("::setActiveDataTable: something went wrong !");
1315 	}
1316 
1317 }
1318 
1319 //------------------------------------------------------------------------
1320 void SAL_CALL BibDataManager::load(  ) throw (RuntimeException)
1321 {
1322 	if ( isLoaded() )
1323 		// nothing to do
1324 		return;
1325 
1326 	Reference< XLoadable > xFormAsLoadable( m_xForm, UNO_QUERY );
1327 	DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::load: invalid form!");
1328 	if ( xFormAsLoadable.is() )
1329 	{
1330 		xFormAsLoadable->load();
1331 		SetMeAsUidListener();
1332 
1333 		EventObject aEvt( static_cast< XWeak* >( this ) );
1334 		m_aLoadListeners.notifyEach( &XLoadListener::loaded, aEvt );
1335 	}
1336 }
1337 
1338 //------------------------------------------------------------------------
1339 void SAL_CALL BibDataManager::unload(  ) throw (RuntimeException)
1340 {
1341 	if ( !isLoaded() )
1342 		// nothing to do
1343 		return;
1344 
1345 	Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1346 	DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
1347 	if ( xFormAsLoadable.is() )
1348 	{
1349 		EventObject aEvt( static_cast< XWeak* >( this ) );
1350 
1351 		{
1352 			m_aLoadListeners.notifyEach( &XLoadListener::unloading, aEvt );
1353 		}
1354 
1355 		RemoveMeAsUidListener();
1356 		xFormAsLoadable->unload();
1357 
1358 		{
1359 			m_aLoadListeners.notifyEach( &XLoadListener::unloaded, aEvt );
1360 		}
1361 	}
1362 }
1363 
1364 //------------------------------------------------------------------------
1365 void SAL_CALL BibDataManager::reload(  ) throw (RuntimeException)
1366 {
1367 	if ( !isLoaded() )
1368 		// nothing to do
1369 		return;
1370 
1371 	Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1372 	DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::unload: invalid form!");
1373 	if ( xFormAsLoadable.is() )
1374 	{
1375 		EventObject aEvt( static_cast< XWeak* >( this ) );
1376 
1377 		{
1378 			m_aLoadListeners.notifyEach( &XLoadListener::reloading, aEvt );
1379 		}
1380 
1381 		xFormAsLoadable->reload();
1382 
1383 		{
1384 			m_aLoadListeners.notifyEach( &XLoadListener::reloaded, aEvt );
1385 		}
1386 	}
1387 }
1388 
1389 //------------------------------------------------------------------------
1390 sal_Bool SAL_CALL BibDataManager::isLoaded(  ) throw (RuntimeException)
1391 {
1392 	Reference< XLoadable >xFormAsLoadable( m_xForm, UNO_QUERY );
1393 	DBG_ASSERT( xFormAsLoadable.is() || !m_xForm.is(), "BibDataManager::isLoaded: invalid form!");
1394 
1395 	sal_Bool bLoaded = sal_False;
1396 	if ( xFormAsLoadable.is() )
1397 		bLoaded = xFormAsLoadable->isLoaded();
1398 	return bLoaded;
1399 }
1400 
1401 //------------------------------------------------------------------------
1402 void SAL_CALL BibDataManager::addLoadListener( const Reference< XLoadListener >& aListener ) throw (RuntimeException)
1403 {
1404 	m_aLoadListeners.addInterface( aListener );
1405 }
1406 
1407 //------------------------------------------------------------------------
1408 void SAL_CALL BibDataManager::removeLoadListener( const Reference< XLoadListener >& aListener ) throw (RuntimeException)
1409 {
1410 	m_aLoadListeners.removeInterface( aListener );
1411 }
1412 
1413 //------------------------------------------------------------------------
1414 Reference< awt::XControlModel >	BibDataManager::createGridModel(const ::rtl::OUString& rName)
1415 {
1416 	Reference< awt::XControlModel >	xModel;
1417 
1418 	try
1419 	{
1420 		// create the control model
1421 		Reference< XMultiServiceFactory >  xMgr = ::comphelper::getProcessServiceFactory();
1422 		Reference< XInterface >  xObject = xMgr->createInstance(C2U("com.sun.star.form.component.GridControl"));
1423 		xModel=Reference< awt::XControlModel > ( xObject, UNO_QUERY );
1424 
1425 		// set the
1426 		Reference< XPropertySet > xPropSet( xModel, UNO_QUERY );
1427 		xPropSet->setPropertyValue( C2U("Name"), makeAny( rName ) );
1428 
1429 		// set the name of the to-be-created control
1430 		::rtl::OUString aControlName(C2U("com.sun.star.form.control.InteractionGridControl"));
1431 		Any aAny; aAny <<= aControlName;
1432 		xPropSet->setPropertyValue( C2U("DefaultControl"),aAny );
1433 
1434 		// the the helpURL
1435 		::rtl::OUString uProp(C2U("HelpURL"));
1436 		Reference< XPropertySetInfo > xPropInfo = xPropSet->getPropertySetInfo();
1437 		if (xPropInfo->hasPropertyByName(uProp))
1438 		{
1439 	        ::rtl::OUString sId = ::rtl::OUString::createFromAscii( INET_HID_SCHEME );
1440 			sId += ::rtl::OUString::createFromAscii( HID_BIB_DB_GRIDCTRL );
1441 			xPropSet->setPropertyValue( uProp, makeAny( sId ) );
1442 		}
1443 	}
1444 	catch(Exception& e )
1445 	{
1446 		(void) e;	// make compiler happy
1447         DBG_ERROR("::createGridModel: something went wrong !");
1448 	}
1449 
1450 
1451 	return xModel;
1452 }
1453 //------------------------------------------------------------------------
1454 ::rtl::OUString BibDataManager::getControlName(sal_Int32 nFormatKey )
1455 {
1456 	::rtl::OUString aResStr;
1457 	switch (nFormatKey)
1458 	{
1459 		case DataType::BIT:
1460 		case DataType::BOOLEAN:
1461 			aResStr=C2U("CheckBox");
1462 			break;
1463 		case DataType::TINYINT:
1464 		case DataType::SMALLINT:
1465 		case DataType::INTEGER:
1466 			aResStr=C2U("NumericField");   ;
1467 			break;
1468 		case DataType::REAL:
1469 		case DataType::DOUBLE:
1470 		case DataType::NUMERIC:
1471 		case DataType::DECIMAL:
1472 			aResStr=C2U("FormattedField");
1473 			break;
1474 		case DataType::TIMESTAMP:
1475 			aResStr=C2U("FormattedField");
1476 			break;
1477 		case DataType::DATE:
1478 			aResStr=C2U("DateField");
1479 			break;
1480 		case DataType::TIME:
1481 			aResStr=C2U("TimeField");
1482 			break;
1483 		case DataType::CHAR:
1484 		case DataType::VARCHAR:
1485 		case DataType::LONGVARCHAR:
1486 		default:
1487 			aResStr=C2U("TextField");
1488 			break;
1489 	}
1490 	return aResStr;
1491 }
1492 //------------------------------------------------------------------------
1493 Reference< awt::XControlModel >	BibDataManager::loadControlModel(
1494 					const ::rtl::OUString& rName, sal_Bool bForceListBox)
1495 {
1496 	Reference< awt::XControlModel >	xModel;
1497 	::rtl::OUString aName(C2U("View_"));
1498 	aName += rName;
1499 
1500 	try
1501 	{
1502 		Reference< XNameAccess >  xFields = getColumns( m_xForm );
1503 		if (!xFields.is())
1504 			return xModel;
1505 		Reference< XPropertySet >  xField;
1506 
1507 		Any aElement;
1508 
1509 		if(xFields->hasByName(rName))
1510 		{
1511 			aElement = xFields->getByName(rName);
1512 			aElement >>= xField;
1513 			Reference< XPropertySetInfo >  xInfo = xField.is() ? xField->getPropertySetInfo() : Reference< XPropertySetInfo > ();
1514 
1515 			::rtl::OUString sCurrentModelType;
1516 			const ::rtl::OUString sType(C2U("Type"));
1517 			sal_Int32 nFormatKey = 0;
1518 			xField->getPropertyValue(sType) >>= nFormatKey;
1519 
1520 			::rtl::OUString aInstanceName(C2U("com.sun.star.form.component."));
1521 
1522 			if (bForceListBox)
1523 				aInstanceName += C2U("ListBox");
1524 			else
1525 				aInstanceName += getControlName(nFormatKey);
1526 
1527 			Reference< XMultiServiceFactory >  xMgr = comphelper::getProcessServiceFactory();
1528 			Reference< XInterface >  xObject = xMgr->createInstance(aInstanceName);
1529 			xModel=Reference< awt::XControlModel > ( xObject, UNO_QUERY );
1530 			Reference< XPropertySet >  xPropSet( xModel, UNO_QUERY );
1531 			Any aFieldName; aFieldName <<= aName;
1532 
1533             xPropSet->setPropertyValue( FM_PROP_NAME,aFieldName);
1534 			xPropSet->setPropertyValue( FM_PROP_CONTROLSOURCE, makeAny( rName ) );
1535 			xPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NativeWidgetLook" ) ), makeAny( (sal_Bool)sal_True ) );
1536 
1537 			Reference< XFormComponent >  aFormComp(xModel,UNO_QUERY );
1538 
1539 			Reference< XNameContainer >  xNameCont( m_xForm, UNO_QUERY );
1540 			xNameCont->insertByName(aName, makeAny( aFormComp ) );
1541 
1542 			// now if the form where we inserted the new model is already loaded, notify the model of this
1543 			// Note that this implementation below is a HACK as it relies on the fact that the model adds itself
1544 			// as load listener to it's parent, which is an implementation detail of the model.
1545 			//
1546 			// the better solution would be the following:
1547 			// in the current scenario, we insert a control model into a form. This results in the control model
1548 			// adding itself as load listener to the form. Now, the form should realize that it's already loaded
1549 			// and notify the model (which it knows as XLoadListener only) immediately. This seems to make sense.
1550 			// (as an anologon to the XStatusListener semantics).
1551 			//
1552 			// But this would be way too risky for this last-day fix here.
1553 			// 97140 - 30.01.2002 - fs@openoffice.org
1554 			Reference< XLoadable > xLoad( m_xForm, UNO_QUERY );
1555 			if ( xLoad.is() && xLoad->isLoaded() )
1556 			{
1557 				Reference< XLoadListener > xListener( aFormComp, UNO_QUERY );
1558 				if ( xListener.is() )
1559 				{
1560 					EventObject aLoadSource;
1561 					aLoadSource.Source = xLoad;
1562 					xListener->loaded( aLoadSource );
1563 				}
1564 			}
1565 		}
1566 	}
1567 	catch(Exception& e )
1568 	{
1569         (void) e;	// make compiler happy
1570         DBG_ERROR("::loadControlModel: something went wrong !");
1571 	}
1572 	return xModel;
1573 }
1574 //------------------------------------------------------------------------
1575 void SAL_CALL BibDataManager::disposing()
1576 {
1577     BibDataManager_Base::WeakComponentImplHelperBase::disposing();
1578 }
1579 
1580 //------------------------------------------------------------------------
1581 void BibDataManager::disposing( const EventObject& /*Source*/ ) throw( ::com::sun::star::uno::RuntimeException )
1582 {
1583 	// not interested in
1584 }
1585 
1586 //------------------------------------------------------------------------
1587 void BibDataManager::propertyChange(const beans::PropertyChangeEvent& evt) throw( RuntimeException )
1588 {
1589 	try
1590 	{
1591 		sal_Bool bFlag=sal_False;
1592 		if(evt.PropertyName == FM_PROP_VALUE)
1593 		{
1594 			if( evt.NewValue.getValueType() == ::getCppuType((Reference<io::XInputStream>*)0) )
1595 			{
1596 				Reference< io::XDataInputStream >  xStream(
1597 					*(const Reference< io::XInputStream > *)evt.NewValue.getValue(), UNO_QUERY );
1598 				aUID <<= xStream->readUTF();
1599 			}
1600 			else
1601 				aUID = evt.NewValue;
1602 
1603 			Reference< XRowLocate > xLocate(xBibCursor, UNO_QUERY);
1604 			DBG_ASSERT(xLocate.is(), "BibDataManager::propertyChange : invalid cursor !");
1605 			bFlag = xLocate->moveToBookmark(aUID);
1606 		}
1607 	}
1608 	catch(Exception& e )
1609 	{
1610 		(void) e;	// make compiler happy
1611         DBG_ERROR("::propertyChange: something went wrong !");
1612 	}
1613 
1614 
1615 }
1616 //------------------------------------------------------------------------
1617 void BibDataManager::SetMeAsUidListener()
1618 {
1619 try
1620 {
1621 	Reference< XNameAccess >  xFields = getColumns( m_xForm );
1622 	if (!xFields.is())
1623 		return;
1624 
1625 	Sequence< ::rtl::OUString > aFields(xFields->getElementNames());
1626 	const ::rtl::OUString* pFields = aFields.getConstArray();
1627 	sal_Int32 nCount=aFields.getLength();
1628 	String StrUID(C2S(STR_UID));
1629 	::rtl::OUString theFieldName;
1630 	for( sal_Int32 i=0; i<nCount; i++ )
1631 	{
1632 		String aName= pFields[i];
1633 
1634 		if(aName.EqualsIgnoreCaseAscii(StrUID))
1635 		{
1636 			theFieldName=pFields[i];
1637 			break;
1638 		}
1639 	}
1640 
1641 	if(theFieldName.getLength()>0)
1642 	{
1643 		Reference< XPropertySet >  xPropSet;
1644 		Any aElement;
1645 
1646 		aElement = xFields->getByName(theFieldName);
1647 		xPropSet = *(Reference< XPropertySet > *)aElement.getValue();
1648 
1649 		xPropSet->addPropertyChangeListener(FM_PROP_VALUE, this);
1650 	}
1651 
1652 }
1653 catch(Exception& e )
1654 {
1655 	(void) e;	// make compiler happy
1656     DBG_ERROR("Exception in BibDataManager::SetMeAsUidListener");
1657 }
1658 
1659 
1660 }
1661 //------------------------------------------------------------------------
1662 void BibDataManager::RemoveMeAsUidListener()
1663 {
1664 try
1665 {
1666 	Reference< XNameAccess >  xFields = getColumns( m_xForm );
1667 	if (!xFields.is())
1668 		return;
1669 
1670 
1671 	Sequence< ::rtl::OUString > aFields(xFields->getElementNames());
1672 	const ::rtl::OUString* pFields = aFields.getConstArray();
1673 	sal_Int32 nCount=aFields.getLength();
1674 	String StrUID(C2S(STR_UID));
1675 	::rtl::OUString theFieldName;
1676 	for( sal_Int32 i=0; i<nCount; i++ )
1677 	{
1678 		String aName= pFields[i];
1679 
1680 		if(aName.EqualsIgnoreCaseAscii(StrUID))
1681 		{
1682 			theFieldName=pFields[i];
1683 			break;
1684 		}
1685 	}
1686 
1687 	if(theFieldName.getLength()>0)
1688 	{
1689 		Reference< XPropertySet >  xPropSet;
1690 		Any aElement;
1691 
1692 		aElement = xFields->getByName(theFieldName);
1693 		xPropSet = *(Reference< XPropertySet > *)aElement.getValue();
1694 
1695 		xPropSet->removePropertyChangeListener(FM_PROP_VALUE, this);
1696 	}
1697 
1698 }
1699 catch(Exception& e )
1700 {
1701 	(void) e;	// make compiler happy
1702     DBG_ERROR("Exception in BibDataManager::RemoveMeAsUidListener");
1703 }
1704 
1705 
1706 }
1707 /* -----------------11.11.99 15:51-------------------
1708 
1709  --------------------------------------------------*/
1710 void BibDataManager::CreateMappingDialog(Window* pParent)
1711 {
1712 	MappingDialog_Impl* pDlg = new MappingDialog_Impl(pParent, this);
1713 	if(RET_OK == pDlg->Execute() && pBibView)
1714 	{
1715 		reload();
1716 //		unload();
1717 //		pBibView->UpdatePages();
1718 //		load();
1719 	}
1720 	delete pDlg;
1721 }
1722 /* --------------------------------------------------
1723 
1724  --------------------------------------------------*/
1725 ::rtl::OUString BibDataManager::CreateDBChangeDialog(Window* pParent)
1726 {
1727 	::rtl::OUString uRet;
1728 	DBChangeDialog_Impl * pDlg = new DBChangeDialog_Impl(pParent, this );
1729 	if(RET_OK == pDlg->Execute())
1730 	{
1731 		String sNewURL = pDlg->GetCurrentURL();
1732 		if(sNewURL != String(getActiveDataSource()))
1733 		{
1734 			uRet = sNewURL;
1735 		}
1736 	}
1737 	delete pDlg;
1738 	return uRet;
1739 }
1740 /*-- 18.05.2004 15:20:15---------------------------------------------------
1741 
1742   -----------------------------------------------------------------------*/
1743 void BibDataManager::DispatchDBChangeDialog()
1744 {
1745     if(pToolbar)
1746         pToolbar->SendDispatch(TBC_BT_CHANGESOURCE, Sequence< PropertyValue >());
1747 }
1748 /* -----------------06.12.99 15:11-------------------
1749 
1750  --------------------------------------------------*/
1751 const ::rtl::OUString& BibDataManager::GetIdentifierMapping()
1752 {
1753 	if(!sIdentifierMapping.getLength())
1754 	{
1755 		BibConfig* pConfig = BibModul::GetConfig();
1756 		BibDBDescriptor aDesc;
1757 		aDesc.sDataSource = getActiveDataSource();
1758 		aDesc.sTableOrQuery = getActiveDataTable();
1759 		aDesc.nCommandType = CommandType::TABLE;
1760 		const Mapping* pMapping = pConfig->GetMapping(aDesc);
1761 		sIdentifierMapping = pConfig->GetDefColumnName(IDENTIFIER_POS);
1762 		if(pMapping)
1763 		{
1764 			for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
1765 			{
1766 				if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == sIdentifierMapping)
1767 				{
1768 					sIdentifierMapping = pMapping->aColumnPairs[nEntry].sRealColumnName;
1769 					break;
1770 				}
1771 			}
1772 		}
1773 	}
1774 	return sIdentifierMapping;
1775 }
1776 /* -----------------------------20.11.00 10:31--------------------------------
1777 
1778  ---------------------------------------------------------------------------*/
1779 void BibDataManager::SetToolbar(BibToolBar* pSet)
1780 {
1781 	pToolbar = pSet;
1782 	if(pToolbar)
1783 		pToolbar->SetDatMan(*this);
1784 }
1785 /* -----------------------------08.05.2002 09:26------------------------------
1786 
1787  ---------------------------------------------------------------------------*/
1788 uno::Reference< form::runtime::XFormController > BibDataManager::GetFormController()
1789 {
1790     if(!m_xFormCtrl.is())
1791     {
1792         Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
1793         m_xFormCtrl = uno::Reference< form::runtime::XFormController > (
1794             xMgr->createInstance(C2U("com.sun.star.form.runtime.FormController")), UNO_QUERY);
1795         m_xFormCtrl->setModel(uno::Reference< awt::XTabControllerModel > (getForm(), UNO_QUERY));
1796         // #100312# -------------
1797         m_xFormDispatch = uno::Reference< frame::XDispatch > ( m_xFormCtrl, UNO_QUERY);
1798     }
1799     return m_xFormCtrl;
1800 }
1801 
1802 // #100312# ----------
1803 void BibDataManager::RegisterInterceptor( ::bib::BibBeamer* pBibBeamer)
1804 {
1805 	DBG_ASSERT( !m_pInterceptorHelper, "BibDataManager::RegisterInterceptor: called twice!" );
1806 
1807 	if( pBibBeamer )
1808 		m_pInterceptorHelper = new BibInterceptorHelper( pBibBeamer, m_xFormDispatch);
1809 	if( m_pInterceptorHelper )
1810 		m_pInterceptorHelper->acquire();
1811 }
1812 
1813 /*-- 18.05.2004 17:04:20---------------------------------------------------
1814 
1815   -----------------------------------------------------------------------*/
1816 sal_Bool BibDataManager::HasActiveConnection()const
1817 {
1818     sal_Bool bRet = sal_False;
1819     Reference< XPropertySet >   xPrSet( m_xForm, UNO_QUERY );
1820     if( xPrSet.is() )
1821     {
1822         Reference< XComponent >  xConnection;
1823         xPrSet->getPropertyValue(C2U("ActiveConnection")) >>= xConnection;
1824         bRet = xConnection.is();
1825     }
1826     return bRet;
1827 }
1828 /*-- 04.06.2004 14:37:29---------------------------------------------------
1829 
1830   -----------------------------------------------------------------------*/
1831 sal_Bool BibDataManager::HasActiveConnection()
1832 {
1833     return getConnection( m_xForm ).is();
1834 }
1835