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 /// @throws css::sdbc::SQLException
61 /// @throws css::uno::RuntimeException
62 bool checkColumns(bool _bNew
)
63 throw (css::sdbc::SQLException
,
64 css::uno::RuntimeException
, std::exception
); // check if we have double column names
65 void appendColumns(css::uno::Reference
< css::sdbcx::XColumnsSupplier
>& _rxColSup
, bool _bNew
, bool _bKeyColumns
= false);
66 void appendPrimaryKey(css::uno::Reference
< css::sdbcx::XKeysSupplier
>& _rxSup
, bool _bNew
);
68 void dropPrimaryKey();
69 css::uno::Reference
< css::container::XNameAccess
> getKeyColumns() const;
70 OUString
createUniqueName(const OUString
& _rName
);
74 // all the features which should be handled by this class
75 virtual void describeSupportedFeatures() override
;
76 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
77 virtual FeatureState
GetState(sal_uInt16 nId
) const override
;
79 virtual void Execute(sal_uInt16 nId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
81 virtual void losingConnection( ) override
;
83 virtual OUString
getPrivateTitle( ) const override
;
86 bool doSaveDoc(bool _bSaveAs
);
88 virtual ~OTableController() override
;
90 OTableController(const css::uno::Reference
< css::uno::XComponentContext
>& _rM
);
92 const css::uno::Reference
< css::beans::XPropertySet
>& getTable() { return m_xTable
;}
94 bool isAddAllowed() const;
95 bool isDropAllowed() const;
96 bool isAlterAllowed() const;
97 bool isAutoIncrementPrimaryKey() const;
99 inline bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue
; }
100 inline const OUString
& getAutoIncrementValue() const { return m_sAutoIncrementValue
; }
102 virtual void impl_onModifyChanged() override
;
104 inline ::std::vector
< std::shared_ptr
<OTableRow
> >& getRows() { return m_vRowList
; }
106 /// returns the position of the first empty row
107 sal_Int32
getFirstEmptyRowPosition();
109 inline const OTypeInfoMap
& getTypeInfo() const { return m_aTypeInfo
; }
111 inline TOTypeInfoSP
getTypeInfo(sal_Int32 _nPos
) const { return m_aTypeInfoIndex
[_nPos
]->second
; }
112 TOTypeInfoSP
getTypeInfoByType(sal_Int32 _nDataType
) const;
114 const TOTypeInfoSP
& getTypeInfoFallBack() const { return m_pTypeInfo
; }
116 virtual bool Construct(vcl::Window
* pParent
) override
;
118 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw(css::uno::RuntimeException
, std::exception
) override
;
120 // css::frame::XController
121 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) throw( css::uno::RuntimeException
, std::exception
) override
;
123 // css::lang::XComponent
124 virtual void SAL_CALL
disposing() override
;
127 virtual OUString SAL_CALL
getImplementationName() throw(css::uno::RuntimeException
, std::exception
) override
;
128 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(css::uno::RuntimeException
, std::exception
) override
;
129 // need by registration
130 /// @throws css::uno::RuntimeException
131 static OUString
getImplementationName_Static() throw( css::uno::RuntimeException
);
132 /// @throws css::uno::RuntimeException
133 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static() throw( css::uno::RuntimeException
);
134 static css::uno::Reference
< css::uno::XInterface
>
135 SAL_CALL
Create(const css::uno::Reference
< css::lang::XMultiServiceFactory
>&);
138 void startTableListening();
139 void stopTableListening();
140 virtual void impl_initialize() override
;
143 #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */