1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
20 #define INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
22 #include "singledoccontroller.hxx"
23 #include "moduledbu.hxx"
24 #include <com/sun/star/sdbc/XConnection.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/io/XObjectOutputStream.hpp>
27 #include <com/sun/star/io/XObjectInputStream.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include "TypeInfo.hxx"
30 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
31 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
32 #include <com/sun/star/container/XNameAccess.hpp>
37 typedef OSingleDocumentController OTableController_BASE
;
38 class OTableController
: public OTableController_BASE
41 OModuleClient m_aModuleClient
;
42 ::std::vector
< ::boost::shared_ptr
<OTableRow
> > m_vRowList
;
43 OTypeInfoMap m_aTypeInfo
;
44 ::std::vector
<OTypeInfoMap::iterator
> m_aTypeInfoIndex
;
46 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> m_xTable
;
48 OUString m_sCatalogName
; // catalog for update data
49 OUString m_sSchemaName
; // schema for update data
50 OUString m_sName
; // table for update data
51 OUString m_sAutoIncrementValue
; // the autoincrement value set in the datasource
52 OUString m_sTypeNames
; // these type names are the ones out of the resource file
53 TOTypeInfoSP m_pTypeInfo
; // fall back when type is unknown because database driver has a failure
55 bool m_bAllowAutoIncrementValue
; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property
56 bool m_bNew
: 1; // is true when we create a new table
60 void assignTable(); // set the table if a name is given
62 bool checkColumns(bool _bNew
)
63 throw (css::sdbc::SQLException
,
64 css::uno::RuntimeException
, std::exception
); // check if we have double column names
65 OUString
createUniqueName(const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& _rxTables
,const OUString
& _rDefault
);
66 void appendColumns(::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
>& _rxColSup
, bool _bNew
, bool _bKeyColumns
= false);
67 void appendPrimaryKey(::com::sun::star::uno::Reference
< ::com::sun::star::sdbcx::XKeysSupplier
>& _rxSup
, bool _bNew
);
69 void dropPrimaryKey();
70 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> getKeyColumns() const;
71 OUString
createUniqueName(const OUString
& _rName
);
75 // all the features which should be handled by this class
76 virtual void describeSupportedFeatures() SAL_OVERRIDE
;
77 // 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.
78 virtual FeatureState
GetState(sal_uInt16 nId
) const SAL_OVERRIDE
;
80 virtual void Execute(sal_uInt16 nId
, const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
) SAL_OVERRIDE
;
82 virtual void losingConnection( ) SAL_OVERRIDE
;
84 virtual OUString
getPrivateTitle( ) const SAL_OVERRIDE
;
87 bool doSaveDoc(bool _bSaveAs
);
89 virtual ~OTableController();
91 OTableController(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rM
);
93 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> getTable() { return m_xTable
;}
95 bool isAddAllowed() const;
96 bool isDropAllowed() const;
97 bool isAlterAllowed() const;
98 bool isAutoIncrementPrimaryKey() const;
100 inline bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue
; }
101 inline const OUString
& getAutoIncrementValue() const { return m_sAutoIncrementValue
; }
103 virtual void impl_onModifyChanged() SAL_OVERRIDE
;
105 inline ::std::vector
< ::boost::shared_ptr
<OTableRow
> >& getRows() { return m_vRowList
; }
107 /// returns the position of the first empty row
108 sal_Int32
getFirstEmptyRowPosition();
110 inline const OTypeInfoMap
& getTypeInfo() const { return m_aTypeInfo
; }
112 inline TOTypeInfoSP
getTypeInfo(sal_Int32 _nPos
) const { return m_aTypeInfoIndex
[_nPos
]->second
; }
113 TOTypeInfoSP
getTypeInfoByType(sal_Int32 _nDataType
) const;
115 inline TOTypeInfoSP
getTypeInfoFallBack() const { return m_pTypeInfo
; }
117 virtual bool Construct(vcl::Window
* pParent
) SAL_OVERRIDE
;
119 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
121 // ::com::sun::star::frame::XController
122 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
124 // ::com::sun::star::lang::XComponent
125 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
128 virtual OUString SAL_CALL
getImplementationName() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
129 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
130 // need by registration
131 static OUString
getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException
);
132 static ::com::sun::star::uno::Sequence
< OUString
> getSupportedServiceNames_Static() throw( ::com::sun::star::uno::RuntimeException
);
133 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
134 SAL_CALL
Create(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>&);
137 void startTableListening();
138 void stopTableListening();
139 virtual void impl_initialize() SAL_OVERRIDE
;
142 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */