1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef DBUI_TABLECONTROLLER_HXX 24 #define DBUI_TABLECONTROLLER_HXX 25 26 #include "singledoccontroller.hxx" 27 #include "moduledbu.hxx" 28 #include <com/sun/star/sdbc/XConnection.hpp> 29 #include <com/sun/star/beans/XPropertySet.hpp> 30 #include <com/sun/star/io/XObjectOutputStream.hpp> 31 #include <com/sun/star/io/XObjectInputStream.hpp> 32 #include "TypeInfo.hxx" 33 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 34 #include <com/sun/star/sdbcx/XKeysSupplier.hpp> 35 #include <com/sun/star/container/XNameAccess.hpp> 36 37 class FixedText; 38 namespace dbaui 39 { 40 class OTableRow; 41 class OFieldDescription; 42 typedef OSingleDocumentController OTableController_BASE; 43 class OTableController : public OTableController_BASE 44 { 45 private: 46 OModuleClient m_aModuleClient; 47 ::std::vector< ::boost::shared_ptr<OTableRow> > m_vRowList; 48 OTypeInfoMap m_aTypeInfo; 49 ::std::vector<OTypeInfoMap::iterator> m_aTypeInfoIndex; 50 51 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; 52 53 ::rtl::OUString m_sCatalogName; // catalog for update data 54 ::rtl::OUString m_sSchemaName; // schema for update data 55 ::rtl::OUString m_sName; // table for update data 56 ::rtl::OUString m_sAutoIncrementValue; // the autoincrement value set in the datasource 57 String m_sTypeNames; // these type names are the ones out of the resource file 58 TOTypeInfoSP m_pTypeInfo; // fall back when type is unknown because database driver has a failure 59 60 sal_Bool m_bAllowAutoIncrementValue; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property 61 sal_Bool m_bNew : 1; // is true when we create a new table 62 63 64 void reSyncRows(); 65 void assignTable(); // set the table if a name is given 66 void loadData(); 67 sal_Bool checkColumns(sal_Bool _bNew) throw(::com::sun::star::sdbc::SQLException); // check if we have double column names 68 String createUniqueName(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _rxTables,const String& _rDefault); 69 void appendColumns(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& _rxColSup,sal_Bool _bNew,sal_Bool _bKeyColumns = sal_False); 70 void appendPrimaryKey(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XKeysSupplier>& _rxSup,sal_Bool _bNew); 71 void alterColumns(); 72 void dropPrimaryKey(); 73 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getKeyColumns() const; 74 ::rtl::OUString createUniqueName(const ::rtl::OUString& _rName); 75 76 void reload(); 77 78 // all the features which should be handled by this class 79 virtual void describeSupportedFeatures(); 80 // 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. 81 virtual FeatureState GetState(sal_uInt16 nId) const; 82 // execute a feature 83 virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); 84 85 virtual void losingConnection( ); 86 87 virtual ::rtl::OUString getPrivateTitle( ) const; 88 89 void doEditIndexes(); 90 sal_Bool doSaveDoc(sal_Bool _bSaveAs); 91 92 virtual ~OTableController(); 93 public: 94 OTableController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); 95 96 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getTable() { return m_xTable;} 97 98 sal_Bool isAddAllowed() const; 99 sal_Bool isDropAllowed() const; 100 sal_Bool isAlterAllowed() const; 101 bool isAutoIncrementPrimaryKey() const; 102 103 inline sal_Bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue; } 104 inline const ::rtl::OUString& getAutoIncrementValue() const { return m_sAutoIncrementValue; } 105 106 virtual void impl_onModifyChanged(); 107 108 inline ::std::vector< ::boost::shared_ptr<OTableRow> >* getRows() { return &m_vRowList; } 109 110 /// returns the position of the the first empty row 111 sal_Int32 getFirstEmptyRowPosition(); 112 113 inline const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo; } 114 115 inline TOTypeInfoSP getTypeInfo(sal_Int32 _nPos) const { return m_aTypeInfoIndex[_nPos]->second; } 116 TOTypeInfoSP getTypeInfoByType(sal_Int32 _nDataType) const; 117 118 inline TOTypeInfoSP getTypeInfoFallBack() const { return m_pTypeInfo; } 119 120 virtual sal_Bool Construct(Window* pParent); 121 // XEventListener 122 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 123 124 // ::com::sun::star::frame::XController 125 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ); 126 127 // ::com::sun::star::lang::XComponent 128 virtual void SAL_CALL disposing(); 129 130 // XServiceInfo 131 virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); 132 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); 133 // need by registration 134 static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException ); 135 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException ); 136 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 137 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 138 139 // 140 virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn); 141 virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut); 142 143 protected: 144 void startTableListening(); 145 void stopTableListening(); 146 virtual void impl_initialize(); 147 }; 148 } 149 #endif // DBUI_TABLECONTROLLER_HXX 150 151 152