Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
20 : #define INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
21 :
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 "TypeInfo.hxx"
29 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
30 : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
31 : #include <com/sun/star/container/XNameAccess.hpp>
32 :
33 : namespace dbaui
34 : {
35 : class OTableRow;
36 : typedef OSingleDocumentController OTableController_BASE;
37 : class OTableController : public OTableController_BASE
38 : {
39 : private:
40 : OModuleClient m_aModuleClient;
41 : ::std::vector< ::boost::shared_ptr<OTableRow> > m_vRowList;
42 : OTypeInfoMap m_aTypeInfo;
43 : ::std::vector<OTypeInfoMap::iterator> m_aTypeInfoIndex;
44 :
45 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable;
46 :
47 : OUString m_sCatalogName; // catalog for update data
48 : OUString m_sSchemaName; // schema for update data
49 : OUString m_sName; // table for update data
50 : OUString m_sAutoIncrementValue; // the autoincrement value set in the datasource
51 : OUString m_sTypeNames; // these type names are the ones out of the resource file
52 : TOTypeInfoSP m_pTypeInfo; // fall back when type is unknown because database driver has a failure
53 :
54 : bool m_bAllowAutoIncrementValue; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property
55 : bool m_bNew : 1; // is true when we create a new table
56 :
57 :
58 : void reSyncRows();
59 : void assignTable(); // set the table if a name is given
60 : void loadData();
61 : bool checkColumns(bool _bNew)
62 : throw (css::sdbc::SQLException,
63 : css::uno::RuntimeException, std::exception); // check if we have double column names
64 : OUString createUniqueName(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _rxTables,const OUString& _rDefault);
65 : void appendColumns(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& _rxColSup, bool _bNew, bool _bKeyColumns = false);
66 : void appendPrimaryKey(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XKeysSupplier>& _rxSup, bool _bNew);
67 : void alterColumns();
68 : void dropPrimaryKey();
69 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getKeyColumns() const;
70 : OUString createUniqueName(const OUString& _rName);
71 :
72 : void reload();
73 :
74 : // all the features which should be handled by this class
75 : virtual void describeSupportedFeatures() SAL_OVERRIDE;
76 : // 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.
77 : virtual FeatureState GetState(sal_uInt16 nId) const SAL_OVERRIDE;
78 : // execute a feature
79 : virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs) SAL_OVERRIDE;
80 :
81 : virtual void losingConnection( ) SAL_OVERRIDE;
82 :
83 : virtual OUString getPrivateTitle( ) const SAL_OVERRIDE;
84 :
85 : void doEditIndexes();
86 : bool doSaveDoc(bool _bSaveAs);
87 :
88 : virtual ~OTableController();
89 : public:
90 : OTableController(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rM);
91 :
92 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getTable() { return m_xTable;}
93 :
94 : bool isAddAllowed() const;
95 : bool isDropAllowed() const;
96 : bool isAlterAllowed() const;
97 : bool isAutoIncrementPrimaryKey() const;
98 :
99 0 : inline bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue; }
100 0 : inline const OUString& getAutoIncrementValue() const { return m_sAutoIncrementValue; }
101 :
102 : virtual void impl_onModifyChanged() SAL_OVERRIDE;
103 :
104 0 : inline ::std::vector< ::boost::shared_ptr<OTableRow> >& getRows() { return m_vRowList; }
105 :
106 : /// returns the position of the first empty row
107 : sal_Int32 getFirstEmptyRowPosition();
108 :
109 0 : inline const OTypeInfoMap& getTypeInfo() const { return m_aTypeInfo; }
110 :
111 0 : inline TOTypeInfoSP getTypeInfo(sal_Int32 _nPos) const { return m_aTypeInfoIndex[_nPos]->second; }
112 : TOTypeInfoSP getTypeInfoByType(sal_Int32 _nDataType) const;
113 :
114 0 : inline TOTypeInfoSP getTypeInfoFallBack() const { return m_pTypeInfo; }
115 :
116 : virtual bool Construct(vcl::Window* pParent) SAL_OVERRIDE;
117 : // XEventListener
118 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
119 :
120 : // ::com::sun::star::frame::XController
121 : virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
122 :
123 : // ::com::sun::star::lang::XComponent
124 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
125 :
126 : // XServiceInfo
127 : virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
128 : virtual ::com::sun::star::uno::Sequence< OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 : // need by registration
130 : static OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
131 : static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
132 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
133 : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
134 :
135 :
136 : virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn);
137 : virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut);
138 :
139 : protected:
140 : void startTableListening();
141 : void stopTableListening();
142 : virtual void impl_initialize() SAL_OVERRIDE;
143 : };
144 : }
145 : #endif // INCLUDED_DBACCESS_SOURCE_UI_INC_TABLECONTROLLER_HXX
146 :
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|