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