1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <sot/formats.hxx>
31cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
35cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
37cdf0e10cSrcweir #include <com/sun/star/sdb/XDatabaseAccess.hpp>
38cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp>
42cdf0e10cSrcweir #include <com/sun/star/container/XContainerListener.hpp>
43cdf0e10cSrcweir #include <com/sun/star/container/XContainer.hpp>
44cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
45cdf0e10cSrcweir #include <svx/dbaexchange.hxx>
46cdf0e10cSrcweir
47cdf0e10cSrcweir #ifndef _DBMGR_HXX
48cdf0e10cSrcweir #include <dbmgr.hxx>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #include <swmodule.hxx>
51cdf0e10cSrcweir #ifndef _VIEW_HXX
52cdf0e10cSrcweir #include <view.hxx>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #include <wrtsh.hxx>
55cdf0e10cSrcweir #include <dbtree.hxx>
56cdf0e10cSrcweir #include <vos/mutex.hxx>
57cdf0e10cSrcweir #include <vcl/svapp.hxx>
58cdf0e10cSrcweir
59cdf0e10cSrcweir #ifndef _HELPID_H
60cdf0e10cSrcweir #include <helpid.h>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #ifndef _UTLUI_HRC
63cdf0e10cSrcweir #include <utlui.hrc>
64cdf0e10cSrcweir #endif
65cdf0e10cSrcweir
66cdf0e10cSrcweir #include <unomid.h>
67cdf0e10cSrcweir
68cdf0e10cSrcweir using namespace ::com::sun::star;
69cdf0e10cSrcweir using namespace ::com::sun::star::uno;
70cdf0e10cSrcweir using namespace ::com::sun::star::container;
71cdf0e10cSrcweir using namespace ::com::sun::star::lang;
72cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
73cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
74cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
75cdf0e10cSrcweir using namespace ::com::sun::star::task;
76cdf0e10cSrcweir using namespace ::com::sun::star::beans;
77cdf0e10cSrcweir
78cdf0e10cSrcweir /* -----------------------------17.07.01 13:10--------------------------------
79cdf0e10cSrcweir
80cdf0e10cSrcweir ---------------------------------------------------------------------------*/
81cdf0e10cSrcweir struct SwConnectionData
82cdf0e10cSrcweir {
83cdf0e10cSrcweir ::rtl::OUString sSourceName;
84cdf0e10cSrcweir Reference<XConnection> xConnection;
85cdf0e10cSrcweir };
86cdf0e10cSrcweir
87cdf0e10cSrcweir typedef SwConnectionData* SwConnectionDataPtr;
88cdf0e10cSrcweir SV_DECL_PTRARR_DEL( SwConnectionArr, SwConnectionDataPtr, 32, 32 )
89cdf0e10cSrcweir SV_IMPL_PTRARR( SwConnectionArr, SwConnectionDataPtr )
90cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
91cdf0e10cSrcweir
92cdf0e10cSrcweir ---------------------------------------------------------------------------*/
93cdf0e10cSrcweir class SwDBTreeList_Impl : public cppu::WeakImplHelper1 < XContainerListener >
94cdf0e10cSrcweir {
95cdf0e10cSrcweir Reference< XNameAccess > xDBContext;
96cdf0e10cSrcweir SwConnectionArr aConnections;
97cdf0e10cSrcweir SwWrtShell* pWrtSh;
98cdf0e10cSrcweir
99cdf0e10cSrcweir public:
SwDBTreeList_Impl(SwWrtShell * pShell)100cdf0e10cSrcweir SwDBTreeList_Impl(SwWrtShell* pShell) :
101cdf0e10cSrcweir pWrtSh(pShell) {}
102cdf0e10cSrcweir ~SwDBTreeList_Impl();
103cdf0e10cSrcweir
104cdf0e10cSrcweir virtual void SAL_CALL elementInserted( const ContainerEvent& Event ) throw (RuntimeException);
105cdf0e10cSrcweir virtual void SAL_CALL elementRemoved( const ContainerEvent& Event ) throw (RuntimeException);
106cdf0e10cSrcweir virtual void SAL_CALL elementReplaced( const ContainerEvent& Event ) throw (RuntimeException);
107cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException);
108cdf0e10cSrcweir
109cdf0e10cSrcweir sal_Bool HasContext();
GetWrtShell()110cdf0e10cSrcweir SwWrtShell* GetWrtShell() { return pWrtSh;}
SetWrtShell(SwWrtShell & rSh)111cdf0e10cSrcweir void SetWrtShell(SwWrtShell& rSh) { pWrtSh = &rSh;}
GetContext()112cdf0e10cSrcweir Reference< XNameAccess > GetContext() {return xDBContext;}
113cdf0e10cSrcweir Reference<XConnection> GetConnection(const rtl::OUString& rSourceName);
114cdf0e10cSrcweir };
115cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
116cdf0e10cSrcweir
117cdf0e10cSrcweir ---------------------------------------------------------------------------*/
~SwDBTreeList_Impl()118cdf0e10cSrcweir SwDBTreeList_Impl::~SwDBTreeList_Impl()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir Reference<XContainer> xContainer(xDBContext, UNO_QUERY);
121cdf0e10cSrcweir if(xContainer.is())
122cdf0e10cSrcweir {
123cdf0e10cSrcweir m_refCount++;
124cdf0e10cSrcweir //block necessary due to solaris' compiler behaviour to
125cdf0e10cSrcweir //remove temporaries at the block's end
126cdf0e10cSrcweir {
127cdf0e10cSrcweir xContainer->removeContainerListener( this );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir m_refCount--;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
133cdf0e10cSrcweir
134cdf0e10cSrcweir ---------------------------------------------------------------------------*/
elementInserted(const ContainerEvent &)135cdf0e10cSrcweir void SwDBTreeList_Impl::elementInserted( const ContainerEvent& ) throw (RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir // information not needed
138cdf0e10cSrcweir }
139cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
140cdf0e10cSrcweir
141cdf0e10cSrcweir ---------------------------------------------------------------------------*/
elementRemoved(const ContainerEvent & rEvent)142cdf0e10cSrcweir void SwDBTreeList_Impl::elementRemoved( const ContainerEvent& rEvent ) throw (RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir vos::OGuard aGuard(Application::GetSolarMutex());
145cdf0e10cSrcweir ::rtl::OUString sSource;
146cdf0e10cSrcweir rEvent.Accessor >>= sSource;
147cdf0e10cSrcweir for(sal_uInt16 i = 0; i < aConnections.Count(); i++)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir SwConnectionDataPtr pPtr = aConnections[i];
150cdf0e10cSrcweir if(pPtr->sSourceName == sSource)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir // SwConnectionDataPtr pPtr = aConnections[i];
153cdf0e10cSrcweir // Reference<XComponent> xComp(pPtr->xConnection, UNO_QUERY);
154cdf0e10cSrcweir // if(xComp.is())
155cdf0e10cSrcweir // xComp->dispose();
156cdf0e10cSrcweir aConnections.DeleteAndDestroy(i);
157cdf0e10cSrcweir break;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir }
161cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
162cdf0e10cSrcweir
163cdf0e10cSrcweir ---------------------------------------------------------------------------*/
disposing(const EventObject &)164cdf0e10cSrcweir void SwDBTreeList_Impl::disposing( const EventObject& ) throw (RuntimeException)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir xDBContext = 0;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
169cdf0e10cSrcweir
170cdf0e10cSrcweir ---------------------------------------------------------------------------*/
elementReplaced(const ContainerEvent & rEvent)171cdf0e10cSrcweir void SwDBTreeList_Impl::elementReplaced( const ContainerEvent& rEvent ) throw (RuntimeException)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir elementRemoved(rEvent);
174cdf0e10cSrcweir }
175cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
176cdf0e10cSrcweir
177cdf0e10cSrcweir ---------------------------------------------------------------------------*/
HasContext()178cdf0e10cSrcweir sal_Bool SwDBTreeList_Impl::HasContext()
179cdf0e10cSrcweir {
180cdf0e10cSrcweir if(!xDBContext.is())
181cdf0e10cSrcweir {
182cdf0e10cSrcweir Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
183cdf0e10cSrcweir if( xMgr.is() )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir Reference<XInterface> xInstance = xMgr->createInstance(
186cdf0e10cSrcweir C2U( "com.sun.star.sdb.DatabaseContext" ));
187cdf0e10cSrcweir xDBContext = Reference<XNameAccess>(xInstance, UNO_QUERY) ;
188cdf0e10cSrcweir Reference<XContainer> xContainer(xDBContext, UNO_QUERY);
189cdf0e10cSrcweir if(xContainer.is())
190cdf0e10cSrcweir xContainer->addContainerListener( this );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir DBG_ASSERT(xDBContext.is(), "com.sun.star.sdb.DataBaseContext: service not available");
193cdf0e10cSrcweir }
194cdf0e10cSrcweir return xDBContext.is();
195cdf0e10cSrcweir }
196cdf0e10cSrcweir /* -----------------------------17.07.01 13:24--------------------------------
197cdf0e10cSrcweir
198cdf0e10cSrcweir ---------------------------------------------------------------------------*/
GetConnection(const rtl::OUString & rSourceName)199cdf0e10cSrcweir Reference<XConnection> SwDBTreeList_Impl::GetConnection(const rtl::OUString& rSourceName)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir Reference<XConnection> xRet;
202cdf0e10cSrcweir for(sal_uInt16 i = 0; i < aConnections.Count(); i++)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir SwConnectionDataPtr pPtr = aConnections[i];
205cdf0e10cSrcweir if(pPtr->sSourceName == rSourceName)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir xRet = pPtr->xConnection;
208cdf0e10cSrcweir break;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir }
211cdf0e10cSrcweir if(!xRet.is() && xDBContext.is() && pWrtSh)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir SwConnectionDataPtr pPtr = new SwConnectionData();
214cdf0e10cSrcweir pPtr->sSourceName = rSourceName;
215cdf0e10cSrcweir xRet = pWrtSh->GetNewDBMgr()->RegisterConnection(pPtr->sSourceName);
216cdf0e10cSrcweir aConnections.Insert(pPtr, aConnections.Count());
217cdf0e10cSrcweir }
218cdf0e10cSrcweir return xRet;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir /*------------------------------------------------------------------------
221cdf0e10cSrcweir Beschreibung:
222cdf0e10cSrcweir ------------------------------------------------------------------------*/
SwDBTreeList(Window * pParent,const ResId & rResId,SwWrtShell * pSh,const String & rDefDBName,const sal_Bool bShowCol)223cdf0e10cSrcweir SwDBTreeList::SwDBTreeList(Window *pParent, const ResId& rResId,
224cdf0e10cSrcweir SwWrtShell* pSh,
225cdf0e10cSrcweir const String& rDefDBName, const sal_Bool bShowCol):
226cdf0e10cSrcweir
227cdf0e10cSrcweir SvTreeListBox (pParent, rResId),
228cdf0e10cSrcweir aImageList (SW_RES(ILIST_DB_DLG )),
229cdf0e10cSrcweir aImageListHC (SW_RES(ILIST_DB_DLG_HC )),
230cdf0e10cSrcweir sDefDBName (rDefDBName),
231cdf0e10cSrcweir bInitialized (sal_False),
232cdf0e10cSrcweir bShowColumns (bShowCol),
233cdf0e10cSrcweir pImpl(new SwDBTreeList_Impl(pSh))
234cdf0e10cSrcweir {
235cdf0e10cSrcweir SetHelpId(HID_DB_SELECTION_TLB);
236cdf0e10cSrcweir
237cdf0e10cSrcweir if (IsVisible())
238cdf0e10cSrcweir InitTreeList();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
241cdf0e10cSrcweir /*------------------------------------------------------------------------
242cdf0e10cSrcweir Beschreibung:
243cdf0e10cSrcweir ------------------------------------------------------------------------*/
~SwDBTreeList()244cdf0e10cSrcweir SwDBTreeList::~SwDBTreeList()
245cdf0e10cSrcweir {
246cdf0e10cSrcweir delete pImpl;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir /*------------------------------------------------------------------------
250cdf0e10cSrcweir Beschreibung:
251cdf0e10cSrcweir ------------------------------------------------------------------------*/
252cdf0e10cSrcweir
253cdf0e10cSrcweir
InitTreeList()254cdf0e10cSrcweir void SwDBTreeList::InitTreeList()
255cdf0e10cSrcweir {
256cdf0e10cSrcweir if(!pImpl->HasContext() && pImpl->GetWrtShell())
257cdf0e10cSrcweir return;
258cdf0e10cSrcweir SetSelectionMode(SINGLE_SELECTION);
259cdf0e10cSrcweir SetStyle(GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|WB_SORT|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
260cdf0e10cSrcweir // Font nicht setzen, damit der Font des Controls uebernommen wird!
261cdf0e10cSrcweir SetSpaceBetweenEntries(0);
262cdf0e10cSrcweir SetNodeBitmaps( aImageList.GetImage(IMG_COLLAPSE),
263cdf0e10cSrcweir aImageList.GetImage(IMG_EXPAND ), BMP_COLOR_NORMAL );
264cdf0e10cSrcweir SetNodeBitmaps( aImageListHC.GetImage(IMG_COLLAPSE),
265cdf0e10cSrcweir aImageListHC.GetImage(IMG_EXPAND ), BMP_COLOR_HIGHCONTRAST );
266cdf0e10cSrcweir
267cdf0e10cSrcweir SetDragDropMode(SV_DRAGDROP_APP_COPY);
268cdf0e10cSrcweir
269cdf0e10cSrcweir GetModel()->SetCompareHdl(LINK(this, SwDBTreeList, DBCompare));
270cdf0e10cSrcweir
271cdf0e10cSrcweir Sequence< ::rtl::OUString > aDBNames = pImpl->GetContext()->getElementNames();
272cdf0e10cSrcweir const ::rtl::OUString* pDBNames = aDBNames.getConstArray();
273cdf0e10cSrcweir long nCount = aDBNames.getLength();
274cdf0e10cSrcweir
275cdf0e10cSrcweir Image aImg = aImageList.GetImage(IMG_DB);
276cdf0e10cSrcweir Image aHCImg = aImageListHC.GetImage(IMG_DB);
277cdf0e10cSrcweir for(long i = 0; i < nCount; i++)
278cdf0e10cSrcweir {
279cdf0e10cSrcweir String sDBName(pDBNames[i]);
280cdf0e10cSrcweir SvLBoxEntry* pEntry = InsertEntry(sDBName, aImg, aImg, NULL, sal_True);
281cdf0e10cSrcweir SetExpandedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
282cdf0e10cSrcweir SetCollapsedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
283cdf0e10cSrcweir }
284cdf0e10cSrcweir String sDBName(sDefDBName.GetToken(0, DB_DELIM));
285cdf0e10cSrcweir String sTableName(sDefDBName.GetToken(1, DB_DELIM));
286cdf0e10cSrcweir String sColumnName(sDefDBName.GetToken(2, DB_DELIM));
287cdf0e10cSrcweir Select(sDBName, sTableName, sColumnName);
288cdf0e10cSrcweir
289cdf0e10cSrcweir
290cdf0e10cSrcweir bInitialized = sal_True;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir /*-- 27.05.2004 09:19:09---------------------------------------------------
293cdf0e10cSrcweir
294cdf0e10cSrcweir -----------------------------------------------------------------------*/
AddDataSource(const String & rSource)295cdf0e10cSrcweir void SwDBTreeList::AddDataSource(const String& rSource)
296cdf0e10cSrcweir {
297cdf0e10cSrcweir Image aImg = aImageList.GetImage(IMG_DB);
298cdf0e10cSrcweir Image aHCImg = aImageListHC.GetImage(IMG_DB);
299cdf0e10cSrcweir SvLBoxEntry* pEntry = InsertEntry(rSource, aImg, aImg, NULL, sal_True);
300cdf0e10cSrcweir SetExpandedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
301cdf0e10cSrcweir SetCollapsedEntryBmp(pEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
302cdf0e10cSrcweir SvTreeListBox::Select(pEntry);
303cdf0e10cSrcweir }
304cdf0e10cSrcweir /*------------------------------------------------------------------------
305cdf0e10cSrcweir Beschreibung:
306cdf0e10cSrcweir ------------------------------------------------------------------------*/
307cdf0e10cSrcweir
ShowColumns(sal_Bool bShowCol)308cdf0e10cSrcweir void SwDBTreeList::ShowColumns(sal_Bool bShowCol)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir if (bShowCol != bShowColumns)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir bShowColumns = bShowCol;
313cdf0e10cSrcweir String sTableName, sColumnName;
314cdf0e10cSrcweir String sDBName(GetDBName(sTableName, sColumnName));
315cdf0e10cSrcweir
316cdf0e10cSrcweir SetUpdateMode(sal_False);
317cdf0e10cSrcweir
318cdf0e10cSrcweir SvLBoxEntry* pEntry = First();
319cdf0e10cSrcweir
320cdf0e10cSrcweir while (pEntry)
321cdf0e10cSrcweir {
322cdf0e10cSrcweir pEntry = (SvLBoxEntry*)GetRootLevelParent( pEntry );
323cdf0e10cSrcweir Collapse(pEntry); // zuklappen
324cdf0e10cSrcweir
325cdf0e10cSrcweir SvLBoxEntry* pChild;
326cdf0e10cSrcweir while ((pChild = FirstChild(pEntry)) != 0L)
327cdf0e10cSrcweir GetModel()->Remove(pChild);
328cdf0e10cSrcweir
329cdf0e10cSrcweir pEntry = Next(pEntry);
330cdf0e10cSrcweir }
331cdf0e10cSrcweir
332cdf0e10cSrcweir if (sDBName.Len())
333cdf0e10cSrcweir {
334cdf0e10cSrcweir Select(sDBName, sTableName, sColumnName); // force RequestingChilds
335cdf0e10cSrcweir }
336cdf0e10cSrcweir SetUpdateMode(sal_True);
337cdf0e10cSrcweir }
338cdf0e10cSrcweir }
339cdf0e10cSrcweir
340cdf0e10cSrcweir /*------------------------------------------------------------------------
341cdf0e10cSrcweir Beschreibung:
342cdf0e10cSrcweir ------------------------------------------------------------------------*/
343cdf0e10cSrcweir
RequestingChilds(SvLBoxEntry * pParent)344cdf0e10cSrcweir void SwDBTreeList::RequestingChilds(SvLBoxEntry* pParent)
345cdf0e10cSrcweir {
346cdf0e10cSrcweir if (!pParent->HasChilds())
347cdf0e10cSrcweir {
348cdf0e10cSrcweir if (GetParent(pParent)) // column names
349cdf0e10cSrcweir {
350cdf0e10cSrcweir try
351cdf0e10cSrcweir {
352cdf0e10cSrcweir
353cdf0e10cSrcweir String sSourceName = GetEntryText(GetParent(pParent));
354cdf0e10cSrcweir String sTableName = GetEntryText(pParent);
355cdf0e10cSrcweir
356cdf0e10cSrcweir if(!pImpl->GetContext()->hasByName(sSourceName))
357cdf0e10cSrcweir return;
358cdf0e10cSrcweir Reference<XConnection> xConnection = pImpl->GetConnection(sSourceName);
359cdf0e10cSrcweir sal_Bool bTable = pParent->GetUserData() == 0;
360cdf0e10cSrcweir Reference<XColumnsSupplier> xColsSupplier;
361cdf0e10cSrcweir if(bTable)
362cdf0e10cSrcweir {
363cdf0e10cSrcweir Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
364cdf0e10cSrcweir if(xTSupplier.is())
365cdf0e10cSrcweir {
366cdf0e10cSrcweir Reference<XNameAccess> xTbls = xTSupplier->getTables();
367cdf0e10cSrcweir DBG_ASSERT(xTbls->hasByName(sTableName), "table not available anymore?");
368cdf0e10cSrcweir try
369cdf0e10cSrcweir {
370cdf0e10cSrcweir Any aTable = xTbls->getByName(sTableName);
371cdf0e10cSrcweir Reference<XPropertySet> xPropSet;
372cdf0e10cSrcweir aTable >>= xPropSet;
373cdf0e10cSrcweir xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
374cdf0e10cSrcweir }
375cdf0e10cSrcweir catch(Exception&)
376cdf0e10cSrcweir {}
377cdf0e10cSrcweir }
378cdf0e10cSrcweir }
379cdf0e10cSrcweir else
380cdf0e10cSrcweir {
381cdf0e10cSrcweir Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
382cdf0e10cSrcweir if(xQSupplier.is())
383cdf0e10cSrcweir {
384cdf0e10cSrcweir Reference<XNameAccess> xQueries = xQSupplier->getQueries();
385cdf0e10cSrcweir DBG_ASSERT(xQueries->hasByName(sTableName), "table not available anymore?");
386cdf0e10cSrcweir try
387cdf0e10cSrcweir {
388cdf0e10cSrcweir Any aQuery = xQueries->getByName(sTableName);
389cdf0e10cSrcweir Reference<XPropertySet> xPropSet;
390cdf0e10cSrcweir aQuery >>= xPropSet;
391cdf0e10cSrcweir xColsSupplier = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
392cdf0e10cSrcweir }
393cdf0e10cSrcweir catch(Exception&)
394cdf0e10cSrcweir {}
395cdf0e10cSrcweir }
396cdf0e10cSrcweir }
397cdf0e10cSrcweir
398cdf0e10cSrcweir if(xColsSupplier.is())
399cdf0e10cSrcweir {
400cdf0e10cSrcweir Reference <XNameAccess> xCols = xColsSupplier->getColumns();
401cdf0e10cSrcweir Sequence< ::rtl::OUString> aColNames = xCols->getElementNames();
402cdf0e10cSrcweir const ::rtl::OUString* pColNames = aColNames.getConstArray();
403cdf0e10cSrcweir long nCount = aColNames.getLength();
404cdf0e10cSrcweir for (long i = 0; i < nCount; i++)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir String sName = pColNames[i];
407cdf0e10cSrcweir if(bTable)
408cdf0e10cSrcweir InsertEntry(sName, pParent);
409cdf0e10cSrcweir else
410cdf0e10cSrcweir InsertEntry(sName, pParent);
411cdf0e10cSrcweir }
412cdf0e10cSrcweir }
413cdf0e10cSrcweir }
414cdf0e10cSrcweir catch(const Exception&)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir }
417cdf0e10cSrcweir }
418cdf0e10cSrcweir else // Tabellennamen
419cdf0e10cSrcweir {
420cdf0e10cSrcweir try
421cdf0e10cSrcweir {
422cdf0e10cSrcweir String sSourceName = GetEntryText(pParent);
423cdf0e10cSrcweir if(!pImpl->GetContext()->hasByName(sSourceName))
424cdf0e10cSrcweir return;
425cdf0e10cSrcweir Reference<XConnection> xConnection = pImpl->GetConnection(sSourceName);
426cdf0e10cSrcweir if (xConnection.is())
427cdf0e10cSrcweir {
428cdf0e10cSrcweir Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
429cdf0e10cSrcweir if(xTSupplier.is())
430cdf0e10cSrcweir {
431cdf0e10cSrcweir Reference<XNameAccess> xTbls = xTSupplier->getTables();
432cdf0e10cSrcweir Sequence< ::rtl::OUString> aTblNames = xTbls->getElementNames();
433cdf0e10cSrcweir String sTableName;
434cdf0e10cSrcweir long nCount = aTblNames.getLength();
435cdf0e10cSrcweir const ::rtl::OUString* pTblNames = aTblNames.getConstArray();
436cdf0e10cSrcweir Image aImg = aImageList.GetImage(IMG_DBTABLE);
437cdf0e10cSrcweir Image aHCImg = aImageListHC.GetImage(IMG_DBTABLE);
438cdf0e10cSrcweir for (long i = 0; i < nCount; i++)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir sTableName = pTblNames[i];
441cdf0e10cSrcweir SvLBoxEntry* pTableEntry = InsertEntry(sTableName, aImg, aImg, pParent, bShowColumns);
442cdf0e10cSrcweir //to discriminate between queries and tables the user data of table entries is set
443cdf0e10cSrcweir pTableEntry->SetUserData((void*)0);
444cdf0e10cSrcweir SetExpandedEntryBmp(pTableEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
445cdf0e10cSrcweir SetCollapsedEntryBmp(pTableEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
446cdf0e10cSrcweir }
447cdf0e10cSrcweir }
448cdf0e10cSrcweir
449cdf0e10cSrcweir Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
450cdf0e10cSrcweir if(xQSupplier.is())
451cdf0e10cSrcweir {
452cdf0e10cSrcweir Reference<XNameAccess> xQueries = xQSupplier->getQueries();
453cdf0e10cSrcweir Sequence< ::rtl::OUString> aQueryNames = xQueries->getElementNames();
454cdf0e10cSrcweir String sQueryName;
455cdf0e10cSrcweir long nCount = aQueryNames.getLength();
456cdf0e10cSrcweir const ::rtl::OUString* pQueryNames = aQueryNames.getConstArray();
457cdf0e10cSrcweir Image aImg = aImageList.GetImage(IMG_DBQUERY);
458cdf0e10cSrcweir Image aHCImg = aImageListHC.GetImage(IMG_DBQUERY);
459cdf0e10cSrcweir for (long i = 0; i < nCount; i++)
460cdf0e10cSrcweir {
461cdf0e10cSrcweir sQueryName = pQueryNames[i];
462cdf0e10cSrcweir SvLBoxEntry* pQueryEntry = InsertEntry(sQueryName, aImg, aImg, pParent, bShowColumns);
463cdf0e10cSrcweir pQueryEntry->SetUserData((void*)1);
464cdf0e10cSrcweir SetExpandedEntryBmp(pQueryEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
465cdf0e10cSrcweir SetCollapsedEntryBmp( pQueryEntry, aHCImg, BMP_COLOR_HIGHCONTRAST);
466cdf0e10cSrcweir }
467cdf0e10cSrcweir }
468cdf0e10cSrcweir }
469cdf0e10cSrcweir }
470cdf0e10cSrcweir catch(const Exception&)
471cdf0e10cSrcweir {
472cdf0e10cSrcweir }
473cdf0e10cSrcweir }
474cdf0e10cSrcweir }
475cdf0e10cSrcweir }
476cdf0e10cSrcweir
477cdf0e10cSrcweir /*------------------------------------------------------------------------
478cdf0e10cSrcweir Beschreibung:
479cdf0e10cSrcweir ------------------------------------------------------------------------*/
480cdf0e10cSrcweir
IMPL_LINK(SwDBTreeList,DBCompare,SvSortData *,pData)481cdf0e10cSrcweir IMPL_LINK( SwDBTreeList, DBCompare, SvSortData*, pData )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir SvLBoxEntry* pRight = (SvLBoxEntry*)(pData->pRight );
484cdf0e10cSrcweir
485cdf0e10cSrcweir if (GetParent(pRight) && GetParent(GetParent(pRight)))
486cdf0e10cSrcweir return COMPARE_GREATER; // Spaltennamen nicht sortieren
487cdf0e10cSrcweir
488cdf0e10cSrcweir return DefaultCompare(pData); // Sonst Basisklasse rufen
489cdf0e10cSrcweir }
490cdf0e10cSrcweir
491cdf0e10cSrcweir /*------------------------------------------------------------------------
492cdf0e10cSrcweir Beschreibung:
493cdf0e10cSrcweir ------------------------------------------------------------------------*/
494cdf0e10cSrcweir
GetDBName(String & rTableName,String & rColumnName,sal_Bool * pbIsTable)495cdf0e10cSrcweir String SwDBTreeList::GetDBName(String& rTableName, String& rColumnName, sal_Bool* pbIsTable)
496cdf0e10cSrcweir {
497cdf0e10cSrcweir String sDBName;
498cdf0e10cSrcweir SvLBoxEntry* pEntry = FirstSelected();
499cdf0e10cSrcweir
500cdf0e10cSrcweir if (pEntry && GetParent(pEntry))
501cdf0e10cSrcweir {
502cdf0e10cSrcweir if (GetParent(GetParent(pEntry)))
503cdf0e10cSrcweir {
504cdf0e10cSrcweir rColumnName = GetEntryText(pEntry);
505cdf0e10cSrcweir pEntry = GetParent(pEntry); // Spaltenname war selektiert
506cdf0e10cSrcweir }
507cdf0e10cSrcweir sDBName = GetEntryText(GetParent(pEntry));
508cdf0e10cSrcweir if(pbIsTable)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir *pbIsTable = pEntry->GetUserData() == 0;
511cdf0e10cSrcweir }
512cdf0e10cSrcweir rTableName = GetEntryText(pEntry);
513cdf0e10cSrcweir }
514cdf0e10cSrcweir return sDBName;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir
517cdf0e10cSrcweir /*------------------------------------------------------------------------
518cdf0e10cSrcweir Beschreibung: Format: Datenbank.Tabelle
519cdf0e10cSrcweir ------------------------------------------------------------------------*/
520cdf0e10cSrcweir
521cdf0e10cSrcweir
Select(const String & rDBName,const String & rTableName,const String & rColumnName)522cdf0e10cSrcweir void SwDBTreeList::Select(const String& rDBName, const String& rTableName, const String& rColumnName)
523cdf0e10cSrcweir {
524cdf0e10cSrcweir SvLBoxEntry* pParent;
525cdf0e10cSrcweir SvLBoxEntry* pChild;
526cdf0e10cSrcweir sal_uInt16 nParent = 0;
527cdf0e10cSrcweir sal_uInt16 nChild = 0;
528cdf0e10cSrcweir
529cdf0e10cSrcweir while ((pParent = GetEntry(nParent++)) != NULL)
530cdf0e10cSrcweir {
531cdf0e10cSrcweir if (rDBName == GetEntryText(pParent))
532cdf0e10cSrcweir {
533cdf0e10cSrcweir if (!pParent->HasChilds())
534cdf0e10cSrcweir RequestingChilds(pParent);
535cdf0e10cSrcweir while ((pChild = GetEntry(pParent, nChild++)) != NULL)
536cdf0e10cSrcweir {
537cdf0e10cSrcweir if (rTableName == GetEntryText(pChild))
538cdf0e10cSrcweir {
539cdf0e10cSrcweir pParent = pChild;
540cdf0e10cSrcweir
541cdf0e10cSrcweir if (bShowColumns && rColumnName.Len())
542cdf0e10cSrcweir {
543cdf0e10cSrcweir nChild = 0;
544cdf0e10cSrcweir
545cdf0e10cSrcweir if (!pParent->HasChilds())
546cdf0e10cSrcweir RequestingChilds(pParent);
547cdf0e10cSrcweir
548cdf0e10cSrcweir while ((pChild = GetEntry(pParent, nChild++)) != NULL)
549cdf0e10cSrcweir if (rColumnName == GetEntryText(pChild))
550cdf0e10cSrcweir break;
551cdf0e10cSrcweir }
552cdf0e10cSrcweir if (!pChild)
553cdf0e10cSrcweir pChild = pParent;
554cdf0e10cSrcweir
555cdf0e10cSrcweir MakeVisible(pChild);
556cdf0e10cSrcweir SvTreeListBox::Select(pChild);
557cdf0e10cSrcweir return;
558cdf0e10cSrcweir }
559cdf0e10cSrcweir }
560cdf0e10cSrcweir }
561cdf0e10cSrcweir }
562cdf0e10cSrcweir }
563cdf0e10cSrcweir
564cdf0e10cSrcweir /*------------------------------------------------------------------------
565cdf0e10cSrcweir Beschreibung:
566cdf0e10cSrcweir ------------------------------------------------------------------------*/
567cdf0e10cSrcweir
StartDrag(sal_Int8,const Point &)568cdf0e10cSrcweir void SwDBTreeList::StartDrag( sal_Int8 /*nAction*/, const Point& /*rPosPixel*/ )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir String sTableName, sColumnName;
571cdf0e10cSrcweir String sDBName( GetDBName( sTableName, sColumnName ));
572cdf0e10cSrcweir if( sDBName.Len() )
573cdf0e10cSrcweir {
574cdf0e10cSrcweir TransferDataContainer* pContainer = new TransferDataContainer;
575cdf0e10cSrcweir STAR_REFERENCE( datatransfer::XTransferable ) xRef( pContainer );
576cdf0e10cSrcweir if( sColumnName.Len() )
577cdf0e10cSrcweir {
578cdf0e10cSrcweir // Datenbankfeld draggen
579cdf0e10cSrcweir svx::OColumnTransferable aColTransfer(
580cdf0e10cSrcweir sDBName
581cdf0e10cSrcweir ,::rtl::OUString()
582cdf0e10cSrcweir , sdb::CommandType::TABLE
583cdf0e10cSrcweir ,sTableName
584cdf0e10cSrcweir , sColumnName
585cdf0e10cSrcweir ,(CTF_FIELD_DESCRIPTOR |CTF_COLUMN_DESCRIPTOR ));
586cdf0e10cSrcweir aColTransfer.addDataToContainer( pContainer );
587cdf0e10cSrcweir }
588cdf0e10cSrcweir
589cdf0e10cSrcweir sDBName += '.';
590cdf0e10cSrcweir sDBName += sTableName;
591cdf0e10cSrcweir if( sColumnName.Len() )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir sDBName += '.';
594cdf0e10cSrcweir sDBName += sColumnName;
595cdf0e10cSrcweir }
596cdf0e10cSrcweir
597cdf0e10cSrcweir pContainer->CopyString( FORMAT_STRING, sDBName );
598cdf0e10cSrcweir pContainer->StartDrag( this, DND_ACTION_COPY | DND_ACTION_LINK,
599cdf0e10cSrcweir Link() );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir }
602cdf0e10cSrcweir
603cdf0e10cSrcweir /*------------------------------------------------------------------------
604cdf0e10cSrcweir Beschreibung:
605cdf0e10cSrcweir ------------------------------------------------------------------------*/
AcceptDrop(const AcceptDropEvent &)606cdf0e10cSrcweir sal_Int8 SwDBTreeList::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
607cdf0e10cSrcweir {
608cdf0e10cSrcweir return DND_ACTION_NONE;
609cdf0e10cSrcweir }
610cdf0e10cSrcweir /*-- 07.10.2003 13:28:22---------------------------------------------------
611cdf0e10cSrcweir
612cdf0e10cSrcweir -----------------------------------------------------------------------*/
SetWrtShell(SwWrtShell & rSh)613cdf0e10cSrcweir void SwDBTreeList::SetWrtShell(SwWrtShell& rSh)
614cdf0e10cSrcweir {
615cdf0e10cSrcweir pImpl->SetWrtShell(rSh);
616cdf0e10cSrcweir if (IsVisible() && !bInitialized)
617cdf0e10cSrcweir InitTreeList();
618cdf0e10cSrcweir }
619