Branch data 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 DBUI_TABLECONTROLLER_HXX
20 : : #define DBUI_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 : : ::rtl::OUString m_sCatalogName; // catalog for update data
48 : : ::rtl::OUString m_sSchemaName; // schema for update data
49 : : ::rtl::OUString m_sName; // table for update data
50 : : ::rtl::OUString m_sAutoIncrementValue; // the autoincrement value set in the datasource
51 : : String m_sTypeNames; // these type names are the ones out of the resource file
52 : : TOTypeInfoSP m_pTypeInfo; // fall back when type is unkown because database driver has a failure
53 : :
54 : : sal_Bool m_bAllowAutoIncrementValue; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property
55 : : sal_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 : : sal_Bool checkColumns(sal_Bool _bNew) throw(::com::sun::star::sdbc::SQLException); // check if we have double column names
62 : : String createUniqueName(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _rxTables,const String& _rDefault);
63 : : void appendColumns(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& _rxColSup,sal_Bool _bNew,sal_Bool _bKeyColumns = sal_False);
64 : : void appendPrimaryKey(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XKeysSupplier>& _rxSup,sal_Bool _bNew);
65 : : void alterColumns();
66 : : void dropPrimaryKey();
67 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getKeyColumns() const;
68 : : ::rtl::OUString createUniqueName(const ::rtl::OUString& _rName);
69 : :
70 : : void reload();
71 : :
72 : : // all the features which should be handled by this class
73 : : virtual void describeSupportedFeatures();
74 : : // 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.
75 : : virtual FeatureState GetState(sal_uInt16 nId) const;
76 : : // execute a feature
77 : : virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs);
78 : :
79 : : virtual void losingConnection( );
80 : :
81 : : virtual ::rtl::OUString getPrivateTitle( ) const;
82 : :
83 : : void doEditIndexes();
84 : : sal_Bool doSaveDoc(sal_Bool _bSaveAs);
85 : :
86 : : virtual ~OTableController();
87 : : public:
88 : : OTableController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM);
89 : :
90 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getTable() { return m_xTable;}
91 : :
92 : : sal_Bool isAddAllowed() const;
93 : : sal_Bool isDropAllowed() const;
94 : : sal_Bool isAlterAllowed() const;
95 : : bool isAutoIncrementPrimaryKey() const;
96 : :
97 : 0 : inline sal_Bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue; }
98 : 0 : inline const ::rtl::OUString& getAutoIncrementValue() const { return m_sAutoIncrementValue; }
99 : :
100 : : virtual void impl_onModifyChanged();
101 : :
102 : 0 : inline ::std::vector< ::boost::shared_ptr<OTableRow> >* getRows() { return &m_vRowList; }
103 : :
104 : : /// returns the postion of the the first empty row
105 : : sal_Int32 getFirstEmptyRowPosition();
106 : :
107 : 0 : inline const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo; }
108 : :
109 : 0 : inline TOTypeInfoSP getTypeInfo(sal_Int32 _nPos) const { return m_aTypeInfoIndex[_nPos]->second; }
110 : : TOTypeInfoSP getTypeInfoByType(sal_Int32 _nDataType) const;
111 : :
112 : 0 : inline TOTypeInfoSP getTypeInfoFallBack() const { return m_pTypeInfo; }
113 : :
114 : : virtual sal_Bool Construct(Window* pParent);
115 : : // XEventListener
116 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
117 : :
118 : : // ::com::sun::star::frame::XController
119 : : virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException );
120 : :
121 : : // ::com::sun::star::lang::XComponent
122 : : virtual void SAL_CALL disposing();
123 : :
124 : : // XServiceInfo
125 : : virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
126 : : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
127 : : // need by registration
128 : : static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException );
129 : : static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException );
130 : : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
131 : : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
132 : :
133 : : //
134 : : virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn);
135 : : virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut);
136 : :
137 : : protected:
138 : : void startTableListening();
139 : : void stopTableListening();
140 : : virtual void impl_initialize();
141 : : };
142 : : }
143 : : #endif // DBUI_TABLECONTROLLER_HXX
144 : :
145 : :
146 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|