1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableWindowData.cxx,v $
10 * $Revision: 1.15.42.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_TABLEWINDOWDATA_HXX
34 #include "TableWindowData.hxx"
36 #ifndef _TOOLS_DEBUG_HXX
37 #include <tools/debug.hxx>
39 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
40 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
41 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
42 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/container/XIndexAccess.hpp>
46 using namespace dbaui
;
47 using namespace ::com::sun::star::lang
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::sdb
;
50 using namespace ::com::sun::star::sdbc
;
51 using namespace ::com::sun::star::sdbcx
;
52 using namespace ::com::sun::star::beans
;
53 using namespace ::com::sun::star::container
;
55 //==================================================================
56 // class OTableWindowData
57 //==================================================================
58 DBG_NAME(OTableWindowData
)
59 //------------------------------------------------------------------------------
60 OTableWindowData::OTableWindowData( const Reference
< XPropertySet
>& _xTable
61 ,const ::rtl::OUString
& _rComposedName
62 ,const ::rtl::OUString
& rTableName
63 ,const ::rtl::OUString
& rWinName
)
65 ,m_aTableName( rTableName
)
66 ,m_aWinName( rWinName
)
67 ,m_sComposedName(_rComposedName
)
68 ,m_aPosition( Point(-1,-1) )
69 ,m_aSize( Size(-1,-1) )
74 DBG_CTOR(OTableWindowData
,NULL
);
75 if( !m_aWinName
.getLength() )
76 m_aWinName
= m_aTableName
;
81 //------------------------------------------------------------------------------
82 OTableWindowData::~OTableWindowData()
84 DBG_DTOR(OTableWindowData
,NULL
);
85 Reference
<XComponent
> xComponent( m_xTable
, UNO_QUERY
);
86 if ( xComponent
.is() )
87 stopComponentListening( xComponent
);
90 //------------------------------------------------------------------------------
91 BOOL
OTableWindowData::HasPosition() const
93 return ( (m_aPosition
.X() != -1) && (m_aPosition
.Y() != -1) );
96 //------------------------------------------------------------------------------
97 BOOL
OTableWindowData::HasSize() const
99 return ( (m_aSize
.Width() != -1) && (m_aSize
.Height() !=-1) );
101 // -----------------------------------------------------------------------------
102 void OTableWindowData::_disposing( const ::com::sun::star::lang::EventObject
& /*_rSource*/ )
104 ::osl::MutexGuard
aGuard( m_aMutex
);
105 // it doesn't matter which one was disposed
110 // -----------------------------------------------------------------------------
111 bool OTableWindowData::init(const Reference
< XConnection
>& _xConnection
,bool _bAllowQueries
)
113 OSL_ENSURE(!m_xTable
.is(),"We are already connected to a table!");
115 ::osl::MutexGuard
aGuard( m_aMutex
);
117 Reference
< XQueriesSupplier
> xSupQueries( _xConnection
, UNO_QUERY_THROW
);
118 Reference
< XNameAccess
> xQueries( xSupQueries
->getQueries(), UNO_QUERY_THROW
);
119 bool bIsKnownQuery
= _bAllowQueries
&& xQueries
->hasByName( m_sComposedName
);
121 Reference
< XTablesSupplier
> xSupTables( _xConnection
, UNO_QUERY_THROW
);
122 Reference
< XNameAccess
> xTables( xSupTables
->getTables(), UNO_QUERY_THROW
);
123 bool bIsKnownTable
= xTables
->hasByName( m_sComposedName
);
126 m_xTable
.set( xQueries
->getByName( m_sComposedName
), UNO_QUERY
);
127 else if ( bIsKnownTable
)
128 m_xTable
.set( xTables
->getByName( m_sComposedName
), UNO_QUERY
);
132 // if we survived so far, we know whether it's a query
133 m_bIsQuery
= bIsKnownQuery
;
137 Reference
< XIndexAccess
> xColumnsAsIndex( m_xColumns
,UNO_QUERY
);
138 return xColumnsAsIndex
.is() && ( xColumnsAsIndex
->getCount() > 0 );
140 // -----------------------------------------------------------------------------
141 void OTableWindowData::listen()
145 // listen for the object being disposed
146 Reference
<XComponent
> xComponent( m_xTable
, UNO_QUERY
);
147 if ( xComponent
.is() )
148 startComponentListening( xComponent
);
150 // obtain the columns
151 Reference
< XColumnsSupplier
> xColumnsSups( m_xTable
, UNO_QUERY
);
152 if ( xColumnsSups
.is() )
153 m_xColumns
= xColumnsSups
->getColumns();
155 Reference
<XKeysSupplier
> xKeySup(m_xTable
,UNO_QUERY
);
157 m_xKeys
= xKeySup
->getKeys();
160 // -----------------------------------------------------------------------------