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