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