1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef DBAUI_TABLEWINDOWDATA_HXX
28 #define DBAUI_TABLEWINDOWDATA_HXX
29 
30 #ifndef _SV_GEN_HXX
31 #include <tools/gen.hxx>
32 #endif
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/container/XIndexAccess.hpp>
36 #include <com/sun/star/sdbc/XConnection.hpp>
37 #include <unotools/eventlisteneradapter.hxx>
38 #include <boost/shared_ptr.hpp>
39 #include <vector>
40 
41 namespace dbaui
42 {
43     class OTableWindowData : public ::utl::OEventListenerAdapter
44 	{
45         mutable ::osl::Mutex	m_aMutex;
46 
47         void listen();
48 	protected:
49         // the columns of the table
50 		::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >       m_xTable; // can either be a table or a query
51         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>    m_xKeys;
52 		::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >    m_xColumns;
53 
54 		::rtl::OUString	m_aTableName;
55 		::rtl::OUString	m_aWinName;
56 		::rtl::OUString	m_sComposedName;
57 		Point			m_aPosition;
58 		Size			m_aSize;
59 		sal_Bool		m_bShowAll;
60         bool            m_bIsQuery;
61         bool            m_bIsValid;
62 
63 	public:
64 		explicit OTableWindowData(  const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable
65                                    ,const ::rtl::OUString& _rComposedName
66                                    ,const ::rtl::OUString& strTableName
67                                    ,const ::rtl::OUString& rWinName = ::rtl::OUString() );
68 		virtual ~OTableWindowData();
69 
70         /** late constructor
71         *
72         * \param _xConnection
73         * \param _bAllowQueries when true, queries are allowed
74         * \return false if the table was unaccessible otherwise true
75         */
76         bool init(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection  >& _xConnection
77                  ,bool _bAllowQueries);
78 
79 		inline ::rtl::OUString GetComposedName()	const { return m_sComposedName; }
80 		inline ::rtl::OUString GetTableName()		const { return m_aTableName; }
81 		inline ::rtl::OUString GetWinName()		    const { return m_aWinName; }
82 		inline Point GetPosition()					const { return m_aPosition; }
83 		inline Size GetSize()						const { return m_aSize; }
84 		inline sal_Bool IsShowAll()					    const { return m_bShowAll; }
85         inline bool isQuery()                       const { return m_bIsQuery; }
86         inline bool isValid()                       const { return m_bIsValid; } // it is either a table or query but it is known
87 		sal_Bool HasPosition()	const;
88 		sal_Bool HasSize()		const;
89 
90 		inline void SetWinName( const ::rtl::OUString& rWinName )		{ m_aWinName = rWinName; }
91 		inline void SetPosition( const Point& rPos )					{ m_aPosition=rPos; }
92 		inline void SetSize( const Size& rSize )						{ m_aSize = rSize; }
93 		inline void ShowAll( sal_Bool bAll )								{ m_bShowAll = bAll; }
94 
95         inline ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> getTable() const { ::osl::MutexGuard aGuard( m_aMutex  ); return m_xTable; }
96         inline ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> getKeys() const { ::osl::MutexGuard aGuard( m_aMutex  ); return m_xKeys; }
97         inline ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getColumns() const { ::osl::MutexGuard aGuard( m_aMutex  ); return m_xColumns; }
98 
99         // OEventListenerAdapter
100 		virtual void _disposing( const ::com::sun::star::lang::EventObject& _rSource );
101 	};
102 
103     typedef ::std::vector< ::boost::shared_ptr<OTableWindowData> >		TTableWindowData;
104 }
105 #endif // DBAUI_TABLEWINDOWDATA_HXX
106 
107