1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "RelationTableView.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "JoinExchange.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <comphelper/extract.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "browserids.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
54cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
55cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
56cdf0e10cSrcweir #include "dbustrings.hrc"
57cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
58cdf0e10cSrcweir #include <comphelper/sequence.hxx>
59cdf0e10cSrcweir #include <tools/debug.hxx>
60cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
61cdf0e10cSrcweir #include "RelationDesignView.hxx"
62cdf0e10cSrcweir #include "JoinController.hxx"
63cdf0e10cSrcweir #include "TableWindow.hxx"
64cdf0e10cSrcweir #include "TableWindowData.hxx"
65cdf0e10cSrcweir #include "RTableConnection.hxx"
66cdf0e10cSrcweir #include "RTableConnectionData.hxx"
67cdf0e10cSrcweir #include "RelationDlg.hxx"
68cdf0e10cSrcweir #include "sqlmessage.hxx"
69cdf0e10cSrcweir #include "dbu_rel.hrc"
70cdf0e10cSrcweir #include "UITools.hxx"
71cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
72cdf0e10cSrcweir #include "RTableWindow.hxx"
73cdf0e10cSrcweir #include "JAccess.hxx"
74cdf0e10cSrcweir #include <svl/undo.hxx>
75cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
76cdf0e10cSrcweir 
77cdf0e10cSrcweir using namespace dbaui;
78cdf0e10cSrcweir using namespace ::dbtools;
79cdf0e10cSrcweir using namespace ::com::sun::star;
80cdf0e10cSrcweir using namespace ::com::sun::star::uno;
81cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
82cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
83cdf0e10cSrcweir using namespace ::com::sun::star::beans;
84cdf0e10cSrcweir using namespace ::com::sun::star::container;
85cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir //==================================================================
88cdf0e10cSrcweir // class ORelationTableView
89cdf0e10cSrcweir //==================================================================
DBG_NAME(ORelationTableView)90cdf0e10cSrcweir DBG_NAME(ORelationTableView)
91cdf0e10cSrcweir //------------------------------------------------------------------------
92cdf0e10cSrcweir ORelationTableView::ORelationTableView( Window* pParent, ORelationDesignView* pView )
93cdf0e10cSrcweir 	:OJoinTableView( pParent, pView )
94cdf0e10cSrcweir     , ::comphelper::OContainerListener(m_aMutex)
95cdf0e10cSrcweir 	,m_pExistingConnection(NULL)
96cdf0e10cSrcweir     ,m_bInRemove(false)
97cdf0e10cSrcweir 
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	DBG_CTOR(ORelationTableView,NULL);
100cdf0e10cSrcweir 	SetHelpId(HID_CTL_RELATIONTAB);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //------------------------------------------------------------------------
~ORelationTableView()104cdf0e10cSrcweir ORelationTableView::~ORelationTableView()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	DBG_DTOR(ORelationTableView,NULL);
107cdf0e10cSrcweir     if ( m_pContainerListener.is() )
108cdf0e10cSrcweir         m_pContainerListener->dispose();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //------------------------------------------------------------------------
ReSync()112cdf0e10cSrcweir void ORelationTableView::ReSync()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	DBG_CHKTHIS(ORelationTableView,NULL);
115cdf0e10cSrcweir     if ( !m_pContainerListener.is() )
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         Reference< XConnection> xConnection = m_pView->getController().getConnection();
118cdf0e10cSrcweir         Reference< XTablesSupplier > xTableSupp( xConnection, UNO_QUERY_THROW );
119cdf0e10cSrcweir         Reference< XNameAccess > xTables = xTableSupp->getTables();
120cdf0e10cSrcweir         Reference< XContainer> xContainer(xTables,uno::UNO_QUERY);
121cdf0e10cSrcweir         if ( xContainer.is() )
122cdf0e10cSrcweir             m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer);
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir 	// Es kann sein, dass in der DB Tabellen ausgeblendet wurden, die eigentlich Bestandteil einer Relation sind. Oder eine Tabelle
125cdf0e10cSrcweir 	// befand sich im Layout (durchaus ohne Relation), existiert aber nicht mehr. In beiden Faellen wird das Anlegen des TabWins schief
126cdf0e10cSrcweir 	// gehen, und alle solchen TabWinDatas oder darauf bezogenen ConnDatas muss ich dann loeschen.
127cdf0e10cSrcweir 	::std::vector< ::rtl::OUString> arrInvalidTables;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
130cdf0e10cSrcweir 	// create and insert windows
131cdf0e10cSrcweir 	TTableWindowData* pTabWinDataList = m_pView->getController().getTableWindowData();
132cdf0e10cSrcweir 	TTableWindowData::reverse_iterator aIter = pTabWinDataList->rbegin();
133cdf0e10cSrcweir 	for(;aIter != pTabWinDataList->rend();++aIter)
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		TTableWindowData::value_type pData = *aIter;
136cdf0e10cSrcweir 	    OTableWindow* pTabWin = createWindow(pData);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	    if (!pTabWin->Init())
139cdf0e10cSrcweir 	    {
140cdf0e10cSrcweir 		    // das Initialisieren ging schief, dass heisst, dieses TabWin steht nicht zur Verfuegung, also muss ich es inklusive
141cdf0e10cSrcweir 		    // seiner Daten am Dokument aufraeumen
142cdf0e10cSrcweir 		    pTabWin->clearListBox();
143cdf0e10cSrcweir 		    delete pTabWin;
144cdf0e10cSrcweir 		    arrInvalidTables.push_back(pData->GetTableName());
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 		    pTabWinDataList->erase( ::std::remove(pTabWinDataList->begin(),pTabWinDataList->end(),*aIter) ,pTabWinDataList->end());
147cdf0e10cSrcweir 		    continue;
148cdf0e10cSrcweir 	    }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	    (*GetTabWinMap())[pData->GetComposedName()] = pTabWin;	// am Anfang einfuegen, da ich die DataList ja rueckwaerts durchlaufe
151cdf0e10cSrcweir 	    // wenn in den Daten keine Position oder Groesse steht -> Default
152cdf0e10cSrcweir 	    if (!pData->HasPosition() && !pData->HasSize())
153cdf0e10cSrcweir 		    SetDefaultTabWinPosSize(pTabWin);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	    pTabWin->Show();
156cdf0e10cSrcweir 	}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	// Verbindungen einfuegen
159cdf0e10cSrcweir 	TTableConnectionData* pTabConnDataList = m_pView->getController().getTableConnectionData();
160cdf0e10cSrcweir 	TTableConnectionData::reverse_iterator aConIter = pTabConnDataList->rbegin();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	for(;aConIter != pTabConnDataList->rend();++aConIter)
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		ORelationTableConnectionData* pTabConnData = static_cast<ORelationTableConnectionData*>(aConIter->get());
165cdf0e10cSrcweir 		if ( !arrInvalidTables.empty() )
166cdf0e10cSrcweir 		{
167cdf0e10cSrcweir 			// gibt es die beiden Tabellen zur Connection ?
168cdf0e10cSrcweir 			::rtl::OUString strTabExistenceTest = pTabConnData->getReferencingTable()->GetTableName();
169cdf0e10cSrcweir 			sal_Bool bInvalid = ::std::find(arrInvalidTables.begin(),arrInvalidTables.end(),strTabExistenceTest) != arrInvalidTables.end();
170cdf0e10cSrcweir 			strTabExistenceTest = pTabConnData->getReferencedTable()->GetTableName();
171cdf0e10cSrcweir 			bInvalid = bInvalid || ::std::find(arrInvalidTables.begin(),arrInvalidTables.end(),strTabExistenceTest) != arrInvalidTables.end();
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 			if (bInvalid)
174cdf0e10cSrcweir 			{	// nein -> Pech gehabt, die Connection faellt weg
175cdf0e10cSrcweir 				pTabConnDataList->erase( ::std::remove(pTabConnDataList->begin(),pTabConnDataList->end(),*aConIter),pTabConnDataList->end() );
176cdf0e10cSrcweir 				continue;
177cdf0e10cSrcweir 			}
178cdf0e10cSrcweir 		} // if ( !arrInvalidTables.empty() )
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		addConnection( new ORelationTableConnection(this, *aConIter), sal_False ); // don't add the data again
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	if ( !GetTabWinMap()->empty() )
184cdf0e10cSrcweir 		GetTabWinMap()->begin()->second->GrabFocus();
185cdf0e10cSrcweir }
186cdf0e10cSrcweir //------------------------------------------------------------------------------
IsAddAllowed()187cdf0e10cSrcweir sal_Bool ORelationTableView::IsAddAllowed()
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	DBG_CHKTHIS(ORelationTableView,NULL);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	return !m_pView->getController().isReadOnly();
192cdf0e10cSrcweir }
193cdf0e10cSrcweir //------------------------------------------------------------------------
AddConnection(const OJoinExchangeData & jxdSource,const OJoinExchangeData & jxdDest)194cdf0e10cSrcweir void ORelationTableView::AddConnection(const OJoinExchangeData& jxdSource, const OJoinExchangeData& jxdDest)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	DBG_CHKTHIS(ORelationTableView,NULL);
197cdf0e10cSrcweir 	// Aus selektierten Feldnamen LineDataObject setzen
198cdf0e10cSrcweir 	// check if relation already exists
199cdf0e10cSrcweir 	OTableWindow* pSourceWin = jxdSource.pListBox->GetTabWin();
200cdf0e10cSrcweir 	OTableWindow* pDestWin = jxdDest.pListBox->GetTabWin();
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	::std::vector<OTableConnection*>::const_iterator aIter = getTableConnections()->begin();
203cdf0e10cSrcweir     ::std::vector<OTableConnection*>::const_iterator aEnd = getTableConnections()->end();
204cdf0e10cSrcweir 	for(;aIter != aEnd;++aIter)
205cdf0e10cSrcweir 	{
206cdf0e10cSrcweir 		OTableConnection* pFirst = *aIter;
207cdf0e10cSrcweir 		if((pFirst->GetSourceWin() == pSourceWin && pFirst->GetDestWin() == pDestWin) ||
208cdf0e10cSrcweir 		   (pFirst->GetSourceWin() == pDestWin  && pFirst->GetDestWin() == pSourceWin))
209cdf0e10cSrcweir 		{
210cdf0e10cSrcweir 			m_pExistingConnection = pFirst;
211cdf0e10cSrcweir 			break;
212cdf0e10cSrcweir 		}
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir 	// insert table connection into view
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	TTableConnectionData::value_type pTabConnData(new ORelationTableConnectionData(pSourceWin->GetData(),
217cdf0e10cSrcweir 														                           pDestWin->GetData()));
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	// die Namen der betroffenen Felder
220cdf0e10cSrcweir     ::rtl::OUString sSourceFieldName = jxdSource.pListBox->GetEntryText(jxdSource.pEntry);
221cdf0e10cSrcweir     ::rtl::OUString sDestFieldName = jxdDest.pListBox->GetEntryText(jxdDest.pEntry);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	// die Anzahl der PKey-Felder in der Quelle
224cdf0e10cSrcweir     const Reference< XNameAccess> xPrimaryKeyColumns = getPrimaryKeyColumns_throw(pSourceWin->GetData()->getTable());
225cdf0e10cSrcweir     bool bAskUser = xPrimaryKeyColumns.is() && Reference< XIndexAccess>(xPrimaryKeyColumns,UNO_QUERY)->getCount() > 1;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     pTabConnData->SetConnLine( 0, sSourceFieldName, sDestFieldName );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	if ( bAskUser || m_pExistingConnection )
230cdf0e10cSrcweir 		m_pCurrentlyTabConnData = pTabConnData; // this implies that we ask the user what to do
231cdf0e10cSrcweir 	else
232cdf0e10cSrcweir 	{
233cdf0e10cSrcweir 		try
234cdf0e10cSrcweir 		{
235cdf0e10cSrcweir 			//////////////////////////////////////////////////////////////////////
236cdf0e10cSrcweir 			// Daten der Datenbank uebergeben
237cdf0e10cSrcweir 			if( pTabConnData->Update() )
238cdf0e10cSrcweir 			{
239cdf0e10cSrcweir 				//////////////////////////////////////////////////////////////////////
240cdf0e10cSrcweir 				// UI-Object in ConnListe eintragen
241cdf0e10cSrcweir 				addConnection( new ORelationTableConnection( this, pTabConnData ) );
242cdf0e10cSrcweir 			}
243cdf0e10cSrcweir 		}
244cdf0e10cSrcweir 		catch(const SQLException&)
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir 			throw;
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 		catch(const Exception&)
249cdf0e10cSrcweir 		{
250cdf0e10cSrcweir 			OSL_ENSURE(0,"ORelationTableView::AddConnection: Exception oocured!");
251cdf0e10cSrcweir 		}
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir //------------------------------------------------------------------------
ConnDoubleClicked(OTableConnection * pConnection)257cdf0e10cSrcweir void ORelationTableView::ConnDoubleClicked( OTableConnection* pConnection )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	DBG_CHKTHIS(ORelationTableView,NULL);
260cdf0e10cSrcweir 	ORelationDialog aRelDlg( this, pConnection->GetData() );
261cdf0e10cSrcweir 	switch (aRelDlg.Execute())
262cdf0e10cSrcweir 	{
263cdf0e10cSrcweir 		case RET_OK:
264cdf0e10cSrcweir 			// successfully updated
265cdf0e10cSrcweir 			pConnection->UpdateLineList();
266cdf0e10cSrcweir 			// The connection references 1 ConnData and n ConnLines, each ConnData references n LineDatas, each Line exactly 1 LineData
267cdf0e10cSrcweir 			// As the Dialog and the ConnData->Update may have changed the LineDatas we have to restore the consistent state
268cdf0e10cSrcweir 			break;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 		case RET_NO:
271cdf0e10cSrcweir 			// tried at least one update, but did not succeed -> the original connection is lost
272cdf0e10cSrcweir 			RemoveConnection( pConnection ,sal_True);
273cdf0e10cSrcweir 			break;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 		case RET_CANCEL:
276cdf0e10cSrcweir 			// no break, as nothing happened and we don't need the code below
277cdf0e10cSrcweir 			return;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	}
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	Invalidate(INVALIDATE_NOCHILDREN);
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir //------------------------------------------------------------------------------
AddNewRelation()285cdf0e10cSrcweir void ORelationTableView::AddNewRelation()
286cdf0e10cSrcweir {
287cdf0e10cSrcweir 	DBG_CHKTHIS(ORelationTableView,NULL);
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	TTableConnectionData::value_type pNewConnData( new ORelationTableConnectionData() );
290cdf0e10cSrcweir 	ORelationDialog aRelDlg(this, pNewConnData, sal_True);
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	sal_Bool bSuccess = (aRelDlg.Execute() == RET_OK);
293cdf0e10cSrcweir 	if (bSuccess)
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		// already updated by the dialog
296cdf0e10cSrcweir 		// dem Dokument bekanntgeben
297cdf0e10cSrcweir 		addConnection( new ORelationTableConnection(this, pNewConnData) );
298cdf0e10cSrcweir 	}
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir //------------------------------------------------------------------------------
RemoveConnection(OTableConnection * pConn,sal_Bool)302cdf0e10cSrcweir bool ORelationTableView::RemoveConnection( OTableConnection* pConn ,sal_Bool /*_bDelete*/)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir 	DBG_CHKTHIS(ORelationTableView,NULL);
305cdf0e10cSrcweir 	ORelationTableConnectionData* pTabConnData = (ORelationTableConnectionData*)pConn->GetData().get();
306cdf0e10cSrcweir 	try
307cdf0e10cSrcweir 	{
308cdf0e10cSrcweir 		if ( m_bInRemove || pTabConnData->DropRelation())
309cdf0e10cSrcweir 			return OJoinTableView::RemoveConnection( pConn ,sal_True);
310cdf0e10cSrcweir 	}
311cdf0e10cSrcweir 	catch(SQLException& e)
312cdf0e10cSrcweir 	{
313cdf0e10cSrcweir 		getDesignView()->getController().showError(SQLExceptionInfo(e));
314cdf0e10cSrcweir 	}
315cdf0e10cSrcweir 	catch(Exception&)
316cdf0e10cSrcweir 	{
317cdf0e10cSrcweir 		OSL_ENSURE(0,"ORelationTableView::RemoveConnection: Something other than SQLException occured!");
318cdf0e10cSrcweir 	}
319cdf0e10cSrcweir 	return false;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir //------------------------------------------------------------------------------
AddTabWin(const::rtl::OUString & _rComposedName,const::rtl::OUString & rWinName,sal_Bool)323cdf0e10cSrcweir void ORelationTableView::AddTabWin(const ::rtl::OUString& _rComposedName, const ::rtl::OUString& rWinName, sal_Bool /*bNewTable*/)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir 	DBG_CHKTHIS(ORelationTableView,NULL);
326cdf0e10cSrcweir 	OSL_ENSURE(_rComposedName.getLength(),"There must be a table name supplied!");
327cdf0e10cSrcweir 	OJoinTableView::OTableWindowMap::iterator aIter = GetTabWinMap()->find(_rComposedName);
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 	if(aIter != GetTabWinMap()->end())
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir 		aIter->second->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
332cdf0e10cSrcweir 		aIter->second->GrabFocus();
333cdf0e10cSrcweir 		EnsureVisible(aIter->second);
334cdf0e10cSrcweir 		// no new one
335cdf0e10cSrcweir 		return;
336cdf0e10cSrcweir 	}
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////
339cdf0e10cSrcweir 	// Neue Datenstruktur in DocShell eintragen
340cdf0e10cSrcweir     TTableWindowData::value_type pNewTabWinData(createTableWindowData( _rComposedName, rWinName,rWinName ));
341cdf0e10cSrcweir 	pNewTabWinData->ShowAll(sal_False);
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////
344cdf0e10cSrcweir 	// Neues Fenster in Fensterliste eintragen
345cdf0e10cSrcweir 	OTableWindow* pNewTabWin = createWindow( pNewTabWinData );
346cdf0e10cSrcweir 	if(pNewTabWin->Init())
347cdf0e10cSrcweir 	{
348cdf0e10cSrcweir 		m_pView->getController().getTableWindowData()->push_back( pNewTabWinData);
349cdf0e10cSrcweir 		// when we already have a table with this name insert the full qualified one instead
350cdf0e10cSrcweir 		(*GetTabWinMap())[_rComposedName] = pNewTabWin;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 		SetDefaultTabWinPosSize( pNewTabWin );
353cdf0e10cSrcweir 		pNewTabWin->Show();
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 		modified();
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 		if ( m_pAccessible )
358cdf0e10cSrcweir 			m_pAccessible->notifyAccessibleEvent(	AccessibleEventId::CHILD,
359cdf0e10cSrcweir 													Any(),
360cdf0e10cSrcweir 													makeAny(pNewTabWin->GetAccessible()));
361cdf0e10cSrcweir 	}
362cdf0e10cSrcweir 	else
363cdf0e10cSrcweir 	{
364cdf0e10cSrcweir 		pNewTabWin->clearListBox();
365cdf0e10cSrcweir 		delete pNewTabWin;
366cdf0e10cSrcweir 	}
367cdf0e10cSrcweir }
368cdf0e10cSrcweir // -----------------------------------------------------------------------------
RemoveTabWin(OTableWindow * pTabWin)369cdf0e10cSrcweir void ORelationTableView::RemoveTabWin( OTableWindow* pTabWin )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir 	OSQLWarningBox aDlg( this, ModuleRes( STR_QUERY_REL_DELETE_WINDOW ), WB_YES_NO | WB_DEF_YES );
372cdf0e10cSrcweir 	if ( m_bInRemove || aDlg.Execute() == RET_YES )
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir         m_pView->getController().ClearUndoManager();
375cdf0e10cSrcweir 		OJoinTableView::RemoveTabWin( pTabWin );
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 		m_pView->getController().InvalidateFeature(SID_RELATION_ADD_RELATION);
378cdf0e10cSrcweir         m_pView->getController().InvalidateFeature(ID_BROWSER_UNDO);
379cdf0e10cSrcweir         m_pView->getController().InvalidateFeature(ID_BROWSER_REDO);
380cdf0e10cSrcweir 	}
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir // -----------------------------------------------------------------------------
lookForUiActivities()384cdf0e10cSrcweir void ORelationTableView::lookForUiActivities()
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	if(m_pExistingConnection)
387cdf0e10cSrcweir 	{
388cdf0e10cSrcweir         String sTitle(ModuleRes(STR_RELATIONDESIGN));
389cdf0e10cSrcweir 	    sTitle.Erase(0,3);
390cdf0e10cSrcweir 		OSQLMessageBox aDlg(this,ModuleRes(STR_QUERY_REL_EDIT_RELATION),String(),0);
391cdf0e10cSrcweir         aDlg.SetText(sTitle);
392cdf0e10cSrcweir         aDlg.RemoveButton(aDlg.GetButtonId(0));
393cdf0e10cSrcweir         aDlg.AddButton( ModuleRes(STR_QUERY_REL_EDIT), BUTTONID_OK, BUTTONDIALOG_DEFBUTTON | BUTTONDIALOG_FOCUSBUTTON);
394cdf0e10cSrcweir         aDlg.AddButton( ModuleRes(STR_QUERY_REL_CREATE), BUTTONID_YES, 0);
395cdf0e10cSrcweir         aDlg.AddButton(BUTTON_CANCEL,BUTTONID_CANCEL,0);
396cdf0e10cSrcweir         sal_uInt16 nRet = aDlg.Execute();
397cdf0e10cSrcweir 		if( nRet == RET_CANCEL)
398cdf0e10cSrcweir         {
399cdf0e10cSrcweir             m_pCurrentlyTabConnData.reset();
400cdf0e10cSrcweir         }
401cdf0e10cSrcweir         else if ( nRet == RET_OK ) // EDIT
402cdf0e10cSrcweir         {
403cdf0e10cSrcweir 			ConnDoubleClicked(m_pExistingConnection);
404cdf0e10cSrcweir             m_pCurrentlyTabConnData.reset();
405cdf0e10cSrcweir         }
406cdf0e10cSrcweir 		m_pExistingConnection = NULL;
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 	if(m_pCurrentlyTabConnData)
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 		ORelationDialog aRelDlg( this, m_pCurrentlyTabConnData );
411cdf0e10cSrcweir 		if (aRelDlg.Execute() == RET_OK)
412cdf0e10cSrcweir 		{
413cdf0e10cSrcweir 			// already updated by the dialog
414cdf0e10cSrcweir 			addConnection( new ORelationTableConnection( this, m_pCurrentlyTabConnData ) );
415cdf0e10cSrcweir 		}
416cdf0e10cSrcweir 		m_pCurrentlyTabConnData.reset();
417cdf0e10cSrcweir 	}
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir // -----------------------------------------------------------------------------
createWindow(const TTableWindowData::value_type & _pData)421cdf0e10cSrcweir OTableWindow* ORelationTableView::createWindow(const TTableWindowData::value_type& _pData)
422cdf0e10cSrcweir {
423cdf0e10cSrcweir 	return new ORelationTableWindow(this,_pData);
424cdf0e10cSrcweir }
425cdf0e10cSrcweir // -----------------------------------------------------------------------------
allowQueries() const426cdf0e10cSrcweir bool ORelationTableView::allowQueries() const
427cdf0e10cSrcweir {
428cdf0e10cSrcweir     return false;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir // -----------------------------------------------------------------------------
_elementInserted(const container::ContainerEvent &)431cdf0e10cSrcweir void ORelationTableView::_elementInserted( const container::ContainerEvent& /*_rEvent*/ )  throw(::com::sun::star::uno::RuntimeException)
432cdf0e10cSrcweir {
433cdf0e10cSrcweir 
434cdf0e10cSrcweir }
435cdf0e10cSrcweir // -----------------------------------------------------------------------------
_elementRemoved(const container::ContainerEvent & _rEvent)436cdf0e10cSrcweir void ORelationTableView::_elementRemoved( const container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException)
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     m_bInRemove = true;
439cdf0e10cSrcweir     ::rtl::OUString sName;
440cdf0e10cSrcweir     if ( _rEvent.Accessor >>= sName )
441cdf0e10cSrcweir     {
442cdf0e10cSrcweir         OTableWindow* pTableWindow = GetTabWindow(sName);
443cdf0e10cSrcweir         if ( pTableWindow )
444cdf0e10cSrcweir         {
445cdf0e10cSrcweir             m_pView->getController().ClearUndoManager();
446cdf0e10cSrcweir 		    OJoinTableView::RemoveTabWin( pTableWindow );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 		    m_pView->getController().InvalidateFeature(SID_RELATION_ADD_RELATION);
449cdf0e10cSrcweir             m_pView->getController().InvalidateFeature(ID_BROWSER_UNDO);
450cdf0e10cSrcweir             m_pView->getController().InvalidateFeature(ID_BROWSER_REDO);
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir     } // if ( _rEvent.Accessor >>= sName )
453cdf0e10cSrcweir     m_bInRemove = false;
454cdf0e10cSrcweir }
455cdf0e10cSrcweir // -----------------------------------------------------------------------------
_elementReplaced(const container::ContainerEvent &)456cdf0e10cSrcweir void ORelationTableView::_elementReplaced( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
460