xref: /trunk/main/dbaccess/source/ui/inc/TableController.hxx (revision 07a3d7f126518b23ae382088cf657ec498e294b1)
12e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52e2212a7SAndrew Rist  * distributed with this work for additional information
62e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
82e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
92e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
142e2212a7SAndrew Rist  * software distributed under the License is distributed on an
152e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
172e2212a7SAndrew Rist  * specific language governing permissions and limitations
182e2212a7SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202e2212a7SAndrew Rist  *************************************************************/
212e2212a7SAndrew Rist 
222e2212a7SAndrew Rist 
23cdf0e10cSrcweir #ifndef DBUI_TABLECONTROLLER_HXX
24cdf0e10cSrcweir #define DBUI_TABLECONTROLLER_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "singledoccontroller.hxx"
27cdf0e10cSrcweir #include "moduledbu.hxx"
28cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
30cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp>
31cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp>
32cdf0e10cSrcweir #include "TypeInfo.hxx"
33cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
34cdf0e10cSrcweir #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
35cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class FixedText;
38cdf0e10cSrcweir namespace dbaui
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     class OTableRow;
41cdf0e10cSrcweir     class OFieldDescription;
42cdf0e10cSrcweir     typedef OSingleDocumentController   OTableController_BASE;
43cdf0e10cSrcweir     class OTableController : public OTableController_BASE
44cdf0e10cSrcweir     {
45cdf0e10cSrcweir     private:
46cdf0e10cSrcweir         OModuleClient                                   m_aModuleClient;
47cdf0e10cSrcweir         ::std::vector< ::boost::shared_ptr<OTableRow> > m_vRowList;
48cdf0e10cSrcweir         OTypeInfoMap                                    m_aTypeInfo;
49cdf0e10cSrcweir         ::std::vector<OTypeInfoMap::iterator>           m_aTypeInfoIndex;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >       m_xTable;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         ::rtl::OUString m_sCatalogName;         // catalog for update data
54cdf0e10cSrcweir         ::rtl::OUString m_sSchemaName;          // schema for update data
55cdf0e10cSrcweir         ::rtl::OUString m_sName;                // table for update data
56cdf0e10cSrcweir         ::rtl::OUString m_sAutoIncrementValue;  // the autoincrement value set in the datasource
57cdf0e10cSrcweir         String          m_sTypeNames;           // these type names are the ones out of the resource file
58*07a3d7f1SPedro Giffuni         TOTypeInfoSP    m_pTypeInfo;            // fall back when type is unknown because database driver has a failure
59cdf0e10cSrcweir 
60cdf0e10cSrcweir         sal_Bool        m_bAllowAutoIncrementValue; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property
61cdf0e10cSrcweir         sal_Bool        m_bNew      : 1;        // is true when we create a new table
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 
64cdf0e10cSrcweir         void reSyncRows();
65cdf0e10cSrcweir         void assignTable();                 // set the table if a name is given
66cdf0e10cSrcweir         void loadData();
67cdf0e10cSrcweir         sal_Bool checkColumns(sal_Bool _bNew) throw(::com::sun::star::sdbc::SQLException);      // check if we have double column names
68cdf0e10cSrcweir         String createUniqueName(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _rxTables,const String& _rDefault);
69cdf0e10cSrcweir         void appendColumns(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& _rxColSup,sal_Bool _bNew,sal_Bool _bKeyColumns = sal_False);
70cdf0e10cSrcweir         void appendPrimaryKey(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XKeysSupplier>& _rxSup,sal_Bool _bNew);
71cdf0e10cSrcweir         void alterColumns();
72cdf0e10cSrcweir         void dropPrimaryKey();
73cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getKeyColumns() const;
74cdf0e10cSrcweir         ::rtl::OUString createUniqueName(const ::rtl::OUString& _rName);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir         void reload();
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         // all the features which should be handled by this class
79cdf0e10cSrcweir         virtual void            describeSupportedFeatures();
80cdf0e10cSrcweir         // state of a feature. 'feature' may be the handle of a ::com::sun::star::util::URL somebody requested a dispatch interface for OR a toolbar slot.
81cdf0e10cSrcweir         virtual FeatureState    GetState(sal_uInt16 nId) const;
82cdf0e10cSrcweir         // execute a feature
83cdf0e10cSrcweir         virtual void            Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         virtual void losingConnection( );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         virtual ::rtl::OUString getPrivateTitle( ) const;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         void        doEditIndexes();
90cdf0e10cSrcweir         sal_Bool    doSaveDoc(sal_Bool _bSaveAs);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         virtual ~OTableController();
93cdf0e10cSrcweir     public:
94cdf0e10cSrcweir         OTableController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >       getTable() { return m_xTable;}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         sal_Bool isAddAllowed()     const;
99cdf0e10cSrcweir         sal_Bool isDropAllowed()    const;
100cdf0e10cSrcweir         sal_Bool isAlterAllowed()   const;
101cdf0e10cSrcweir         bool     isAutoIncrementPrimaryKey() const;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         inline sal_Bool                 isAutoIncrementValueEnabled()   const { return m_bAllowAutoIncrementValue; }
104cdf0e10cSrcweir         inline const ::rtl::OUString&   getAutoIncrementValue()         const { return m_sAutoIncrementValue; }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         virtual void impl_onModifyChanged();
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         inline ::std::vector< ::boost::shared_ptr<OTableRow> >* getRows() { return &m_vRowList; }
109cdf0e10cSrcweir 
110*07a3d7f1SPedro Giffuni         /// returns the position of the the first empty row
111cdf0e10cSrcweir         sal_Int32                           getFirstEmptyRowPosition();
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         inline const OTypeInfoMap*          getTypeInfo() const { return &m_aTypeInfo; }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         inline TOTypeInfoSP                 getTypeInfo(sal_Int32 _nPos) const { return m_aTypeInfoIndex[_nPos]->second; }
116cdf0e10cSrcweir         TOTypeInfoSP                        getTypeInfoByType(sal_Int32 _nDataType) const;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         inline TOTypeInfoSP                 getTypeInfoFallBack() const { return m_pTypeInfo; }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         virtual sal_Bool                    Construct(Window* pParent);
121cdf0e10cSrcweir         // XEventListener
122cdf0e10cSrcweir         virtual void SAL_CALL               disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         // ::com::sun::star::frame::XController
125cdf0e10cSrcweir         virtual sal_Bool SAL_CALL           suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         // ::com::sun::star::lang::XComponent
128cdf0e10cSrcweir         virtual void        SAL_CALL disposing();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // XServiceInfo
131cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
132cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
133cdf0e10cSrcweir         // need by registration
134cdf0e10cSrcweir         static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
135cdf0e10cSrcweir         static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
136cdf0e10cSrcweir         static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
137cdf0e10cSrcweir                 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         //
140cdf0e10cSrcweir         virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn);
141cdf0e10cSrcweir         virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     protected:
144cdf0e10cSrcweir         void startTableListening();
145cdf0e10cSrcweir         void stopTableListening();
146cdf0e10cSrcweir         virtual void impl_initialize();
147cdf0e10cSrcweir     };
148cdf0e10cSrcweir }
149cdf0e10cSrcweir #endif // DBUI_TABLECONTROLLER_HXX
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152