1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef DBUI_TABLECONTROLLER_HXX 28 #define DBUI_TABLECONTROLLER_HXX 29 30 #include "singledoccontroller.hxx" 31 #include "moduledbu.hxx" 32 #include <com/sun/star/sdbc/XConnection.hpp> 33 #include <com/sun/star/beans/XPropertySet.hpp> 34 #include <com/sun/star/io/XObjectOutputStream.hpp> 35 #include <com/sun/star/io/XObjectInputStream.hpp> 36 #include "TypeInfo.hxx" 37 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 38 #include <com/sun/star/sdbcx/XKeysSupplier.hpp> 39 #include <com/sun/star/container/XNameAccess.hpp> 40 41 class FixedText; 42 namespace dbaui 43 { 44 class OTableRow; 45 class OFieldDescription; 46 typedef OSingleDocumentController OTableController_BASE; 47 class OTableController : public OTableController_BASE 48 { 49 private: 50 OModuleClient m_aModuleClient; 51 ::std::vector< ::boost::shared_ptr<OTableRow> > m_vRowList; 52 OTypeInfoMap m_aTypeInfo; 53 ::std::vector<OTypeInfoMap::iterator> m_aTypeInfoIndex; 54 55 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; 56 57 ::rtl::OUString m_sCatalogName; // catalog for update data 58 ::rtl::OUString m_sSchemaName; // schema for update data 59 ::rtl::OUString m_sName; // table for update data 60 ::rtl::OUString m_sAutoIncrementValue; // the autoincrement value set in the datasource 61 String m_sTypeNames; // these type names are the ones out of the resource file 62 TOTypeInfoSP m_pTypeInfo; // fall back when type is unkown because database driver has a failure 63 64 sal_Bool m_bAllowAutoIncrementValue; // no : 1 NO BIT , is true when the datasource has a AutoIncrementValue property in their info property 65 sal_Bool m_bNew : 1; // is true when we create a new table 66 67 68 void reSyncRows(); 69 void assignTable(); // set the table if a name is given 70 void loadData(); 71 sal_Bool checkColumns(sal_Bool _bNew) throw(::com::sun::star::sdbc::SQLException); // check if we have double column names 72 String createUniqueName(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& _rxTables,const String& _rDefault); 73 void appendColumns(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>& _rxColSup,sal_Bool _bNew,sal_Bool _bKeyColumns = sal_False); 74 void appendPrimaryKey(::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XKeysSupplier>& _rxSup,sal_Bool _bNew); 75 void alterColumns(); 76 void dropPrimaryKey(); 77 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> getKeyColumns() const; 78 ::rtl::OUString createUniqueName(const ::rtl::OUString& _rName); 79 80 void reload(); 81 82 // all the features which should be handled by this class 83 virtual void describeSupportedFeatures(); 84 // 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. 85 virtual FeatureState GetState(sal_uInt16 nId) const; 86 // execute a feature 87 virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); 88 89 virtual void losingConnection( ); 90 91 virtual ::rtl::OUString getPrivateTitle( ) const; 92 93 void doEditIndexes(); 94 sal_Bool doSaveDoc(sal_Bool _bSaveAs); 95 96 virtual ~OTableController(); 97 public: 98 OTableController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); 99 100 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getTable() { return m_xTable;} 101 102 sal_Bool isAddAllowed() const; 103 sal_Bool isDropAllowed() const; 104 sal_Bool isAlterAllowed() const; 105 bool isAutoIncrementPrimaryKey() const; 106 107 inline sal_Bool isAutoIncrementValueEnabled() const { return m_bAllowAutoIncrementValue; } 108 inline const ::rtl::OUString& getAutoIncrementValue() const { return m_sAutoIncrementValue; } 109 110 virtual void impl_onModifyChanged(); 111 112 inline ::std::vector< ::boost::shared_ptr<OTableRow> >* getRows() { return &m_vRowList; } 113 114 /// returns the postion of the the first empty row 115 sal_Int32 getFirstEmptyRowPosition(); 116 117 inline const OTypeInfoMap* getTypeInfo() const { return &m_aTypeInfo; } 118 119 inline TOTypeInfoSP getTypeInfo(sal_Int32 _nPos) const { return m_aTypeInfoIndex[_nPos]->second; } 120 TOTypeInfoSP getTypeInfoByType(sal_Int32 _nDataType) const; 121 122 inline TOTypeInfoSP getTypeInfoFallBack() const { return m_pTypeInfo; } 123 124 virtual sal_Bool Construct(Window* pParent); 125 // XEventListener 126 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 127 128 // ::com::sun::star::frame::XController 129 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ); 130 131 // ::com::sun::star::lang::XComponent 132 virtual void SAL_CALL disposing(); 133 134 // XServiceInfo 135 virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); 136 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); 137 // need by registration 138 static ::rtl::OUString getImplementationName_Static() throw( ::com::sun::star::uno::RuntimeException ); 139 static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void) throw( ::com::sun::star::uno::RuntimeException ); 140 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 141 SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); 142 143 // 144 virtual void Load(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxIn); 145 virtual void Save(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOut); 146 147 protected: 148 void startTableListening(); 149 void stopTableListening(); 150 virtual void impl_initialize(); 151 }; 152 } 153 #endif // DBUI_TABLECONTROLLER_HXX 154 155 156