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 .
21 #include "singledoccontroller.hxx"
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include "TypeInfo.hxx"
24 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25 #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
31 typedef OSingleDocumentController OTableController_BASE
;
32 class OTableController final
: public OTableController_BASE
35 std::vector
< std::shared_ptr
<OTableRow
> > m_vRowList
;
36 OTypeInfoMap m_aTypeInfo
;
37 std::vector
<OTypeInfoMap::iterator
> m_aTypeInfoIndex
;
39 css::uno::Reference
< css::beans::XPropertySet
> m_xTable
;
41 OUString m_sName
; // table for update data
42 OUString m_sAutoIncrementValue
; // the autoincrement value set in the datasource
43 OUString m_sTypeNames
; // these type names are the ones out of the resource file
44 TOTypeInfoSP m_pTypeInfo
; // fall back when type is unknown because database driver has a failure
46 bool m_bAllowAutoIncrementValue
; // no : 1 NO BIT , is true when the datasource has an AutoIncrementValue property in their info property
47 bool m_bNew
: 1; // is true when we create a new table
51 void assignTable(); // set the table if a name is given
53 /// @throws css::sdbc::SQLException
54 /// @throws css::uno::RuntimeException
55 bool checkColumns(bool _bNew
); // check if we have double column names
56 void appendColumns(css::uno::Reference
< css::sdbcx::XColumnsSupplier
> const & _rxColSup
, bool _bNew
, bool _bKeyColumns
= false);
57 void appendPrimaryKey(css::uno::Reference
< css::sdbcx::XKeysSupplier
> const & _rxSup
, bool _bNew
);
59 void dropPrimaryKey();
60 css::uno::Reference
< css::container::XNameAccess
> getKeyColumns() const;
61 OUString
createUniqueName(const OUString
& _rName
);
65 // all the features which should be handled by this class
66 virtual void describeSupportedFeatures() override
;
67 // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot.
68 virtual FeatureState
GetState(sal_uInt16 nId
) const override
;
70 virtual void Execute(sal_uInt16 nId
, const css::uno::Sequence
< css::beans::PropertyValue
>& aArgs
) override
;
72 virtual void losingConnection( ) override
;
74 virtual OUString
getPrivateTitle( ) const override
;
77 bool doSaveDoc(bool _bSaveAs
);
79 virtual ~OTableController() override
;
81 OTableController(const css::uno::Reference
< css::uno::XComponentContext
>& _rM
);
83 const css::uno::Reference
< css::beans::XPropertySet
>& getTable() const { return m_xTable
;}
85 bool isAddAllowed() const;
86 bool isDropAllowed() const;
87 bool isAlterAllowed() const;
88 bool isAutoIncrementPrimaryKey() const;
90 bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue
; }
91 const OUString
& getAutoIncrementValue() const { return m_sAutoIncrementValue
; }
93 virtual void impl_onModifyChanged() override
;
95 std::vector
< std::shared_ptr
<OTableRow
> >& getRows() { return m_vRowList
; }
97 /// returns the position of the first empty row
98 sal_Int32
getFirstEmptyRowPosition();
100 const OTypeInfoMap
& getTypeInfo() const { return m_aTypeInfo
; }
102 TOTypeInfoSP
const & getTypeInfo(sal_Int32 _nPos
) const { return m_aTypeInfoIndex
[_nPos
]->second
; }
103 TOTypeInfoSP
getTypeInfoByType(sal_Int32 _nDataType
) const;
105 const TOTypeInfoSP
& getTypeInfoFallBack() const { return m_pTypeInfo
; }
107 virtual bool Construct(vcl::Window
* pParent
) override
;
109 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
111 // css::frame::XController
112 virtual sal_Bool SAL_CALL
suspend(sal_Bool bSuspend
) override
;
114 // css::lang::XComponent
115 virtual void SAL_CALL
disposing() override
;
118 virtual OUString SAL_CALL
getImplementationName() override
;
119 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
122 void startTableListening();
123 void stopTableListening();
124 virtual void impl_initialize(const ::comphelper::NamedValueCollection
& rArguments
) override
;
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */