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
< std::shared_ptr
<OTableRow
> > m_vRowList
;
43 OTypeInfoMap m_aTypeInfo
;
44 ::std::vector
<OTypeInfoMap::iterator
> m_aTypeInfoIndex
;
46 css::uno::Reference
< css::beans::XPropertySet
> m_xTable
;
48 OUString m_sName
; // table for update data
49 OUString m_sAutoIncrementValue
; // the autoincrement value set in the datasource
50 OUString m_sTypeNames
; // these type names are the ones out of the resource file
51 TOTypeInfoSP m_pTypeInfo
; // fall back when type is unknown because database driver has a failure
53 bool m_bAllowAutoIncrementValue
; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property
54 bool m_bNew
: 1; // is true when we create a new table
58 void assignTable(); // set the table if a name is given
60 bool checkColumns(bool _bNew
)
61 throw (css::sdbc::SQLException
,
62 css::uno::RuntimeException
, std::exception
); // check if we have double column names
63 void appendColumns(css::uno::Reference
< css::sdbcx::XColumnsSupplier
>& _rxColSup
, bool _bNew
, bool _bKeyColumns
= false);
64 void appendPrimaryKey(css::uno::Reference
< css::sdbcx::XKeysSupplier
>& _rxSup
, bool _bNew
);
66 void dropPrimaryKey();
67 css::uno::Reference
< css::container::XNameAccess
> getKeyColumns() const;
68 OUString
createUniqueName(const OUString
& _rName
);
72 // all the features which should be handled by this class
73 virtual void describeSupportedFeatures() override
;
74 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
75 virtual FeatureState
GetState(sal_uInt16 nId
) const override
;
77 virtual void Execute(sal_uInt16 nId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
79 virtual void losingConnection( ) override
;
81 virtual OUString
getPrivateTitle( ) const override
;
84 bool doSaveDoc(bool _bSaveAs
);
86 virtual ~OTableController();
88 OTableController(const css::uno::Reference
< css::uno::XComponentContext
>& _rM
);
90 const css::uno::Reference
< css::beans::XPropertySet
>& getTable() { return m_xTable
;}
92 bool isAddAllowed() const;
93 bool isDropAllowed() const;
94 bool isAlterAllowed() const;
95 bool isAutoIncrementPrimaryKey() const;
97 inline bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue
; }
98 inline const OUString
& getAutoIncrementValue() const { return m_sAutoIncrementValue
; }
100 virtual void impl_onModifyChanged() override
;
102 inline ::std::vector
< std::shared_ptr
<OTableRow
> >& getRows() { return m_vRowList
; }
104 /// returns the position of the first empty row
105 sal_Int32
getFirstEmptyRowPosition();
107 inline const OTypeInfoMap
& getTypeInfo() const { return m_aTypeInfo
; }
109 inline TOTypeInfoSP
getTypeInfo(sal_Int32 _nPos
) const { return m_aTypeInfoIndex
[_nPos
]->second
; }
110 TOTypeInfoSP
getTypeInfoByType(sal_Int32 _nDataType
) const;
112 const TOTypeInfoSP
& getTypeInfoFallBack() const { return m_pTypeInfo
; }
114 virtual bool Construct(vcl::Window
* pParent
) override
;
116 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw(css::uno::RuntimeException
, std::exception
) override
;
118 // css::frame::XController
119 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) throw( css::uno::RuntimeException
, std::exception
) override
;
121 // css::lang::XComponent
122 virtual void SAL_CALL
disposing() override
;
125 virtual OUString SAL_CALL
getImplementationName() throw(css::uno::RuntimeException
, std::exception
) override
;
126 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(css::uno::RuntimeException
, std::exception
) override
;
127 // need by registration
128 static OUString
getImplementationName_Static() throw( css::uno::RuntimeException
);
129 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static() throw( css::uno::RuntimeException
);
130 static css::uno::Reference
< css::uno::XInterface
>
131 SAL_CALL
Create(const css::uno::Reference
< css::lang::XMultiServiceFactory
>&);
134 void startTableListening();
135 void stopTableListening();
136 virtual void impl_initialize() override
;
139 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */