merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / relationdesign / RelationController.cxx
blobb47782baa23f2e2d4d45aa7300b6c250f50c851b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RelationController.cxx,v $
10 * $Revision: 1.56.24.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef _DBAU_REGHELPER_HXX_
34 #include "dbu_reghelper.hxx"
35 #endif
36 #ifndef _SFXSIDS_HRC
37 #include <sfx2/sfxsids.hrc>
38 #endif
39 #ifndef _DBU_REL_HRC_
40 #include "dbu_rel.hrc"
41 #endif
42 #ifndef _SV_SVAPP_HXX
43 #include <vcl/svapp.hxx>
44 #endif
45 #ifndef DBACCESS_UI_BROWSER_ID_HXX
46 #include "browserids.hxx"
47 #endif
48 #ifndef _COMPHELPER_TYPES_HXX_
49 #include <comphelper/types.hxx>
50 #endif
51 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
52 #include "dbustrings.hrc"
53 #endif
54 #ifndef _CONNECTIVITY_DBTOOLS_HXX_
55 #include <connectivity/dbtools.hxx>
56 #endif
57 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
58 #include <com/sun/star/frame/FrameSearchFlag.hpp>
59 #endif
60 #ifndef _COMPHELPER_EXTRACT_HXX_
61 #include <comphelper/extract.hxx>
62 #endif
63 #ifndef _COM_SUN_STAR_CONTAINER_XCHILD_HPP_
64 #include <com/sun/star/container/XChild.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
67 #include <com/sun/star/container/XNameContainer.hpp>
68 #endif
69 #ifndef _COM_SUN_STAR_SDBCX_XDATADESCRIPTORFACTORY_HPP_
70 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
71 #endif
72 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
73 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
74 #endif
75 #ifndef _COM_SUN_STAR_SDBCX_KEYTYPE_HPP_
76 #include <com/sun/star/sdbcx/KeyType.hpp>
77 #endif
78 #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
79 #include <com/sun/star/sdbcx/XDrop.hpp>
80 #endif
81 #ifndef _COM_SUN_STAR_SDBCX_XALTERTABLE_HPP_
82 #include <com/sun/star/sdbcx/XAlterTable.hpp>
83 #endif
84 #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
85 #include <com/sun/star/sdbcx/XAppend.hpp>
86 #endif
87 #ifndef _COM_SUN_STAR_SDBCX_XKEYSSUPPLIER_HPP_
88 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
89 #endif
90 #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
91 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
92 #endif
93 #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
94 #include <com/sun/star/sdb/SQLContext.hpp>
95 #endif
96 #ifndef _COM_SUN_STAR_SDBC_SQLWARNING_HPP_
97 #include <com/sun/star/sdbc/SQLWarning.hpp>
98 #endif
99 #ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
100 #include <com/sun/star/sdbc/ColumnValue.hpp>
101 #endif
102 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
103 #include <com/sun/star/sdbc/XRow.hpp>
104 #endif
105 #ifndef _DBHELPER_DBEXCEPTION_HXX_
106 #include <connectivity/dbexception.hxx>
107 #endif
108 #ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
109 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
110 #endif
111 #ifndef _COMPHELPER_STREAMSECTION_HXX_
112 #include <comphelper/streamsection.hxx>
113 #endif
114 #ifndef _COMPHELPER_BASIC_IO_HXX_
115 #include <comphelper/basicio.hxx>
116 #endif
117 #ifndef _COMPHELPER_SEQSTREAM_HXX
118 #include <comphelper/seqstream.hxx>
119 #endif
120 #ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
121 #include <com/sun/star/io/XActiveDataSource.hpp>
122 #endif
123 #ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_
124 #include <com/sun/star/io/XActiveDataSink.hpp>
125 #endif
126 #ifndef _DBAUI_SQLMESSAGE_HXX_
127 #include "sqlmessage.hxx"
128 #endif
129 #ifndef DBAUI_RELATIONCONTROLLER_HXX
130 #include "RelationController.hxx"
131 #endif
132 #ifndef _SV_MSGBOX_HXX
133 #include <vcl/msgbox.hxx>
134 #endif
135 #include "TableWindowData.hxx"
136 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
137 #include "dbustrings.hrc"
138 #endif
139 #ifndef DBAUI_TOOLS_HXX
140 #include "UITools.hxx"
141 #endif
142 #ifndef DBAUI_RTABLECONNECTIONDATA_HXX
143 #include "RTableConnectionData.hxx"
144 #endif
145 #ifndef DBAUI_RELATION_TABLEVIEW_HXX
146 #include "RelationTableView.hxx"
147 #endif
148 #ifndef DBAUI_RELATIONDESIGNVIEW_HXX
149 #include "RelationDesignView.hxx"
150 #endif
151 #ifndef _TOOLS_DEBUG_HXX
152 #include <tools/debug.hxx>
153 #endif
154 #ifndef TOOLS_DIAGNOSE_EX_H
155 #include <tools/diagnose_ex.h>
156 #endif
157 #ifndef _SV_WAITOBJ_HXX
158 #include <vcl/waitobj.hxx>
159 #endif
160 #include <osl/thread.hxx>
161 #include <vos/mutex.hxx>
164 #define MAX_THREADS 10
166 extern "C" void SAL_CALL createRegistryInfo_ORelationControl()
168 static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::ORelationController > aAutoRegistration;
172 using namespace ::com::sun::star::uno;
173 using namespace ::com::sun::star::io;
174 using namespace ::com::sun::star::beans;
175 using namespace ::com::sun::star::frame;
176 using namespace ::com::sun::star::util;
177 using namespace ::com::sun::star::lang;
178 using namespace ::com::sun::star::container;
179 using namespace ::com::sun::star::sdbcx;
180 using namespace ::com::sun::star::sdbc;
181 using namespace ::com::sun::star::sdb;
182 using namespace ::com::sun::star::ui::dialogs;
183 using namespace ::com::sun::star::util;
184 // using namespace ::com::sun::star::sdbcx;
185 // using namespace ::connectivity;
186 using namespace ::dbtools;
187 using namespace ::dbaui;
188 using namespace ::comphelper;
189 using namespace ::osl;
191 //------------------------------------------------------------------------------
192 ::rtl::OUString SAL_CALL ORelationController::getImplementationName() throw( RuntimeException )
194 return getImplementationName_Static();
197 //------------------------------------------------------------------------------
198 ::rtl::OUString ORelationController::getImplementationName_Static() throw( RuntimeException )
200 return ::rtl::OUString::createFromAscii("org.openoffice.comp.dbu.ORelationDesign");
202 //------------------------------------------------------------------------------
203 Sequence< ::rtl::OUString> ORelationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
205 Sequence< ::rtl::OUString> aSupported(1);
206 aSupported.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.RelationDesign");
207 return aSupported;
209 //-------------------------------------------------------------------------
210 Sequence< ::rtl::OUString> SAL_CALL ORelationController::getSupportedServiceNames() throw(RuntimeException)
212 return getSupportedServiceNames_Static();
214 // -------------------------------------------------------------------------
215 Reference< XInterface > SAL_CALL ORelationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
217 return *(new ORelationController(_rxFactory));
219 DBG_NAME(ORelationController);
220 // -----------------------------------------------------------------------------
221 ORelationController::ORelationController(const Reference< XMultiServiceFactory >& _rM)
222 : OJoinController(_rM)
223 ,m_nThreadEvent(0)
224 ,m_bRelationsPossible(sal_True)
226 DBG_CTOR(ORelationController,NULL);
227 InvalidateAll();
229 // -----------------------------------------------------------------------------
230 ORelationController::~ORelationController()
232 DBG_DTOR(ORelationController,NULL);
234 // -----------------------------------------------------------------------------
235 FeatureState ORelationController::GetState(sal_uInt16 _nId) const
237 FeatureState aReturn;
238 aReturn.bEnabled = m_bRelationsPossible;
239 switch (_nId)
241 case SID_RELATION_ADD_RELATION:
242 aReturn.bEnabled = !m_vTableData.empty() && isConnected() && isEditable();
243 aReturn.bChecked = false;
244 break;
245 case ID_BROWSER_SAVEDOC:
246 aReturn.bEnabled = haveDataSource() && isModified();
247 break;
248 default:
249 aReturn = OJoinController::GetState(_nId);
250 break;
252 return aReturn;
254 // -----------------------------------------------------------------------------
255 void ORelationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
257 switch(_nId)
259 case ID_BROWSER_SAVEDOC:
261 OSL_ENSURE(isEditable(),"Slot ID_BROWSER_SAVEDOC should not be enabled!");
262 if(!::dbaui::checkDataSourceAvailable(::comphelper::getString(getDataSource()->getPropertyValue(PROPERTY_NAME)),getORB()))
264 String aMessage(ModuleRes(STR_DATASOURCE_DELETED));
265 OSQLWarningBox( getView(), aMessage ).Execute();
267 else
269 // now we save the layout information
270 // create the output stream
273 if ( haveDataSource() && getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) )
275 Sequence<PropertyValue> aWindows;
276 saveTableWindows(aWindows);
277 getDataSource()->setPropertyValue(PROPERTY_LAYOUTINFORMATION,makeAny(aWindows));
278 setModified(sal_False);
281 catch(Exception&)
286 break;
287 case SID_RELATION_ADD_RELATION:
288 static_cast<ORelationTableView*>(static_cast<ORelationDesignView*>(m_pView)->getTableView())->AddNewRelation();
289 break;
290 default:
291 OJoinController::Execute(_nId,aArgs);
292 return;
294 InvalidateFeature(_nId);
296 // -----------------------------------------------------------------------------
297 void ORelationController::impl_initialize()
299 OJoinController::impl_initialize();
301 if( !getSdbMetaData().supportsRelations() )
302 {// check if this database supports relations
304 setEditable(sal_False);
305 m_bRelationsPossible = sal_False;
307 String sTitle(ModuleRes(STR_RELATIONDESIGN));
308 sTitle.Erase(0,3);
309 OSQLMessageBox aDlg(NULL,sTitle,ModuleRes(STR_RELATIONDESIGN_NOT_AVAILABLE));
310 aDlg.Execute();
312 disconnect();
313 throw SQLException();
316 if(!m_bRelationsPossible)
317 InvalidateAll();
319 // we need a datasource
320 OSL_ENSURE(haveDataSource(),"ORelationController::initialize: need a datasource!");
322 Reference<XTablesSupplier> xSup(getConnection(),UNO_QUERY);
323 OSL_ENSURE(xSup.is(),"Connection isn't a XTablesSupplier!");
324 if(xSup.is())
325 m_xTables = xSup->getTables();
326 // load the layoutInformation
327 loadLayoutInformation();
330 loadData();
331 if ( !m_nThreadEvent )
332 Application::PostUserEvent(LINK(this, ORelationController, OnThreadFinished));
334 catch( const Exception& )
336 DBG_UNHANDLED_EXCEPTION();
340 // -----------------------------------------------------------------------------
341 ::rtl::OUString ORelationController::getPrivateTitle( ) const
343 ::rtl::OUString sName = getDataSourceName();
344 return ::dbaui::getStrippedDatabaseName(getDataSource(),sName);
346 // -----------------------------------------------------------------------------
347 sal_Bool ORelationController::Construct(Window* pParent)
349 m_pView = new ORelationDesignView( pParent, *this, getORB() );
350 OJoinController::Construct(pParent);
351 // m_pView->Construct();
352 // m_pView->Show();
353 return sal_True;
355 // -----------------------------------------------------------------------------
356 short ORelationController::saveModified()
358 short nSaved = RET_YES;
359 if(haveDataSource() && isModified())
361 QueryBox aQry(getView(), ModuleRes(RELATION_DESIGN_SAVEMODIFIED));
362 nSaved = aQry.Execute();
363 if(nSaved == RET_YES)
364 Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
366 return nSaved;
368 // -----------------------------------------------------------------------------
369 void ORelationController::describeSupportedFeatures()
371 OJoinController::describeSupportedFeatures();
372 implDescribeSupportedFeature( ".uno:DBAddRelation", SID_RELATION_ADD_RELATION, CommandGroup::EDIT );
374 namespace
376 class RelationLoader : public ::osl::Thread
378 DECLARE_STL_MAP(::rtl::OUString,::boost::shared_ptr<OTableWindowData>,::comphelper::UStringMixLess,TTableDataHelper);
379 TTableDataHelper m_aTableData;
380 TTableConnectionData m_vTableConnectionData;
381 const Sequence< ::rtl::OUString> m_aTableList;
382 ORelationController* m_pParent;
383 const Reference< XDatabaseMetaData> m_xMetaData;
384 const Reference< XNameAccess > m_xTables;
385 const sal_Int32 m_nStartIndex;
386 const sal_Int32 m_nEndIndex;
388 public:
389 RelationLoader(ORelationController* _pParent
390 ,const Reference< XDatabaseMetaData>& _xMetaData
391 ,const Reference< XNameAccess >& _xTables
392 ,const Sequence< ::rtl::OUString>& _aTableList
393 ,const sal_Int32 _nStartIndex
394 ,const sal_Int32 _nEndIndex)
395 :m_aTableData(_xMetaData.is() && _xMetaData->supportsMixedCaseQuotedIdentifiers())
396 ,m_aTableList(_aTableList)
397 ,m_pParent(_pParent)
398 ,m_xMetaData(_xMetaData)
399 ,m_xTables(_xTables)
400 ,m_nStartIndex(_nStartIndex)
401 ,m_nEndIndex(_nEndIndex)
405 protected:
406 virtual ~RelationLoader(){}
408 /// Working method which should be overridden.
409 virtual void SAL_CALL run();
410 virtual void SAL_CALL onTerminated();
411 void loadTableData(const Any& _aTable);
414 void SAL_CALL RelationLoader::run()
416 const ::rtl::OUString* pIter = m_aTableList.getConstArray() + m_nStartIndex;
417 for(sal_Int32 i = m_nStartIndex; i < m_nEndIndex;++i,++pIter)
419 ::rtl::OUString sCatalog,sSchema,sTable;
420 ::dbtools::qualifiedNameComponents(m_xMetaData,
421 *pIter,
422 sCatalog,
423 sSchema,
424 sTable,
425 ::dbtools::eInDataManipulation);
426 Any aCatalog;
427 if ( sCatalog.getLength() )
428 aCatalog <<= sCatalog;
432 Reference< XResultSet > xResult = m_xMetaData->getImportedKeys(aCatalog, sSchema,sTable);
433 if ( xResult.is() && xResult->next() )
435 ::comphelper::disposeComponent(xResult);
436 loadTableData(m_xTables->getByName(*pIter));
437 } // if ( xResult.is() && xResult->next() )
439 catch( const Exception& )
441 DBG_UNHANDLED_EXCEPTION();
445 void SAL_CALL RelationLoader::onTerminated()
447 m_pParent->mergeData(m_vTableConnectionData);
448 delete this;
451 void RelationLoader::loadTableData(const Any& _aTable)
453 Reference<XPropertySet> xTableProp(_aTable,UNO_QUERY);
454 const ::rtl::OUString sSourceName = ::dbtools::composeTableName( m_xMetaData, xTableProp, ::dbtools::eInTableDefinitions, false, false, false );
455 TTableDataHelper::iterator aFind = m_aTableData.find(sSourceName);
456 bool bNotFound = true, bAdded = false;
457 if ( aFind == m_aTableData.end() )
459 aFind = m_aTableData.insert(TTableDataHelper::value_type(sSourceName,::boost::shared_ptr<OTableWindowData>(new OTableWindowData(xTableProp,sSourceName, sSourceName)))).first;
460 aFind->second->ShowAll(FALSE);
461 bAdded = true;
463 TTableWindowData::value_type pReferencingTable = aFind->second;
464 Reference<XIndexAccess> xKeys = pReferencingTable->getKeys();
465 const Reference<XKeysSupplier> xKeySup(xTableProp,UNO_QUERY);
467 if ( !xKeys.is() && xKeySup.is() )
469 xKeys = xKeySup->getKeys();
472 if ( xKeys.is() )
474 Reference<XPropertySet> xKey;
475 const sal_Int32 nCount = xKeys->getCount();
476 for(sal_Int32 i = 0 ; i < nCount ; ++i)
478 xKeys->getByIndex(i) >>= xKey;
479 sal_Int32 nKeyType = 0;
480 xKey->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
481 if ( KeyType::FOREIGN == nKeyType )
483 bNotFound = false;
484 ::rtl::OUString sReferencedTable;
485 xKey->getPropertyValue(PROPERTY_REFERENCEDTABLE) >>= sReferencedTable;
486 //////////////////////////////////////////////////////////////////////
487 // insert windows
488 TTableDataHelper::iterator aRefFind = m_aTableData.find(sReferencedTable);
489 if ( aRefFind == m_aTableData.end() )
491 if ( m_xTables->hasByName(sReferencedTable) )
493 Reference<XPropertySet> xReferencedTable(m_xTables->getByName(sReferencedTable),UNO_QUERY);
494 aRefFind = m_aTableData.insert(TTableDataHelper::value_type(sReferencedTable,::boost::shared_ptr<OTableWindowData>(new OTableWindowData(xReferencedTable,sReferencedTable, sReferencedTable)))).first;
495 aRefFind->second->ShowAll(FALSE);
497 else
498 continue; // table name could not be found so we do not show this table releation
499 } // if ( aFind == m_aTableData.end() )
500 TTableWindowData::value_type pReferencedTable = aRefFind->second;
502 ::rtl::OUString sKeyName;
503 xKey->getPropertyValue(PROPERTY_NAME) >>= sKeyName;
504 //////////////////////////////////////////////////////////////////////
505 // insert connection
506 ORelationTableConnectionData* pTabConnData = new ORelationTableConnectionData( pReferencingTable, pReferencedTable, sKeyName );
507 m_vTableConnectionData.push_back(TTableConnectionData::value_type(pTabConnData));
508 //////////////////////////////////////////////////////////////////////
509 // insert columns
510 const Reference<XColumnsSupplier> xColsSup(xKey,UNO_QUERY);
511 OSL_ENSURE(xColsSup.is(),"Key is no XColumnsSupplier!");
512 const Reference<XNameAccess> xColumns = xColsSup->getColumns();
513 const Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
514 const ::rtl::OUString* pIter = aNames.getConstArray();
515 const ::rtl::OUString* pEnd = pIter + aNames.getLength();
516 ::rtl::OUString sColumnName,sRelatedName;
517 for(sal_uInt16 j=0;pIter != pEnd;++pIter,++j)
519 const Reference<XPropertySet> xPropSet(xColumns->getByName(*pIter),UNO_QUERY);
520 OSL_ENSURE(xPropSet.is(),"Invalid column found in KeyColumns!");
521 if ( xPropSet.is() )
523 xPropSet->getPropertyValue(PROPERTY_NAME) >>= sColumnName;
524 xPropSet->getPropertyValue(PROPERTY_RELATEDCOLUMN) >>= sRelatedName;
526 pTabConnData->SetConnLine( j, sColumnName, sRelatedName );
528 //////////////////////////////////////////////////////////////////////
529 // Update/Del-Flags setzen
530 sal_Int32 nUpdateRule = 0;
531 sal_Int32 nDeleteRule = 0;
532 xKey->getPropertyValue(PROPERTY_UPDATERULE) >>= nUpdateRule;
533 xKey->getPropertyValue(PROPERTY_DELETERULE) >>= nDeleteRule;
535 pTabConnData->SetUpdateRules( nUpdateRule );
536 pTabConnData->SetDeleteRules( nDeleteRule );
538 //////////////////////////////////////////////////////////////////////
539 // Kardinalitaet setzen
540 pTabConnData->SetCardinality();
543 } // if ( xKeys.is() )
547 void ORelationController::mergeData(const TTableConnectionData& _aConnectionData)
549 ::osl::MutexGuard aGuard( getMutex() );
551 ::std::copy( _aConnectionData.begin(), _aConnectionData.end(), ::std::back_inserter( m_vTableConnectionData ));
552 //const Reference< XDatabaseMetaData> xMetaData = getConnection()->getMetaData();
553 const sal_Bool bCase = sal_True;//xMetaData.is() && xMetaData->supportsMixedCaseQuotedIdentifiers();
554 // here we are finished, so we can collect the table from connection data
555 TTableConnectionData::iterator aConnDataIter = m_vTableConnectionData.begin();
556 TTableConnectionData::iterator aConnDataEnd = m_vTableConnectionData.end();
557 for(;aConnDataIter != aConnDataEnd;++aConnDataIter)
559 if ( !existsTable((*aConnDataIter)->getReferencingTable()->GetComposedName(),bCase) )
561 m_vTableData.push_back((*aConnDataIter)->getReferencingTable());
563 if ( !existsTable((*aConnDataIter)->getReferencedTable()->GetComposedName(),bCase) )
565 m_vTableData.push_back((*aConnDataIter)->getReferencedTable());
567 } // for(;aConnDataIter != aConnDataEnd;++aConnDataIter)
568 --m_nThreadEvent;
569 if ( !m_nThreadEvent )
570 Application::PostUserEvent(LINK(this, ORelationController, OnThreadFinished));
572 // -----------------------------------------------------------------------------
573 IMPL_LINK( ORelationController, OnThreadFinished, void*, /*NOTINTERESTEDIN*/ )
575 vos::OGuard aSolarGuard( Application::GetSolarMutex() );
576 ::osl::MutexGuard aGuard( getMutex() );
579 getView()->initialize(); // show the windows and fill with our informations
580 getView()->Invalidate(INVALIDATE_NOERASE);
581 getUndoMgr()->Clear(); // clear all undo redo things
582 setModified(sal_False); // and we are not modified yet
584 if(m_vTableData.empty())
585 Execute(ID_BROWSER_ADDTABLE,Sequence<PropertyValue>());
587 catch( const Exception& )
589 DBG_UNHANDLED_EXCEPTION();
591 m_pWaitObject.reset();
592 return 0L;
594 // -----------------------------------------------------------------------------
595 void ORelationController::loadData()
597 m_pWaitObject.reset( new WaitObject(getView()) );
600 if ( !m_xTables.is() )
601 return;
602 // this may take some time
603 const Reference< XDatabaseMetaData> xMetaData = getConnection()->getMetaData();
604 const Sequence< ::rtl::OUString> aNames = m_xTables->getElementNames();
605 const sal_Int32 nCount = aNames.getLength();
606 const sal_Int32 nMaxElements = (nCount / MAX_THREADS) +1;
608 sal_Int32 nStart = 0,nEnd = ::std::min(nMaxElements,nCount);
609 while(nStart != nEnd)
611 ++m_nThreadEvent;
612 RelationLoader* pThread = new RelationLoader(this,xMetaData,m_xTables,aNames,nStart,nEnd);
613 pThread->createSuspended();
614 pThread->setPriority(osl_Thread_PriorityBelowNormal);
615 pThread->resume();
616 nStart = nEnd;
617 nEnd += nMaxElements;
618 nEnd = ::std::min(nEnd,nCount);
619 } // for(;pIter != pEnd;++pIter)
621 catch(SQLException& e)
623 showError(SQLExceptionInfo(e));
625 catch(const Exception&)
627 DBG_UNHANDLED_EXCEPTION();
630 // -----------------------------------------------------------------------------
631 TTableWindowData::value_type ORelationController::existsTable(const ::rtl::OUString& _rComposedTableName,sal_Bool _bCase) const
633 ::comphelper::UStringMixEqual bCase(_bCase);
634 TTableWindowData::const_iterator aIter = m_vTableData.begin();
635 TTableWindowData::const_iterator aEnd = m_vTableData.end();
636 for(;aIter != aEnd;++aIter)
638 if(bCase((*aIter)->GetComposedName(),_rComposedTableName))
639 break;
641 return ( aIter != aEnd) ? *aIter : TTableWindowData::value_type();
643 // -----------------------------------------------------------------------------
644 void ORelationController::loadLayoutInformation()
648 OSL_ENSURE(haveDataSource(),"We need a datasource from our connection!");
649 if ( haveDataSource() )
651 if ( getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) )
653 Sequence<PropertyValue> aWindows;
654 getDataSource()->getPropertyValue(PROPERTY_LAYOUTINFORMATION) >>= aWindows;
655 loadTableWindows(aWindows);
659 catch(Exception&)
663 // -----------------------------------------------------------------------------
664 void ORelationController::reset()
666 loadLayoutInformation();
667 ODataView* pView = getView();
668 OSL_ENSURE(pView,"No current view!");
669 if(pView)
671 pView->initialize();
672 pView->Invalidate(INVALIDATE_NOERASE);
676 // -----------------------------------------------------------------------------
677 bool ORelationController::allowViews() const
679 return false;
682 // -----------------------------------------------------------------------------
683 bool ORelationController::allowQueries() const
685 return false;
688 // -----------------------------------------------------------------------------