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 24 #ifndef _SBA_BWRCTRLR_HXX 25 #define _SBA_BWRCTRLR_HXX 26 27 #include "genericcontroller.hxx" 28 #include "moduledbu.hxx" 29 #include "brwview.hxx" 30 #include "sbagrid.hxx" 31 32 /** === begin UNO includes === **/ 33 #include <com/sun/star/form/XLoadable.hpp> 34 #include <com/sun/star/container/XContainerListener.hpp> 35 #include <com/sun/star/sdb/XSQLErrorListener.hpp> 36 #include <com/sun/star/sdbc/XRowSet.hpp> 37 #include <com/sun/star/form/XResetListener.hpp> 38 #include <com/sun/star/form/XDatabaseParameterListener.hpp> 39 #include <com/sun/star/form/XConfirmDeleteListener.hpp> 40 #include <com/sun/star/form/XFormComponent.hpp> 41 #include <com/sun/star/awt/XFocusListener.hpp> 42 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> 43 #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp> 44 #include <com/sun/star/beans/XPropertyChangeListener.hpp> 45 #include <com/sun/star/frame/XModule.hpp> 46 /** === end UNO includes === **/ 47 48 #include <vcl/timer.hxx> 49 #include <svtools/transfer.hxx> 50 #include <osl/mutex.hxx> 51 #include <vos/thread.hxx> 52 #include <cppuhelper/implbase9.hxx> 53 #include <svtools/cliplistener.hxx> 54 55 class ResMgr; 56 struct FmFoundRecordInformation; 57 struct FmSearchContext; 58 59 namespace dbtools 60 { 61 class SQLExceptionInfo; 62 } 63 64 namespace dbaui 65 { 66 // ========================================================================= 67 68 typedef ::cppu::ImplInheritanceHelper9 < OGenericUnoController 69 , ::com::sun::star::sdb::XSQLErrorListener 70 , ::com::sun::star::form::XDatabaseParameterListener 71 , ::com::sun::star::form::XConfirmDeleteListener 72 , ::com::sun::star::form::XLoadListener 73 , ::com::sun::star::form::XResetListener 74 , ::com::sun::star::awt::XFocusListener 75 , ::com::sun::star::container::XContainerListener 76 , ::com::sun::star::beans::XPropertyChangeListener 77 , ::com::sun::star::frame::XModule 78 > SbaXDataBrowserController_Base; 79 80 class SbaXDataBrowserController :public SbaXDataBrowserController_Base 81 ,public SbaGridListener 82 { 83 // ========== 84 // attributes 85 private: 86 // for implementing the XFormController 87 class FormControllerImpl; 88 friend class FormControllerImpl; 89 OModuleClient m_aModuleClient; 90 91 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > m_xRowSet; // our rowset 92 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > m_xColumnsSupplier; // queried from the rowset member 93 ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > m_xLoadable; // queried from the rowset member as well 94 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > m_xGridModel; // the model of our grid 95 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; // a number formatter working with the connection's NumberFormatsSupplier 96 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xFormControllerImpl; 97 mutable ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer > 98 m_xParser; // for sorting 'n filtering 99 100 sal_Int32 m_nRowSetPrivileges; // cached Privileges property of m_xRowSet 101 102 AutoTimer m_aInvalidateClipboard; // for testing the state of the CUT/COPY/PASTE-slots 103 104 TransferableDataHelper m_aSystemClipboard; // content of the clipboard 105 TransferableClipboardListener* 106 m_pClipbordNotifier; // notifier for changes in the clipboard 107 108 ::osl::Mutex m_aAsyncLoadSafety; // for multi-thread access to our members 109 110 OAsyncronousLink m_aAsyncGetCellFocus; 111 OAsyncronousLink m_aAsyncDisplayError; 112 ::dbtools::SQLExceptionInfo m_aCurrentError; 113 114 String m_sStateSaveRecord; 115 String m_sStateUndoRecord; 116 ::rtl::OUString m_sModuleIdentifier; 117 118 // members for asynchronous load operations 119 FormControllerImpl* m_pFormControllerImpl; // implementing the XFormController 120 121 sal_uLong m_nPendingLoadFinished; // the event used to tell ourself that the load is finished 122 sal_uInt16 m_nFormActionNestingLevel; // see enter-/leaveFormAction 123 124 sal_Bool m_bLoadCanceled : 1; // the load was canceled somehow 125 sal_Bool m_bClosingKillOpen : 1; // are we killing the load thread because we are to be suspended ? 126 bool m_bCannotSelectUnfiltered : 1; // recieved an DATA_CANNOT_SELECT_UNFILTERED error 127 128 protected: 129 class FormErrorHelper 130 { 131 SbaXDataBrowserController* m_pOwner; 132 public: 133 FormErrorHelper(SbaXDataBrowserController* pOwner) : m_pOwner(pOwner) { m_pOwner->enterFormAction(); } 134 virtual ~FormErrorHelper() { m_pOwner->leaveFormAction(); } 135 }; 136 friend class FormErrorHelper; 137 138 // ================ 139 // attribute access 140 protected: 141 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > getRowSet() const { return m_xRowSet; } 142 ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier > getColumnsSupplier()const { return m_xColumnsSupplier; } 143 ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable > getLoadable() const { return m_xLoadable; } 144 145 ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > getFormComponent() const { return m_xGridModel; } 146 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > getControlModel() const { return ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > (m_xGridModel, ::com::sun::star::uno::UNO_QUERY); } 147 ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > getNumberFormatter()const { return m_xFormatter; } 148 149 sal_Bool isValid() const { return m_xRowSet.is() && m_xGridModel.is(); } 150 sal_Bool isValidCursor() const; // checks the ::com::sun::star::data::XDatabaseCursor-interface of m_xRowSet 151 sal_Bool isLoaded() const; 152 sal_Bool loadingCancelled() const { return m_bLoadCanceled; } 153 void onStartLoading( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable ); 154 void setLoadingCancelled() { m_bLoadCanceled = sal_True; } 155 156 const TransferableDataHelper& 157 getViewClipboard() const { return m_aSystemClipboard; } 158 159 public: 160 SbaXDataBrowserController(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM); 161 162 UnoDataBrowserView* getBrowserView() const { return static_cast< UnoDataBrowserView*>(getView()); } 163 // late construction 164 virtual sal_Bool Construct(Window* pParent); 165 166 // UNO 167 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException); 168 169 // XTypeProvider 170 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); 171 virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) throw (::com::sun::star::uno::RuntimeException); 172 173 // ::com::sun::star::lang::XEventListener 174 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException ); 175 176 // ::com::sun::star::util::XModifyListener 177 virtual void SAL_CALL modified(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 178 179 // ::com::sun::star::container::XContainerListener 180 virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException ); 181 virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException ); 182 virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& Event) throw( ::com::sun::star::uno::RuntimeException ); 183 184 // XPropertyChangeListener 185 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw (::com::sun::star::uno::RuntimeException); 186 187 // XModule 188 virtual void SAL_CALL setIdentifier( const ::rtl::OUString& Identifier ) throw (::com::sun::star::uno::RuntimeException); 189 virtual ::rtl::OUString SAL_CALL getIdentifier( ) throw (::com::sun::star::uno::RuntimeException); 190 191 // ::com::sun::star::awt::XFocusListener 192 virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException ); 193 virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& e) throw( ::com::sun::star::uno::RuntimeException ); 194 195 // ::com::sun::star::frame::XController 196 virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) throw( ::com::sun::star::uno::RuntimeException ); 197 198 // ::com::sun::star::lang::XComponent 199 virtual void SAL_CALL disposing(); 200 201 // ::com::sun::star::frame::XFrameActionListener 202 virtual void SAL_CALL frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 203 204 // ::com::sun::star::sdb::XSQLErrorListener 205 virtual void SAL_CALL errorOccured(const ::com::sun::star::sdb::SQLErrorEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 206 207 // ::com::sun::star::form::XDatabaseParameterListener 208 virtual sal_Bool SAL_CALL approveParameter(const ::com::sun::star::form::DatabaseParameterEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 209 210 // ::com::sun::star::form::XConfirmDeleteListener 211 virtual sal_Bool SAL_CALL confirmDelete(const ::com::sun::star::sdb::RowChangeEvent& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 212 213 // ::com::sun::star::form::XLoadListener 214 virtual void SAL_CALL loaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 215 virtual void SAL_CALL unloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 216 virtual void SAL_CALL unloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 217 virtual void SAL_CALL reloading(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 218 virtual void SAL_CALL reloaded(const ::com::sun::star::lang::EventObject& aEvent) throw( ::com::sun::star::uno::RuntimeException ); 219 220 // ::com::sun::star::form::XResetListener 221 virtual sal_Bool SAL_CALL approveReset(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException ); 222 virtual void SAL_CALL resetted(const ::com::sun::star::lang::EventObject& rEvent) throw( ::com::sun::star::uno::RuntimeException ); 223 224 // SbaGridListener 225 virtual void RowChanged(); 226 virtual void ColumnChanged(); 227 virtual void SelectionChanged(); 228 virtual void CellActivated(); 229 virtual void CellDeactivated(); 230 virtual void BeforeDrop(); 231 virtual void AfterDrop(); 232 233 public: 234 235 protected: 236 virtual ~SbaXDataBrowserController(); 237 238 // all the features which should be handled by this class 239 virtual void describeSupportedFeatures(); 240 // 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. 241 virtual FeatureState GetState(sal_uInt16 nId) const; 242 // execute a feature 243 virtual void Execute(sal_uInt16 nId, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& aArgs); 244 245 virtual void startFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ); 246 virtual void stopFrameListening( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ); 247 248 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet > CreateForm(); 249 // our default implementation simply instantiates a stardiv.one.form.component.Form service 250 // (probably this needs not to be overloaded, but you may return anything you want as long as it 251 // supports the ::com::sun::star::form::DatabaseForm service. For instance you may want to create an adapter here which 252 // is synchronized with a foreign ::com::sun::star::form::DatabaseForm you got elsewhere) 253 virtual sal_Bool InitializeForm( 254 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& i_formProperties ) = 0; 255 // called immediately after a successfull CreateForm 256 // do any initialization (data source etc.) here. the form should be fully functional after that. 257 // return sal_False if you didn't succeed (don't throw exceptions, they won't be caught) 258 259 virtual sal_Bool InitializeGridModel(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > & xGrid); 260 261 262 virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > CreateGridModel(); 263 // our default implementation simply instantiates a stardiv.one.form.component.Grid service 264 // you most probably don't want to override this behaviuor 265 266 // the default implementation of disposing distributes the events to the following disposingXXX functions 267 virtual void disposingGridControl(const ::com::sun::star::lang::EventObject& Source); // calls removeControlListeners 268 virtual void disposingGridModel(const ::com::sun::star::lang::EventObject& Source); // calls removeModelListeners 269 virtual void disposingFormModel(const ::com::sun::star::lang::EventObject& Source); 270 virtual void disposingColumnModel(const ::com::sun::star::lang::EventObject& Source); 271 272 // want to be a listener to the grid control ? use this ! 273 virtual void addControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl); 274 virtual void removeControlListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > & _xGridControl); 275 276 // want to be a listener to the grid model ? use this ! 277 virtual void addModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel); 278 virtual void removeModelListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel); 279 280 // want to be a listener grid columns ? use this ! 281 virtual void AddColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol); 282 virtual void RemoveColumnListener(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xCol); 283 284 285 // call after "major changes" (e.g. the completion of the async load). 286 // invalidates all toolbox slots and all supported features. 287 288 virtual sal_Bool LoadForm(); 289 // load the form 290 // the default implementation does an direct load or starts a load thread, depending on the multithread capabilities 291 // of the data source. 292 // the default implementation also calls LoadFinished after a syncronous load, so be sure to do the same if you override 293 // this metod and don't call the base class' method 294 295 virtual void LoadFinished(sal_Bool bWasSynch); 296 // called if the loading (the _complete_ loading process) is done (no matter if synchron or asynchron). 297 298 virtual void criticalFail(); 299 // called whenever a reload operation on the rowset failed 300 // (a "operation" is not only a simple reload: If the user sets a filter, an reloading the form 301 // after setting this filter fails, the filter is reset and the form is reloaded, again. Only the 302 // whole process (_both_ XLoadable::reload calls _together_) form the "reload operation" 303 304 // -------------------- 305 306 // empty the frame where our view resides 307 virtual sal_Bool CommitCurrent(); 308 // commit the current column (i.e. cell) 309 virtual sal_Bool SaveModified(sal_Bool bAskFor = sal_True); 310 // save the modified record 311 312 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > getBoundField(sal_uInt16 nViewPos = (sal_uInt16)-1) const; 313 // a PropertySet corresponding to the cursor field a column is bound to 314 // if nViewPos is (sal_uInt16)-1 (the default) then the field for the current column will be retrieved 315 316 void enterFormAction(); 317 void leaveFormAction(); 318 319 // init the formatter if form changes 320 void initFormatter(); 321 322 /// loads or reloads the form 323 virtual sal_Bool reloadForm(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XLoadable >& _rxLoadable); 324 325 virtual sal_Bool preReloadForm(){ return sal_False; } 326 virtual void postReloadForm(){} 327 328 ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer > 329 createParser_nothrow(); 330 331 private: 332 void setCurrentModified( sal_Bool _bSet ); 333 334 // execute the filter or sort slot 335 void ExecuteFilterSortCrit(sal_Bool bFilter); 336 337 // execute the search slot 338 void ExecuteSearch(); 339 340 void initializeParser() const; // changes the mutable member m_xParser 341 void applyParserFilter(const ::rtl::OUString& _rOldFilter, sal_Bool _bOldFilterApplied,const ::rtl::OUString& _sOldHaving,const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >& _xParser); 342 void applyParserOrder(const ::rtl::OUString& _rOldOrder,const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer >& _xParser); 343 344 sal_Int16 getCurrentColumnPosition(); 345 void setCurrentColumnPosition( sal_Int16 _nPos ); 346 void addColumnListeners(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > & _xGridControlModel); 347 348 void impl_checkForCannotSelectUnfiltered( const ::dbtools::SQLExceptionInfo& _rError ); 349 350 // time to check the CUT/COPY/PASTE-slot-states 351 DECL_LINK( OnInvalidateClipboard, AutoTimer* ); 352 DECL_LINK( OnClipboardChanged, void* ); 353 354 // search callbacks 355 DECL_LINK(OnSearchContextRequest, FmSearchContext*); 356 DECL_LINK(OnFoundData, FmFoundRecordInformation*); 357 DECL_LINK(OnCanceledNotFound, FmFoundRecordInformation*); 358 359 DECL_LINK(OnAsyncGetCellFocus, void*); 360 361 DECL_LINK( OnAsyncDisplayError, void* ); 362 }; 363 } 364 365 #endif // _SBA_BWRCTRLR_HXX 366 367